Skip to content

Commit 3aa5ca3

Browse files
authored
fix(legend): item hideInLegend prop (#307)
Fix `hideInLegend` prop to work again fix #306
1 parent e11697f commit 3aa5ca3

File tree

3 files changed

+22
-34
lines changed

3 files changed

+22
-34
lines changed

src/components/legend/_legend_item.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
text-align: right;
5353
font-feature-settings: 'tnum';
5454

55-
&.echLegendItem__displayValue--hidden {
55+
&--hidden {
5656
display: none;
5757
}
5858
}

src/components/legend/legend.tsx

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -48,27 +48,7 @@ class LegendComponent extends React.Component<LegendProps> {
4848
return (
4949
<div className={legendClasses} style={paddingStyle} id={legendId} aria-hidden={legendCollapsed.get()}>
5050
<div className="echLegendListContainer">
51-
<div className="echLegendList">
52-
{[...legendItems.values()].map((item) => {
53-
// const { isLegendItemVisible } = item;
54-
55-
// const legendItemProps = {
56-
// key: item.key,
57-
// className: classNames('echLegendList__item', {
58-
// 'echLegendList__item--hidden': !isLegendItemVisible,
59-
// }),
60-
// onMouseEnter: this.onLegendItemMouseover(item.key),
61-
// onMouseLeave: this.onLegendItemMouseout,
62-
// };
63-
64-
return this.renderLegendElement(
65-
item,
66-
item.key,
67-
this.onLegendItemMouseover(item.key),
68-
this.onLegendItemMouseout,
69-
);
70-
})}
71-
</div>
51+
<div className="echLegendList">{[...legendItems.values()].map(this.renderLegendElement)}</div>
7252
</div>
7353
</div>
7454
);
@@ -82,23 +62,28 @@ class LegendComponent extends React.Component<LegendProps> {
8262
this.props.chartStore!.onLegendItemOut();
8363
};
8464

85-
private renderLegendElement = (
86-
{ color, label, isSeriesVisible, displayValue }: SeriesLegendItem,
87-
legendItemKey: string,
88-
onMouseEnter: (event: React.MouseEvent) => void,
89-
onMouseLeave: () => void,
90-
) => {
65+
private renderLegendElement = (item: SeriesLegendItem) => {
66+
const { key, displayValue } = item;
9167
const tooltipValues = this.props.chartStore!.legendItemTooltipValues.get();
9268
let tooltipValue;
9369

94-
if (tooltipValues && tooltipValues.get(legendItemKey)) {
95-
tooltipValue = tooltipValues.get(legendItemKey);
70+
if (tooltipValues && tooltipValues.get(key)) {
71+
tooltipValue = tooltipValues.get(key);
9672
}
9773

98-
const display = tooltipValue != null ? tooltipValue : displayValue.formatted;
99-
const props = { color, label, isSeriesVisible, legendItemKey, displayValue: display };
74+
const newDisplayValue = tooltipValue != null ? tooltipValue : displayValue.formatted;
75+
console.log('renderLegendElement', item.key, item.isLegendItemVisible);
10076

101-
return <LegendItem {...props} key={legendItemKey} onMouseEnter={onMouseEnter} onMouseLeave={onMouseLeave} />;
77+
return (
78+
<LegendItem
79+
{...item}
80+
key={key}
81+
legendItemKey={key}
82+
displayValue={newDisplayValue}
83+
onMouseEnter={this.onLegendItemMouseover(key)}
84+
onMouseLeave={this.onLegendItemMouseout}
85+
/>
86+
);
10287
};
10388
}
10489

src/components/legend/legend_item.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ interface LegendItemProps {
1111
color: string | undefined;
1212
label: string | undefined;
1313
isSeriesVisible?: boolean;
14+
isLegendItemVisible?: boolean;
1415
displayValue: string;
1516
onMouseEnter: (event: React.MouseEvent) => void;
1617
onMouseLeave: () => void;
@@ -44,7 +45,7 @@ class LegendItemComponent extends React.Component<LegendItemProps, LegendItemSta
4445

4546
render() {
4647
const { legendItemKey } = this.props;
47-
const { color, label, isSeriesVisible, displayValue, onMouseEnter, onMouseLeave } = this.props;
48+
const { color, label, isSeriesVisible, isLegendItemVisible, displayValue, onMouseEnter, onMouseLeave } = this.props;
4849

4950
const onTitleClick = this.onVisibilityClick(legendItemKey);
5051

@@ -54,7 +55,9 @@ class LegendItemComponent extends React.Component<LegendItemProps, LegendItemSta
5455
const hasTitleClickListener = Boolean(this.props.chartStore!.onLegendItemClickListener);
5556
const itemClasses = classNames('echLegendItem', {
5657
'echLegendItem-isHidden': !isSeriesVisible,
58+
'echLegendItem__displayValue--hidden': !isLegendItemVisible,
5759
});
60+
5861
return (
5962
<div className={itemClasses} onMouseEnter={onMouseEnter} onMouseLeave={onMouseLeave}>
6063
{this.renderColor(this.toggleColorPicker, color, isSeriesVisible)}

0 commit comments

Comments
 (0)