Skip to content

Commit

Permalink
geosolutions-it#4297 Use suspense for plotly (geosolutions-it#6622)
Browse files Browse the repository at this point in the history
  • Loading branch information
offtherailz authored and agpenton committed Jul 8, 2021
1 parent f0dd856 commit db578e5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
3 changes: 2 additions & 1 deletion web/client/components/charts/PlotlyChart.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// customizable method: use your own `Plotly` object
import createPlotlyComponent from 'react-plotly.js/factory';
import Plotly from 'plotly.js-cartesian-dist';
export const Plot = createPlotlyComponent(Plotly);
const Plot = createPlotlyComponent(Plotly);
export default Plot;
19 changes: 11 additions & 8 deletions web/client/components/charts/WidgetChart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
* LICENSE file in the root directory of this source tree.
*/

import React from 'react';
import { Plot } from './PlotlyChart';
import React, { Suspense } from 'react';
import { sameToneRangeColors } from '../../utils/ColorUtils';
import { parseExpression } from '../../utils/ExpressionUtils';
import LoadingView from '../misc/LoadingView';

const Plot = React.lazy(() => import('./PlotlyChart'));

export const COLOR_DEFAULTS = {
base: 190,
Expand Down Expand Up @@ -196,11 +197,13 @@ export default function WidgetChart({
}) {
const { data, layout, config } = toPlotly(props);
return (
<Plot
onInitialized={onInitialized}
data={data}
layout={layout}
config={config}
/>
<Suspense fallback={<LoadingView />}>
<Plot
onInitialized={onInitialized}
data={data}
layout={layout}
config={config}
/>
</Suspense>
);
}

0 comments on commit db578e5

Please sign in to comment.