Skip to content

Commit ff3df78

Browse files
timestamp formatting in XY scatter
1 parent 1de8836 commit ff3df78

2 files changed

Lines changed: 35 additions & 2 deletions

File tree

src/plotxy.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,16 @@ export class PlotXY extends React.Component<PlotXYProps, PlotXYState> {
192192
if (!paramDef) {
193193
return null;
194194
}
195+
if (paramDef.type === ParamType.TIMESTAMP) {
196+
return null;
197+
}
195198
if (paramDef.ticks_format) {
196199
return d3.format(paramDef.ticks_format);
197200
}
198201
const isNumericLike =
199202
paramDef.type === ParamType.NUMERIC ||
200203
paramDef.type === ParamType.NUMERICLOG ||
201-
paramDef.type === ParamType.NUMERICPERCENTILE ||
202-
paramDef.type === ParamType.TIMESTAMP;
204+
paramDef.type === ParamType.NUMERICPERCENTILE;
203205
if (!isNumericLike || typeof scale.domain !== "function") {
204206
return null;
205207
}

tests/hiplot.spec.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,3 +559,34 @@ test("table keeps correct column-value mapping after column reorder and brush up
559559
expect(result.numericCount).toBeGreaterThan(0);
560560
expect(result.uidLikeHexCount).toBe(0);
561561
});
562+
563+
test("plotxy timestamp axis labels are not scientific notation", async ({ page }) => {
564+
await loadDemo(page);
565+
const result = await page.evaluate(async () => {
566+
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
567+
const hiplot = (window as any).hiplot_last_instance;
568+
const plotxy = hiplot?.plugins_ref?.XY?.current;
569+
if (!plotxy || !plotxy.plot) {
570+
return { error: "missing-plotxy" };
571+
}
572+
plotxy.setState({ axis_x: "timestamp" });
573+
await sleep(250);
574+
const axisGroups = Array.from(document.querySelectorAll("svg .axis_render"));
575+
const xAxis = axisGroups[0];
576+
if (!xAxis) {
577+
return { error: "missing-x-axis-group" };
578+
}
579+
const labels = Array.from(xAxis.querySelectorAll(".tick text")).map((el) =>
580+
(el.textContent || "").trim(),
581+
);
582+
const nonEmpty = labels.filter((l) => l.length > 0);
583+
if (nonEmpty.length === 0) {
584+
return { error: "no-tick-labels" };
585+
}
586+
const sciCount = nonEmpty.filter((l) => /e[+-]?\d+/i.test(l)).length;
587+
return { nonEmptyCount: nonEmpty.length, sciCount, labels: nonEmpty.slice(0, 12) };
588+
});
589+
expect(result.error).toBeUndefined();
590+
expect(result.nonEmptyCount).toBeGreaterThan(0);
591+
expect(result.sciCount).toBe(0);
592+
});

0 commit comments

Comments
 (0)