From 97afcfbaef9fbb8d122029bafb8707c3353db636 Mon Sep 17 00:00:00 2001 From: sophiamersmann Date: Tue, 5 Mar 2024 09:20:11 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20(slope)=20draw=20tick=20marks=20and?= =?UTF-8?q?=20connecting=20grid=20lines?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../grapher/src/axis/AxisViews.tsx | 46 +++++++++++++++++-- .../grapher/src/slopeCharts/SlopeChart.tsx | 32 +++++++++---- .../src/stackedCharts/StackedBarChart.tsx | 4 +- 3 files changed, 68 insertions(+), 14 deletions(-) diff --git a/packages/@ourworldindata/grapher/src/axis/AxisViews.tsx b/packages/@ourworldindata/grapher/src/axis/AxisViews.tsx index 42c68ffd089..a5664d927f7 100644 --- a/packages/@ourworldindata/grapher/src/axis/AxisViews.tsx +++ b/packages/@ourworldindata/grapher/src/axis/AxisViews.tsx @@ -218,13 +218,25 @@ export class DualAxisComponent extends React.Component { export class VerticalAxisComponent extends React.Component<{ bounds: Bounds verticalAxis: VerticalAxis + showTickMarks?: boolean labelColor?: string tickColor?: string }> { render(): JSX.Element { - const { bounds, verticalAxis, labelColor, tickColor } = this.props + const { bounds, verticalAxis, labelColor, tickColor, showTickMarks } = + this.props const { tickLabels, labelTextWrap } = verticalAxis + const tickMarks = showTickMarks ? ( + + verticalAxis.place(label.value) + )} + tickMarkLeftPosition={bounds.left + verticalAxis.width} + color={SOLID_TICK_COLOR} + /> + ) : undefined + return ( {labelTextWrap && @@ -236,6 +248,7 @@ export class VerticalAxisComponent extends React.Component<{ fill: labelColor || GRAPHER_DARK_TEXT, } )} + {tickMarks} {tickLabels.map((label, i) => { const { y, xAlign, yAlign, formattedValue } = label return ( @@ -309,7 +322,7 @@ export class HorizontalAxisComponent extends React.Component<{ : preferredAxisPosition ?? bounds.bottom const tickMarks = showTickMarks ? ( - axis.place(label.value) @@ -353,7 +366,7 @@ export class HorizontalAxisComponent extends React.Component<{ } } -export class AxisTickMarks extends React.Component<{ +export class HorizontalAxisTickMarks extends React.Component<{ tickMarkTopPosition: number tickMarkXPositions: number[] color: string @@ -379,3 +392,30 @@ export class AxisTickMarks extends React.Component<{ }) } } + +export class VerticalAxisTickMarks extends React.Component<{ + tickMarkLeftPosition: number + tickMarkYPositions: number[] + color: string + width?: number +}> { + render(): JSX.Element[] { + const { tickMarkYPositions, tickMarkLeftPosition, color, width } = + this.props + const tickSize = 5 + const tickRight = tickMarkLeftPosition + tickSize + return tickMarkYPositions.map((tickMarkPosition, index) => { + return ( + + ) + }) + } +} diff --git a/packages/@ourworldindata/grapher/src/slopeCharts/SlopeChart.tsx b/packages/@ourworldindata/grapher/src/slopeCharts/SlopeChart.tsx index b0e9f21e9e3..2c8aa6d9921 100644 --- a/packages/@ourworldindata/grapher/src/slopeCharts/SlopeChart.tsx +++ b/packages/@ourworldindata/grapher/src/slopeCharts/SlopeChart.tsx @@ -1097,16 +1097,28 @@ class LabelledSlopes /> {this.yAxis.tickLabels.map((tick, i) => { + const y = yAxis.place(tick.value) return ( - + + {/* grid lines connecting the chart area to the axis */} + + {/* grid lines within the chart area */} + + ) })} @@ -1114,6 +1126,8 @@ class LabelledSlopes )} diff --git a/packages/@ourworldindata/grapher/src/stackedCharts/StackedBarChart.tsx b/packages/@ourworldindata/grapher/src/stackedCharts/StackedBarChart.tsx index 629dc3bbf37..b01c423a0f9 100644 --- a/packages/@ourworldindata/grapher/src/stackedCharts/StackedBarChart.tsx +++ b/packages/@ourworldindata/grapher/src/stackedCharts/StackedBarChart.tsx @@ -12,7 +12,7 @@ import { } from "@ourworldindata/utils" import { VerticalAxisComponent, - AxisTickMarks, + HorizontalAxisTickMarks, VerticalAxisGridLines, } from "../axis/AxisViews" import { NoDataModal } from "../noDataModal/NoDataModal" @@ -457,7 +457,7 @@ export class StackedBarChart strokeWidth={axisLineWidth} /> - tick.bounds.centerX