Skip to content

Commit 722716f

Browse files
authored
Merge pull request #2364 from visualize-admin/fix/formatting
fix: Tick formatting
2 parents 2d24731 + f607555 commit 722716f

File tree

7 files changed

+45
-32
lines changed

7 files changed

+45
-32
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ You can also check the
1414
- Fixes
1515
- Segmented bar and column charts now correctly display value labels when
1616
downloading an image
17+
- Ticks of X and Y axes in bar and column charts are now correctly formatted
1718

1819
# 5.8.2 - 2025-06-03
1920

app/charts/bar/bars-grouped-state.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -394,11 +394,13 @@ const useBarsGroupedState = (
394394

395395
const isMobile = useIsMobile();
396396

397-
const maybeFormatDate = useCallback(
397+
const formatYAxisTick = useCallback(
398398
(tick: string) => {
399-
return isTemporalDimension(yDimension) ? formatYDate(tick) : tick;
399+
return isTemporalDimension(yDimension)
400+
? formatYDate(tick)
401+
: getYLabel(tick);
400402
},
401-
[yDimension, formatYDate]
403+
[yDimension, formatYDate, getYLabel]
402404
);
403405

404406
// Tooltip
@@ -439,7 +441,7 @@ const useBarsGroupedState = (
439441
yAnchor: yAnchorRaw + (placement.y === "bottom" ? 0.5 : -0.5) * bw,
440442
xAnchor,
441443
placement,
442-
value: maybeFormatDate(yLabel),
444+
value: formatYAxisTick(yLabel),
443445
datum: {
444446
label: fields.segment && getSegmentAbbreviationOrLabel(datum),
445447
value: xValueFormatter(getX(datum)),
@@ -475,7 +477,7 @@ const useBarsGroupedState = (
475477
leftAxisLabelSize,
476478
leftAxisLabelOffsetTop: top,
477479
bottomAxisLabelSize,
478-
formatYAxisTick: maybeFormatDate,
480+
formatYAxisTick,
479481
...variables,
480482
};
481483
};

app/charts/bar/bars-stacked-state.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -465,11 +465,13 @@ const useBarsStackedState = (
465465

466466
const isMobile = useIsMobile();
467467

468-
const maybeFormatDate = useCallback(
468+
const formatYAxisTick = useCallback(
469469
(tick: string) => {
470-
return isTemporalDimension(yDimension) ? formatYDate(tick) : tick;
470+
return isTemporalDimension(yDimension)
471+
? formatYDate(tick)
472+
: getYLabel(tick);
471473
},
472-
[yDimension, formatYDate]
474+
[yDimension, formatYDate, getYLabel]
473475
);
474476

475477
// Tooltips
@@ -512,7 +514,7 @@ const useBarsStackedState = (
512514
yAnchor: yAnchorRaw + (placement.y === "top" ? 0.5 : -0.5) * bw,
513515
xAnchor,
514516
placement,
515-
value: maybeFormatDate(yLabel),
517+
value: formatYAxisTick(yLabel),
516518
datum: {
517519
label: fields.segment && getSegmentAbbreviationOrLabel(datum),
518520
value: xValueFormatter(getX(datum), getIdentityX(datum)),
@@ -546,7 +548,7 @@ const useBarsStackedState = (
546548
isMobile,
547549
normalize,
548550
yScale,
549-
maybeFormatDate,
551+
formatYAxisTick,
550552
]
551553
);
552554

@@ -579,7 +581,7 @@ const useBarsStackedState = (
579581
leftAxisLabelOffsetTop: top,
580582
bottomAxisLabelSize,
581583
valueLabelFormatter,
582-
formatYAxisTick: maybeFormatDate,
584+
formatYAxisTick,
583585
...variables,
584586
};
585587
};

app/charts/bar/bars-state.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,11 +295,13 @@ const useBarsState = (
295295

296296
const isMobile = useIsMobile();
297297

298-
const maybeFormatDate = useCallback(
298+
const formatYAxisTick = useCallback(
299299
(tick: string) => {
300-
return isTemporalDimension(yDimension) ? formatYDate(tick) : tick;
300+
return isTemporalDimension(yDimension)
301+
? formatYDate(tick)
302+
: getYLabel(tick);
301303
},
302-
[yDimension, formatYDate]
304+
[yDimension, formatYDate, getYLabel]
303305
);
304306

305307
// Tooltip
@@ -331,7 +333,7 @@ const useBarsState = (
331333
xAnchor,
332334
yAnchor,
333335
placement,
334-
value: maybeFormatDate(yLabel),
336+
value: formatYAxisTick(yLabel),
335337
datum: {
336338
label: undefined,
337339
value: x !== null && isNaN(x) ? "-" : `${xValueFormatter(getX(d))}`,
@@ -374,7 +376,7 @@ const useBarsState = (
374376
leftAxisLabelSize,
375377
leftAxisLabelOffsetTop: top,
376378
bottomAxisLabelSize,
377-
formatYAxisTick: maybeFormatDate,
379+
formatYAxisTick,
378380
...showValuesVariables,
379381
...variables,
380382
};

app/charts/column/columns-grouped-state.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -395,11 +395,13 @@ const useColumnsGroupedState = (
395395

396396
const isMobile = useIsMobile();
397397

398-
const maybeFormatDate = useCallback(
398+
const formatXAxisTick = useCallback(
399399
(tick: string) => {
400-
return isTemporalDimension(xDimension) ? formatXDate(tick) : tick;
400+
return isTemporalDimension(xDimension)
401+
? formatXDate(tick)
402+
: getXLabel(tick);
401403
},
402-
[xDimension, formatXDate]
404+
[xDimension, formatXDate, getXLabel]
403405
);
404406

405407
// Tooltip
@@ -440,7 +442,7 @@ const useColumnsGroupedState = (
440442
xAnchor: xAnchorRaw + (placement.x === "right" ? 0.5 : -0.5) * bw,
441443
yAnchor,
442444
placement,
443-
value: maybeFormatDate(xLabel),
445+
value: formatXAxisTick(xLabel),
444446
datum: {
445447
label: fields.segment && getSegmentAbbreviationOrLabel(datum),
446448
value: yValueFormatter(getY(datum)),
@@ -476,7 +478,7 @@ const useColumnsGroupedState = (
476478
leftAxisLabelSize,
477479
leftAxisLabelOffsetTop: top,
478480
bottomAxisLabelSize,
479-
formatXAxisTick: maybeFormatDate,
481+
formatXAxisTick,
480482
...variables,
481483
};
482484
};

app/charts/column/columns-stacked-state.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -453,11 +453,13 @@ const useColumnsStackedState = (
453453

454454
const isMobile = useIsMobile();
455455

456-
const maybeFormatDate = useCallback(
456+
const formatXAxisTick = useCallback(
457457
(tick: string) => {
458-
return isTemporalDimension(xDimension) ? formatXDate(tick) : tick;
458+
return isTemporalDimension(xDimension)
459+
? formatXDate(tick)
460+
: getXLabel(tick);
459461
},
460-
[xDimension, formatXDate]
462+
[xDimension, formatXDate, getXLabel]
461463
);
462464

463465
// Tooltips
@@ -499,7 +501,7 @@ const useColumnsStackedState = (
499501
xAnchor: xAnchorRaw + (placement.x === "right" ? 0.5 : -0.5) * bw,
500502
yAnchor,
501503
placement,
502-
value: maybeFormatDate(xLabel),
504+
value: formatXAxisTick(xLabel),
503505
datum: {
504506
label: fields.segment && getSegmentAbbreviationOrLabel(datum),
505507
value: yValueFormatter(getY(datum), getIdentityY(datum)),
@@ -533,7 +535,7 @@ const useColumnsStackedState = (
533535
isMobile,
534536
normalize,
535537
yScale,
536-
maybeFormatDate,
538+
formatXAxisTick,
537539
]
538540
);
539541

@@ -563,7 +565,7 @@ const useColumnsStackedState = (
563565
leftAxisLabelOffsetTop: top,
564566
bottomAxisLabelSize,
565567
valueLabelFormatter,
566-
formatXAxisTick: maybeFormatDate,
568+
formatXAxisTick: formatXAxisTick,
567569
...variables,
568570
};
569571
};

app/charts/column/columns-state.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -294,11 +294,13 @@ const useColumnsState = (
294294
yScale.range([chartHeight, 0]);
295295
const isMobile = useIsMobile();
296296

297-
const maybeFormatDate = useCallback(
297+
const formatXAxisTick = useCallback(
298298
(tick: string) => {
299-
return isTemporalDimension(xDimension) ? formatXDate(tick) : tick;
299+
return isTemporalDimension(xDimension)
300+
? formatXDate(tick)
301+
: getXLabel(tick);
300302
},
301-
[xDimension, formatXDate]
303+
[xDimension, formatXDate, getXLabel]
302304
);
303305

304306
// Tooltip
@@ -327,7 +329,7 @@ const useColumnsState = (
327329
xAnchor,
328330
yAnchor,
329331
placement,
330-
value: maybeFormatDate(xLabel),
332+
value: formatXAxisTick(xLabel),
331333
datum: {
332334
label: undefined,
333335
value: y !== null && isNaN(y) ? "-" : `${yValueUnitFormatter(getY(d))}`,
@@ -353,7 +355,7 @@ const useColumnsState = (
353355
leftAxisLabelSize,
354356
leftAxisLabelOffsetTop: top,
355357
bottomAxisLabelSize,
356-
formatXAxisTick: maybeFormatDate,
358+
formatXAxisTick,
357359
...showValuesVariables,
358360
...variables,
359361
};

0 commit comments

Comments
 (0)