Skip to content
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

fix(legend): item hideInLegend prop #307

Merged
merged 1 commit into from
Aug 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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