Skip to content

Commit bbb99d0

Browse files
committed
build: fix issue with plotly.js
1 parent c9fa1c8 commit bbb99d0

File tree

4 files changed

+42
-2269
lines changed

4 files changed

+42
-2269
lines changed

packages/shared/charts/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
"dependencies": {
3838
"classnames": "^2.3.2",
3939
"deepmerge": "^4.3.1",
40-
"plotly.js": "npm:[email protected]",
4140
"plotly.js-dist-min": "^3.0.0",
4241
"react-plotly.js": "^2.6.0"
4342
},

packages/shared/charts/rollup/shared-libs-config.cts

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,17 @@ interface Args {
2020

2121
const bundles = {
2222
plotly: {
23-
// [email protected] use: `import Plotly from 'plotly.js/dist/plotly';`
24-
// We redirect this import to min version.
2523
input: "plotly.js-dist-min",
2624
file: {
2725
amd: "plotly.min.js",
2826
esm: "plotly.min.mjs"
2927
}
3028
},
3129
reactPlotly: {
32-
input: "react-plotly.js",
30+
input: "react-plotly.js/factory",
3331
file: {
34-
amd: "react-plotly.js",
35-
esm: "react-plotly.mjs"
32+
amd: "react-plotly_factory.js",
33+
esm: "react-plotly_factory.mjs"
3634
}
3735
},
3836
sharedCharts: {
@@ -116,7 +114,9 @@ function sharedCode(bundle: BundleBuildConfig): RollupOptions {
116114
file: format({ dir: bundle.esmDir, base: bundle.sharedCharts.file.esm }),
117115
paths: {
118116
// Replace imports of react-plotly.js with relative path.
119-
[bundle.reactPlotly.input]: `./${bundle.reactPlotly.file.esm}`
117+
[bundle.reactPlotly.input]: `./${bundle.reactPlotly.file.esm}`,
118+
// Replace imports of plotly.js with relative path.
119+
[bundle.plotly.input]: `./${bundle.plotly.file.esm}`
120120
}
121121
};
122122

@@ -125,44 +125,38 @@ function sharedCode(bundle: BundleBuildConfig): RollupOptions {
125125
file: format({ dir: bundle.amdDir, base: bundle.sharedCharts.file.amd }),
126126
paths: {
127127
// Replace imports of react-plotly.js with relative path.
128-
[bundle.reactPlotly.input]: `./${bundle.reactPlotly.file.amd}`
128+
[bundle.reactPlotly.input]: `./${bundle.reactPlotly.file.amd}`,
129+
// Replace imports of plotly.js with relative path.
130+
[bundle.plotly.input]: `./${bundle.plotly.file.amd}`
129131
}
130132
};
131133

132134
return {
133135
input: bundle.sharedCharts.input,
134136
plugins: stdPlugins(bundle),
135137
// Mark reactPlotly as external to not include react-plotly.js in bundle.
136-
external: [...bundle.external, bundle.reactPlotly.input],
138+
// Mark plotly as external to not include plotly.js in bundle.
139+
external: [...bundle.external, bundle.reactPlotly.input, bundle.plotly.input],
137140
output: [esmOutput, amdOutput]
138141
};
139142
}
140143

141-
/** react-plotly.js bundle config */
144+
/** This entry create standalone react-plotly.js/factory bundle */
142145
function reactPlotly(bundle: BundleBuildConfig): RollupOptions {
143-
const plotlyImport = "plotly.js/dist/plotly";
144146
const esmOutput: OutputOptions = {
145147
format: "es",
146-
file: format({ dir: bundle.esmDir, base: bundle.reactPlotly.file.esm }),
147-
paths: {
148-
// Replace imports of plotly.js with relative path.
149-
[plotlyImport]: `./${bundle.plotly.file.esm}`
150-
}
148+
file: format({ dir: bundle.esmDir, base: bundle.reactPlotly.file.esm })
151149
};
152150

153151
const amdOutput: OutputOptions = {
154152
format: "amd",
155-
file: format({ dir: bundle.amdDir, base: bundle.reactPlotly.file.amd }),
156-
paths: {
157-
// Replace imports of plotly.js with relative path.
158-
[plotlyImport]: `./${bundle.plotly.file.amd}`
159-
}
153+
file: format({ dir: bundle.amdDir, base: bundle.reactPlotly.file.amd })
160154
};
161155

162156
return {
163157
input: bundle.reactPlotly.input,
164158
// Mark plotly as external to not include plotly.js in bundle.
165-
external: [...bundle.external, plotlyImport],
159+
external: [...bundle.external],
166160
plugins: stdPlugins(bundle),
167161
output: [esmOutput, amdOutput]
168162
};
@@ -199,8 +193,8 @@ function plotly(bundle: BundleBuildConfig): RollupOptions {
199193
// Here we just copy the license file.
200194
copy({
201195
targets: [
202-
{ src: "node_modules/plotly.js/dist/plotly.min.js.LICENSE.txt", dest: bundle.amdDir },
203-
{ src: "node_modules/plotly.js/dist/plotly.min.js.LICENSE.txt", dest: bundle.esmDir }
196+
{ src: "node_modules/plotly.js-dist-min/LICENSE", dest: bundle.amdDir },
197+
{ src: "node_modules/plotly.js-dist-min/LICENSE", dest: bundle.esmDir }
204198
],
205199
verbose: true
206200
})

packages/shared/charts/src/components/ChartView.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
import { Config, Data, Layout } from "plotly.js-dist-min";
2-
import { createElement, ReactElement, useCallback, useEffect, useMemo, useRef } from "react";
3-
import ReactPlotlyChartComponent, { PlotParams } from "react-plotly.js";
41
import deepmerge from "deepmerge";
2+
import Plotly, { Config, Data, Layout } from "plotly.js-dist-min";
3+
import { createElement, ReactElement, useCallback, useEffect, useMemo, useRef } from "react";
4+
import { type PlotParams } from "react-plotly.js";
5+
import createPlotComponent from "react-plotly.js/factory";
56
import { ChartViewProps, PlotTrace } from "./types";
67

78
const PREVENT_DEFAULT_INLINE_STYLES_BY_PASSING_EMPTY_OBJ = {};
89

10+
const Plot = createPlotComponent(Plotly);
11+
912
export const ChartView = ({
1013
data,
1114
configOptions,
@@ -43,7 +46,7 @@ export const ChartView = ({
4346
useResizeOnDataReadyEffect(data);
4447

4548
return (
46-
<ReactPlotlyChartComponent
49+
<Plot
4750
className="mx-react-plotly-chart"
4851
data={plotlyData}
4952
style={PREVENT_DEFAULT_INLINE_STYLES_BY_PASSING_EMPTY_OBJ}

0 commit comments

Comments
 (0)