svelte-plots-basic 1.0.5 → 1.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/package.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "svelte": "^3.0.0"
15
15
  },
16
16
  "dependencies": {
17
- "mdatools": "^0.1.0"
17
+ "mdatools": "^0.5.3"
18
18
  },
19
19
  "keywords": [
20
20
  "svelte",
@@ -25,7 +25,7 @@
25
25
  "dist"
26
26
  ],
27
27
  "description": "Svelte components for creating simple plots",
28
- "version": "1.0.5",
28
+ "version": "1.1.0",
29
29
  "repository": {
30
30
  "type": "git",
31
31
  "url": "svkucheryavski/svelte-plots-basic"
package/src/Axes.svelte CHANGED
@@ -1,5 +1,5 @@
1
1
  <script>
2
- import { onMount, setContext, createEventDispatcher } from 'svelte';
2
+ import { setContext, createEventDispatcher } from 'svelte';
3
3
  import { writable } from 'svelte/store';
4
4
 
5
5
  /* input parameters */
@@ -34,6 +34,7 @@
34
34
  "large": 20
35
35
  };
36
36
 
37
+
37
38
  // line styles for different scales and types
38
39
  const LINE_STYLES = {
39
40
  small: ["0", "3,3", "1,1", "3,1"],
@@ -45,7 +46,8 @@
45
46
  const clipPathID = "plottingArea" + Math.round(Math.random() * 10000);
46
47
 
47
48
  /* parameters for internal use inside the component */
48
- let axesWrapper; // pointer to axes wrapper DOM element
49
+ let plotWidth; // width of plot
50
+ let plotHeight; // height of plot
49
51
  let axesMargins = [0.034, 0.034, 0.034, 0.034]; // initial margins (will be multiplied to FACTORS)
50
52
 
51
53
  /* reactive parameters to be shared with children via context */
@@ -263,19 +265,8 @@
263
265
 
264
266
  setContext('axes', context);
265
267
 
266
- /* observer for the plotting area size */
267
- var ro = new ResizeObserver(entries => {
268
- for (let entry of entries) {
269
- const cr = entry.contentRect;
270
- width.update(x => cr.width);
271
- height.update(x => cr.height);
272
- scale.update(x => getScale(cr.width, cr.height));
273
- }
274
- });
275
-
276
- onMount(() => {
277
- ro.observe(axesWrapper);
278
- });
268
+ // update plot scale based on its size
269
+ $: scale.update(x => getScale(plotWidth, plotHeight));
279
270
 
280
271
 
281
272
  // handle click on plot elements and dispatch manual events
@@ -332,7 +323,7 @@
332
323
  </script>
333
324
 
334
325
 
335
- <div class="plot {'plot_' + $scale}" class:plot_error="{!$isOk}">
326
+ <div class="plot {'plot_' + $scale}" bind:clientHeight={plotHeight} bind:clientWidth={plotWidth} class:plot_error="{!$isOk}">
336
327
 
337
328
  <!-- plot title and axis labels -->
338
329
  {#if title !== ""}<div class="axes__title">{@html title}</div>{/if}
@@ -340,7 +331,7 @@
340
331
  {#if xLabel !== ""}<div class="axes__xlabel"><span>{@html xLabel}</span></div>{/if}
341
332
 
342
333
  <!-- axes (coordinate system) -->
343
- <div class="axes-wrapper" bind:this={axesWrapper} >
334
+ <div class="axes-wrapper" bind:clientHeight={$height} bind:clientWidth={$width} >
344
335
  <svg on:click={handleClick} preserveAspectRatio="none" class="axes">
345
336
 
346
337
  <!-- define clipping path -->
@@ -14,8 +14,6 @@
14
14
  export let title = "";
15
15
  export let style = "series_rect";
16
16
 
17
- // styles for bars and labels
18
- const barsStyleStr = `fill:${faceColor};stroke:${borderColor};stroke-width: ${lineWidth}px;`;
19
17
 
20
18
  // multiply width and height values if needed
21
19
  if (!Array.isArray(left) || !Array.isArray(top) || left.length < 1 || left.length != top.length) {
@@ -48,6 +46,10 @@
48
46
  $: ry = axes.scaleY(top, $yLim, $axesHeight);
49
47
  $: rw = axes.scaleX(width, $xLim, $axesWidth, true);
50
48
  $: rh = axes.scaleY(height, $yLim, $axesHeight, true);
49
+
50
+ // styles for bars and labels
51
+ $: barsStyleStr = `fill:${faceColor};stroke:${borderColor};stroke-width: ${lineWidth}px;`;
52
+
51
53
  </script>
52
54
 
53
55
  {#if rx !== undefined && ry !== undefined}
@@ -72,7 +72,7 @@
72
72
  {/if}
73
73
 
74
74
  <style>
75
- text {
75
+ text, text > :global(tspan) {
76
76
  dominant-baseline: middle;
77
77
  }
78
78
  </style>