Skip to content

Commit

Permalink
Fix legend color mismatch.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecao committed Jan 6, 2022
1 parent 56cf55e commit 5f359b3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion components/metrics/BarChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import { formatLongNumber } from 'lib/format';
import { dateFormat } from 'lib/date';
import useLocale from 'hooks/useLocale';
import useTheme from 'hooks/useTheme';
import useForceUpdate from 'hooks/useForceUpdate';
import { DEFAUL_CHART_HEIGHT, DEFAULT_ANIMATION_DURATION, THEME_COLORS } from 'lib/constants';
import styles from './BarChart.module.css';
import ChartTooltip from './ChartTooltip';
import useForceUpdate from '../../hooks/useForceUpdate';

export default function BarChart({
chartId,
Expand Down
27 changes: 16 additions & 11 deletions components/metrics/Legend.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React from 'react';
import tinycolor from 'tinycolor2';
import classNames from 'classnames';
import Dot from 'components/common/Dot';
import useLocale from 'hooks/useLocale';
import useForceUpdate from 'hooks/useForceUpdate';
import styles from './Legend.module.css';
import useForceUpdate from '../../hooks/useForceUpdate';

export default function Legend({ chart }) {
const { locale } = useLocale();
Expand All @@ -25,16 +26,20 @@ export default function Legend({ chart }) {

return (
<div className={styles.legend}>
{chart.legend.legendItems.map(({ text, fillStyle, datasetIndex, hidden }) => (
<div
key={text}
className={classNames(styles.label, { [styles.hidden]: hidden })}
onClick={() => handleClick(datasetIndex)}
>
<Dot color={fillStyle} />
<span className={locale}>{text}</span>
</div>
))}
{chart.legend.legendItems.map(({ text, fillStyle, datasetIndex, hidden }) => {
const color = tinycolor(fillStyle);

return (
<div
key={text}
className={classNames(styles.label, { [styles.hidden]: hidden })}
onClick={() => handleClick(datasetIndex)}
>
<Dot color={color.setAlpha(color.getAlpha() + 0.2)} />
<span className={locale}>{text}</span>
</div>
);
})}
</div>
);
}

0 comments on commit 5f359b3

Please sign in to comment.