@adecore/charts 0.53.2 → 0.53.3

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/dist/scale.js CHANGED
@@ -72,16 +72,26 @@ export function extentOf(stacked, kind, ground = true) {
72
72
  return low === Infinity ? null : [low, high];
73
73
  }
74
74
  /* Ticks every `step` from `low` to `high`, both rounded out to it. */
75
- function steppedScale(low, high, step, options, range) {
75
+ function steppedScale(low, high, step, options, range, count) {
76
76
  const start = options.min ?? Math.floor(low / step) * step;
77
77
  let end = options.max ?? Math.ceil(high / step) * step;
78
78
  if (end <= start) {
79
79
  end = start + step;
80
80
  }
81
+ const first = Math.ceil(start / step) * step;
82
+ const intervals = Math.floor((end - first) / step + 1e-6);
83
+ if (!Number.isFinite(first) || !Number.isSafeInteger(intervals) || first + step === first) {
84
+ return null;
85
+ }
86
+ const limit = Math.max(2, Math.min(1024, Number.isFinite(count) ? Math.ceil(count) * 4 : 20));
87
+ const stride = Math.max(1, Math.ceil(intervals / (limit - 1)));
81
88
  const scale = scaleLinear().domain([start, end]).range(range);
82
89
  const ticks = [];
83
- for (let tick = Math.ceil(start / step) * step; tick <= end + step / 1e6; tick += step) {
84
- ticks.push(Number(tick.toFixed(10)));
90
+ for (let i = 0; i <= intervals; i += stride) {
91
+ const tick = Number((first + i * step).toFixed(10));
92
+ if (Number.isFinite(tick) && (ticks.length === 0 || tick > ticks[ticks.length - 1])) {
93
+ ticks.push(tick);
94
+ }
85
95
  }
86
96
  return {
87
97
  domain: [start, end],
@@ -116,8 +126,11 @@ export function yScaleOf(kind, data, options, range, count, ground = true) {
116
126
  }
117
127
  const floor = ground ? 0 : extent?.[0] ?? 0;
118
128
  const ceiling = ground ? 0 : extent?.[1] ?? 0;
119
- if (options.step !== undefined && options.step > 0) {
120
- return steppedScale(Math.min(floor, extent?.[0] ?? 0), Math.max(ceiling, extent?.[1] ?? 0), options.step, options, range);
129
+ if (options.step !== undefined && Number.isFinite(options.step) && options.step > 0) {
130
+ const stepped = steppedScale(Math.min(floor, extent?.[0] ?? 0), Math.max(ceiling, extent?.[1] ?? 0), options.step, options, range, count);
131
+ if (stepped !== null) {
132
+ return stepped;
133
+ }
121
134
  }
122
135
  let low = options.min ?? Math.min(floor, extent?.[0] ?? 0);
123
136
  let high = options.max ?? Math.max(ceiling, extent?.[1] ?? 0);
@@ -140,7 +153,7 @@ export function yScaleOf(kind, data, options, range, count, ground = true) {
140
153
  }
141
154
  const domain = [options.min ?? low, options.max ?? high];
142
155
  scale.domain(domain);
143
- let ticks = scale.ticks(count);
156
+ let ticks = [...new Set(scale.ticks(count))];
144
157
  if (options.integer === true) {
145
158
  ticks = ticks.filter(tick => Number.isInteger(tick));
146
159
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adecore/charts",
3
- "version": "0.53.2",
3
+ "version": "0.53.3",
4
4
  "description": "Series charts, scatters, heatmaps, trace timelines and sparklines in the theme of @adecore/ui, readable by keyboard and screen reader.",
5
5
  "license": "FSL-1.1-MIT",
6
6
  "author": "Bas Milius",
@@ -43,14 +43,14 @@
43
43
  "lucide-react": "^1.65.0"
44
44
  },
45
45
  "peerDependencies": {
46
- "@adecore/ui": "^0.53.2",
46
+ "@adecore/ui": "^0.53.3",
47
47
  "i18next": "^26.4.2",
48
48
  "react": "^19.3.0",
49
49
  "react-dom": "^19.3.0",
50
50
  "react-i18next": "^17.0.15"
51
51
  },
52
52
  "devDependencies": {
53
- "@adecore/ui": "0.53.2",
53
+ "@adecore/ui": "0.53.3",
54
54
  "@types/bun": "^1.4.4",
55
55
  "@types/react": "^19.3.0",
56
56
  "@types/react-dom": "^19.3.0",
package/src/scale.ts CHANGED
@@ -87,7 +87,7 @@ export interface YAxisScale {
87
87
  }
88
88
 
89
89
  /* Ticks every `step` from `low` to `high`, both rounded out to it. */
90
- function steppedScale(low: number, high: number, step: number, options: ChartYOptions, range: [number, number]): YAxisScale {
90
+ function steppedScale(low: number, high: number, step: number, options: ChartYOptions, range: [number, number], count: number): YAxisScale | null {
91
91
  const start = options.min ?? Math.floor(low / step) * step;
92
92
  let end = options.max ?? Math.ceil(high / step) * step;
93
93
 
@@ -95,11 +95,24 @@ function steppedScale(low: number, high: number, step: number, options: ChartYOp
95
95
  end = start + step;
96
96
  }
97
97
 
98
+ const first = Math.ceil(start / step) * step;
99
+ const intervals = Math.floor((end - first) / step + 1e-6);
100
+
101
+ if (!Number.isFinite(first) || !Number.isSafeInteger(intervals) || first + step === first) {
102
+ return null;
103
+ }
104
+
105
+ const limit = Math.max(2, Math.min(1024, Number.isFinite(count) ? Math.ceil(count) * 4 : 20));
106
+ const stride = Math.max(1, Math.ceil(intervals / (limit - 1)));
98
107
  const scale = scaleLinear().domain([start, end]).range(range);
99
108
  const ticks: number[] = [];
100
109
 
101
- for (let tick = Math.ceil(start / step) * step; tick <= end + step / 1e6; tick += step) {
102
- ticks.push(Number(tick.toFixed(10)));
110
+ for (let i = 0; i <= intervals; i += stride) {
111
+ const tick = Number((first + i * step).toFixed(10));
112
+
113
+ if (Number.isFinite(tick) && (ticks.length === 0 || tick > ticks[ticks.length - 1]!)) {
114
+ ticks.push(tick);
115
+ }
103
116
  }
104
117
 
105
118
  return { domain: [start, end], ticks, at: (value) => scale(value) };
@@ -143,8 +156,12 @@ export function yScaleOf(
143
156
  const floor = ground ? 0 : (extent?.[0] ?? 0);
144
157
  const ceiling = ground ? 0 : (extent?.[1] ?? 0);
145
158
 
146
- if (options.step !== undefined && options.step > 0) {
147
- return steppedScale(Math.min(floor, extent?.[0] ?? 0), Math.max(ceiling, extent?.[1] ?? 0), options.step, options, range);
159
+ if (options.step !== undefined && Number.isFinite(options.step) && options.step > 0) {
160
+ const stepped = steppedScale(Math.min(floor, extent?.[0] ?? 0), Math.max(ceiling, extent?.[1] ?? 0), options.step, options, range, count);
161
+
162
+ if (stepped !== null) {
163
+ return stepped;
164
+ }
148
165
  }
149
166
 
150
167
  let low = options.min ?? Math.min(floor, extent?.[0] ?? 0);
@@ -173,7 +190,7 @@ export function yScaleOf(
173
190
 
174
191
  const domain: [number, number] = [options.min ?? low, options.max ?? high];
175
192
  scale.domain(domain);
176
- let ticks = scale.ticks(count);
193
+ let ticks = [...new Set(scale.ticks(count))];
177
194
 
178
195
  if (options.integer === true) {
179
196
  ticks = ticks.filter((tick) => Number.isInteger(tick));