Skip to content

Commit 594e2f2

Browse files
Upgrade plotly.js to version 2 to fix the UI crashing issue (#7359)
* Upgrade plotly.js to version 2 * Fix styling error reported by styled
1 parent 3275a9e commit 594e2f2

File tree

12 files changed

+1204
-2846
lines changed

12 files changed

+1204
-2846
lines changed

client/cypress/support/visualizations/chart.js

Lines changed: 16 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,26 @@
33
* @param should Passed to should expression after plot points are captured
44
*/
55
export function assertPlotPreview(should = "exist") {
6-
cy.getByTestId("VisualizationPreview")
7-
.find("g.plot")
8-
.should("exist")
9-
.find("g.points")
10-
.should(should);
6+
cy.getByTestId("VisualizationPreview").find("g.overplot").should("exist").find("g.points").should(should);
117
}
128

139
export function createChartThroughUI(chartName, chartSpecificAssertionFn = () => {}) {
1410
cy.getByTestId("NewVisualization").click();
1511
cy.getByTestId("VisualizationType").selectAntdOption("VisualizationType.CHART");
16-
cy.getByTestId("VisualizationName")
17-
.clear()
18-
.type(chartName);
12+
cy.getByTestId("VisualizationName").clear().type(chartName);
1913

2014
chartSpecificAssertionFn();
2115

2216
cy.server();
2317
cy.route("POST", "**/api/visualizations").as("SaveVisualization");
2418

25-
cy.getByTestId("EditVisualizationDialog")
26-
.contains("button", "Save")
27-
.click();
19+
cy.getByTestId("EditVisualizationDialog").contains("button", "Save").click();
2820

29-
cy.getByTestId("QueryPageVisualizationTabs")
30-
.contains("span", chartName)
31-
.should("exist");
21+
cy.getByTestId("QueryPageVisualizationTabs").contains("span", chartName).should("exist");
3222

3323
cy.wait("@SaveVisualization").should("have.property", "status", 200);
3424

35-
return cy.get("@SaveVisualization").then(xhr => {
25+
return cy.get("@SaveVisualization").then((xhr) => {
3626
const { id, name, options } = xhr.response.body;
3727
return cy.wrap({ id, name, options });
3828
});
@@ -42,19 +32,13 @@ export function assertTabbedEditor(chartSpecificTabbedEditorAssertionFn = () =>
4232
cy.getByTestId("Chart.GlobalSeriesType").should("exist");
4333

4434
cy.getByTestId("VisualizationEditor.Tabs.Series").click();
45-
cy.getByTestId("VisualizationEditor")
46-
.find("table")
47-
.should("exist");
35+
cy.getByTestId("VisualizationEditor").find("table").should("exist");
4836

4937
cy.getByTestId("VisualizationEditor.Tabs.Colors").click();
50-
cy.getByTestId("VisualizationEditor")
51-
.find("table")
52-
.should("exist");
38+
cy.getByTestId("VisualizationEditor").find("table").should("exist");
5339

5440
cy.getByTestId("VisualizationEditor.Tabs.DataLabels").click();
55-
cy.getByTestId("VisualizationEditor")
56-
.getByTestId("Chart.DataLabels.ShowDataLabels")
57-
.should("exist");
41+
cy.getByTestId("VisualizationEditor").getByTestId("Chart.DataLabels.ShowDataLabels").should("exist");
5842

5943
chartSpecificTabbedEditorAssertionFn();
6044

@@ -63,39 +47,29 @@ export function assertTabbedEditor(chartSpecificTabbedEditorAssertionFn = () =>
6347

6448
export function assertAxesAndAddLabels(xaxisLabel, yaxisLabel) {
6549
cy.getByTestId("VisualizationEditor.Tabs.XAxis").click();
66-
cy.getByTestId("Chart.XAxis.Type")
67-
.contains(".ant-select-selection-item", "Auto Detect")
68-
.should("exist");
50+
cy.getByTestId("Chart.XAxis.Type").contains(".ant-select-selection-item", "Auto Detect").should("exist");
6951

70-
cy.getByTestId("Chart.XAxis.Name")
71-
.clear()
72-
.type(xaxisLabel);
52+
cy.getByTestId("Chart.XAxis.Name").clear().type(xaxisLabel);
7353

7454
cy.getByTestId("VisualizationEditor.Tabs.YAxis").click();
75-
cy.getByTestId("Chart.LeftYAxis.Type")
76-
.contains(".ant-select-selection-item", "Linear")
77-
.should("exist");
55+
cy.getByTestId("Chart.LeftYAxis.Type").contains(".ant-select-selection-item", "Linear").should("exist");
7856

79-
cy.getByTestId("Chart.LeftYAxis.Name")
80-
.clear()
81-
.type(yaxisLabel);
57+
cy.getByTestId("Chart.LeftYAxis.Name").clear().type(yaxisLabel);
8258

83-
cy.getByTestId("Chart.LeftYAxis.TickFormat")
84-
.clear()
85-
.type("+");
59+
cy.getByTestId("Chart.LeftYAxis.TickFormat").clear().type("+");
8660

8761
cy.getByTestId("VisualizationEditor.Tabs.General").click();
8862
}
8963

9064
export function createDashboardWithCharts(title, chartGetters, widgetsAssertionFn = () => {}) {
91-
cy.createDashboard(title).then(dashboard => {
65+
cy.createDashboard(title).then((dashboard) => {
9266
const dashboardUrl = `/dashboards/${dashboard.id}`;
93-
const widgetGetters = chartGetters.map(chartGetter => `${chartGetter}Widget`);
67+
const widgetGetters = chartGetters.map((chartGetter) => `${chartGetter}Widget`);
9468

9569
chartGetters.forEach((chartGetter, i) => {
9670
const position = { autoHeight: false, sizeY: 8, sizeX: 3, col: (i % 2) * 3 };
9771
cy.get(`@${chartGetter}`)
98-
.then(chart => cy.addWidget(dashboard.id, chart.id, { position }))
72+
.then((chart) => cy.addWidget(dashboard.id, chart.id, { position }))
9973
.as(widgetGetters[i]);
10074
});
10175

viz-lib/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"@types/jest": "^26.0.18",
4747
"@types/leaflet": "^1.5.19",
4848
"@types/numeral": "0.0.28",
49-
"@types/plotly.js": "^1.54.22",
49+
"@types/plotly.js": "^2.35.2",
5050
"@types/react": "^17.0.0",
5151
"@types/react-dom": "^17.0.0",
5252
"@types/tinycolor2": "^1.4.2",
@@ -91,7 +91,7 @@
9191
"leaflet.markercluster": "^1.1.0",
9292
"lodash": "^4.17.10",
9393
"numeral": "^2.0.6",
94-
"plotly.js": "1.58.5",
94+
"plotly.js": "2.35.3",
9595
"react-pivottable": "^0.9.0",
9696
"react-sortable-hoc": "^1.10.1",
9797
"tinycolor2": "^1.4.1",

viz-lib/src/visualizations/chart/plotly/fixtures/prepareLayout/box-single-axis.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,17 @@
2727
"automargin": true,
2828
"showticklabels": true,
2929
"title": null,
30+
"tickformat": null,
3031
"type": "-"
3132
},
3233
"yaxis": {
3334
"automargin": true,
3435
"title": null,
36+
"tickformat": null,
3537
"type": "linear",
3638
"autorange": true,
3739
"range": null
38-
},
40+
},
3941
"hoverlabel": {
4042
"namelength": -1
4143
}

viz-lib/src/visualizations/chart/plotly/fixtures/prepareLayout/box-with-second-axis.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,27 @@
3030
"automargin": true,
3131
"showticklabels": true,
3232
"title": null,
33+
"tickformat": null,
3334
"type": "-"
3435
},
3536
"yaxis": {
3637
"automargin": true,
3738
"title": null,
39+
"tickformat": null,
3840
"type": "linear",
3941
"autorange": true,
4042
"range": null
4143
},
4244
"yaxis2": {
4345
"automargin": true,
4446
"title": null,
47+
"tickformat": null,
4548
"type": "linear",
4649
"autorange": true,
4750
"range": null,
4851
"overlaying": "y",
4952
"side": "right"
50-
},
53+
},
5154
"hoverlabel": {
5255
"namelength": -1
5356
}

viz-lib/src/visualizations/chart/plotly/fixtures/prepareLayout/default-single-axis.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,21 @@
2525
"automargin": true,
2626
"showticklabels": true,
2727
"title": null,
28+
"tickformat": null,
2829
"type": "-"
2930
},
3031
"yaxis": {
3132
"automargin": true,
3233
"title": null,
34+
"tickformat": null,
3335
"type": "linear",
3436
"autorange": true,
3537
"range": null
36-
},
38+
},
3739
"hoverlabel": {
3840
"namelength": -1
39-
}
41+
},
42+
"hovermode": "x"
4043
}
4144
}
4245
}

viz-lib/src/visualizations/chart/plotly/fixtures/prepareLayout/default-with-second-axis.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,31 @@
2828
"automargin": true,
2929
"showticklabels": true,
3030
"title": null,
31+
"tickformat": null,
3132
"type": "-"
3233
},
3334
"yaxis": {
3435
"automargin": true,
3536
"title": null,
37+
"tickformat": null,
3638
"type": "linear",
3739
"autorange": true,
3840
"range": null
3941
},
4042
"yaxis2": {
4143
"automargin": true,
4244
"title": null,
45+
"tickformat": null,
4346
"type": "linear",
4447
"autorange": true,
4548
"range": null,
4649
"overlaying": "y",
4750
"side": "right"
48-
},
51+
},
4952
"hoverlabel": {
5053
"namelength": -1
51-
}
54+
},
55+
"hovermode": "x"
5256
}
5357
}
5458
}

