Skip to content

Commit

Permalink
fix: detect style changes from dashboard for re-rendering visualizati…
Browse files Browse the repository at this point in the history
…on (#1667)

Key features:
Visualizations in dashboard were not rerendering to fit the item size in the following situations:
* item fullscreen
* edit item resize
* change screen width (e.g., switch to/from small screen)

Description
Dashboard and Data Visualizer apps have different approaches regarding visualization size and resizing. DV vis containers have display flex and use a counter that updates when the window is resized, to trigger a re-render of the visualization. In Dashboard, the container has a set width and height, which change on any of the above resizing scenarios. It does not use a counter.

The new effect will end up being specific to dashboard, while the existing effect that responds to renderCounter will be specific to DV. A future improvement would possibly be to use the same mechanisms for both apps. But playing it safe for now, since we are in a hard freeze.
  • Loading branch information
jenniferarnesen authored and janhenrikoverland committed Mar 31, 2021
1 parent 88bd9db commit e0a34e4
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packages/plugin/src/ChartPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const ChartPlugin = ({
animation: defaultAnimation,
}) => {
const canvasRef = useRef(undefined)
const prevStyle = useRef(style)

const renderVisualization = useCallback(
animation => {
Expand Down Expand Up @@ -61,7 +62,19 @@ const ChartPlugin = ({
renderCounter !== null && renderVisualization(0)

/* eslint-disable-next-line react-hooks/exhaustive-deps */
}, [renderCounter, style])
}, [renderCounter])

useEffect(() => {
if (
style.width !== prevStyle.current.width ||
style.height !== prevStyle.current.height
) {
renderVisualization(0)
prevStyle.current = style
}

/* eslint-disable-next-line react-hooks/exhaustive-deps */
}, [style])

return <div ref={canvasRef} style={style} />
}
Expand Down

0 comments on commit e0a34e4

Please sign in to comment.