Fix getYTicksByIndex truncating integers by using toFixed

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-09 14:10:09 +08:00
parent 4dbed9fe56
commit c6d073e119
2 changed files with 2 additions and 6 deletions

View File

@@ -76,11 +76,7 @@ const getTimeUnitAndValueToUse = (secondToDecide) => {
* @returns {string} The formatted tick label (e.g. "2.5h").
*/
export function getYTicksByIndex(stepSize, index, unitToUse) {
const rawStepsizeMultIndex = (stepSize * index).toString();
const shortenStepsizeMultIndex = rawStepsizeMultIndex.substring(
0,
rawStepsizeMultIndex.indexOf(".") + 1 + TOFIXED_DECIMAL,
);
const shortenStepsizeMultIndex = (stepSize * index).toFixed(TOFIXED_DECIMAL);
return `${shortenStepsizeMultIndex}${unitToUse}`;
}

View File

@@ -123,7 +123,7 @@ describe("getStepSizeOfYTicks", () => {
describe("getYTicksByIndex", () => {
it("formats tick label with unit", () => {
expect(getYTicksByIndex(2, 3, "h")).toBe("6h");
expect(getYTicksByIndex(2, 3, "h")).toBe("6.0h");
});
it("truncates to 1 decimal place", () => {