viz-lib/src/visualizations/chart/plotly/fixtures/prepareLayout/default-with-stacking.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,21 @@
2424
"automargin": true,
2525
"showticklabels": true,
2626
"title": null,
27+
"tickformat": null,
2728
"type": "-"
2829
},
2930
"yaxis": {
3031
"automargin": true,
3132
"title": null,
33+
"tickformat": null,
3234
"type": "linear",
3335
"autorange": true,
3436
"range": null
35-
},
37+
},
3638
"hoverlabel": {
3739
"namelength": -1
38-
}
40+
},
41+
"hovermode": "x"
3942
}
4043
}
4144
}

viz-lib/src/visualizations/chart/plotly/fixtures/prepareLayout/default-without-legend.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,21 @@
2323
"automargin": true,
2424
"showticklabels": true,
2525
"title": null,
26+
"tickformat": null,
2627
"type": "-"
2728
},
2829
"yaxis": {
2930
"automargin": true,
3031
"title": null,
32+
"tickformat": null,
3133
"type": "linear",
3234
"autorange": true,
3335
"range": null
34-
},
36+
},
3537
"hoverlabel": {
3638
"namelength": -1
37-
}
39+
},
40+
"hovermode": "x"
3841
}
3942
}
4043
}

viz-lib/src/visualizations/chart/plotly/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { prepareCustomChartData, createCustomChartRenderer } from "./customChart
1010
// @ts-expect-error ts-migrate(2339) FIXME: Property 'setPlotConfig' does not exist on type 't... Remove this comment to see the full error message
1111
Plotly.setPlotConfig({
1212
modeBarButtonsToRemove: ["sendDataToCloud"],
13+
modeBarButtonsToAdd: ["togglespikelines", "v1hovermode"],
1314
});
1415

