Skip to content

Commit

Permalink
feat(legend/series): set highlighted legend item to null on mouseout
Browse files Browse the repository at this point in the history
addresses elastic#24
  • Loading branch information
emmacunningham committed Feb 8, 2019
1 parent 455a033 commit a063717
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/components/legend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class LegendComponent extends React.Component<ReactiveChartProps> {
key: index,
className: 'euiChartLegendList__item',
onMouseOver: this.onLegendItemMouseover(index),
onMouseOut: this.onLegendItemMouseout,
};

return (
Expand All @@ -107,6 +108,10 @@ class LegendComponent extends React.Component<ReactiveChartProps> {
private onLegendItemMouseover = (legendItemIndex: number) => () => {
this.props.chartStore!.updateHighlightedLegendItem(legendItemIndex);
}

private onLegendItemMouseout = () => {
this.props.chartStore!.updateHighlightedLegendItem(null);
}
}
function LegendElement({ color, label }: Partial<LegendItem>) {
return (
Expand Down
2 changes: 1 addition & 1 deletion src/state/chart_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ export class ChartStore {
return this.xScale.type !== ScaleType.Ordinal && Boolean(this.onBrushEndListener);
}

updateHighlightedLegendItem(legendItemIndex: number) {
updateHighlightedLegendItem(legendItemIndex: number | null) {
if (legendItemIndex !== this.highlightedLegendItemIndex) {
this.highlightedLegendItemIndex = legendItemIndex;
this.computeChart();
Expand Down

0 comments on commit a063717

Please sign in to comment.