Skip to content

Commit 21cff6b

Browse files
committed
Widen the Y-axis gap threshold to 2% of the span
A nudge only large enough to break an exact tie left the gap unchanged whenever the data sat just above a tick rather than on it, so a chart could still render with a hairline of headroom. Because ECharts rounds out to a whole tick afterwards, this constant does not set the size of the resulting gap — it decides which axes count as too flat to leave alone. At 2% the worst case over the tick cycle goes from nothing to around 3% of the plot, while every measured chart keeps the framing it had.
1 parent 0775434 commit 21cff6b

3 files changed

Lines changed: 15 additions & 13 deletions

File tree

src/components/chart/y-axis-fraction-digits.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ const NEGLIGIBLE_RANGE_RATIO = 1e-10;
99
// precision derived here cannot drift from the ticks it renders.
1010
const SPLIT_NUMBER = 5;
1111

12-
// Fraction of the data span added at each end, so that ECharts' tick rounding —
13-
// which floors the minimum and ceils the maximum to a tick multiple — always has
14-
// something to round away. Quantized states otherwise land exactly on a tick,
15-
// the rounding changes nothing, and area-filled series collapse to zero height.
16-
// Any value between roughly 1e-15 and 1 / SPLIT_NUMBER works: large enough to
17-
// survive float64 addition at the data's magnitude, small enough that it can
18-
// never cross a tick by itself.
19-
const GAP_FRACTION_OF_SPAN = 1e-6;
12+
// How thin a gap between the data and the plot edge counts as no gap at all,
13+
// as a fraction of the data span. ECharts floors the axis minimum and ceils the
14+
// maximum to a tick multiple, which usually leaves headroom, but quantized
15+
// states often land exactly on a tick and get none — collapsing area-filled
16+
// series, which are drawn from their value down to the axis minimum. Widening
17+
// the extent by this much before that rounding bumps any axis with less
18+
// headroom out to a full tick, and leaves the rest where they are.
19+
const GAP_FRACTION_OF_SPAN = 0.02;
2020

2121
// Derive the number of decimal digits to use for Y-axis labels from the
2222
// observed data range, by asking ECharts for the same tick interval it will

test/components/chart/y-axis-boundary-gap.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,10 @@ describe("Y-axis tick nudge", () => {
5858
expect(renderExtent([18, 21.2, 19], withGap())).toEqual([17.5, 21.5]);
5959
});
6060

61-
it("leaves an axis that already had a gap untouched", () => {
62-
const data = [1.11109, 1.85849, 1.4];
61+
it("leaves an axis with real headroom untouched", () => {
62+
// Its minimum sits well clear of the tick below it, so the rounding it
63+
// already gets is enough and the widened extent floors to the same place.
64+
const data = [18.3, 21.2, 19.5];
6365
expect(renderExtent(data, withGap())).toEqual(
6466
renderExtent(data, { scale: true })
6567
);
@@ -71,7 +73,7 @@ describe("Y-axis tick nudge", () => {
7173
expect(
7274
renderExtent([0, 3500, 1200], {
7375
scale: true,
74-
boundaryGap: [1e-6, 1e-6],
76+
boundaryGap: [0.02, 0.02],
7577
})[0]
7678
).toBe(-1000);
7779
});

test/components/chart/y-axis-fraction-digits.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ describe("createYAxisPrecisionBounds", () => {
142142
const { min, max, boundaryGap, splitNumber } = makeBounds();
143143

144144
// The gap is applied by ECharts, so the bounds stay auto-scaled.
145-
expect(boundaryGap).toEqual([1e-6, 1e-6]);
145+
expect(boundaryGap).toEqual([0.02, 0.02]);
146146
// Pinned rather than assumed, since the precision here is derived from it.
147147
expect(splitNumber).toBe(5);
148148
expect(min({ min: 18, max: 21.2 })).toBeUndefined();
@@ -158,7 +158,7 @@ describe("createYAxisPrecisionBounds", () => {
158158
expect(max({ min: 0, max: 3500 })).toBeUndefined();
159159

160160
// A minimum clear of the gap is left to ECharts.
161-
expect(min({ min: 0.01, max: 3500 })).toBeUndefined();
161+
expect(min({ min: 100, max: 3500 })).toBeUndefined();
162162
});
163163

164164
it("anchors an all-negative series at zero from above", () => {

0 commit comments

Comments
 (0)