1516
export {

viz-lib/src/visualizations/chart/plotly/prepareLayout.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function prepareXAxis(axisOptions: any, additionalOptions: any) {
2121
title: getAxisTitle(axisOptions),
2222
type: getAxisScaleType(axisOptions),
2323
automargin: true,
24-
tickformat: axisOptions.tickFormat,
24+
tickformat: axisOptions.tickFormat ?? null,
2525
};
2626

2727
if (additionalOptions.sortX && axis.type === "category") {
@@ -49,7 +49,7 @@ function prepareYAxis(axisOptions: any) {
4949
automargin: true,
5050
autorange: true,
5151
range: null,
52-
tickformat: axisOptions.tickFormat,
52+
tickformat: axisOptions.tickFormat ?? null,
5353
};
5454
}
5555

@@ -109,7 +109,7 @@ function prepareBoxLayout(layout: any, options: any, data: any) {
109109
}
110110

111111
export default function prepareLayout(element: any, options: any, data: any) {
112-
const layout = {
112+
const layout: any = {
113113
margin: { l: 10, r: 10, b: 5, t: 20, pad: 4 },
114114
// plot size should be at least 5x5px
115115
width: Math.max(5, Math.floor(element.offsetWidth)),
@@ -124,6 +124,10 @@ export default function prepareLayout(element: any, options: any, data: any) {
124124
},
125125
};
126126

127+
if (["line", "area", "column"].includes(options.globalSeriesType)) {
128+
layout.hovermode = options.swappedAxes ? 'y' : 'x';
129+
}
130+
127131
switch (options.globalSeriesType) {
128132
case "pie":
129133
return preparePieLayout(layout, options, data);

0 commit comments

Comments
 (0)