layerchart 0.36.0 → 0.36.1

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.
@@ -9,6 +9,8 @@ import Rect from './Rect.svelte';
9
9
  import { tooltipContext } from './TooltipContext.svelte';
10
10
  const { flatData, x, xDomain, xScale, xRange, xGet, y, yDomain, yScale, yRange, yGet, rGet, config, } = getContext('LayerCake');
11
11
  const tooltip = tooltipContext();
12
+ /** Highlight specific data (annotate), espect uses tooltip data */
13
+ export let data = undefined;
12
14
  export let axis = undefined;
13
15
  /** Show points and pass props to Circles */
14
16
  export let points = false;
@@ -27,10 +29,11 @@ let _area = {
27
29
  width: 0,
28
30
  height: 0,
29
31
  };
30
- $: if ($tooltip.data) {
31
- let xCoord = $xGet($tooltip.data);
32
+ $: highlightData = data ?? $tooltip.data;
33
+ $: if (highlightData) {
34
+ let xCoord = $xGet(highlightData);
32
35
  let xOffset = isScaleBand($xScale) ? $xScale.bandwidth() / 2 : 0;
33
- let yCoord = $yGet($tooltip.data);
36
+ let yCoord = $yGet(highlightData);
34
37
  let yOffset = isScaleBand($yScale) ? $yScale.bandwidth() / 2 : 0;
35
38
  // Reset lines
36
39
  _lines = [];
@@ -73,7 +76,7 @@ $: if ($tooltip.data) {
73
76
  }
74
77
  else {
75
78
  // Find width to next data point
76
- const index = $flatData.findIndex((d) => Number($x(d)) === Number($x($tooltip.data)));
79
+ const index = $flatData.findIndex((d) => Number($x(d)) === Number($x(highlightData)));
77
80
  const isLastPoint = index + 1 === $flatData.length;
78
81
  const nextDataPoint = isLastPoint ? max($xDomain) : $x($flatData[index + 1]);
79
82
  _area.width = ($xScale(nextDataPoint) ?? 0) - (xCoord ?? 0);
@@ -121,7 +124,7 @@ $: if ($tooltip.data) {
121
124
  }
122
125
  else {
123
126
  // Find width to next data point
124
- const index = $flatData.findIndex((d) => Number($x(d)) === Number($x($tooltip.data)));
127
+ const index = $flatData.findIndex((d) => Number($x(d)) === Number($x(highlightData)));
125
128
  const isLastPoint = index + 1 === $flatData.length;
126
129
  const nextDataPoint = isLastPoint ? max($yDomain) : $x($flatData[index + 1]);
127
130
  _area.height = ($yScale(nextDataPoint) ?? 0) - (yCoord ?? 0);
@@ -139,12 +142,12 @@ $: if ($tooltip.data) {
139
142
  // `x` accessor with multiple properties (ex. `x={['start', 'end']})`)
140
143
  _points = xCoord.filter(notNull).map((xItem, i) => ({
141
144
  x: xItem + xOffset,
142
- y: $yGet($tooltip.data) + yOffset,
145
+ y: $yGet(highlightData) + yOffset,
143
146
  }));
144
147
  }
145
- else if (Array.isArray($tooltip.data)) {
148
+ else if (Array.isArray(highlightData)) {
146
149
  // Stack series
147
- _points = $tooltip.data.map((yValue, i) => ({
150
+ _points = highlightData.map((yValue, i) => ({
148
151
  x: xCoord + xOffset,
149
152
  y: $yScale(yValue) + yOffset,
150
153
  }));
@@ -153,14 +156,14 @@ $: if ($tooltip.data) {
153
156
  _points = [
154
157
  {
155
158
  x: xCoord + xOffset,
156
- y: $yGet($tooltip.data) + yOffset,
159
+ y: $yGet(highlightData) + yOffset,
157
160
  },
158
161
  ];
159
162
  }
160
163
  }
161
164
  </script>
162
165
 
163
- {#if $tooltip.data}
166
+ {#if highlightData}
164
167
  {#if area}
165
168
  <slot name="area" area={_area}>
166
169
  <Rect
@@ -186,7 +189,7 @@ $: if ($tooltip.data) {
186
189
  stroke={typeof bar === 'object' ? bar.stroke : null}
187
190
  strokeWidth={typeof bar === 'object' ? bar.strokeWidth : null}
188
191
  radius={typeof bar === 'object' ? bar.radius : null}
189
- bar={$tooltip.data}
192
+ bar={highlightData}
190
193
  class={cls(!bar.fill && 'fill-primary', typeof bar === 'object' ? bar.class : null)}
191
194
  on:click
192
195
  />
@@ -216,7 +219,7 @@ $: if ($tooltip.data) {
216
219
  <slot name="points" points={_points}>
217
220
  {#each _points as point}
218
221
  <!-- TODO: Improve color with stacked data -->
219
- {@const fill = $config.r ? $rGet($tooltip.data) : null}
222
+ {@const fill = $config.r ? $rGet(highlightData) : null}
220
223
  <Circle
221
224
  spring
222
225
  cx={point.x}
@@ -1,6 +1,7 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
2
  declare const __propDef: {
3
3
  props: {
4
+ /** Highlight specific data (annotate), espect uses tooltip data */ data?: any;
4
5
  axis?: 'x' | 'y' | 'both' | 'none' | undefined;
5
6
  /** Show points and pass props to Circles */ points?: boolean | Partial<{
6
7
  [x: string]: any;
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "author": "Sean Lynch <techniq35@gmail.com>",
5
5
  "license": "MIT",
6
6
  "repository": "techniq/layerchart",
7
- "version": "0.36.0",
7
+ "version": "0.36.1",
8
8
  "devDependencies": {
9
9
  "@changesets/cli": "^2.27.1",
10
10
  "@mdi/js": "^7.4.47",