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