svelte-plots-basic 2.5.0 → 2.5.2
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/package.json +1 -1
- package/src/Utils.js +10 -5
package/package.json
CHANGED
package/src/Utils.js
CHANGED
|
@@ -12,18 +12,18 @@ import { min, max, diff } from 'mdatools/stat';
|
|
|
12
12
|
export function getTickLabels(ticks) {
|
|
13
13
|
|
|
14
14
|
if (ticks === undefined) return undefined;
|
|
15
|
+
if (ticks.length === 1) return [0, [ticks[0].toString()]];
|
|
15
16
|
|
|
16
17
|
const step = Math.abs(min(diff(ticks)));
|
|
17
18
|
let tickFactor = 0;
|
|
18
19
|
|
|
19
20
|
// step is large (over 1)
|
|
20
|
-
if (step >= 1) {
|
|
21
|
+
if (step >= 1 && ticks.length > 1) {
|
|
21
22
|
if (step < 100) return [0, Array.from(ticks).map(v => v.toFixed(0))];
|
|
22
23
|
|
|
23
24
|
let digNum = Math.ceil(Math.log10(step));
|
|
24
25
|
tickFactor = digNum - 2;
|
|
25
26
|
return [tickFactor, Array.from(ticks).map(v => (v / Math.pow(10, tickFactor)).toFixed(0))];
|
|
26
|
-
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
if (Math.abs(max(ticks)) < 1) {
|
|
@@ -37,7 +37,8 @@ export function getTickLabels(ticks) {
|
|
|
37
37
|
return [-tickFactor, Array.from(ticks).map(v => (v * Math.pow(10, tickFactor)).toFixed(decNum))];
|
|
38
38
|
} else {
|
|
39
39
|
// tick values above 1 (absolute) and step is below 1
|
|
40
|
-
let decNum =
|
|
40
|
+
let decNum = -Math.log10(step);
|
|
41
|
+
decNum = Math.ceil(Math.round(decNum * 10)/100);
|
|
41
42
|
if (decNum <= 2) {
|
|
42
43
|
return [0, Array.from(ticks).map(v => v.toFixed(decNum))];
|
|
43
44
|
}
|
|
@@ -188,14 +189,18 @@ export function getAxisTicks(ticks, lim, maxTickNum, round, whole) {
|
|
|
188
189
|
tickSpacing = Math.round(tickSpacing);
|
|
189
190
|
}
|
|
190
191
|
|
|
192
|
+
// compute smallest and largest tick rounded to tickSpacing
|
|
191
193
|
const tickMin = Math.ceil((lim[0] + delta) / tickSpacing) * tickSpacing;
|
|
192
194
|
const tickMax = Math.floor((lim[1] - delta) / tickSpacing) * tickSpacing;
|
|
193
195
|
|
|
194
196
|
// recompute maxTickNum
|
|
195
|
-
maxTickNum = Math.
|
|
197
|
+
maxTickNum = Math.ceil((tickMax - tickMin) / tickSpacing) + 1;
|
|
196
198
|
|
|
197
199
|
// create a sequence of ticks
|
|
198
|
-
ticks = Vector.
|
|
200
|
+
ticks = Vector.zeros(maxTickNum);
|
|
201
|
+
for (let i = 0; i < maxTickNum; i++) {
|
|
202
|
+
ticks.v[i] = tickMin + tickSpacing * i;
|
|
203
|
+
}
|
|
199
204
|
|
|
200
205
|
// if step is smaller than 1 round values to remove small decimals accidentially added by JS
|
|
201
206
|
if (Math.abs(tickSpacing) < 1) {
|