svelte-plots-basic 2.5.4 → 2.5.6
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 +2 -1
- package/src/Utils.js +7 -2
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svelte-plots-basic",
|
|
3
3
|
"description": "Svelte components for creating simple plots",
|
|
4
|
-
"version": "2.5.
|
|
4
|
+
"version": "2.5.6",
|
|
5
5
|
"author": "Sergey Kucheryavskiy",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"private": false,
|
|
8
8
|
"exports": {
|
|
9
|
+
"./utils": "./src/Utils.js",
|
|
9
10
|
"./2d": "./src/2d/index.js",
|
|
10
11
|
"./2d/*.svelte": "./src/2d/*.svelte",
|
|
11
12
|
"./3d": "./src/3d/index.js",
|
package/src/Utils.js
CHANGED
|
@@ -157,11 +157,12 @@ export function val2p(x, y, tX, tY, axes) {
|
|
|
157
157
|
* @param {number} maxTickNum - maximum number of ticks to compute.
|
|
158
158
|
* @param {boolean} round - round or not the fractions when computing nice numbers for the ticks.
|
|
159
159
|
* @param {boolean} whole - should the ticks be a whole number.
|
|
160
|
+
* @param {Number} deltaFactor - percent of range to use as internal margins
|
|
160
161
|
*
|
|
161
162
|
* @returns {Array} an array with computed tick positions.
|
|
162
163
|
*
|
|
163
164
|
*/
|
|
164
|
-
export function getAxisTicks(ticks, lim, maxTickNum, round, whole) {
|
|
165
|
+
export function getAxisTicks(ticks, lim, maxTickNum, round, whole, deltaFactor) {
|
|
165
166
|
|
|
166
167
|
if (round === undefined || round === null) {
|
|
167
168
|
round = true;
|
|
@@ -171,6 +172,10 @@ export function getAxisTicks(ticks, lim, maxTickNum, round, whole) {
|
|
|
171
172
|
whole = false;
|
|
172
173
|
}
|
|
173
174
|
|
|
175
|
+
if (deltaFactor === undefined) {
|
|
176
|
+
deltaFactor = 0.001;
|
|
177
|
+
}
|
|
178
|
+
|
|
174
179
|
// if ticks are already provided do not recompute them
|
|
175
180
|
if (ticks !== undefined) {
|
|
176
181
|
if (Array.isArray(ticks)) {
|
|
@@ -188,7 +193,7 @@ export function getAxisTicks(ticks, lim, maxTickNum, round, whole) {
|
|
|
188
193
|
if (typeof(lim) !== "object" || lim[0] === undefined || lim[1] === undefined) return undefined;
|
|
189
194
|
|
|
190
195
|
// get range as a nice number and compute min, max and steps for the tick sequence
|
|
191
|
-
const delta = (lim[1] - lim[0])
|
|
196
|
+
const delta = (lim[1] - lim[0]) * deltaFactor;
|
|
192
197
|
const localRange = lim[1] - lim[0] - delta;
|
|
193
198
|
const exponent = Math.floor(Math.log10(localRange));
|
|
194
199
|
const fraction = 1 / Math.pow(10, exponent - 1);
|