Skip to content

Commit

Permalink
feat: Add chart event for title change (#2352)
Browse files Browse the repository at this point in the history
These are for deephaven/deephaven-plugins#1088

Currently the layout is only set once, but with indicator it may change,
although specifically the title, so I added an event for that. Not sure
if it's the best approach.
  • Loading branch information
jnumainville authored Feb 4, 2025
1 parent 6a20d69 commit 25563dc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/chart/src/Chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,14 @@ class Chart extends Component<ChartProps, ChartState> {
this.setState({ shownBlocker: null });
break;
}
case ChartModel.EVENT_LAYOUT_UPDATED: {
const newLayout = detail as Partial<Layout>;
this.setState(({ layout, revision }) => ({
layout: { ...layout, ...newLayout },
revision: revision + 1,
}));
break;
}
default:
log.debug('Unknown event type', type, event);
}
Expand Down
8 changes: 8 additions & 0 deletions packages/chart/src/ChartModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class ChartModel {

static EVENT_BLOCKER_CLEAR = 'ChartModel.EVENT_BLOCKER_CLEAR';

static EVENT_LAYOUT_UPDATED = 'ChartModel.EVENT_LAYOUT_UPDATED';

constructor(dh: typeof DhType) {
this.dh = dh;
this.listeners = [];
Expand Down Expand Up @@ -205,6 +207,12 @@ class ChartModel {
fireBlockerClear(): void {
this.fireEvent(new CustomEvent(ChartModel.EVENT_BLOCKER_CLEAR));
}

fireLayoutUpdated(detail: Partial<Layout>): void {
this.fireEvent(
new CustomEvent(ChartModel.EVENT_LAYOUT_UPDATED, { detail })
);
}
}

export default ChartModel;

0 comments on commit 25563dc

Please sign in to comment.