svelte-plots-basic 3.0.6 → 3.1.0
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/README.md +6 -1
- package/package.json +1 -1
- package/src/2d/Axes.svelte +3 -5
- package/src/constants.js +1 -1
- package/src/methods.js +9 -3
package/README.md
CHANGED
|
@@ -15,6 +15,11 @@ These websites and web-applications use `svelte-plots-basic` library:
|
|
|
15
15
|
|
|
16
16
|
## News
|
|
17
17
|
|
|
18
|
+
### 3.1.0
|
|
19
|
+
|
|
20
|
+
* Added possibility to reverse the axis, just swap the limit values.
|
|
21
|
+
|
|
22
|
+
|
|
18
23
|
### 3.0.0
|
|
19
24
|
|
|
20
25
|
New major release (v. 3.0.0, released 20/01/2025) introduces many breaking changes as the library has been re-written using Svelte 5. If you use previous versions of `svelte-plots-basic` in your projects, and do not want to change anything, stick to the latest 2.x.x version.
|
|
@@ -77,7 +82,7 @@ Properties `limX` and `limY` define limits of the coordinates system in *plot's
|
|
|
77
82
|
</style>
|
|
78
83
|
```
|
|
79
84
|
|
|
80
|
-
These two properties must always be provided as an array with two values
|
|
85
|
+
These two properties must always be provided as an array with two values (left and right). If the first value is larger than the second one, the corresponding axis will be reversed. Both properties have default value of `[0, 1]`.
|
|
81
86
|
|
|
82
87
|
Second important property is `margins`, it defines margins around the plotting area — the one which will be used for positioning of actual plot elements. Margins should be provided as an array with four values: relative margins for bottom, left, top and right parts of the plot.
|
|
83
88
|
|
package/package.json
CHANGED
package/src/2d/Axes.svelte
CHANGED
|
@@ -130,8 +130,6 @@
|
|
|
130
130
|
const isOk = $derived(
|
|
131
131
|
checkArray(limX, 2) &&
|
|
132
132
|
checkArray(limY, 2) &&
|
|
133
|
-
limX[0] < limX[1] &&
|
|
134
|
-
limY[0] < limY[1] &&
|
|
135
133
|
width > (pxMargins[1] + pxMargins[3]) &&
|
|
136
134
|
height > (pxMargins[0] + pxMargins[2])
|
|
137
135
|
);
|
|
@@ -256,11 +254,11 @@
|
|
|
256
254
|
|
|
257
255
|
|
|
258
256
|
{#if params.labelsFactor !== 0}
|
|
259
|
-
{@const x = coords.start +
|
|
260
|
-
<text {x} y={coords.ltop} dx=
|
|
257
|
+
{@const x = coords.start + n * coords.width }
|
|
258
|
+
<text {x} y={coords.ltop} dx="1.2em" dy="-0.25em" dominant-baseline="hanging"
|
|
261
259
|
fill={params.labelColor}
|
|
262
260
|
font-size="{params.fontSize}em"
|
|
263
|
-
text-anchor="
|
|
261
|
+
text-anchor="right"
|
|
264
262
|
>{@html getTickFactorLabel(params.labelsFactor)}</text>
|
|
265
263
|
{/if}
|
|
266
264
|
{/snippet}
|
package/src/constants.js
CHANGED
package/src/methods.js
CHANGED
|
@@ -284,12 +284,15 @@ export function validateTicks(ticks, lim) {
|
|
|
284
284
|
return [null, 'ticks values must be unique.'];
|
|
285
285
|
}
|
|
286
286
|
|
|
287
|
+
// swap limits if necessary
|
|
288
|
+
const left = lim[0] < lim[1] ? lim[0] : lim[1];
|
|
289
|
+
const right = lim[0] < lim[1] ? lim[1] : lim[0];
|
|
290
|
+
|
|
287
291
|
// check if provided ticks values are outside the axis limit range continue with automatic ticks
|
|
288
|
-
const newTicks = ticks.filter(x => x >=
|
|
292
|
+
const newTicks = ticks.filter(x => x >= left & x <= right);
|
|
289
293
|
if (newTicks.length !== ticks.length) {
|
|
290
294
|
return [null, 'some of ticks values are outside axis limits.'];
|
|
291
295
|
}
|
|
292
|
-
|
|
293
296
|
return [newTicks, ''];
|
|
294
297
|
}
|
|
295
298
|
|
|
@@ -307,7 +310,7 @@ export function validateTicks(ticks, lim) {
|
|
|
307
310
|
* @returns {Array} an array with computed tick positions.
|
|
308
311
|
*
|
|
309
312
|
*/
|
|
310
|
-
export function getAxisTicks(ticks,
|
|
313
|
+
export function getAxisTicks(ticks, limIn, maxTickNum, round, whole, deltaFactor) {
|
|
311
314
|
|
|
312
315
|
if (round === undefined || round === null) {
|
|
313
316
|
round = true;
|
|
@@ -321,6 +324,9 @@ export function getAxisTicks(ticks, lim, maxTickNum, round, whole, deltaFactor)
|
|
|
321
324
|
deltaFactor = 0.0001;
|
|
322
325
|
}
|
|
323
326
|
|
|
327
|
+
// correct limits internally if they are reverse
|
|
328
|
+
const lim = limIn[0] < limIn[1] ? limIn : [limIn[1], limIn[0]];
|
|
329
|
+
|
|
324
330
|
// if ticks are already provided do not recompute them
|
|
325
331
|
// the validation is done in corresponding component, so no need to do it again
|
|
326
332
|
if (ticks) return ticks;
|