From 4d1ad2902d377f37f1d05b58d06465f89559cb11 Mon Sep 17 00:00:00 2001 From: Sophia Mersmann Date: Thu, 12 Dec 2024 15:29:41 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20(slope)=20improve=20svg=20output=20?= =?UTF-8?q?for=20figma?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../grapher/src/slopeCharts/SlopeChart.tsx | 128 ++++++++++-------- 1 file changed, 70 insertions(+), 58 deletions(-) diff --git a/packages/@ourworldindata/grapher/src/slopeCharts/SlopeChart.tsx b/packages/@ourworldindata/grapher/src/slopeCharts/SlopeChart.tsx index 99314571805..c815f0d0728 100644 --- a/packages/@ourworldindata/grapher/src/slopeCharts/SlopeChart.tsx +++ b/packages/@ourworldindata/grapher/src/slopeCharts/SlopeChart.tsx @@ -58,7 +58,7 @@ import { } from "../chart/ChartUtils" import { AxisConfig } from "../axis/AxisConfig" import { VerticalAxis } from "../axis/Axis" -import { VerticalAxisComponent } from "../axis/AxisViews" +import { VerticalAxisComponent, VerticalAxisGridLines } from "../axis/AxisViews" import { NoDataSection } from "../scatterCharts/NoDataSection" import { CategoricalColorAssigner } from "../color/CategoricalColorAssigner" import { ColorScheme } from "../color/ColorScheme" @@ -1141,7 +1141,7 @@ export class SlopeChart private renderSlopes() { return ( - <> + {this.renderSeries.map((series) => ( ))} - + + ) + } + + private renderInteractiveSlopes(): React.ReactElement { + return ( + + + {this.renderSlopes()} + ) } @@ -1176,7 +1197,7 @@ export class SlopeChart const { xDomain, startX, endX } = this return ( - <> + - - ) - } - - private renderChartArea() { - return ( - - {this.renderYAxis()} - {this.renderXAxis()} - - - {this.renderSlopes()} - ) } @@ -1284,6 +1279,30 @@ export class SlopeChart ) } + private renderInteractive(): React.ReactElement { + return ( + <> + {this.renderYAxis()} + {this.renderXAxis()} + {this.renderInteractiveSlopes()} + {this.renderLineLegends()} + {this.renderNoDataSection()} + {this.tooltip} + + ) + } + + private renderStatic(): React.ReactElement { + return ( + <> + {this.renderYAxis()} + {this.renderXAxis()} + {this.renderSlopes()} + {this.renderLineLegends()} + + ) + } + render() { if (this.failMessage) return ( @@ -1297,14 +1316,9 @@ export class SlopeChart ) - return ( - - {this.renderChartArea()} - {this.renderLineLegends()} - {this.renderNoDataSection()} - {this.tooltip} - - ) + return this.manager.isStatic + ? this.renderStatic() + : this.renderInteractive() } } @@ -1334,10 +1348,7 @@ function Slope({ : NON_FOCUSED_LINE_COLOR return ( - + {showOutline && ( { const y = yAxis.place(tick.value) return ( - - - + x1={bounds.left + yAxis.width} + y1={y} + x2={bounds.right} + y2={y} + stroke="#ddd" + strokeDasharray="3,2" + /> ) })} @@ -1448,7 +1453,14 @@ function MarkX({ }) { return ( <> - +