Skip to content

Commit

Permalink
Merge pull request #265 from flatironinstitute/improve-lazy-plotly-lag
Browse files Browse the repository at this point in the history
Improve LazyPlotlyPlot lagging on resize
  • Loading branch information
WardBrian authored Jan 29, 2025
2 parents ebc0fd1 + 02b86af commit 2e5ff6d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
25 changes: 14 additions & 11 deletions gui/src/app/components/LazyPlotlyPlot.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
import CircularProgress from "@mui/material/CircularProgress";
import React, { FunctionComponent, Suspense } from "react";
import React, { FunctionComponent, Suspense, useMemo } from "react";
import useMeasure from "react-use-measure";

import type { PlotParams } from "react-plotly.js";
import createPlotlyComponent from "react-plotly.js/factory";
import useMeasure from "react-use-measure";
const Plot = React.lazy(async () => {
const plotly = await import("plotly.js-cartesian-dist");
return { default: createPlotlyComponent(plotly) };
});

const LazyPlotlyPlot: FunctionComponent<PlotParams> = ({ data, layout }) => {
// plotly has a reactive setting, but it is buggy
const [ref, { width }] = useMeasure();
const [ref, { width }] = useMeasure({ debounce: 100 });

const layoutWithWidth = {
...layout,
width: width,
};
const layoutWithWidth = useMemo(
() => ({
...layout,
width: width,
}),
[layout, width],
);

return (
<div ref={ref}>
<Suspense
fallback={
<>
<CircularProgress />
<p>Loading Plotly.js</p>
</>
<div className="PlotLoader">
<CircularProgress color="info" />
<p className="details">Loading Plotly.js</p>
</div>
}
>
<Plot data={data} layout={layoutWithWidth} />
Expand Down
6 changes: 6 additions & 0 deletions gui/src/localStyles.css
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@ span.EditorTitle {
height: 4px;
}

.PlotLoader {
padding: 10px;
display: grid;
place-items: center;
}

/* Sampling Opts ------ */
.SamplingOptsWrapper {
padding: 10px;
Expand Down

0 comments on commit 2e5ff6d

Please sign in to comment.