Skip to content

Commit db508c4

Browse files
committed
fix(chart): align x-axis labels properly
1 parent a32267a commit db508c4

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

site/src/components/HomeDailyChart/generator/chart-generator.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,12 +320,12 @@ const render = async ({ mobile } = { mobile: false }) => {
320320

321321
const axisStepMinDistance = width * 0.1;
322322
const xAxisPoints = xAxisSteps.reduce((points, stepValue) => {
323-
const idx = Math.min(stepValue, data.chart.length - 1);
323+
const idx = Math.min(stepValue - 1, data.chart.length - 1);
324324
const point: [number, number] = [
325325
x(data.chart[idx].date) as number,
326326
y(data.chart[idx].value) as number,
327327
];
328-
const lastPointX = points[points.length - 1]?.[0] ?? 0;
328+
const lastPointX = points[points.length - 1]?.[0] ?? -Infinity;
329329
// don't allow axis ticks too close together, particularly
330330
// near the right-side end where TODAY takes up more space
331331
if (point[0] < lastPointX + axisStepMinDistance) {

site/src/components/HomeDailyChart/generator/svg-helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ const addAxisTickLabel =
7676
}) => {
7777
svg
7878
.append("text")
79-
.attr("x", x - 10)
79+
.attr("x", x)
8080
.attr("y", height + 30)
8181
.attr("fill", "#777")
8282
.attr("text-anchor", "middle")

0 commit comments

Comments
 (0)