@@ -3,7 +3,8 @@ import { IAction } from 'mobx';
33import React from 'react' ;
44import { Group , Rect } from 'react-konva' ;
55import { animated , Spring } from 'react-spring/konva' ;
6- import { BarGeometry , GeometryValue } from '../../lib/series/rendering' ;
6+ import { LegendItem } from '../../lib/series/legend' ;
7+ import { BarGeometry , GeometryValue , getGeometryStyle } from '../../lib/series/rendering' ;
78import { ElementClickListener , TooltipData } from '../../state/chart_state' ;
89
910interface BarGeometriesDataProps {
@@ -12,14 +13,15 @@ interface BarGeometriesDataProps {
1213 onElementClick ?: ElementClickListener ;
1314 onElementOver : ( ( tooltip : TooltipData ) => void ) & IAction ;
1415 onElementOut : ( ( ) => void ) & IAction ;
16+ highlightedLegendItem : LegendItem | null ;
1517}
1618interface BarGeometriesDataState {
1719 overBar ?: BarGeometry ;
1820}
1921export class BarGeometries extends React . PureComponent <
2022 BarGeometriesDataProps ,
2123 BarGeometriesDataState
22- > {
24+ > {
2325 static defaultProps : Partial < BarGeometriesDataProps > = {
2426 animated : false ,
2527 } ;
@@ -70,14 +72,22 @@ export class BarGeometries extends React.PureComponent<
7072 } ) ;
7173 onElementOut ( ) ;
7274 }
75+
7376 private renderBarGeoms = ( bars : BarGeometry [ ] ) : JSX . Element [ ] => {
7477 const { overBar } = this . state ;
7578 return bars . map ( ( bar , i ) => {
7679 const { x, y, width, height, color, value } = bar ;
77- let opacity = 1 ;
78- if ( overBar && overBar !== bar ) {
79- opacity = 0.6 ;
80- }
80+
81+ // Properties to determine if we need to highlight individual bars depending on hover state
82+ const hasGeometryHover = overBar != null ;
83+ const hasHighlight = overBar === bar ;
84+ const individualHighlight = {
85+ hasGeometryHover,
86+ hasHighlight,
87+ } ;
88+
89+ const geometryStyle = getGeometryStyle ( bar . geometryId , this . props . highlightedLegendItem , individualHighlight ) ;
90+
8191 if ( this . props . animated ) {
8292 return (
8393 < Group key = { i } >
@@ -91,11 +101,11 @@ export class BarGeometries extends React.PureComponent<
91101 height = { props . height }
92102 fill = { color }
93103 strokeWidth = { 0 }
94- opacity = { opacity }
95104 perfectDrawEnabled = { true }
96105 onMouseOver = { this . onOverBar ( bar ) }
97106 onMouseLeave = { this . onOutBar }
98107 onClick = { this . onElementClick ( value ) }
108+ { ...geometryStyle }
99109 />
100110 ) }
101111 </ Spring >
@@ -111,11 +121,11 @@ export class BarGeometries extends React.PureComponent<
111121 height = { height }
112122 fill = { color }
113123 strokeWidth = { 0 }
114- opacity = { opacity }
115124 perfectDrawEnabled = { false }
116125 onMouseOver = { this . onOverBar ( bar ) }
117126 onMouseLeave = { this . onOutBar }
118127 onClick = { this . onElementClick ( bar . value ) }
128+ { ...geometryStyle }
119129 />
120130 ) ;
121131 }
0 commit comments