-
Notifications
You must be signed in to change notification settings - Fork 24
Description
Describe the bug
Layouts passed to stack()
and plot()
require all properties, rather than a partial.
To Reproduce
- npm install nodeplotlib (0.7.1 is what I tested), use typescript
- Call stack or plot with a layout object that doesn't have all properties. For example:
var layout: Layout = {
showlegend: false,
autosize: false,
width: 600,
height: 550,
margin: { t: 50 },
hovermode: 'closest',
bargap: 0,
xaxis: {
domain: [0, 0.85],
showgrid: false,
zeroline: false
},
yaxis: {
domain: [0, 0.85],
showgrid: false,
zeroline: false
},
xaxis2: {
domain: [0.85, 1],
showgrid: false,
zeroline: false
},
yaxis2: {
domain: [0.85, 1],
showgrid: false,
zeroline: false
}
};
- Observe type issues (error:
missing the following properties from Layout [..] and 67 more
), code won't compile. - You can type that Layout as a Partial Layout and then force cast it to
any
in your callplot(traces, layout as any);
and it generates graphs correctly, so it seems like the issue is that the type def is wrong rather than the implementation.
Expected behavior
Not to have to cast Partials to any to use library. It really just seems like a quick fix on the type defs for the methods, if you make the second parameter be a Partial<Layout>
instead of a Layout
. If this is actually intended behavior, then it would be great to note that this breaks the contracts for methods, so a direct upgrade from 0.6.x to 0.7.x requires some changes.
Additional context
In previous versions 0.6.5, it had the following definition:
models/plot.d.ts
import { Layout as PlotlyLayout, PlotData } from './plotly.js/index';
export declare type Plot = Partial<PlotData>;
export declare type Layout = Partial<PlotlyLayout>;
export interface IPlot {
data: Plot[];
layout?: Layout;
}
and
plot.d.ts
import { IPlot, IPlotsContainer } from './models/index';
import { Layout, Plot } from './models/index';
export declare let plots: IPlot[];
export declare const plotContainer: IPlotsContainer;
export declare function clear(): void;
export declare function stack(data: Plot[], layout?: Layout): void;
export declare function plot(data?: Plot[] | null, layout?: Layout): void;
You can see how this has changed in the current version 0.7.1:
models/plot.d.ts
import { Layout, PlotData } from 'plotly.js';
export declare type Plot = Partial<PlotData>;
export interface IPlot {
data: Plot[];
layout?: Partial<Layout>;
}
and
plot.d.ts
import { IPlot, IPlotsContainer } from './models/index';
import { Layout, Plot } from './models/index';
export declare let plots: IPlot[];
export declare const plotContainer: IPlotsContainer;
export declare function clear(): void;
export declare function stack(data: Plot[], layout?: Layout): void;
export declare function plot(data?: Plot[] | null, layout?: Layout): void;
Notice how the definition of Layout has changed from a Partial to not a partial in the high level calls to stack
and plot
.