svelte-plots-basic 2.5.7 → 3.0.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 +530 -445
- package/package.json +5 -2
- package/src/2d/Area.svelte +56 -48
- package/src/2d/Axes.svelte +409 -373
- package/src/2d/AxisLines.svelte +37 -36
- package/src/2d/AxisTickLabels.svelte +41 -49
- package/src/2d/Bars.svelte +102 -47
- package/src/2d/Box.svelte +21 -41
- package/src/2d/ColormapLegend.svelte +47 -111
- package/src/2d/Heatmap.svelte +107 -85
- package/src/2d/Legend.svelte +115 -126
- package/src/2d/Lines.svelte +54 -40
- package/src/2d/Multilines.svelte +73 -46
- package/src/2d/Points.svelte +76 -58
- package/src/2d/Rectangles.svelte +67 -58
- package/src/2d/Segments.svelte +59 -46
- package/src/2d/TextLabels.svelte +102 -72
- package/src/2d/TextLegend.svelte +17 -39
- package/src/2d/XAxis.svelte +49 -98
- package/src/2d/YAxis.svelte +47 -93
- package/src/2d/index.js +2 -1
- package/src/3d/Axes.svelte +306 -348
- package/src/3d/AxisLines.svelte +19 -37
- package/src/3d/AxisTickLabels.svelte +15 -32
- package/src/3d/Lines.svelte +59 -32
- package/src/3d/Mesh.svelte +106 -128
- package/src/3d/Points.svelte +56 -36
- package/src/3d/Segments.svelte +68 -52
- package/src/3d/TextLabels.svelte +63 -49
- package/src/3d/XAxis.svelte +36 -113
- package/src/3d/YAxis.svelte +36 -113
- package/src/3d/ZAxis.svelte +37 -114
- package/src/3d/index.js +2 -1
- package/src/constants.js +103 -0
- package/src/methods.js +1484 -0
- package/src/2d/Axis.svelte +0 -60
- package/src/3d/Axis.svelte +0 -64
- package/src/Colors.js +0 -51
- package/src/Utils.js +0 -626
package/package.json
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svelte-plots-basic",
|
|
3
3
|
"description": "Svelte components for creating simple plots",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "3.0.0",
|
|
5
5
|
"author": "Sergey Kucheryavskiy",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"private": false,
|
|
8
8
|
"exports": {
|
|
9
|
-
"./utils": "./src/
|
|
9
|
+
"./utils": "./src/methods.js",
|
|
10
10
|
"./2d": "./src/2d/index.js",
|
|
11
11
|
"./2d/*.svelte": "./src/2d/*.svelte",
|
|
12
12
|
"./3d": "./src/3d/index.js",
|
|
13
13
|
"./3d/*.svelte": "./src/3d/*.svelte"
|
|
14
14
|
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"svelte": "^5.x.x"
|
|
17
|
+
},
|
|
15
18
|
"dependencies": {
|
|
16
19
|
"mdatools": "^1.x.x"
|
|
17
20
|
},
|
package/src/2d/Area.svelte
CHANGED
|
@@ -1,61 +1,69 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* Area *
|
|
4
|
-
* -------------------- *
|
|
5
|
-
* shows area of a polygon defined by set of points *
|
|
6
|
-
*****************************************************/
|
|
1
|
+
<!--
|
|
2
|
+
@component Adds a closed polygon (area).
|
|
7
3
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
Main properties:
|
|
5
|
+
- `xValues` - array of vector with x-coordinates of the polygon's points.
|
|
6
|
+
- `yValues` - array of vector with y-coordinates of the polygon's points.
|
|
7
|
+
- `lineWidth` - width (thickness) of the polygon's line in pixels, defailt: `1`.
|
|
8
|
+
- `lineColor` - line color, default: `Colors.PRIMARY`.
|
|
9
|
+
- `lineType` - type of line (`1` - solid, `2` - dashed, `3` - dotted, `4` - dashdot).
|
|
10
|
+
- `facColor` - face (fill) color of the polygon, default: `'transparent'`.
|
|
11
|
+
- `opacity` - opacity of the face color, default: `1`.
|
|
12
|
+
- `onclick` - function (callback) to be called when user clicks on a polygon.
|
|
13
|
+
|
|
14
|
+
Example:
|
|
12
15
|
|
|
16
|
+
```svelte
|
|
17
|
+
<script>
|
|
18
|
+
import { Axes, Area } from 'svelte-plots-basic/2d';
|
|
13
19
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
20
|
+
const xValues = [-3, -2, -1, 0, 1, 2, 3];
|
|
21
|
+
const yValues = [9, 4, 1, 0, 1, 4, 9];
|
|
22
|
+
</script>
|
|
17
23
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
<Axes limX={[-4, 4]} limY={[-2, 10]}>
|
|
25
|
+
<Area {xValues} {yValues} />
|
|
26
|
+
</Axes>
|
|
27
|
+
```
|
|
28
|
+
-->
|
|
29
|
+
<script>
|
|
30
|
+
import { getContext } from 'svelte';
|
|
31
|
+
import { Colors } from '../constants';
|
|
32
|
+
import { val2p, checkCoords, handleClick, transformCoords } from '../methods';
|
|
33
|
+
import { LINE_STYLES } from '../constants';
|
|
26
34
|
|
|
35
|
+
/** @type {Props} */
|
|
36
|
+
let {
|
|
37
|
+
xValues, // vector or array with x-coordinates of the points
|
|
38
|
+
yValues, // vector or array with y-coordinates of the points
|
|
39
|
+
lineColor = Colors.PRIMARY, // color of segment lines
|
|
40
|
+
lineType = 1, // type of segment lines (1 - solid, 2 - dashed, 3 - dotted, 4 - dashdot)
|
|
41
|
+
lineWidth = 1, // width (thickness) of segment lines
|
|
42
|
+
faceColor = 'transparent', // color of segment lines
|
|
43
|
+
opacity = 1, // opacity of the area color
|
|
44
|
+
onclick, // function to be called if onclick event fires
|
|
45
|
+
} = $props();
|
|
27
46
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
47
|
+
// check user provided coordinates
|
|
48
|
+
const xv = $derived(checkCoords(xValues, 'Area'));
|
|
49
|
+
const yv = $derived(xv ? checkCoords(yValues, 'Area', xv.length) : null);
|
|
31
50
|
|
|
32
|
-
// get axes context
|
|
51
|
+
// get axes context and compute coordinates of polyline
|
|
33
52
|
const axes = getContext('axes');
|
|
53
|
+
const p = $derived(xv && yv ? val2p(xv, yv, axes.tX(), axes.tY()) : null);
|
|
54
|
+
|
|
55
|
+
const ys = $derived(yv ? transformCoords(yv.subset(1), axes.tY()) : null);
|
|
56
|
+
const xs = $derived(xv ? transformCoords(xv.subset(1), axes.tX()) : null);
|
|
57
|
+
const pa = $derived(p && xs && ys ? xs + ',' + ys + ' ' + p + ' ' + xs + ',' + ys : null);
|
|
34
58
|
|
|
35
|
-
const
|
|
36
|
-
const isOk = axes.isOk;
|
|
37
|
-
const tX = axes.tX;
|
|
38
|
-
const tY = axes.tY;
|
|
39
|
-
|
|
40
|
-
// reactive variables for coordinates of data points in pixels
|
|
41
|
-
let p, xs, y0, xe = undefined;
|
|
42
|
-
$: {
|
|
43
|
-
|
|
44
|
-
if ($isOk) {
|
|
45
|
-
const xv = checkCoords(xValues, 'AreaSeries');
|
|
46
|
-
p = val2p(xv, yValues, $tX, $tY, axes);
|
|
47
|
-
y0 = axes.transform(vector([0]), $tY.coords)[0];
|
|
48
|
-
xs = axes.transform(xv.subset(1), $tX.coords)[0];
|
|
49
|
-
xe = axes.transform(xv.subset(xValues.length), $tX.coords)[0];
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
$: areaStyleStr = `opacity:${opacity};fill:${fillColor};stroke:${lineColor};stroke-width: ${lineWidth}px;stroke-dasharray:${axes.LINE_STYLES[$scale][lineType - 1]}`;
|
|
59
|
+
const areaStyleStr = $derived(`opacity:${opacity};fill:${faceColor};stroke:${lineColor};stroke-width: ${lineWidth}px;stroke-dasharray:${LINE_STYLES[axes.scales().plot][lineType - 1]}`);
|
|
54
60
|
</script>
|
|
55
61
|
|
|
56
|
-
{#if
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
62
|
+
{#if pa}
|
|
63
|
+
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
|
64
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
65
|
+
<g onclick={(e) => handleClick(e, 'polygon', onclick)} class="series series-area" style={areaStyleStr}>
|
|
66
|
+
<polygon points={pa}/>
|
|
67
|
+
</g>
|
|
60
68
|
{/if}
|
|
61
69
|
|