layerchart 0.81.0 → 0.81.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.
@@ -15,7 +15,7 @@
15
15
  import type { DomainType } from '../utils/scales.js';
16
16
  import { asAny } from '../utils/types.js';
17
17
 
18
- const { xScale, yScale, width, height, padding } = chartContext();
18
+ const { xScale, yScale, width, height, padding, config } = chartContext();
19
19
 
20
20
  /** Axis to apply brushing */
21
21
  export let axis: 'x' | 'y' | 'both' = 'x';
@@ -31,9 +31,15 @@
31
31
 
32
32
  export let labels: ComponentProps<Text> | boolean = false;
33
33
 
34
+ /** Mode of operation
35
+ * `integrated`: use with single chart
36
+ * `separated`: use with separate (typically smaller) chart and state can be managed externally (sync with other charts, etc). Show active selection when domain does not equal original
37
+ */
38
+ export let mode: 'integrated' | 'separated' = 'integrated';
39
+
34
40
  // Capture original domains for reset()
35
- const originalXDomain = $xScale.domain() as [number, number];
36
- const originalYDomain = $yScale.domain() as [number, number];
41
+ const originalXDomain = $config.xDomain;
42
+ const originalYDomain = $config.yDomain;
37
43
 
38
44
  $: [xDomainMin, xDomainMax] = extent<number>($xScale.domain()) as [number, number];
39
45
  $: [yDomainMin, yDomainMax] = extent<number>($yScale.domain()) as [number, number];
@@ -58,6 +64,7 @@
58
64
  export let onChange: (e: { xDomain?: DomainType; yDomain?: DomainType }) => void = () => {};
59
65
  export let onBrushStart: (e: { xDomain?: DomainType; yDomain?: DomainType }) => void = () => {};
60
66
  export let onBrushEnd: (e: { xDomain?: DomainType; yDomain?: DomainType }) => void = () => {};
67
+ export let onReset: (e: { xDomain?: DomainType; yDomain?: DomainType }) => void = () => {};
61
68
 
62
69
  let frameEl: SVGRectElement;
63
70
 
@@ -195,6 +202,8 @@
195
202
 
196
203
  xDomain = originalXDomain;
197
204
  yDomain = originalYDomain;
205
+
206
+ onReset({ xDomain, yDomain });
198
207
  }
199
208
 
200
209
  function selectAll() {
@@ -212,12 +221,15 @@
212
221
  $: rangeWidth = axis === 'both' || axis === 'x' ? right - left : $width;
213
222
  $: rangeHeight = axis === 'both' || axis === 'y' ? bottom - top : $height;
214
223
 
215
- // Set reactively to handle cases where xDomain/yDomain are set externally (ex. `bind:xDomain`)
216
- $: isActive =
217
- xDomain?.[0]?.valueOf() !== originalXDomain[0]?.valueOf() ||
218
- xDomain?.[1]?.valueOf() !== originalXDomain[1]?.valueOf() ||
219
- yDomain?.[0]?.valueOf() !== originalYDomain[0]?.valueOf() ||
220
- yDomain?.[1]?.valueOf() !== originalYDomain[1]?.valueOf();
224
+ let isActive = false;
225
+ $: if (mode === 'separated') {
226
+ // Set reactively to handle cases where xDomain/yDomain are set externally (ex. `bind:xDomain`)
227
+ isActive =
228
+ xDomain?.[0]?.valueOf() !== originalXDomain?.[0]?.valueOf() ||
229
+ xDomain?.[1]?.valueOf() !== originalXDomain?.[1]?.valueOf() ||
230
+ yDomain?.[0]?.valueOf() !== originalYDomain?.[0]?.valueOf() ||
231
+ yDomain?.[1]?.valueOf() !== originalYDomain?.[1]?.valueOf();
232
+ }
221
233
  </script>
222
234
 
223
235
  <g class={cls('Brush select-none', classes.root, $$props.class)}>
@@ -13,6 +13,7 @@ declare const __propDef: {
13
13
  xDomain?: DomainType | undefined;
14
14
  yDomain?: DomainType | undefined;
15
15
  labels?: (ComponentProps<Text> | boolean) | undefined;
16
+ mode?: "integrated" | "separated" | undefined;
16
17
  range?: SVGAttributes<SVGRectElement> | undefined;
17
18
  handle?: SVGAttributes<SVGRectElement> | undefined;
18
19
  format?: FormatType | undefined;
@@ -35,6 +36,10 @@ declare const __propDef: {
35
36
  xDomain?: DomainType;
36
37
  yDomain?: DomainType;
37
38
  }) => void) | undefined;
