Repository navigation
Conversation
In scientific notation the fraction digits apply to the significand, so count them from the tick's exponent instead of from the spacing alone. 1.5e15 was shown as 2E15 and 1e-5 as 1.00000E-5. When a tick is not a multiple of the spacing, as with bounds: 'data' where ticks are min + k * spacing, show enough digits for its offset from the nearest multiple. The last two ticks of [-0.0936, 0.0917] were both shown as 0.09.
TARUNTEjjjj
left a comment
There was a problem hiding this comment.
AI-assisted review with independent browser validation on the current head. Details and scope are in the inline comment.
| // The tick might not be a multiple of the spacing, e.g. with `bounds: 'data'` the ticks are | ||
| // `min + k * spacing`. Show enough decimal places for its offset from the nearest multiple. | ||
| const unit = Math.pow(10, Math.floor(log10(Math.abs(delta)))); | ||
| const offset = Math.abs(tickValue - Math.round(tickValue / unit) * unit); |
There was a problem hiding this comment.
I checked a symmetric fractional grid in addition to the offset-bound example: [-0.075, -0.05, -0.025, 0, 0.025, 0.05, 0.075] now preserves the quarter-grid values, whereas base labels ±0.075 as ±0.08 and ±0.025 as ±0.03. The same case works with de-DE decimal commas. This would be useful regression coverage because it exercises negative values on both sides of zero with a spacing that is not a power of ten. I also verified distinct labels across [9.8e-9, 9.9e-9, 1e-8, 1.01e-8, 1.02e-8] and that explicit user fraction-digit limits still override the computed precision. The 7 existing tick tests plus these 3 additional tests pass in Chrome Headless 157. I did not run Firefox/Safari or the full repository suite. AI-assisted review and local validation with OpenAI Codex.
There was a problem hiding this comment.
Thanks for checking these. Added all three as tests in 01cf988:
- the symmetric grid
[-0.075 … 0.075]keeps-0.075/-0.025/0.025/0.075, inen-USandde-DE [9.8e-9, 9.9e-9, 1e-8, 1.01e-8, 1.02e-8]gives9.8E-9,9.9E-9,1.00E-8,1.01E-8,1.02E-8(exact strings, since the base labels were already distinct but padded to 10 digits)- explicit
minimumFractionDigits/maximumFractionDigitsstill override the computed precision
The first two fail without the change in core.ticks.js; the third passes on both, as expected.
…n numeric tick labels
Fixes #12382
Ticks.formatters.numericpicks the number of fraction digits from the tick spacing only. That goes wrong in two cases:Scientific notation. With
notation: 'scientific'the fraction digits apply to the significand, so the digits the spacing needs have to be counted from the tick's exponent. The formatter now addsfloor(log10(|tick|))to the digit count when the notation is scientific (whether picked automatically or set inticks.format).Ticks that are not multiples of the spacing. With
bounds: 'data'the ticks aremin + k * spacing, plus the data max.calculateDeltaalready handles this for spacings of 1 or more (a tick like 2.5 gets a decimal). For spacings below 1 it now does the same thing: if the tick is off the grid of the shown resolution, it uses the offset from the nearest multiple to pick the digits. A small relative tolerance keeps floating point noise such as0.6000000000000001from counting as an offset.This shows enough digits to tell the ticks apart, not every digit of the data.
-0.0936becomes-0.094rather than-0.0936, and data like1/3gives0.33, 0.83, ...instead of 16 decimals.Before / after
Using the script from the issue (Node,
BasicPlatform, 400x300 canvas):[1e15, 5e15]1E15, 2E15, 2E15, 3E15, 3E15, ...1.0E15, 1.5E15, 2.0E15, 2.5E15, ..., 5.0E15[0, 2e16]0, 2E15, ..., 1E16, 1E16, 1E16, 2E16, 2E16, 2E160, 2E15, ..., 8E15, 1.0E16, 1.2E16, ..., 2.0E16[0, 5e-5]0, 1.00000E-5, 2.00000E-5, ...0, 1E-5, 2E-5, ..., 6E-5[-0.0936, 0.0917],bounds: 'data'-0.09, -0.07, ..., 0.07, 0.09, 0.09-0.094, -0.074, ..., 0.066, 0.086, 0.092Ordinary axes (for example
0, 0.1, ..., 1or integer ticks) format the same as before.Tests
Added specs to
test/specs/core.ticks.tests.js: formatter-level cases for large and small scientific values and for off-grid ticks, plus a chart-levelbounds: 'data'case. All three fail onmasterand pass with this change.pnpm run lint: passes (no new warnings)karma start ./karma.conf.cjs --single-run --browsers chrome --grep core.ticks: 7 of 7 passradialLinear/ticks-below-zeroin Chrome,min-max-skip/rotated-case-4in Firefox). The same 7 fail on unmodifiedmasteron my macOS machine, so they come from local rendering, not from this change.