svelte-plots-basic 2.3.2 → 2.3.4

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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "svelte-plots-basic",
3
3
  "description": "Svelte components for creating simple plots",
4
- "version": "2.3.2",
4
+ "version": "2.3.4",
5
5
  "author": "Sergey Kucheryavskiy",
6
6
  "license": "MIT",
7
7
  "private": false,
@@ -67,7 +67,7 @@
67
67
  // font size for plot element
68
68
  const LEGEND_FONT_SIZE = {
69
69
  "small": 11,
70
- "medium": 13,
70
+ "medium": 14,
71
71
  "large": 16,
72
72
  "xlarge": 18
73
73
  };
@@ -75,15 +75,15 @@
75
75
  // font size for legend items in pixels
76
76
  const PLOT_FONT_SIZE = {
77
77
  "small": 12,
78
- "medium": 14,
79
- "large": 18,
78
+ "medium": 15,
79
+ "large": 19,
80
80
  "xlarge": 21
81
81
  };
82
82
 
83
83
  // margin between plot series elements and data labels
84
84
  const LABELS_MARGIN = {
85
85
  'small': 11,
86
- 'medium': 14,
86
+ 'medium': 15,
87
87
  'large': 17,
88
88
  'xlarge': 19
89
89
  };
@@ -14,13 +14,16 @@
14
14
  /* Input parameters */
15
15
  /*****************************************/
16
16
 
17
- export let breaks; // vector with breaks for color intervals
17
+ export let breaks; // vector with breaks for color intervals or vector with their indices
18
18
  export let colmap; // array with colors for each interval
19
19
  export let decNum = 1; // number of decimals to show the interval boundaries with
20
- export let labels = null; // optional vector with labels for interval boundaries
20
+ export let labels = null; // optional vector with labels for interval boundaries or elements
21
21
  export let labelColor = '#909090'; // color of labels
22
22
  export let fontSize = 0.85; // font size for labels in em
23
23
 
24
+ // if number of breaks is the same as number of elements in color map
25
+ // the corresponding labels will be placed in the middle inder each color element in the legend
26
+ // if this number is by one larger, the labels will be placed on the boundaries
24
27
 
25
28
  /*****************************************/
26
29
  /* Component code */
@@ -40,7 +43,10 @@
40
43
  }
41
44
 
42
45
  // check colormap values
43
- $: if (!colmap || colmap.length !== breaks.length - 1) {
46
+ $: if (!colmap || !(colmap.length === breaks.length - 1 || colmap.length === breaks.length )) {
47
+ console.log(colmap)
48
+ console.log(breaks)
49
+ console.log(labels)
44
50
  throw new Error('ColormapLegend: number of color values in colormap does not match number of intervals defined by breaks.');
45
51
  }
46
52
 
@@ -61,9 +67,10 @@
61
67
 
62
68
  // number of elements
63
69
  $: n = colmap.length;
70
+ $: isCentered = lLabels && lLabels.length === n;
64
71
 
65
72
  // compute screen coordinates of the elements
66
- let rx, ry, rw, rh = undefined;
73
+ let dxl, rx, ry, rw, rh = undefined;
67
74
  $: {
68
75
  if ($isOk) {
69
76
  // compute size of the whole block in plot coordinates
@@ -82,6 +89,7 @@
82
89
  rx = axes.transform(Vector.seq(0, n).apply(v => left + v * elWidth), $tX.coords);
83
90
  rw = axes.transform([elWidth], $tX.objects);
84
91
  rh = EL_HEIGHTS_PX[$scale];
92
+ dxl = isCentered ? rw[0] / 2 : 0
85
93
  }
86
94
  };
87
95
  </script>
@@ -90,9 +98,11 @@
90
98
  <g class="series colormap_legend" style="stroke:0;stroke-width:0px;">
91
99
  {#each colmap as col, i}
92
100
  <rect x={rx[i]} y={ry} width={rw} height={rh} fill="{col}"/>
93
- <text x={rx[i]} y={ry} dx={0} dy={rh * 1.25} dominant-baseline="hanging" fill={labelColor} font-size="{fontSize}em" text-anchor="middle">{@html lLabels[i]}</text>
101
+ <text x={rx[i]} y={ry} dx={dxl} dy={rh * 1.25} dominant-baseline="hanging" fill={labelColor} font-size="{fontSize}em" text-anchor="middle">{@html lLabels[i]}</text>
94
102
  {/each}
103
+ {#if !isCentered}
95
104
  <text x={rx[n]} y={ry} dx={0} dy={rh * 1.25} dominant-baseline="hanging" fill={labelColor} font-size="{fontSize}em" text-anchor="middle">{@html lLabels[n]}</text>
105
+ {/if}
96
106
  </g>
97
107
  {/if}
98
108