svelte-plots-basic 2.5.1 → 2.5.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/Utils.js +16 -6
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "svelte-plots-basic",
3
3
  "description": "Svelte components for creating simple plots",
4
- "version": "2.5.1",
4
+ "version": "2.5.3",
5
5
  "author": "Sergey Kucheryavskiy",
6
6
  "license": "MIT",
7
7
  "private": false,
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,12 +24,15 @@ 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) {
32
30
  // tick values between 0 and 1 (absolute) and step is below 1
33
- let decNum = Math.ceil(-Math.log10(step));
31
+ let decNum = -Math.log10(step);
32
+
33
+ // adjust the decNum value in case if small decimals are present
34
+ decNum = Math.ceil(Math.round(decNum * 100)/100);
35
+
34
36
  if (decNum <= 2) {
35
37
  return [0, Array.from(ticks).map(v => v.toFixed(decNum))];
36
38
  }
@@ -39,7 +41,11 @@ export function getTickLabels(ticks) {
39
41
  return [-tickFactor, Array.from(ticks).map(v => (v * Math.pow(10, tickFactor)).toFixed(decNum))];
40
42
  } else {
41
43
  // tick values above 1 (absolute) and step is below 1
42
- let decNum = Math.ceil(-Math.log10(step));
44
+ let decNum = -Math.log10(step);
45
+
46
+ // adjust the decNum value in case if small decimals are present
47
+ decNum = Math.ceil(Math.round(decNum * 100)/100);
48
+
43
49
  if (decNum <= 2) {
44
50
  return [0, Array.from(ticks).map(v => v.toFixed(decNum))];
45
51
  }
@@ -190,14 +196,18 @@ export function getAxisTicks(ticks, lim, maxTickNum, round, whole) {
190
196
  tickSpacing = Math.round(tickSpacing);
191
197
  }
192
198
 
199
+ // compute smallest and largest tick rounded to tickSpacing
193
200
  const tickMin = Math.ceil((lim[0] + delta) / tickSpacing) * tickSpacing;
194
201
  const tickMax = Math.floor((lim[1] - delta) / tickSpacing) * tickSpacing;
195
202
 
196
203
  // recompute maxTickNum
197
- maxTickNum = Math.round((tickMax - tickMin + 1) / tickSpacing) + 1;
204
+ maxTickNum = Math.ceil((tickMax - tickMin) / tickSpacing) + 1;
198
205
 
199
206
  // create a sequence of ticks
200
- ticks = Vector.seq(tickMin, tickMax, tickSpacing);
207
+ ticks = Vector.zeros(maxTickNum);
208
+ for (let i = 0; i < maxTickNum; i++) {
209
+ ticks.v[i] = tickMin + tickSpacing * i;
210
+ }
201
211
 
202
212
  // if step is smaller than 1 round values to remove small decimals accidentially added by JS
203
213
  if (Math.abs(tickSpacing) < 1) {