Skip to content

Commit 044e900

Browse files
committed
Tighten up a few types
1 parent d8028ee commit 044e900

3 files changed

Lines changed: 46 additions & 30 deletions

File tree

src/types/core/api.d.ts

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ import type { Icon, Template } from './layout';
1919
export type Root = string | HTMLElement;
2020

2121
/**
22-
* Figure-shaped object accepted by `toImage`/`downloadImage` when called
23-
* without an attached graph div.
22+
* Figure-shaped object accepted by `newPlot` (in the `data` position) and
23+
* by `toImage`/`downloadImage` when called without an attached graph div.
2424
*/
2525
export interface PlotlyDataLayoutConfig {
2626
/** Trace data array. */
@@ -29,6 +29,8 @@ export interface PlotlyDataLayoutConfig {
2929
layout?: Partial<Layout>;
3030
/** Optional config overrides. */
3131
config?: Partial<Config>;
32+
/** Optional animation frames. */
33+
frames?: Frame[];
3234
}
3335

3436
/** Either a regular root target or a figure-shaped object. */
@@ -46,34 +48,34 @@ export interface StaticPlots {
4648

4749
/** Names of icons bundled with Plotly's mode-bar. */
4850
export type DefaultIcons =
49-
| 'undo'
50-
| 'home'
51-
| 'camera-retro'
52-
| 'zoombox'
53-
| 'pan'
54-
| 'zoom_plus'
55-
| 'zoom_minus'
56-
| 'autoscale'
57-
| 'tooltip_basic'
58-
| 'tooltip_compare'
59-
| 'plotlylogo'
60-
| 'z-axis'
6151
| '3d_rotate'
52+
| 'autoscale'
53+
| 'camera-retro'
6254
| 'camera'
63-
| 'movie'
64-
| 'question'
6555
| 'disk'
66-
| 'drawopenpath'
56+
| 'drawcircle'
6757
| 'drawclosedpath'
68-
| 'lasso'
69-
| 'selectbox'
7058
| 'drawline'
59+
| 'drawopenpath'
7160
| 'drawrect'
72-
| 'drawcircle'
7361
| 'eraseshape'
74-
| 'spikeline'
62+
| 'home'
63+
| 'lasso'
64+
| 'movie'
65+
| 'newplotlylogo'
66+
| 'pan'
7567
| 'pencil'
76-
| 'newplotlylogo';
68+
| 'plotlylogo'
69+
| 'question'
70+
| 'selectbox'
71+
| 'spikeline'
72+
| 'tooltip_basic'
73+
| 'tooltip_compare'
74+
| 'undo'
75+
| 'z-axis'
76+
| 'zoom_minus'
77+
| 'zoom_plus'
78+
| 'zoombox';
7779

7880
/** Map of built-in icon name → `Icon` definition. */
7981
export type IconsMap = { [K in DefaultIcons]: Icon };
@@ -194,6 +196,18 @@ export function newPlot(
194196
layout?: Partial<Layout>,
195197
config?: Partial<Config>
196198
): Promise<PlotlyHTMLElement>;
199+
/**
200+
* Create a new plot at `root` from a figure-shaped object containing
201+
* `data`/`layout`/`config`/`frames`. Replaces any existing plot.
202+
*
203+
* @param root - graph div id or element
204+
* @param figure - figure-shaped object
205+
* @returns the graph div once the plot has rendered
206+
*/
207+
export function newPlot(
208+
root: Root,
209+
figure: PlotlyDataLayoutConfig
210+
): Promise<PlotlyHTMLElement>;
197211

198212
/** Update layout properties on an existing plot. */
199213
export function relayout(root: Root, layout: Partial<Layout>): Promise<PlotlyHTMLElement>;

src/types/core/data.internal.d.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* properties. For public trace types, see data.d.ts.
66
*/
77

8+
import type { Datum } from '../lib/common';
89
import type { Data } from './data';
910

1011
/**
@@ -21,11 +22,11 @@ export interface CalcData {
2122
/** Back-reference to the fully-populated trace this calcdata belongs to. */
2223
trace?: FullData;
2324
/** Computed x coordinate(s). */
24-
x?: any;
25+
x?: Datum | Datum[];
2526
/** Computed y coordinate(s). */
26-
y?: any;
27+
y?: Datum | Datum[];
2728
/** Computed z coordinate(s) (for 3-D traces). */
28-
z?: any;
29+
z?: Datum | Datum[];
2930
/** Trace-module-specific calc fields. */
3031
[key: string]: any;
3132
}
@@ -43,13 +44,13 @@ interface FullDataInternals {
4344
/** Cached extremes (per axis) for autorange computation. */
4445
_extremes?: Record<string, any>;
4546
/** Snapshot of the trace before transforms were applied. */
46-
_fullInput?: any;
47+
_fullInput?: Data;
4748
/** True when the trace has a transform that affects `calcdata`. */
4849
_hasCalcTransform?: boolean;
4950
/** Map from `_expandedIndex` back to original point indices. */
5051
_indexToPoints?: { [key: number]: number[] };
5152
/** Original user-supplied trace object (pre-defaults). */
52-
_input?: any;
53+
_input?: Data;
5354
/** Length of the trace's data arrays (after coercion). */
5455
_length?: number;
5556
/** Captured `meta` references from trace and layout for template binding. */

src/types/core/layout.internal.d.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import type { Locale, Selection } from 'd3';
1010
import type { Layout } from '../generated/schema';
1111
import type { Color } from '../lib/common';
12+
import type { GraphDiv } from './graph-div.internal';
1213

1314
/**
1415
* Fully processed layout with all defaults applied (internal use).
@@ -22,7 +23,7 @@ export interface FullLayout extends Layout {
2223
/** Resolved list of base-plot modules in use (cartesian, polar, …). */
2324
_basePlotModules?: any[];
2425
/** Recomputes inverse-transform caches after a transform change. */
25-
_calcInverseTransform?: (gd: any) => void;
26+
_calcInverseTransform?: (gd: GraphDiv) => void;
2627
/** True once initial autosize has completed at least once. */
2728
_initialAutoSizeIsDone?: boolean;
2829
/** Cached inverse CSS transform for hit-testing. */
@@ -242,9 +243,9 @@ export interface FullLayout extends Layout {
242243
/** Index of the active shape in `layout.shapes`. */
243244
_activeShapeIndex?: number;
244245
/** Callback to deactivate the active selection. */
245-
_deactivateSelection?: (gd: any) => void;
246+
_deactivateSelection?: (gd: GraphDiv) => void;
246247
/** Callback to deactivate the active shape. */
247-
_deactivateShape?: (gd: any) => void;
248+
_deactivateShape?: (gd: GraphDiv) => void;
248249
/** Cached deselect callback. */
249250
_deselect?: any;
250251
/** Vertical offset for colorbar title repositioning. */

0 commit comments

Comments
 (0)