39
+ onReset?: ((e: {
40
+ xDomain?: DomainType;
41
+ yDomain?: DomainType;
42
+ }) => void) | undefined;
38
43
  };
39
44
  events: {
40
45
  [evt: string]: CustomEvent<any>;
@@ -75,7 +75,7 @@
75
75
  $: stackSeries = seriesLayout.startsWith('stack');
76
76
 
77
77
  export let axis: ComponentProps<Axis> | 'x' | 'y' | boolean = true;
78
- export let brush: ({ mode: 'integrated' } & ComponentProps<Brush>) | false = false;
78
+ export let brush: ComponentProps<Brush> | boolean = false;
79
79
  export let grid: ComponentProps<Grid> | boolean = true;
80
80
  export let labels: ComponentProps<Labels> | boolean = false;
81
81
  export let legend: ComponentProps<Legend> | boolean = false;
@@ -396,7 +396,7 @@
396
396
  {/if}
397
397
  </svelte:component>
398
398
 
399
- {#if brush && brush.mode === 'integrated'}
399
+ {#if brush && (brush === true || brush.mode == undefined || brush.mode === 'integrated')}
400
400
  <Svg>
401
401
  {@const brushProps = { ...(typeof brush === 'object' ? brush : null), ...props.brush }}
402
402
  <Brush
@@ -67,7 +67,7 @@
67
67
  $: isDefaultSeries = series.length === 1 && series[0].key === 'default';
68
68
 
69
69
  export let axis: ComponentProps<Axis> | 'x' | 'y' | boolean = true;
70
- export let brush: ({ mode: 'integrated' } & ComponentProps<Brush>) | false = false;
70
+ export let brush: ComponentProps<Brush> | boolean = false;
71
71
  export let grid: ComponentProps<Grid> | boolean = true;
72
72
  export let labels: ComponentProps<Labels> | boolean = false;
73
73
  export let legend: ComponentProps<Legend> | boolean = false;
@@ -322,7 +322,7 @@
322
322
  </slot>
323
323
  </svelte:component>
324
324
 
325
- {#if brush && brush.mode === 'integrated'}
325
+ {#if brush && (brush === true || brush.mode == undefined || brush.mode === 'integrated')}
326
326
  <Svg>
327
327
  {@const brushProps = { ...(typeof brush === 'object' ? brush : null), ...props.brush }}
328
328
  <Brush
@@ -58,7 +58,7 @@
58
58
  $: isDefaultSeries = series.length === 1 && series[0].key === 'default';
59
59
 
60
60
  export let axis: ComponentProps<Axis> | 'x' | 'y' | boolean = true;
61
- export let brush: ({ mode: 'integrated' } & ComponentProps<Brush>) | false = false;
61
+ export let brush: ComponentProps<Brush> | boolean = false;
62
62
  export let grid: ComponentProps<Grid> | boolean = true;
63
63
  export let labels: ComponentProps<Labels> | boolean = false;
64
64
  export let legend: ComponentProps<Legend> | boolean = false;
@@ -270,7 +270,7 @@
270
270
  </svelte:component>
271
271
 
272
272
  <!-- TODO: Determine how to coordinate with `tooltip={{ mode: 'voronoi' }} -->
273
- {#if brush && brush.mode === 'integrated'}
273
+ {#if brush && (brush === true || brush.mode == undefined || brush.mode === 'integrated')}
274
274
  <Svg>
275
275
  {@const brushProps = { ...(typeof brush === 'object' ? brush : null), ...props.brush }}
276
276
  <Brush
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.81.0",
7
+ "version": "0.81.2",
8
8
  "devDependencies": {
9
9
  "@changesets/cli": "^2.27.12",
10
10
  "@mdi/js": "^7.4.47",