Skip to content

Commit

Permalink
Deephaven express chart title not updating
Browse files Browse the repository at this point in the history
  • Loading branch information
mattrunyon committed Mar 23, 2024
1 parent 09c8eec commit a50ca4f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions plugins/plotly-express/src/js/src/PlotlyExpressChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ export function PlotlyExpressChart(
const { fetch } = props;
const containerRef = useRef<HTMLDivElement>(null);
const [model, setModel] = useState<PlotlyExpressChartModel>();
const [widgetRevision, setWidgetRevision] = useState(0); // Used to force a clean chart state on widget change

useEffect(() => {
let cancelled = false;
async function init() {
const widgetData = await fetch();
if (!cancelled) {
setModel(new PlotlyExpressChartModel(dh, widgetData, fetch));
setWidgetRevision(r => r + 1);
}
}

Expand All @@ -37,6 +39,7 @@ export function PlotlyExpressChart(
<Chart
// eslint-disable-next-line react/jsx-props-no-spreading, @typescript-eslint/ban-ts-comment
// @ts-ignore
key={widgetRevision}
containerRef={containerRef}
model={model}
Plotly={Plotly}
Expand Down
3 changes: 3 additions & 0 deletions plugins/plotly-express/src/js/src/PlotlyExpressChartPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ export function PlotlyExpressChartPanel(props: WidgetPanelProps<Widget>) {
const { fetch, metadata = {}, ...rest } = props;
const containerRef = useRef<HTMLDivElement>(null);
const [model, setModel] = useState<PlotlyExpressChartModel>();
const [widgetRevision, setWidgetRevision] = useState(0); // Used to force a clean chart state on widget change

const makeModel = useCallback(async () => {
const widgetData = await fetch();
const m = new PlotlyExpressChartModel(dh, widgetData, fetch);
setModel(m);
setWidgetRevision(r => r + 1);
return m;
}, [dh, fetch]);

Expand All @@ -26,6 +28,7 @@ export function PlotlyExpressChartPanel(props: WidgetPanelProps<Widget>) {
<ChartPanel
// eslint-disable-next-line react/jsx-props-no-spreading
{...(rest as ChartPanelProps)}
key={widgetRevision}
containerRef={containerRef}
makeModel={makeModel}
Plotly={Plotly}
Expand Down

0 comments on commit a50ca4f

Please sign in to comment.