:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(charts): keep fractional y-axis tick labels distinct (#89855)
Sam Pennington657b452b70bf
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 0b11a5b933f9..b54ceb0bd446 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -701,9 +701,9 @@ snapshots:components-hogcharts-combochart--dual-y-axis-bar-and-line--light:hash: v1.k794b7964.bb896cfe5e38de470ae51a45952265afa1e49d050e7e6f8ccde53ecaaf3d6dec.U2Fnts1YVtnj0ybLM8rEMuMvrjttJ-Mutt1Css4jdfgcomponents-hogcharts-combochart--empty--dark:- hash: v1.k794b7964.5e2418901314a92d0a0eee5aacba4498f5f90d99c4036d2c2cf5536165e2faba.GGCzCvLTxtWNGfctTt9MXcrGaxkfHkIIF_IpcEzE-CM+ hash: v1.k794b7964.3075a07543d3a2b6ba2dbcc7cc28e8a5d869180ffca19c2482a6a01a92defa76.rZ6Dut57u1RBZzHDBmS0xHVmWs8Q09idcUD4M7yE8cgcomponents-hogcharts-combochart--empty--light:- hash: v1.k794b7964.1cc4abb6ea1b8cca00721fcdeb2cd02d42810843ce6cc46c7922bd430882fc2c.WVU5T3SpbBzdTAvSdQevowdbwM_DcK21Rz8sAvY4TGU+ hash: v1.k794b7964.451ee286ae0a820c29a67715f6bde8fb44b3b78b64150e370a61573da8194f9d.k6L-Li2F8lU0tDvf8ZBZiyu47I5oFXRFdTL0JMSIHhIcomponents-hogcharts-combochart--grouped-bars-and-line--dark:hash: v1.k794b7964.0559b410cec5572e82240f4b673fa5cfbfb564574a13b851f0d11e9fc6e88987.PNySTn-8lz0Gb9Qlh5uYT3-SfoFM-FRNGIDPlcP-LdEcomponents-hogcharts-combochart--grouped-bars-and-line--light:@@ -813,9 +813,9 @@ snapshots:components-hogcharts-linechart--dual-y-axis--light:hash: v1.k794b7964.963951c3d892093c039818f639c2f047e0c6e67b56bffd16c94d2d75074bfd41.H0wvH80GEBbF4nAVbQ1Z0LhrXabZZxhc0spQ4UEB6sEcomponents-hogcharts-linechart--empty--dark:- hash: v1.k794b7964.5e2418901314a92d0a0eee5aacba4498f5f90d99c4036d2c2cf5536165e2faba.125GZWTSCwazRjwESWd3rDBG2hVpaAaKVe0qEw01-UE+ hash: v1.k794b7964.3075a07543d3a2b6ba2dbcc7cc28e8a5d869180ffca19c2482a6a01a92defa76.BdRS_jXsz_wF07DP4QF69Lq8G6_qop4wdxhEDTvE7NUcomponents-hogcharts-linechart--empty--light:- hash: v1.k794b7964.1cc4abb6ea1b8cca00721fcdeb2cd02d42810843ce6cc46c7922bd430882fc2c.gjsFmqn_u61-MmVialGYWoYSi4QrqTQYWavzbK_fS50+ hash: v1.k794b7964.451ee286ae0a820c29a67715f6bde8fb44b3b78b64150e370a61573da8194f9d.xbsGYrJdw-qVXK0w3YjtXRgi50ICscYojXCpblNKEgUcomponents-hogcharts-linechart--error-boundary--dark:hash: v1.k794b7964.7ffed111d1467ff1155a14f8767c7dab3fd7f5d50959340d947996dd84c11fd3.kY97jQr9ekIVuPU_k6xzO-95pWMageVS9L5Mt5FN_Nwcomponents-hogcharts-linechart--error-boundary--light:@@ -6157,9 +6157,9 @@ snapshots:scenes-app-batchexports--logs--light:hash: v1.k794b7964.e265553d5c243631fced861ca2dbb10efc1a88319e202fc9aa9086b61d8ee874.1VMGmnsHciZgtC1WSGUths4rtSma-Q4iCefG3RpNXSkscenes-app-batchexports--metrics--dark:- hash: v1.k794b7964.98ee7a9dec55ed8685f3ebd033fba9bde0435881d71fd6c260711b3061ad456c.lBD7LI0wObN6jxEH2N8xO9SoJ-Hgscou5eKffDEMvS0+ hash: v1.k794b7964.8059910f3c736e118ff46e610822c78e6e7a53bcb5b8579fe68bcb90a5bd74bd.OEMLVw9I74hihuIrJ_2RfFQOtjwWHkV1ypZYM9wmdP8scenes-app-batchexports--metrics--light:- hash: v1.k794b7964.1c2fb9dc1d82caf47348260815675680ba3c3961fe8a76571209271d69b8831b.ITESrPcN--JfW91s4W40L3aZjHaQuRaTrrKzJQ_xFyg+ hash: v1.k794b7964.10f81ce3e49d6479547a131bd57f15a9549caa0ba2a6411b7262cad22a7f25bf.hkgM7Ev7IxkhOsLKI0l50gpOYO63JczEC3Xwuhw8n1Escenes-app-batchexports--new-aws-s-3-export--dark:hash: v1.k794b7964.7b9a43632c140e2b448a80e77e5a76a35369164cfb146c46d6802eba8dff9890.qePrTrYjvW-8vY773v6YmBU8mx0u3179FEYHinwS35Uscenes-app-batchexports--new-aws-s-3-export--light:@@ -6523,7 +6523,7 @@ snapshots:scenes-app-data-pipelines-event-filtering--at-max-depth--dark:hash: v1.k794b7964.0635bf387f78912da289283f3ca7a2262d1e743c75aef25f2db572d8b2e3b98b.arP2515vrqFQ7wq3ZvYFmpfTIyp6bZGvmtFuAdhERpEscenes-app-data-pipelines-event-filtering--at-max-depth--light:- hash: v1.k794b7964.0a8e128953d1c9c8496936f89490afa5dc5e38b176195001264f5167957bb111.sAfeYudNxdE51vnz1DVzkVcWj7lfHDZVxv-rtjtsD0E+ hash: v1.k794b7964.6cd0a04e2f94d514da7e5f9dd9a7afa28feb04f34beb11edbde5d7df477d1676.u_fpV7r8_X2p2HvWKd7ScaLYLp9mL9napChs44bx2Qwscenes-app-data-pipelines-event-filtering--build-filter-from-scratch--dark:hash: v1.k794b7964.69aeaa3a34b5ca4f4e786bef8aba9b9b3b0addb2da889dbe20e690af3a037caa.SOD-8vDaf-X9ZjsRtsWQeezUT0jqgJniCNY7Y4sGu9cscenes-app-data-pipelines-event-filtering--build-filter-from-scratch--light:@@ -6535,7 +6535,7 @@ snapshots:scenes-app-data-pipelines-event-filtering--disabled-with-conditions--dark:hash: v1.k794b7964.9124bb162fc62f2ad5cd586bbda7a7a6474d1043dce2ab1ce4bb5450abebc593.UP2YAsE2jZT-0ZtwdzRXLsniU_j5tbZLXtuDSzCH_8Escenes-app-data-pipelines-event-filtering--disabled-with-conditions--light:- hash: v1.k794b7964.b629a7448261f358fc4258d50772ae1354ef1e1635b6f334f40d2540e95bc74d.5yB99fkS2d5LZlRzZ2AqHpLqB8jE-E0ra27i14w_s8o+ hash: v1.k794b7964.9d068a45324c80135071f98d3a60d463f89c834832e01f0c6038ad492a5b9f5e.iGAwM3YPdMFK5EH8W_stIppa4v7DLPlI3td6WaUsQKIscenes-app-data-pipelines-event-filtering--dry-run-with-tests--dark:hash: v1.k794b7964.ce754080430554152857a626725248ce2361ae098f53bceaee8d7c46ee413cbf.yi_G_piLj-9lzZ_pqD5P0IK10PsbusqCNlVrzF-XyKUscenes-app-data-pipelines-event-filtering--dry-run-with-tests--light:@@ -6543,7 +6543,7 @@ snapshots:scenes-app-data-pipelines-event-filtering--empty-groups-in-tree--dark:hash: v1.k794b7964.3b1768713040aae6f365d182cda38dc347e4d329d08fe14bcb2fbbb05ea5364e.gVRUpdnQYBF_s18IRo6wrwJVzVG71ACjKjRyc0prJjAscenes-app-data-pipelines-event-filtering--empty-groups-in-tree--light:- hash: v1.k794b7964.b7209cb8d0382a2865b907986f3515bcf4634869a1b5018eee04d213ec3ed886.MY4KKmhZlJWGqOZgj2ivbgkrOr7WGpNLstMUNA4b09E+ hash: v1.k794b7964.98e8b0de707a74c150f22f77bf133af58b9a38c128fb38f57a3c15b487246137.s6ZocPjbTqRcp7yyDDLVl3J8U--86WuQtABQRKIbZR4scenes-app-data-pipelines-event-filtering--empty-state--dark:hash: v1.k794b7964.a6f4331fbe7c125de05c6fc36f2806969d108f6ae11cd2e09bd59f77ab7bb32d.DGVEs_CqPEMPdk0sX6IbBogAH7a0CgD0lgz59BFoxloscenes-app-data-pipelines-event-filtering--empty-state--light:@@ -6555,7 +6555,7 @@ snapshots:scenes-app-data-pipelines-event-filtering--fix-failing-test-and-go-live--dark:hash: v1.k794b7964.53ea698952f14778b0ff72b30809d62279957cbfdbfc3c83aebe363a58b59f8d.jz1RQ2AGvSAPzlrB0uqUB2McPSTAs9d4JwQneQEyBgEscenes-app-data-pipelines-event-filtering--fix-failing-test-and-go-live--light:- hash: v1.k794b7964.087e46f31e5345ddc996a378af9e7de7bef65b20e34feda26853326980f6b20f.7m2ABXiptJ170Xyju0Uw28KGTlofVDFeXcrdEWppepE+ hash: v1.k794b7964.05d15ceb10810a133116441388ee0111d0ae1ab1f2ba779308cf138f15cdcbdc.RjcRu5pT6KkpHpTGDG3vOPmgWFivDzsVHuL1H1taJ8wscenes-app-data-pipelines-event-filtering--live-mode--dark:hash: v1.k794b7964.7be14e056ed591baf85ba6ad2e9f1e05ac987c67fae76ec8357469328cac0a44.JrxvrO5_vKadWU9TzVx9ZNzBES7NIiIsGGX2i8o28Vcscenes-app-data-pipelines-event-filtering--live-mode--light:@@ -6563,7 +6563,7 @@ snapshots:scenes-app-data-pipelines-event-filtering--many-conditions--dark:hash: v1.k794b7964.d9266229388042ccfd488ccf006b7a874993730a8dc95c59f04d2ca09178a35c.wuElmCY8MXnW8Pu6pZxur9gbsbO4_aKjN5MouBvBnM0scenes-app-data-pipelines-event-filtering--many-conditions--light:- hash: v1.k794b7964.6883a93a012b15e5c8836d57cb36fbe2fa25ab8653e0563a7e3d7dec608a4d1a.A93sxoCSvKnbVCB7tjhfNPN3rFutyP61ni87gk2TIiI+ hash: v1.k794b7964.0c5632f7ca29b9da6e30feca7028ccae5b46ebc837bb5ab0c305345b3c05d27f.RxhZiWGVY0ip5PHJ9DgfYR3ETb10PvqBe9yN55Xt1Ugscenes-app-data-pipelines-event-filtering--many-test-cases--dark:hash: v1.k794b7964.6682e903c8d02abeb22dd1b471492e6a054569d63bba5f3a1a63dd470191854e.dNeaFevJVrVD4hseDqmv85LUPZNypAS4msPO1gBHj_Uscenes-app-data-pipelines-event-filtering--many-test-cases--light:@@ -6571,7 +6571,7 @@ snapshots:scenes-app-data-pipelines-event-filtering--not-wrapped-condition--dark:hash: v1.k794b7964.9cb5c5cfc1b75fa1438625d8da90aedc071c763e352c80f9a630d52c125319c3.3J9wzQTEq1KLhxkzx_nSau3tVTW9EM1cb5CjkJdrBHMscenes-app-data-pipelines-event-filtering--not-wrapped-condition--light:- hash: v1.k794b7964.6208018d81a5b15e9d2d959c186b0859d6b43c93874d1f66fa5979adc2246684.xztEfjjM8ImA9FIm7MLFzOfCB8iJEFyUJAd0iGHtwf0+ hash: v1.k794b7964.2d8356c43aabb1dbf74bf076925aa7359fe8d4508f98d6abf8ec4f0f2e283277.UXN7DM7i_ExYiwVxdR__wqay2BCXorueEF8uz04QP-0scenes-app-data-pipelines-event-filtering--open-ascii-modal--dark:hash: v1.k794b7964.55af0528336c74024926b6505476ddc55f49fbbdaa111a391abccc48eced2b15.o93dH2_UXK7mEvcovEE0VoNvWh3zaTr978k2GB6j-0oscenes-app-data-pipelines-event-filtering--open-ascii-modal--light:@@ -6583,15 +6583,15 @@ snapshots:scenes-app-data-pipelines-event-filtering--single-condition--dark:hash: v1.k794b7964.2b1bea4d9073dac6061c72a96384b1def4d0005a22b788f6c9457aac7871a890.2DlhrN5RfDJIxKCXP4s7UzoQsPWQMWFnCPSaqS8xNHUscenes-app-data-pipelines-event-filtering--single-condition--light:- hash: v1.k794b7964.0aa5da7d616d7fb5f383cdcae2ff016d2ca23131b43c67e8d6d9528910e5fc75.lXzPNBRlCRhzOy-164aV8c8FsozJpjoCT1ti-vhNTWA+ hash: v1.k794b7964.f7a21e6295d125cda374b022d54835336e4fa5e0734277199b3630d4e7252d32.wqrwzBMO5bNQGzXQYNgNM0K1AP9QJRa1ItJNu_grse4scenes-app-data-pipelines-event-filtering--single-condition-root-is-editable--dark:- hash: v1.k794b7964.de0c6ccb695e0592b1c5181a4efeb6302c0946e7e504df60a7ffa67cb53620d0.Duy5mTqtbgpZ3PTResaqcET7v_pPPPNq2n-q4Y4HnAw+ hash: v1.k794b7964.95f7c399a6f5b676224307269009b8b1617d66519261848926652ee38e7a2fca.8rYFHXIiq3hVCpCqL570VkYqZC_D2MMPoGPHZWQbsZgscenes-app-data-pipelines-event-filtering--single-condition-root-is-editable--light:- hash: v1.k794b7964.fd8e457273a7a8ec7cf07f7435d95c993eba92b25b7fb4cdd517d1ab0de4031f.jr6nQ3P_l02YO8rnfvFVq2rUMSjfZIOmuGYwss0KcqE+ hash: v1.k794b7964.2426d7c2856fe1584415af7ce98d3c6ff9ac9f7a2f33f1254668554e8a3d6715.-BIPbD3doaRGFZRJrjNaxS5kSLBUqr5c37u0wLFGtxMscenes-app-data-pipelines-event-filtering--switch-mode-to-dry-run--dark:hash: v1.k794b7964.f90080b48e02650b50bee9d714dc226f41aec9108a4878a67abccc18735aa7a2.9vBFfiHItb00dBAS4YWq2EugPAeQUVjYFkobGWL8pHEscenes-app-data-pipelines-event-filtering--switch-mode-to-dry-run--light:- hash: v1.k794b7964.3708d5dd091da98ff4fe36c820270151d0fbd4a5cec31afa03956f1a85bfefa4.96jKaZE5nf0iQjd6-CQo8JSaAcQ64JssqLmmwhMs5cM+ hash: v1.k794b7964.ac76cb9e4e3fb7b45c5feadceb9e14744becd1935a7a6bbe7f5f775a7d3ef9e2.z3k9FQwdN9CDRW-qb07bLD5FTh2wGHdRVMhKL9Fbzmsscenes-app-data-warehouse-query-index-usage--every-filter-indexed--dark:hash: v1.k794b7964.5593a848fb86d8d93d2d347b17de81b878cff3e9d69ccf976562e60bddeb71fa.-EnSwW5B20DYmE0dRl-8VfENfxJMJrMl-vWmmkJ1sG0scenes-app-data-warehouse-query-index-usage--every-filter-indexed--light:@@ -8197,9 +8197,9 @@ snapshots:scenes-app-replay-vision--scanner-alerts-empty--light:hash: v1.k794b7964.0ef826b7658d0bd8ccaa3089d76cea2a4410b4124c3c81b957af439d5f9f549d.lEAwMkjqNuZhxqmK2y8cKPkc1lC8wUIQUJHmY9-04UYscenes-app-replay-vision--scanner-calibration--dark:- hash: v1.k794b7964.f89638a02ebc9db1e2c8190b6f8f794fa2036c981b0d0e7e2fc624fc516f5534.lwjllffOrBWrn8bTeGlPquS5J-3lfWzUK4noVI9jIDc+ hash: v1.k794b7964.a26243a987e2b4895534fbeac048c77cc74fb9d58868784d82290e0c996cf565.n4HkfbUGlqGqgpy--Qo849HfSM-EZkm204m2dgcVRF0scenes-app-replay-vision--scanner-calibration--light:- hash: v1.k794b7964.d5a443d0773fa20d70d606d7f255ea5be360145e382d76d895e3c15aca9d9025.zUac10pNPYiW6S7iFqIWW3hiKOSWDU7E8ocdGd6H7PQ+ hash: v1.k794b7964.cdf91ec4504fccf3ccfae307f7e22fadcc244b5a6ac23f3e87c2b0ed5eeb06f5.wsou90F9Zx4JAQtKBZ7hW7bqb6rkNC8NHLTUwfZg7M0scenes-app-replay-vision--scanner-configuration--dark:hash: v1.k794b7964.4596bbf4c6a43f0c735477d4a63b40aab754676d777ee5a4e93aaf480cd96bfe.J9MGM9riSXhFjfBTCC8UbnT5e323clk16BfpggM2Tykscenes-app-replay-vision--scanner-configuration--light:diff --git a/packages/quill/packages/charts/AGENTS.md b/packages/quill/packages/charts/AGENTS.mdindex b7747e31e951..6346720273f4 100644--- a/packages/quill/packages/charts/AGENTS.md+++ b/packages/quill/packages/charts/AGENTS.md@@ -100,7 +100,7 @@ Safari is the exception: it never fires `contextrestored`, so a context lost the- The composable form of `MetricCard` lives one layer up as `Metric` in `@posthog/quill-components` (it needs `Card`/`Badge` from primitives, which charts can't depend on). It's built on `Sparkline` plus the headless metric helpers this package exports — `resolveDelta` / `computeFallbackChangePercent` (delta math), `useAnimatedNumber` (count-up headline), `useHoverIntent` (hover dwell) — and the `MetricChange` / `ResolvedDelta` types. Reach for `Metric` when you need a custom layout; use the monolithic `MetricCard` here for the default self-contained tile.- `TimeSeriesComboChart` wraps `ComboChart` the way `TimeSeriesLineChart`/`TimeSeriesBarChart` wrap their base charts: `config.xAxis`/`config.yAxis` (date tick formatter, y-format, scale, grid), `config.goalLines` (off-scale targets stretch the value axis via `ComboChart`'s `valueDomain`), `config.legend` (click-to-toggle), and `config.valueLabels`. Per-series `type` (`'bar' | 'line' | 'area'`) drives rendering; `barLayout` (`'stacked' | 'grouped' | 'percent'`), `divergingStack` (stacked only — negative bar values stack below the zero baseline instead of being clamped to 0, same semantics as `BarsConfig.divergingStack`), and right-axis series (`yAxisId: 'right'`) carry over from `ComboChart`. `ComboChart` itself now also honors `valueDomain` (primary axis only) and `showAxisLines`.- `TimeSeriesBarChart` also takes `config.valueDomain` (same `ValueDomain` semantics as `BarChartConfig.bars.valueDomain`): setting both `min` and `max` skips `d3.nice()` and wins over the goal-line stretch — pin `{ min: 0, max: dataMax }` so the tallest bar reaches the plot top on an axis-less volume chart, where nice-rounded headroom is invisible waste; `include` merges with the goal-line stretch (`mergeValueDomains` in `utils/goal-lines.ts`).-- y-axis `format`: `numeric | short | percentage | percentage_scaled | currency | duration | duration_ms | duration_ns`, plus `prefix`/`suffix`. Numeric and percentage ticks default to two decimals but gain a decimal per leading zero below 0.1, so a small-valued axis (say latency in seconds over 0–0.012) doesn't render every tick as `0.01`; `decimalPlaces` pins the precision instead. The duration formats keep three significant digits below a minute for the same reason, then switch to the `1m 30s` unit breakdown.+- y-axis `format`: `numeric | short | percentage | percentage_scaled | currency | duration | duration_ms | duration_ns`, plus `prefix`/`suffix`. Without a `format` or `tickFormatter`, the axis uses the fewest uniform decimal places that keep its generated ticks distinct. Numeric and percentage formats default to two decimals but gain a decimal per leading zero below 0.1, so a small-valued axis (say latency in seconds over 0–0.012) doesn't render every tick as `0.01`; `decimalPlaces` pins the precision instead. The duration formats keep three significant digits below a minute for the same reason, then switch to the `1m 30s` unit breakdown.- Fixed x-axis tick rotation: set `xAxis.tickLabelRotation` on a time-series chart (`-45` tilts labels left). Values are clamped to `-90..90`; omit it to keep horizontal labels and existing collision behavior.- y-axis baseline: defaults to clamping a non-negative axis down to 0 (matching the classic insight axis). To float the axis to its data range instead — zooming in on the variation — set `yAxis.startAtZero: false` on `TimeSeriesLineChart`, or `config.floatBaseline: true` on the lower-level `LineChart`. Ignored on a log scale (no zero baseline) and applied to the primary axis only. Bar charts always draw from a zero baseline, so the flag is a no-op there.- y-axis min/max: `yAxis.min` / `yAxis.max` pin either end of a value axis on `TimeSeriesLineChart` (the primary one here; see the multi-axis entry below for secondary axes) (`config.valueDomain: { min, max }` on the lower-level `LineChart` — the same option that carries `include`, since a capped axis still has to stretch to reach an off-scale goal line; `mergeValueDomains` combines them field by field). How many ends are set decides the behavior: **both** pins the axis (skips `nice()`, discards `include`, overrides percent layout), **one** clamps that end and leaves the other automatic. A single clamp composes with auto-scaling — it runs after `include` folding, the zero-baseline clamp and `nice()`, so only the extreme label is the raw bound while interior ticks stay round — and is ignored under a percent layout, where the domain is already 0..1. On a log scale a non-positive bound is dropped. A non-finite bound counts as unset, so `{ min: 0, max: Math.max(...[]) }` floors at zero rather than collapsing. An inverted `min >= max` pair falls back to the automatic domain rather than swapping. Overlays positioned off the value scale hide themselves outside the bounded window rather than painting over the chrome: a goal line drops out, and so does the value label of a clipped point (a point sitting exactly on the bound keeps its label). Bar and combo charts deliberately ignore `min`/`max`, even though they take the same `yAxis` config: a bar encodes magnitude as length from zero, so a bounded baseline misreads it — 10 vs 11 would draw as 1 vs 2. Pin `valueDomain` there instead, which rescales the bars rather than truncating them.diff --git a/packages/quill/packages/charts/src/core/hooks/useChartMargins.ts b/packages/quill/packages/charts/src/core/hooks/useChartMargins.tsindex dc03f1a69d1f..4ca52ca9c28b 100644--- a/packages/quill/packages/charts/src/core/hooks/useChartMargins.ts+++ b/packages/quill/packages/charts/src/core/hooks/useChartMargins.ts@@ -122,8 +122,8 @@ function categoryLabelWidths(function widestValueLabelWidth(series: Series[], yTickFormatter: ((value: number) => string) | undefined): number {const range = seriesValueRange(series)- // No data: the scale falls back to a [0, 1] domain (see `buildValueScale`), whose ticks render- // as "0.00".."1.00". Measure those so the empty-state margin still fits its labels — returning 0+ // No data: the scale falls back to a [0, 1] domain (see `buildValueScale`), whose automatic ticks+ // render as "0".."1". Measure those so the empty-state margin still fits its labels — returning 0// here collapses the margin to its floor and clips the labels against the wrapper's overflow.const [min, max] = range.count === 0 ? [0, 1] : [range.min > 0 ? 0 : range.min, range.max < 0 ? 0 : range.max]const ticks = scaleLinear().domain([min, max]).nice(6).ticks(6)diff --git a/packages/quill/packages/charts/src/core/scales.test.ts b/packages/quill/packages/charts/src/core/scales.test.tsindex 382c633bcbe1..7a7ceec3b350 100644--- a/packages/quill/packages/charts/src/core/scales.test.ts+++ b/packages/quill/packages/charts/src/core/scales.test.ts@@ -1,7 +1,7 @@import { dimensions, makeSeries } from '../testing'import {applyValueBounds,- autoFormatYTick,+ autoFormatterFor,buildSegmentResolveValue,buildStackedPositionValue,computeDivergingStackData,@@ -832,43 +832,49 @@ describe('hog-charts scales', () => {})})- describe('autoFormatYTick', () => {+ describe('autoFormatterFor', () => {it.each([- { domainMax: 0, value: 0.5, expected: '0.50', label: 'two decimal places when domainMax < 2' },- { domainMax: 1, value: 0.123, expected: '0.12', label: 'two decimal places when domainMax equals 1' },- { domainMax: 1.99, value: 1.5, expected: '1.50', label: 'two decimal places when domainMax is 1.99' },- { domainMax: 2, value: 3.5, expected: '3.5', label: 'one decimal place when domainMax equals 2' },- { domainMax: 4.99, value: 2.7, expected: '2.7', label: 'one decimal place when domainMax is 4.99' },- { domainMax: 5, value: 42, expected: '42', label: 'no decimal places when domainMax equals 5' },- { domainMax: 1000, value: 999, expected: '999', label: 'no decimal places when domainMax is large' },- { domainMax: 10000, value: 1234, expected: '1,234', label: 'adds thousands separator' },{- domainMax: 1000000,- value: 123456,- expected: '123,456',- label: 'adds thousands separators for large values',+ label: 'integer ticks need no decimals',+ ticks: [0, 1, 2, 3, 4, 5],+ expected: ['0', '1', '2', '3', '4', '5'],},- ])('returns $expected: $label', ({ domainMax, value, expected }) => {- expect(autoFormatYTick(value, domainMax)).toBe(expected)- })-- it.each([- { domainMax: 0.012, value: 0.012, expected: '0.012' },- { domainMax: 0.012, value: 0.002, expected: '0.002' },- { domainMax: 0.0005, value: 0.0001, expected: '0.0001' },- ])(- 'scales precision to the domain so small ticks stay distinct: $value over 0–$domainMax → $expected',- ({ domainMax, value, expected }) => {- expect(autoFormatYTick(value, domainMax)).toBe(expected)- }- )-- it('formats zero correctly when domainMax is large', () => {- expect(autoFormatYTick(0, 100)).toBe('0')+ {+ label: 'half-step ticks get one uniform decimal',+ ticks: [0, 0.5, 1, 1.5, 2],+ expected: ['0.0', '0.5', '1.0', '1.5', '2.0'],+ },+ {+ label: 'fractional ticks stay distinct on an axis that extends past five',+ ticks: [0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5],+ expected: ['0.0', '0.5', '1.0', '1.5', '2.0', '2.5', '3.0', '3.5', '4.0', '4.5', '5.0'],+ },+ {+ label: 'small ticks get exactly the decimals their step needs',+ ticks: [0, 0.004, 0.008, 0.012],+ expected: ['0.000', '0.004', '0.008', '0.012'],+ },+ {+ label: 'large integer ticks keep thousands separators',+ ticks: [0, 2500, 5000],+ expected: ['0', '2,500', '5,000'],+ },+ {+ label: 'negative ticks format like positive ones',+ ticks: [-10, -5, 0, 5, 10],+ expected: ['-10', '-5', '0', '5', '10'],+ },+ {+ label: 'float noise in computed ticks does not leak into labels',+ ticks: [0, 0.1, 0.2, 0.1 + 0.2],+ expected: ['0.0', '0.1', '0.2', '0.3'],+ },+ ])('$label', ({ ticks, expected }) => {+ expect(ticks.map(autoFormatterFor(ticks))).toEqual(expected)})- it('formats negative values correctly', () => {- expect(autoFormatYTick(-5, 10)).toBe('-5')+ it('falls back to integer formatting for an empty tick list', () => {+ expect(autoFormatterFor([])(1234)).toBe('1,234')})})diff --git a/packages/quill/packages/charts/src/core/scales.ts b/packages/quill/packages/charts/src/core/scales.tsindex f0de612e2e5b..bccb9f1427b7 100644--- a/packages/quill/packages/charts/src/core/scales.ts+++ b/packages/quill/packages/charts/src/core/scales.ts@@ -10,7 +10,6 @@ import {} from 'd3-scale'import { stack as stackGen, stackOffsetDiverging, stackOffsetExpand, stackOffsetNone } from 'd3-shape'-import { significantDecimalPlaces } from '../utils/format'import type { BandSlot, ChartDimensions, ResolveValueFn, Series, ValueDomain, YAxisScale } from './types'import { DEFAULT_Y_AXIS_ID } from './types'@@ -866,24 +865,22 @@ function padValueRange(return [min < 0 ? start - reserve : start, max > 0 ? end + reserve : end]}-export function autoFormatYTick(value: number, domainMax: number): string {- if (domainMax < 2) {- // Two decimals only resolve a domain down to ~0.1; below that every tick rounds to the same- // label, so scale the precision to the domain instead.- return value.toLocaleString('en-US', {- minimumFractionDigits: 2,- maximumFractionDigits: significantDecimalPlaces(domainMax),- })- }- if (domainMax < 5) {- return value.toFixed(1)- }- return value.toLocaleString('en-US', { maximumFractionDigits: 0 })-}+// Caps runaway precision if a tick set never resolves (e.g. NaN), and stops float+// residue from rendering as a wall of digits.+const MAX_TICK_FRACTION_DIGITS = 10+/** Labels an axis's ticks with the fewest fraction digits that keep every distinct tick's label+ * distinct, applied uniformly so the column of labels reads as one unit. Trying digit counts+ * against the rendered labels sidesteps float noise in computed tick values. */export function autoFormatterFor(ticks: number[]): (value: number) => string {- const domainMax = ticks.length > 0 ? Math.max(...ticks.map((t) => Math.abs(t))) : 1- return (v) => autoFormatYTick(v, domainMax)+ const label = (value: number, digits: number): string =>+ value.toLocaleString('en-US', { minimumFractionDigits: digits, maximumFractionDigits: digits })+ const distinct = new Set(ticks).size+ let digits = 0+ while (digits < MAX_TICK_FRACTION_DIGITS && new Set(ticks.map((tick) => label(tick, digits))).size < distinct) {+ digits+++ }+ return (value) => label(value, digits)}export function resolveYScaleForSeries<S extends (value: number) => number>(