svelte-plots-basic 3.0.1 → 3.0.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.
- package/package.json +1 -1
- package/src/2d/Axes.svelte +16 -2
- package/src/2d/Points.svelte +3 -5
- package/src/2d/TextLabels.svelte +10 -7
package/package.json
CHANGED
package/src/2d/Axes.svelte
CHANGED
|
@@ -62,8 +62,8 @@
|
|
|
62
62
|
/* handler for mouse events */
|
|
63
63
|
function handleMouse(e, f) {
|
|
64
64
|
if (f && e.target.id == "axes-box") {
|
|
65
|
-
const x = invTransformCoords([e.offsetX -
|
|
66
|
-
const y = invTransformCoords([e.offsetY], tY)[0];
|
|
65
|
+
const x = invTransformCoords([e.offsetX - left], tX)[0];
|
|
66
|
+
const y = invTransformCoords([e.offsetY - top], tY)[0];
|
|
67
67
|
f(x, y);
|
|
68
68
|
}
|
|
69
69
|
}
|
|
@@ -363,8 +363,22 @@
|
|
|
363
363
|
-webkit-user-select: none;
|
|
364
364
|
}
|
|
365
365
|
|
|
366
|
+
.series-points1 text,
|
|
367
|
+
.series-points1 tspan {
|
|
368
|
+
dominant-baseline: middle;
|
|
369
|
+
alignment-baseline: middle;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
.series-points2 text,
|
|
373
|
+
.series-points2 tspan {
|
|
374
|
+
dominant-baseline: central;
|
|
375
|
+
alignment-baseline: central;
|
|
376
|
+
}
|
|
377
|
+
|
|
366
378
|
.series-text text,
|
|
367
379
|
.series-text tspan {
|
|
380
|
+
dominant-baseline: middle;
|
|
381
|
+
alignment-baseline: middle;
|
|
368
382
|
text-anchor: middle;
|
|
369
383
|
user-select: none;
|
|
370
384
|
-webkit-user-select: none;
|
package/src/2d/Points.svelte
CHANGED
|
@@ -68,10 +68,8 @@
|
|
|
68
68
|
`fill:${faceColor};stroke-width:${lineWidth}px;stroke:${lineColor}; font-size:${markerSize}em;`
|
|
69
69
|
);
|
|
70
70
|
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
`dominant-baseline:middle;alignment-baseline:middle;`
|
|
74
|
-
);
|
|
71
|
+
const className = $derived(['◼', '⬥', '+', '✳', '✕'].includes(markerSymbol) ? 'series-points2' : 'series-points1');
|
|
72
|
+
|
|
75
73
|
// check if all coordinates are correct
|
|
76
74
|
const isOk = $derived(x && y && x.length === y.length);
|
|
77
75
|
</script>
|
|
@@ -80,7 +78,7 @@
|
|
|
80
78
|
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
|
81
79
|
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
82
80
|
<g onclick={(e) => handleClick(e, 'text', onclick)}
|
|
83
|
-
class="series series-points" style={textStyleStr
|
|
81
|
+
class="series series-points {className}" style={textStyleStr} text-anchor="middle">
|
|
84
82
|
{#each x as v, i}
|
|
85
83
|
<text x={x[i]} y={y[i]}>{markerSymbol}</text>
|
|
86
84
|
{/each}
|
package/src/2d/TextLabels.svelte
CHANGED
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
- `lineColor`- border colors of label symbols, default: `'transparent'`.
|
|
11
11
|
- `lineWidth`- border width of label symbols in pixels, default: `0`.
|
|
12
12
|
- `textSize`- size of label symbols in em, default: `1`.
|
|
13
|
-
- `className`- CSS class name for the labels group, default: `'series-text'`.
|
|
14
13
|
- `rotateAngle`- angle to rotate labels, default: `0`.
|
|
15
14
|
- `onclick` - function (callback) to be called when user clicks on a label.
|
|
16
15
|
|
|
@@ -42,8 +41,8 @@
|
|
|
42
41
|
labels, // array with labels (strings)
|
|
43
42
|
pos = 0, // position of labels related to coordinates (middle, bottom, left, top, right)
|
|
44
43
|
faceColor = Colors.PRIMARY_TEXT, // face color of label symbols
|
|
45
|
-
lineColor = 'transparent',
|
|
46
|
-
lineWidth = 0,
|
|
44
|
+
lineColor = 'transparent', // border colors of label symbols
|
|
45
|
+
lineWidth = 0, // border width of label symbols
|
|
47
46
|
textSize = 1, // size of label symbols
|
|
48
47
|
rotateAngle = 0, // angle to rotate labels
|
|
49
48
|
onclick, // function to be called if onclick event fires
|
|
@@ -87,8 +86,8 @@
|
|
|
87
86
|
|
|
88
87
|
// define x and y shifts for positioning
|
|
89
88
|
const m = $derived(LABELS_MARGIN[axes.scales().plot]);
|
|
90
|
-
const dx = $derived([0, 0, m, 0,
|
|
91
|
-
const dy = $derived([0, m,
|
|
89
|
+
const dx = $derived([0, 0, -m, 0, m, m]);
|
|
90
|
+
const dy = $derived([0, m, 0, -m, 0, m]);
|
|
92
91
|
|
|
93
92
|
// styles for the elements
|
|
94
93
|
const textStyleStr = $derived(`fill:${faceColor};stroke-width:${lineWidth}px;stroke:${lineColor};font-size:${textSize}em;`);
|
|
@@ -113,13 +112,17 @@
|
|
|
113
112
|
{:else if (Array.isArray(pos) || ArrayBuffer.isView(pos))}
|
|
114
113
|
|
|
115
114
|
{#each x as v, i}
|
|
116
|
-
<text data-id={i} x={x[i]} y={y[i]} dx={dx[pos[i]]} dy={dy[pos[i]]}
|
|
115
|
+
<text data-id={i} x={x[i]} y={y[i]} dx={dx[pos[i]]} dy={dy[pos[i]]}
|
|
116
|
+
transform={rotateAngle !== undefined ? `rotate(${rotateAngle}, ${x[i] + dx[pos]}, ${y[i] + dy[pos]})` : ''}
|
|
117
|
+
text-anchor={textAnchors[pos[i]]}>{@html labels[i]}</text>
|
|
117
118
|
{/each}
|
|
118
119
|
|
|
119
120
|
{:else}
|
|
120
121
|
|
|
121
122
|
{#each x as v, i}
|
|
122
|
-
<text data-id={i} x={x[i]} y={y[i]} dx={dx[pos]} dy={dy[pos]}
|
|
123
|
+
<text data-id={i} x={x[i]} y={y[i]} dx={dx[pos]} dy={dy[pos]}
|
|
124
|
+
transform={rotateAngle !== undefined ? `rotate(${rotateAngle}, ${x[i] + dx[pos]}, ${y[i] + dy[pos]})` : ''}
|
|
125
|
+
text-anchor={textAnchors[pos]}>{@html labels[i]}</text>
|
|
123
126
|
{/each}
|
|
124
127
|
|
|
125
128
|
{/if}
|