Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Deephaven express chart title does not update dynamically #386

Merged
merged 2 commits into from
Mar 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we not get a descriptor in props as well? Pattern I've used elsewhere is memoize on the descriptor to generate a shortid for the element.

Though this seems fine.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the types we only have fetch in WidgetComponentProps. The panel gets the metadata descriptor, but when it's used in dh.ui, the metadata is for the dh.ui widget, not the plotly widget


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
Loading