Skip to content

Commit

Permalink
✨ (slope) improve svg output for figma
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiamersmann committed Dec 12, 2024
1 parent 8e8cc62 commit 4d1ad29
Showing 1 changed file with 70 additions and 58 deletions.
128 changes: 70 additions & 58 deletions packages/@ourworldindata/grapher/src/slopeCharts/SlopeChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Check warning on line 61 in packages/@ourworldindata/grapher/src/slopeCharts/SlopeChart.tsx

View workflow job for this annotation

GitHub Actions / eslint

'VerticalAxisGridLines' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 61 in packages/@ourworldindata/grapher/src/slopeCharts/SlopeChart.tsx

View workflow job for this annotation

GitHub Actions / eslint

'VerticalAxisGridLines' is defined but never used. Allowed unused vars must match /^_/u
import { NoDataSection } from "../scatterCharts/NoDataSection"
import { CategoricalColorAssigner } from "../color/CategoricalColorAssigner"
import { ColorScheme } from "../color/ColorScheme"
Expand Down Expand Up @@ -1141,7 +1141,7 @@ export class SlopeChart

private renderSlopes() {
return (
<>
<g id={makeIdForHumanConsumption("slopes")}>
{this.renderSeries.map((series) => (
<Slope
key={series.seriesName}
Expand All @@ -1151,7 +1151,28 @@ export class SlopeChart
outlineStroke={this.backgroundColor}
/>
))}
</>
</g>
)
}

private renderInteractiveSlopes(): React.ReactElement {
return (
<g
ref={this.slopeAreaRef}
onMouseMove={this.onMouseMove}
onTouchMove={this.onMouseMove}
onTouchStart={this.onMouseMove}
onMouseLeave={this.onMouseLeave}
>
<rect
x={this.startX}
y={this.bounds.y}
width={this.endX - this.startX}
height={this.bounds.height}
fillOpacity={0}
/>
{this.renderSlopes()}
</g>
)
}

Expand All @@ -1176,7 +1197,7 @@ export class SlopeChart
const { xDomain, startX, endX } = this

return (
<>
<g id={makeIdForHumanConsumption("horizontal-axis")}>
<MarkX
label={this.formatColumn.formatTime(xDomain[0])}
x={startX}
Expand All @@ -1193,32 +1214,6 @@ export class SlopeChart
labelPadding={this.xLabelPadding}
fontSize={this.yAxis.tickFontSize}
/>
</>
)
}

private renderChartArea() {
return (
<g>
{this.renderYAxis()}
{this.renderXAxis()}
<g
id={makeIdForHumanConsumption("slopes")}
ref={this.slopeAreaRef}
onMouseMove={this.onMouseMove}
onTouchMove={this.onMouseMove}
onTouchStart={this.onMouseMove}
onMouseLeave={this.onMouseLeave}
>
<rect
x={this.startX}
y={this.bounds.y}
width={this.endX - this.startX}
height={this.bounds.height}
fillOpacity={0}
/>
{this.renderSlopes()}
</g>
</g>
)
}
Expand Down Expand Up @@ -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 (
Expand All @@ -1297,14 +1316,9 @@ export class SlopeChart
</>
)

return (
<g>
{this.renderChartArea()}
{this.renderLineLegends()}
{this.renderNoDataSection()}
{this.tooltip}
</g>
)
return this.manager.isStatic
? this.renderStatic()
: this.renderInteractive()
}
}

Expand Down Expand Up @@ -1334,10 +1348,7 @@ function Slope({
: NON_FOCUSED_LINE_COLOR

return (
<g
id={makeIdForHumanConsumption("slope", displayName)}
className="slope"
>
<g id={makeIdForHumanConsumption(displayName)} className="slope">
{showOutline && (
<LineWithDots
startPoint={startPoint}
Expand Down Expand Up @@ -1409,22 +1420,16 @@ function GridLines({ bounds, yAxis }: GridLinesProps) {
{yAxis.tickLabels.map((tick) => {
const y = yAxis.place(tick.value)
return (
<g
id={makeIdForHumanConsumption(
"grid-line",
tick.formattedValue
)}
<line
id={makeIdForHumanConsumption(tick.formattedValue)}
key={tick.formattedValue}
>
<line
x1={bounds.left + yAxis.width}
y1={y}
x2={bounds.right}
y2={y}
stroke="#ddd"
strokeDasharray="3,2"
/>
</g>
x1={bounds.left + yAxis.width}
y1={y}
x2={bounds.right}
y2={y}
stroke="#ddd"
strokeDasharray="3,2"
/>
)
})}
</g>
Expand All @@ -1448,7 +1453,14 @@ function MarkX({
}) {
return (
<>
<line x1={x} y1={top} x2={x} y2={bottom} stroke="#999" />
<line
id={makeIdForHumanConsumption(label)}
x1={x}
y1={top}
x2={x}
y2={bottom}
stroke="#999"
/>
<text
x={x}
y={bottom + labelPadding}
Expand Down

0 comments on commit 4d1ad29

Please sign in to comment.