From c5cd96ae7956319cb5b00c3718208b9602406707 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 | 126 ++++++++++-------- 1 file changed, 69 insertions(+), 57 deletions(-) diff --git a/packages/@ourworldindata/grapher/src/slopeCharts/SlopeChart.tsx b/packages/@ourworldindata/grapher/src/slopeCharts/SlopeChart.tsx index 8907d040e79..cf1e6915dec 100644 --- a/packages/@ourworldindata/grapher/src/slopeCharts/SlopeChart.tsx +++ b/packages/@ourworldindata/grapher/src/slopeCharts/SlopeChart.tsx @@ -1143,7 +1143,7 @@ export class SlopeChart private renderSlopes() { return ( - <> + {this.renderSeries.map((series) => ( ))} - + + ) + } + + private renderInteractiveSlopes(): React.ReactElement { + return ( + + + {this.renderSlopes()} + ) } @@ -1178,7 +1199,7 @@ export class SlopeChart const { xDomain, startX, endX } = this return ( - <> + - - ) - } - - private renderChartArea() { - return ( - - {this.renderYAxis()} - {this.renderXAxis()} - - - {this.renderSlopes()} - ) } @@ -1286,6 +1281,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 ( @@ -1299,14 +1318,9 @@ export class SlopeChart ) - return ( - - {this.renderChartArea()} - {this.renderLineLegends()} - {this.renderNoDataSection()} - {this.tooltip} - - ) + return this.manager.isStatic + ? this.renderStatic() + : this.renderInteractive() } } @@ -1338,10 +1352,7 @@ function Slope({ hover.background || focus.background ? 0.66 * strokeWidth : strokeWidth 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" + /> ) })} @@ -1452,7 +1457,14 @@ function MarkX({ }) { return ( <> - +