Skip to content

Commit 73037e8

Browse files
ianrobertsRyanCavanaughCopilot
authored
🤖 Merge PR DefinitelyTyped#72326 Typing updates for Plotly version 3 by @ianroberts
Co-authored-by: Ryan Cavanaugh <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent a6ab8aa commit 73037e8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+6218
-159
lines changed

types/plotly.js/.eslintrc.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

types/plotly.js/.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
!**/*.d.cts
44
!**/*.d.mts
55
!**/*.d.*.ts
6+
/v2/

types/plotly.js/index.d.ts

Lines changed: 32 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -435,26 +435,23 @@ export function validateTemplate(figure: TemplateFigure, template: Template): Va
435435
// Layout
436436
export interface Layout {
437437
colorway: string[];
438-
title:
439-
| string
440-
| Partial<{
441-
text: string;
442-
font: Partial<Font>;
443-
xref: "container" | "paper";
444-
yref: "container" | "paper";
445-
x: number;
446-
y: number;
447-
xanchor: "auto" | "left" | "center" | "right";
448-
yanchor: "auto" | "top" | "middle" | "bottom";
449-
pad: Partial<Padding>;
450-
subtitle:
451-
| string
452-
| Partial<{
453-
text: string;
454-
font: Partial<Font>;
455-
}>;
456-
}>;
457-
titlefont: Partial<Font>;
438+
title: Partial<{
439+
text: string;
440+
font: Partial<Font>;
441+
xref: "container" | "paper";
442+
yref: "container" | "paper";
443+
x: number;
444+
y: number;
445+
xanchor: "auto" | "left" | "center" | "right";
446+
yanchor: "auto" | "top" | "middle" | "bottom";
447+
pad: Partial<Padding>;
448+
subtitle:
449+
| string
450+
| Partial<{
451+
text: string;
452+
font: Partial<Font>;
453+
}>;
454+
}>;
458455
autosize: boolean;
459456
showlegend: boolean;
460457
paper_bgcolor: Color;
@@ -486,6 +483,12 @@ export interface Layout {
486483
hoverdistance: number;
487484
hoverlabel: Partial<HoverLabel>;
488485
calendar: Calendar;
486+
487+
// these are just the most common nested property updates that you might
488+
// want to pass to Plotly.relayout - *any* dotted property path through the
489+
// normal nested structure is valid here, and enumerating them all including
490+
// all possible [n] array indices would be infeasible (if it weren't for the
491+
// array indices, the pure a.b.c bit might be doable with conditional types)
489492
"xaxis.range": [Datum, Datum];
490493
"xaxis.range[0]": Datum;
491494
"xaxis.range[1]": Datum;
@@ -496,8 +499,8 @@ export interface Layout {
496499
"xaxis.type": AxisType;
497500
"xaxis.autorange": boolean;
498501
"yaxis.autorange": boolean;
499-
"xaxis.title": string;
500-
"yaxis.title": string;
502+
"xaxis.title": Partial<DataTitle>;
503+
"yaxis.title": Partial<DataTitle>;
501504
ternary: {}; // TODO
502505
geo: {}; // TODO
503506
mapbox: Partial<Mapbox>;
@@ -690,12 +693,7 @@ export interface Axis {
690693
* Individual pieces can override this.
691694
*/
692695
color: Color;
693-
title: string | Partial<DataTitle>;
694-
/**
695-
* Former `titlefont` is now the sub-attribute `font` of `title`.
696-
* To customize title font properties, please use `title.font` now.
697-
*/
698-
titlefont: Partial<Font>;
696+
title: Partial<DataTitle>;
699697
type: AxisType;
700698
autorange: true | false | "reversed" | "min reversed" | "max reversed" | "min" | "max";
701699
autorangeoptions: Partial<AutoRangeOptions>;
@@ -967,7 +965,6 @@ export interface LayoutAxis extends Axis {
967965
rangeslider: Partial<RangeSlider>;
968966
rangeselector: Partial<RangeSelector>;
969967
automargin: boolean;
970-
autotick: boolean;
971968
angle: any;
972969
griddash: Dash;
973970
l2p: (v: Datum) => number;
@@ -1260,7 +1257,6 @@ export interface ErrorOptions {
12601257
color: Color;
12611258
thickness: number;
12621259
width: number;
1263-
opacity: number;
12641260
}
12651261

12661262
export type ErrorBar =
@@ -1294,7 +1290,6 @@ export type PlotType =
12941290
| "funnel"
12951291
| "funnelarea"
12961292
| "heatmap"
1297-
| "heatmapgl"
12981293
| "histogram"
12991294
| "histogram2d"
13001295
| "histogram2dcontour"
@@ -1306,7 +1301,6 @@ export type PlotType =
13061301
| "parcats"
13071302
| "parcoords"
13081303
| "pie"
1309-
| "pointcloud"
13101304
| "sankey"
13111305
| "scatter"
13121306
| "scatter3d"
@@ -1342,7 +1336,6 @@ export type Color =
13421336
| Array<string | number | undefined | null>
13431337
| Array<Array<string | number | undefined | null>>;
13441338
export type ColorScale = string | string[] | Array<[number, string]>;
1345-
export type DataTransform = Partial<Transform>;
13461339
export type ScatterData = PlotData;
13471340

13481341
export interface PlotData {
@@ -1506,7 +1499,6 @@ export interface PlotData {
15061499
delta: Partial<Delta>;
15071500
gauge: Partial<Gauge>;
15081501
number: Partial<PlotNumber>;
1509-
transforms: DataTransform[];
15101502
orientation: "v" | "h";
15111503
width: number | number[];
15121504
boxmean: boolean | "sd";
@@ -1575,46 +1567,10 @@ export interface PlotData {
15751567
uid: string;
15761568
}
15771569

1578-
/**
1579-
* These interfaces are based on attribute descriptions in
1580-
* https://github.com/plotly/plotly.js/tree/9d6144304308fc3007f0facf2535d38ea3e9b26c/src/transforms
1581-
*/
1582-
export interface TransformStyle {
1583-
target: number | string | number[] | string[];
1584-
value: Partial<PlotData>;
1585-
}
1586-
1587-
export interface TransformAggregation {
1588-
target: string;
1589-
func?:
1590-
| "count"
1591-
| "sum"
1592-
| "avg"
1593-
| "median"
1594-
| "mode"
1595-
| "rms"
1596-
| "stddev"
1597-
| "min"
1598-
| "max"
1599-
| "first"
1600-
| "last"
1601-
| undefined;
1602-
funcmode?: "sample" | "population" | undefined;
1603-
enabled?: boolean | undefined;
1604-
}
1605-
1606-
export interface Transform {
1607-
type: "aggregate" | "filter" | "groupby" | "sort";
1608-
enabled: boolean;
1609-
target: number | string | number[] | string[];
1610-
operation: string;
1611-
aggregations: TransformAggregation[];
1612-
preservegaps: boolean;
1613-
groups: string | number[] | string[];
1614-
nameformat: string;
1615-
styles: TransformStyle[];
1616-
value: any;
1617-
order: "ascending" | "descending";
1570+
export interface ColorBarTitle {
1571+
text: string;
1572+
font: Partial<Font>;
1573+
side: "right" | "top" | "bottom";
16181574
}
16191575

16201576
export interface ColorBar {
@@ -1656,9 +1612,7 @@ export interface ColorBar {
16561612
exponentformat: "none" | "e" | "E" | "power" | "SI" | "B";
16571613
showexponent: "all" | "first" | "last" | "none";
16581614
minexponent: number;
1659-
title: string;
1660-
titlefont: Font;
1661-
titleside: "right" | "top" | "bottom";
1615+
title: Partial<ColorBarTitle>;
16621616
tickvalssrc: any;
16631617
ticktextsrc: any;
16641618
}
@@ -1908,9 +1862,6 @@ export interface Config {
19081862
*/
19091863
logging: boolean | 0 | 1 | 2;
19101864

1911-
/** Set global transform to be applied to all traces with no specification needed */
1912-
globalTransforms: any[];
1913-
19141865
/** Which localization should we use? Should be a string like 'en' or 'en-US' */
19151866
locale: string;
19161867

@@ -2774,15 +2725,6 @@ interface LocaleModule {
27742725
format: Record<string, unknown>;
27752726
}
27762727

2777-
interface TransformModule {
2778-
moduleType: "transform";
2779-
name: string;
2780-
transform: any;
2781-
calcTransform: any;
2782-
attributes: Record<string, unknown>;
2783-
supplyDefaults: any;
2784-
}
2785-
27862728
interface ComponentModule {
27872729
moduleType: "component";
27882730
name: string;
@@ -2794,4 +2736,4 @@ interface ApiMethodModule {
27942736
fn: any;
27952737
}
27962738

2797-
type PlotlyModule = TraceModule | LocaleModule | TransformModule | ComponentModule | ApiMethodModule;
2739+
type PlotlyModule = TraceModule | LocaleModule | ComponentModule | ApiMethodModule;

types/plotly.js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": true,
33
"name": "@types/plotly.js",
4-
"version": "2.35.9999",
4+
"version": "3.0.9999",
55
"projects": [
66
"https://plot.ly/javascript/",
77
"https://github.com/plotly/plotly.js"

types/plotly.js/test/core-tests.ts

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,17 @@ const layout = {
3636
subtitle: "Annual sales growth between 1999 and 2002",
3737
},
3838
xaxis: {
39-
title: "Year",
39+
title: {
40+
text: "Year",
41+
},
4042
showgrid: false,
4143
zeroline: false,
4244
tickangle,
4345
},
4446
yaxis: {
45-
title: "Percent",
47+
title: {
48+
text: "Percent",
49+
},
4650
showline: false,
4751
},
4852
uirevision: "true",
@@ -71,7 +75,7 @@ const layout = {
7175
opacity: 0.6,
7276
meanline: { visible: true },
7377
} as ViolinData;
74-
Plotly.newPlot(graphDiv, [violinTrace], { title: "Sales growth" });
78+
Plotly.newPlot(graphDiv, [violinTrace], { title: { text: "Sales growth" } });
7579

7680
const candlestickTrace: Partial<CandlestickData> = {
7781
x: [
@@ -247,7 +251,7 @@ const layout = {
247251
type: "candlestick",
248252
xaxis: "x",
249253
};
250-
Plotly.newPlot(graphDiv, [candlestickTrace], { title: "Stock price" });
254+
Plotly.newPlot(graphDiv, [candlestickTrace], { title: { text: "Stock price" } });
251255
})();
252256
(() => {
253257
const data: Array<Partial<SankeyData>> = [
@@ -272,7 +276,9 @@ const layout = {
272276
},
273277
];
274278
const layout = {
275-
title: "Basic Sankey",
279+
title: {
280+
text: "Basic Sankey",
281+
},
276282
font: {
277283
size: 10,
278284
},
@@ -289,7 +295,7 @@ const layout = {
289295
type: "scatter",
290296
} as ScatterData,
291297
];
292-
const layout2 = { title: "Revenue" };
298+
const layout2 = { title: { text: "Revenue" } };
293299
Plotly.newPlot(graphDiv, data2, layout2);
294300
})();
295301

@@ -424,7 +430,9 @@ const layout = {
424430
];
425431

426432
const layout = {
427-
title: "Global Emissions 1990-2011",
433+
title: {
434+
text: "Global Emissions 1990-2011",
435+
},
428436
annotations: [
429437
{
430438
font: {
@@ -612,7 +620,9 @@ const layout = {
612620
// update only values within nested objects
613621
(() => {
614622
const update: Partial<Layout> = {
615-
title: "some new title", // updates the title
623+
title: { // updates the title
624+
text: "some new title",
625+
},
616626
"xaxis.range": [0, 5], // updates the xaxis range
617627
"yaxis.range[1]": 15, // updates the end of the yaxis range
618628
};
@@ -624,7 +634,9 @@ const layout = {
624634
marker: { color: "red" },
625635
};
626636
const layout_update = {
627-
title: "some new title", // updates the title
637+
title: { // updates the title
638+
text: "some new title",
639+
},
628640
};
629641
Plotly.update(graphDiv, data_update, layout_update);
630642
})();
@@ -638,7 +650,9 @@ const layout = {
638650
type: "bar",
639651
};
640652
const layout_update: Partial<Layout> = {
641-
title: "some new title", // updates the title
653+
title: { // updates the title
654+
text: "some new title",
655+
},
642656
barmode: "stack",
643657
barnorm: "fraction",
644658
bargap: 0,

0 commit comments

Comments
 (0)