Skip to content

Commit

Permalink
fix(legend): item hideInLegend prop (#307)
Browse files Browse the repository at this point in the history
Fix `hideInLegend` prop to work again

fix #306
  • Loading branch information
nickofthyme authored Aug 13, 2019
1 parent e11697f commit 3aa5ca3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/components/legend/_legend_item.scss
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
text-align: right;
font-feature-settings: 'tnum';

&.echLegendItem__displayValue--hidden {
&--hidden {
display: none;
}
}
Expand Down
49 changes: 17 additions & 32 deletions src/components/legend/legend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,27 +48,7 @@ class LegendComponent extends React.Component<LegendProps> {
return (
<div className={legendClasses} style={paddingStyle} id={legendId} aria-hidden={legendCollapsed.get()}>
<div className="echLegendListContainer">
<div className="echLegendList">
{[...legendItems.values()].map((item) => {
// const { isLegendItemVisible } = item;

// const legendItemProps = {
// key: item.key,
// className: classNames('echLegendList__item', {
// 'echLegendList__item--hidden': !isLegendItemVisible,
// }),
// onMouseEnter: this.onLegendItemMouseover(item.key),
// onMouseLeave: this.onLegendItemMouseout,
// };

return this.renderLegendElement(
item,
item.key,
this.onLegendItemMouseover(item.key),
this.onLegendItemMouseout,
);
})}
</div>
<div className="echLegendList">{[...legendItems.values()].map(this.renderLegendElement)}</div>
</div>
</div>
);
Expand All @@ -82,23 +62,28 @@ class LegendComponent extends React.Component<LegendProps> {
this.props.chartStore!.onLegendItemOut();
};

private renderLegendElement = (
{ color, label, isSeriesVisible, displayValue }: SeriesLegendItem,
legendItemKey: string,
onMouseEnter: (event: React.MouseEvent) => void,
onMouseLeave: () => void,
) => {
private renderLegendElement = (item: SeriesLegendItem) => {
const { key, displayValue } = item;
const tooltipValues = this.props.chartStore!.legendItemTooltipValues.get();
let tooltipValue;

if (tooltipValues && tooltipValues.get(legendItemKey)) {
tooltipValue = tooltipValues.get(legendItemKey);
if (tooltipValues && tooltipValues.get(key)) {
tooltipValue = tooltipValues.get(key);
}

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

return <LegendItem {...props} key={legendItemKey} onMouseEnter={onMouseEnter} onMouseLeave={onMouseLeave} />;
return (
<LegendItem
{...item}
key={key}
legendItemKey={key}
displayValue={newDisplayValue}
onMouseEnter={this.onLegendItemMouseover(key)}
onMouseLeave={this.onLegendItemMouseout}
/>
);
};
}

Expand Down
5 changes: 4 additions & 1 deletion src/components/legend/legend_item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ interface LegendItemProps {
color: string | undefined;
label: string | undefined;
isSeriesVisible?: boolean;
isLegendItemVisible?: boolean;
displayValue: string;
onMouseEnter: (event: React.MouseEvent) => void;
onMouseLeave: () => void;
Expand Down Expand Up @@ -44,7 +45,7 @@ class LegendItemComponent extends React.Component<LegendItemProps, LegendItemSta

render() {
const { legendItemKey } = this.props;
const { color, label, isSeriesVisible, displayValue, onMouseEnter, onMouseLeave } = this.props;
const { color, label, isSeriesVisible, isLegendItemVisible, displayValue, onMouseEnter, onMouseLeave } = this.props;

const onTitleClick = this.onVisibilityClick(legendItemKey);

Expand All @@ -54,7 +55,9 @@ class LegendItemComponent extends React.Component<LegendItemProps, LegendItemSta
const hasTitleClickListener = Boolean(this.props.chartStore!.onLegendItemClickListener);
const itemClasses = classNames('echLegendItem', {
'echLegendItem-isHidden': !isSeriesVisible,
'echLegendItem__displayValue--hidden': !isLegendItemVisible,
});

return (
<div className={itemClasses} onMouseEnter={onMouseEnter} onMouseLeave={onMouseLeave}>
{this.renderColor(this.toggleColorPicker, color, isSeriesVisible)}
Expand Down

0 comments on commit 3aa5ca3

Please sign in to comment.