@pushwoosh/kit-charts 0.0.11 → 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ai-documentation.md +6 -0
- package/core/model/build-model.js +1 -0
- package/core/scale/linear.d.ts +2 -0
- package/core/scale/linear.js +18 -4
- package/package.json +1 -1
package/ai-documentation.md
CHANGED
|
@@ -92,6 +92,12 @@ own `formatter` or `format` wins over it.
|
|
|
92
92
|
the step is chosen from the candidates that stay integral at its magnitude, and
|
|
93
93
|
never falls below 1.
|
|
94
94
|
|
|
95
|
+
`tickAmount` is Highcharts' demand and not a hint: the y axis stretches the end
|
|
96
|
+
the caller left open until exactly that many ticks fit, so a count of 2 on a
|
|
97
|
+
`tickAmount: 5` axis still draws 0..4 and reads against a stable grid rather than
|
|
98
|
+
filling the plot. An end pinned with `max` cannot be stretched, so a tick amount
|
|
99
|
+
alongside one is ignored.
|
|
100
|
+
|
|
95
101
|
`labels.allowOverlap` defaults to false on both axes and on data labels. A label
|
|
96
102
|
whose box would run into one already placed loses its text — Highcharts hides
|
|
97
103
|
the label and keeps the tick, and so do we.
|
package/core/scale/linear.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ export interface LinearScaleOptions {
|
|
|
9
9
|
range: readonly [number, number];
|
|
10
10
|
nice?: boolean | NiceEnds;
|
|
11
11
|
tickHint?: number;
|
|
12
|
+
/** Highcharts' `tickAmount`: stretch the open end so exactly this many ticks fit. */
|
|
13
|
+
tickCount?: number;
|
|
12
14
|
/** False keeps every tick a whole number, as a count axis needs. */
|
|
13
15
|
allowDecimals?: boolean;
|
|
14
16
|
}
|
package/core/scale/linear.js
CHANGED
|
@@ -31,18 +31,32 @@ export function createLinearScale(options) {
|
|
|
31
31
|
range,
|
|
32
32
|
nice = false,
|
|
33
33
|
tickHint = 5,
|
|
34
|
+
tickCount,
|
|
34
35
|
allowDecimals = true
|
|
35
36
|
} = options;
|
|
36
37
|
let [min, max] = options.domain;
|
|
38
|
+
const niceMin = nice === true || typeof nice === 'object' && nice.min === true;
|
|
39
|
+
const niceMax = nice === true || typeof nice === 'object' && nice.max === true;
|
|
37
40
|
if (!Number.isFinite(min) || !Number.isFinite(max)) {
|
|
38
41
|
[min, max] = [0, 1];
|
|
39
42
|
} else if (min === max) {
|
|
40
43
|
const pad = Math.abs(min) || 1;
|
|
41
|
-
|
|
44
|
+
// An end the caller pinned stays put: padding both would take a `min: 0`
|
|
45
|
+
// count axis below zero on a day where every value is zero.
|
|
46
|
+
[min, max] = [min - (niceMin || !niceMax ? pad : 0), max + (niceMax || !niceMin ? pad : 0)];
|
|
42
47
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
48
|
+
if (tickCount !== undefined && tickCount > 1 && niceMax) {
|
|
49
|
+
let step = niceStep((max - min) / (tickCount - 1), allowDecimals);
|
|
50
|
+
if (niceMin) {
|
|
51
|
+
min = Math.floor(min / step) * step;
|
|
52
|
+
}
|
|
53
|
+
// Rounding the low end down lengthens the run, which can leave the last tick
|
|
54
|
+
// short of the data; widen the step until the fixed number of them covers it.
|
|
55
|
+
while (min + (tickCount - 1) * step < max) {
|
|
56
|
+
step = niceStep(step * 1.5, allowDecimals);
|
|
57
|
+
}
|
|
58
|
+
max = min + (tickCount - 1) * step;
|
|
59
|
+
} else if (niceMin || niceMax) {
|
|
46
60
|
const step = niceStep((max - min) / tickHint, allowDecimals);
|
|
47
61
|
if (niceMin) {
|
|
48
62
|
min = Math.floor(min / step) * step;
|