From fdc0fe31c0df86a39a828a6a11945b59df109e92 Mon Sep 17 00:00:00 2001 From: sophiamersmann Date: Fri, 8 Nov 2024 15:42:11 +0100 Subject: [PATCH 1/9] =?UTF-8?q?=E2=9C=A8=20(stacked=20area)=20clean=20up?= =?UTF-8?q?=20hover=20states?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../grapher/src/chart/ChartManager.ts | 2 +- .../grapher/src/facetChart/FacetChart.tsx | 8 +- .../grapher/src/lineCharts/LineChart.tsx | 11 +- .../src/stackedCharts/StackedAreaChart.tsx | 121 ++++++++++-------- .../src/stackedCharts/StackedBarChart.tsx | 6 +- 5 files changed, 80 insertions(+), 68 deletions(-) diff --git a/packages/@ourworldindata/grapher/src/chart/ChartManager.ts b/packages/@ourworldindata/grapher/src/chart/ChartManager.ts index e4116cf0410..d00e2912578 100644 --- a/packages/@ourworldindata/grapher/src/chart/ChartManager.ts +++ b/packages/@ourworldindata/grapher/src/chart/ChartManager.ts @@ -80,7 +80,7 @@ export interface ChartManager { sortConfig?: SortConfig showNoDataArea?: boolean - externalLegendFocusBin?: ColorScaleBin | undefined + externalLegendHoverBin?: ColorScaleBin | undefined disableIntroAnimation?: boolean missingDataStrategy?: MissingDataStrategy diff --git a/packages/@ourworldindata/grapher/src/facetChart/FacetChart.tsx b/packages/@ourworldindata/grapher/src/facetChart/FacetChart.tsx index 8fd30e2bed9..bf54337c070 100644 --- a/packages/@ourworldindata/grapher/src/facetChart/FacetChart.tsx +++ b/packages/@ourworldindata/grapher/src/facetChart/FacetChart.tsx @@ -475,7 +475,7 @@ export class FacetChart const manager = { ...series.manager, useValueBasedColorScheme, - externalLegendFocusBin: this.legendFocusBin, + externalLegendHoverBin: this.legendHoverBin, xAxisConfig: { // For now, sharing an x axis means hiding the tick labels of inner facets. // This means that none of the x axes are actually hidden (we just don't plot their tick labels). @@ -757,15 +757,15 @@ export class FacetChart return newBins } - @observable.ref private legendFocusBin: ColorScaleBin | undefined = + @observable.ref private legendHoverBin: ColorScaleBin | undefined = undefined @action.bound onLegendMouseOver(bin: ColorScaleBin): void { - this.legendFocusBin = bin + this.legendHoverBin = bin } @action.bound onLegendMouseLeave(): void { - this.legendFocusBin = undefined + this.legendHoverBin = undefined } // end of legend props diff --git a/packages/@ourworldindata/grapher/src/lineCharts/LineChart.tsx b/packages/@ourworldindata/grapher/src/lineCharts/LineChart.tsx index 2559f9e8a62..8dc8ab27ee2 100644 --- a/packages/@ourworldindata/grapher/src/lineCharts/LineChart.tsx +++ b/packages/@ourworldindata/grapher/src/lineCharts/LineChart.tsx @@ -550,7 +550,7 @@ export class LineChart seriesIsBlurred(series: LineChartSeries): boolean { return ( - this.isFocusMode && + this.isFocusModeActive && !this.focusedSeriesNames.includes(series.seriesName) ) } @@ -746,7 +746,6 @@ export class LineChart defaultRightPadding = 1 @observable hoveredSeriesName?: SeriesName - @observable private hoverTimer?: NodeJS.Timeout @action.bound onLineLegendMouseOver(seriesName: SeriesName): void { @@ -767,22 +766,22 @@ export class LineChart } @computed get focusedSeriesNames(): string[] { - const { externalLegendFocusBin } = this.manager + const { externalLegendHoverBin } = this.manager const focusedSeriesNames = excludeUndefined([ this.props.manager.entityYearHighlight?.entityName, this.hoveredSeriesName, ]) - if (externalLegendFocusBin) { + if (externalLegendHoverBin) { focusedSeriesNames.push( ...this.series .map((s) => s.seriesName) - .filter((name) => externalLegendFocusBin.contains(name)) + .filter((name) => externalLegendHoverBin.contains(name)) ) } return focusedSeriesNames } - @computed get isFocusMode(): boolean { + @computed get isFocusModeActive(): boolean { return this.focusedSeriesNames.length > 0 } diff --git a/packages/@ourworldindata/grapher/src/stackedCharts/StackedAreaChart.tsx b/packages/@ourworldindata/grapher/src/stackedCharts/StackedAreaChart.tsx index 5ca7f9e4636..d3777f2f36b 100644 --- a/packages/@ourworldindata/grapher/src/stackedCharts/StackedAreaChart.tsx +++ b/packages/@ourworldindata/grapher/src/stackedCharts/StackedAreaChart.tsx @@ -59,25 +59,31 @@ import { AxisConfig } from "../axis/AxisConfig.js" interface AreasProps extends React.SVGAttributes { dualAxis: DualAxis seriesArr: readonly StackedSeries