-
Notifications
You must be signed in to change notification settings - Fork 122
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
feat(heatmap): move onBrushEnd from config to Settings #1369
Conversation
7148acf
to
604b153
Compare
export type BrushArea = XYBrushArea | HeatmapBrushEvent; | ||
|
||
/** @public */ | ||
export type BrushEndListener = (brushArea: XYBrushArea) => void; | ||
export type BrushEndListener = (brushArea: BrushArea) => void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nickofthyme @monfera @rshen91
I'd like to have your opinion here: this is not the only place where we have an union type as an argument of a chart callback.
It happens on the onClick event, but also in other situations.
Most chart consumers automatically cast to the right type depending on their needs: e.g. I'm using a bar chart so I'm cast with as XYBrushArea
the brushArea.
Right now we don't offer a Generic type for the chart and I also don't fully know if and how this can work.
I'm wondering if we can, in the meantime, find a simpler and cleaner solution to the problem.
Tagging the callback argument type with the chart type could be a solution:
type HeatmapBrushEvent = {
type: 'heatmap';
cells: Cell[];
x: (string | number)[];
y: (string | number)[];
};
interface XYBrushArea {
type: 'cartesian';
x?: [number, number];
y?: Array<GroupBrushExtent>;
}
what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I was thinking one way to do this would be in the function somehow like this...
<Settings
onBrushEnd={('heatmap', event: HeatmapBrushEvent) => null}
// or with multiple
onBrushEnd={(['line', 'area'], event: LineBrushEvent | AreaBrushEvent) => null}
/>
The issue with this is that they could pass 'heatmap
when there is no HeatmapSpec
defined.
<Settings
onBrushEnd={{
types: ['heatmap'],
callback: (event: HeatmapBrushEvent) => null
}}
/>
The idea behind the types is something like below... (see TS Playground)
Screen.Recording.2021-09-14.at.08.38.04.AM.mp4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found a slightly simpler way to avoid the type recursion. See demo
interface HeatmapEvent {
type: "heatmap"
getHeatmap: () => {}
}
interface XYEvent {
type: "xy"
getXY: () => {}
}
interface EventMap {
'heatmap': HeatmapEvent;
'xy': XYEvent;
}
// There may be a less verbose way of doing this...
type Callback<Type> = Type extends keyof EventMap ?
EventMap[Type] : never
type HeatmapCb = Callback<'heatmap'>; // HeatmapEvent
type XYCb = Callback<'xy'>; // XYEvent
type AnyCb = Callback<'xy'|'heatmap'>; // HeatmapEvent | XYEvent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export type BrushArea = XYBrushArea | HeatmapBrushEvent; | ||
|
||
/** @public */ | ||
export type BrushEndListener = (brushArea: XYBrushArea) => void; | ||
export type BrushEndListener = (brushArea: BrushArea) => void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I was thinking one way to do this would be in the function somehow like this...
<Settings
onBrushEnd={('heatmap', event: HeatmapBrushEvent) => null}
// or with multiple
onBrushEnd={(['line', 'area'], event: LineBrushEvent | AreaBrushEvent) => null}
/>
The issue with this is that they could pass 'heatmap
when there is no HeatmapSpec
defined.
<Settings
onBrushEnd={{
types: ['heatmap'],
callback: (event: HeatmapBrushEvent) => null
}}
/>
The idea behind the types is something like below... (see TS Playground)
Screen.Recording.2021-09-14.at.08.38.04.AM.mp4
db968f6
to
bd1c02d
Compare
CHANGELOG.md
Outdated
@@ -1,31 +1,3 @@ | |||
# [35.0.0](https://github.com/elastic/elastic-charts/compare/v34.2.1...v35.0.0) (2021-09-13) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh sorry for got about git checkout
would also wipe any auto changes in between. I just git reset
to the good pr with the unit test fix on top 🍒 and force pushed 🙊
jenkins test this please |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 🎉
BREAKING CHANGE: remove onBrushEnd from heatmap config and merge onBrushEnd in Settings with cartesian onBrushEnd
# [36.0.0](v35.0.0...v36.0.0) (2021-09-15) ### Features * **heatmap:** move onBrushEnd from config to Settings ([#1369](#1369)) ([409a0c4](409a0c4)) ### BREAKING CHANGES * **heatmap:** remove onBrushEnd from heatmap config and merge onBrushEnd in Settings with cartesian onBrushEnd
Summary
BREAKING CHANGE
The
onBrushEnd
prop is removed from the heatmap config. It can now be pulled off the Setting to match the other chart types.Details
In
settings.tsx
I created a new typeBrushArea
:This satisfies
chart_state.interactions.test.tsx
andon_brushed_highlighted_shapes.test.ts
Issues
Closes #1214
Checklist
:xy
,:partition
)closes #123
,fixes #123
)packages/charts/src/index.ts