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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/Utils.js +8 -5
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.2",
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,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 = Math.ceil(-Math.log10(step));
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.round((tickMax - tickMin + 1) / tickSpacing) + 1;
197
+ maxTickNum = Math.ceil((tickMax - tickMin) / tickSpacing) + 1;
198
198
 
199
199
  // create a sequence of ticks
200
- ticks = Vector.seq(tickMin, tickMax, tickSpacing);
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) {