svelte-plots-basic 3.0.0 → 3.0.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.
package/README.md CHANGED
@@ -373,7 +373,7 @@ Lines components is similar to `<Points>` but instead of showing markers, it con
373
373
  </script>
374
374
 
375
375
  <div class="plot-wrapper">
376
- <Axes limX={[0, 6]} limY={[0, 10]} >
376
+ <Axes limX={[-10, 10]} limY={[-2, 20]} >
377
377
 
378
378
  <Lines {xValues} {yValues} lineWidth={2} lineColor="#ff4422" />
379
379
 
@@ -419,20 +419,20 @@ Here is an example of using the component with all available parameters:
419
419
  import { Vector, cbind } from 'mdatools/arrays';
420
420
 
421
421
  // create x-values
422
- const x = Vector.seq(0, 15, 0.1);
422
+ const xValues = Vector.seq(0, 15, 0.1);
423
423
 
424
424
  // compute y-values for four lines
425
- const y1 = x.apply(v => Math.sin(v));
425
+ const y1 = xValues.apply(v => Math.sin(v));
426
426
  const y2 = y1.add(0.2);
427
427
  const y3 = y2.add(0.2);
428
428
  const y4 = y3.add(0.2);
429
429
 
430
430
  // combine y-values so they form columns of matrix Y
431
- const Y = cbind(y1, y2, y3, y4);
431
+ const yValues = cbind(y1, y2, y3, y4);
432
432
  </script>
433
433
 
434
434
  <div class="plot-wrapper">
435
- <Axes limX={[0, 6]} limY={[0, 10]} >
435
+ <Axes limX={[-1, 16]} limY={[-2,2]} >
436
436
 
437
437
  <Multilines {xValues} {yValues} lineWidth={2} lineColor="#ff4422" />
438
438
 
@@ -465,7 +465,7 @@ Use this component if you want to show a series of rectangles. The component has
465
465
  const left = [-3, -2, -1, 0, 1, 2, 3];
466
466
  const top = [9, 8, 7, 6, 7, 8, 9];
467
467
  const width = [0.75, 0.75, 0.75, 0.75, 0.75, 0.75, 0.75];
468
- const height = [8, 6, 7, 5, 6, 7, 8];
468
+ const height = [8, 6, 4, 2, 4, 6, 8];
469
469
 
470
470
  </script>
471
471
 
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": "3.0.0",
4
+ "version": "3.0.2",
5
5
  "author": "Sergey Kucheryavskiy",
6
6
  "license": "MIT",
7
7
  "private": false,
@@ -33,8 +33,7 @@
33
33
  import { downloadSVG, downloadPNG, copyToClipboard, checkArray, getScale, getAxisScale, getXAxisParams, getYAxisParams,
34
34
  transformCoords, getColormapLegendParams, getColormapLegendCoords, getTickFactorLabel,
35
35
  getGroupLegendCoords, text2svg,
36
- invTransformCoords,
37
- invTransformObjects} from '../methods.js';
36
+ invTransformCoords } from '../methods.js';
38
37
 
39
38
  import AxisLines from './AxisLines.svelte';
40
39
  import AxisTickLabels from './AxisTickLabels.svelte';
@@ -63,8 +62,8 @@
63
62
  /* handler for mouse events */
64
63
  function handleMouse(e, f) {
65
64
  if (f && e.target.id == "axes-box") {
66
- const x = invTransformCoords([e.offsetX], tX)[0];
67
- 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];
68
67
  f(x, y);
69
68
  }
70
69
  }
@@ -137,8 +136,9 @@
137
136
  height > (pxMargins[0] + pxMargins[2])
138
137
  );
139
138
 
140
-
141
139
  // transformation matrix for x
140
+ // fw: a - tA[1]) * tA[0] + tA[2]
141
+ // in: a - tA[2]) / tA[0] + tA[1]
142
142
  const tX = $derived(!isOk ? {'coords': [1, 0, 0], 'objects': [1, 0, 0]} :
143
143
  {
144
144
  'coords': [ axisWidth / (limX[1] - limX[0]), limX[0], pxMargins[1]],
@@ -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;
@@ -68,10 +68,8 @@
68
68
  `fill:${faceColor};stroke-width:${lineWidth}px;stroke:${lineColor}; font-size:${markerSize}em;`
69
69
  );
70
70
 
71
- const alignStyleStr = $derived(['◼', '⬥', '+', '✳', '✕'].includes(markerSymbol) ?
72
- `dominant-baseline:central;alignment-baseline:mathematical;` :
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 + alignStyleStr} text-anchor="middle">
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}