layerchart 0.4.0 → 0.5.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.
Files changed (45) hide show
  1. package/components/Arc.svelte +2 -2
  2. package/components/Arc.svelte.d.ts +2 -0
  3. package/components/Area.svelte +1 -1
  4. package/components/AreaStack.svelte +1 -1
  5. package/components/AxisX.svelte +2 -2
  6. package/components/AxisY.svelte +2 -2
  7. package/components/Bars.svelte +1 -1
  8. package/components/Baseline.svelte +2 -2
  9. package/components/Bounds.svelte +24 -0
  10. package/components/Bounds.svelte.d.ts +48 -0
  11. package/components/Chart.svelte +2 -2
  12. package/components/ChartClipPath.svelte +1 -1
  13. package/components/Circle.svelte +1 -1
  14. package/components/CircleClipPath.svelte +1 -1
  15. package/components/ClipPath.svelte +1 -1
  16. package/components/ConnectedPoints.svelte +1 -1
  17. package/components/Group.svelte +1 -1
  18. package/components/HighlightLine.svelte +1 -1
  19. package/components/HighlightRect.svelte +1 -1
  20. package/components/Labels.svelte +1 -1
  21. package/components/Line.svelte +1 -1
  22. package/components/LinearGradient.svelte +1 -1
  23. package/components/Link.svelte +1 -1
  24. package/components/Partition.svelte +27 -0
  25. package/components/Partition.svelte.d.ts +27 -0
  26. package/components/Path.svelte +2 -2
  27. package/components/Pattern.svelte +1 -1
  28. package/components/Pie.svelte +1 -1
  29. package/components/Points.svelte +1 -1
  30. package/components/Rect.svelte +1 -1
  31. package/components/RectClipPath.svelte +1 -1
  32. package/components/Sankey.svelte +1 -1
  33. package/components/Text.svelte +1 -1
  34. package/components/Threshold.svelte +1 -1
  35. package/components/Tooltip.svelte +1 -1
  36. package/components/Tree.svelte +1 -1
  37. package/components/Treemap.svelte +10 -41
  38. package/components/Treemap.svelte.d.ts +0 -6
  39. package/components/Zoom.svelte +1 -1
  40. package/components/index.d.ts +3 -0
  41. package/components/index.js +3 -0
  42. package/docs/Preview.svelte +1 -1
  43. package/package.json +22 -20
  44. package/utils/scales.d.ts +17 -0
  45. package/utils/scales.js +46 -0
@@ -1,4 +1,4 @@
1
- <script >/*
1
+ <script>/*
2
2
  TODO:
3
3
  - [ ] Allow spring/tweened to be reactive (but ignore value)
4
4
  */
@@ -110,6 +110,6 @@ $: yOffset = -Math.cos(angle) * offset;
110
110
  <path d={trackArc()} class="track" bind:this={trackArcEl} {...track} />
111
111
  {/if}
112
112
 
113
- <path d={arc()} transform="translate({xOffset}, {yOffset})" {...$$restProps} />
113
+ <path d={arc()} transform="translate({xOffset}, {yOffset})" {...$$restProps} on:click />
114
114
 
115
115
  <slot value={$tweened_value} centroid={trackArcCentroid} {boundingBox} />
@@ -18,6 +18,8 @@ declare const __propDef: {
18
18
  offset?: number;
19
19
  };
20
20
  events: {
21
+ click: MouseEvent;
22
+ } & {
21
23
  [evt: string]: CustomEvent<any>;
22
24
  };
23
25
  slots: {
@@ -1,4 +1,4 @@
1
- <script >import { getContext } from 'svelte';
1
+ <script>import { getContext } from 'svelte';
2
2
  import { area as d3Area } from 'd3-shape';
3
3
  import { interpolatePath } from 'd3-interpolate-path';
4
4
  import { createMotionStore } from '../stores/motionStore';
@@ -1,4 +1,4 @@
1
- <script >import { getContext } from 'svelte';
1
+ <script>import { getContext } from 'svelte';
2
2
  import Area from './Area.svelte';
3
3
  import Path from './Path.svelte';
4
4
  const { data, yScale, zGet } = getContext('LayerCake');
@@ -1,4 +1,4 @@
1
- <script >import { getContext } from 'svelte';
1
+ <script>import { getContext } from 'svelte';
2
2
  import { format } from 'svelte-ux/utils/format';
3
3
  import Text from './Text.svelte';
4
4
  import { isScaleBand } from '../utils/scales';
@@ -39,7 +39,7 @@ $: tickVals = Array.isArray(ticks)
39
39
  {/each}
40
40
  </g>
41
41
 
42
- <style >
42
+ <style>
43
43
  .tick {
44
44
  font-size: 0.725em;
45
45
  font-weight: 200;
@@ -1,4 +1,4 @@
1
- <script >import { getContext } from 'svelte';
1
+ <script>import { getContext } from 'svelte';
2
2
  import { format } from 'svelte-ux/utils/format';
3
3
  import Text from './Text.svelte';
4
4
  import { isScaleBand } from '../utils/scales';
@@ -53,7 +53,7 @@ $: tickVals = Array.isArray(ticks)
53
53
  {/each}
54
54
  </g>
55
55
 
56
- <style >
56
+ <style>
57
57
  .tick {
58
58
  font-size: 0.725em;
59
59
  font-weight: 200;
@@ -1,4 +1,4 @@
1
- <script >import { getContext } from 'svelte';
1
+ <script>import { getContext } from 'svelte';
2
2
  import { scaleBand } from 'd3-scale';
3
3
  import { max, min } from 'd3-array';
4
4
  import { unique } from 'svelte-ux/utils/array';
@@ -1,4 +1,4 @@
1
- <script >import { getContext } from 'svelte';
1
+ <script>import { getContext } from 'svelte';
2
2
  const { xRange, yScale, yRange } = getContext('LayerCake');
3
3
  export let x = false;
4
4
  export let y = false;
@@ -14,7 +14,7 @@ export let y = false;
14
14
  {/if}
15
15
  </g>
16
16
 
17
- <style >
17
+ <style>
18
18
  .baseline {
19
19
  stroke: #777;
20
20
  }
@@ -0,0 +1,24 @@
1
+ <script>import { getContext } from 'svelte';
2
+ import { cubicOut } from 'svelte/easing';
3
+ import { scaleLinear } from 'd3-scale';
4
+ import { tweenedScale } from '../utils/scales';
5
+ const { width, height } = getContext('LayerCake');
6
+ export let domain;
7
+ export let range;
8
+ const tweenedOptions = { easing: cubicOut, duration: 800 };
9
+ function getExtents(extents, axis, fallback) {
10
+ const resolvedExtents = typeof extents === 'function' ? extents({ width: $width, height: $height }) : extents;
11
+ return [
12
+ resolvedExtents?.[axis + '0'] ?? 0,
13
+ resolvedExtents?.[axis + '1'] ?? fallback // x1 or y1, fallback as $width or $height
14
+ ];
15
+ }
16
+ const xScale = tweenedScale(scaleLinear, tweenedOptions);
17
+ $: xScale.domain(getExtents(domain, 'x', $width));
18
+ $: xScale.range(getExtents(range, 'x', $width));
19
+ const yScale = tweenedScale(scaleLinear, tweenedOptions);
20
+ $: yScale.domain(getExtents(domain, 'y', $height));
21
+ $: yScale.range(getExtents(range, 'y', $height));
22
+ </script>
23
+
24
+ <slot xScale={$xScale} yScale={$yScale} />
@@ -0,0 +1,48 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ declare const __propDef: {
3
+ props: {
4
+ domain: {
5
+ x0: number;
6
+ y0: number;
7
+ x1: number;
8
+ y1: number;
9
+ } | ((dimensions: {
10
+ width: number;
11
+ height: number;
12
+ }) => {
13
+ x0: number;
14
+ y0: number;
15
+ x1: number;
16
+ y1: number;
17
+ });
18
+ range: {
19
+ x0: number;
20
+ y0: number;
21
+ x1: number;
22
+ y1: number;
23
+ } | ((dimensions: {
24
+ width: number;
25
+ height: number;
26
+ }) => {
27
+ x0: number;
28
+ y0: number;
29
+ x1: number;
30
+ y1: number;
31
+ });
32
+ };
33
+ events: {
34
+ [evt: string]: CustomEvent<any>;
35
+ };
36
+ slots: {
37
+ default: {
38
+ xScale: any;
39
+ yScale: any;
40
+ };
41
+ };
42
+ };
43
+ export declare type BoundsProps = typeof __propDef.props;
44
+ export declare type BoundsEvents = typeof __propDef.events;
45
+ export declare type BoundsSlots = typeof __propDef.slots;
46
+ export default class Bounds extends SvelteComponentTyped<BoundsProps, BoundsEvents, BoundsSlots> {
47
+ }
48
+ export {};
@@ -1,8 +1,8 @@
1
- <script context="module" >import { LayerCake, Svg, Html } from 'layercake';
1
+ <script context="module">import { LayerCake, Svg, Html } from 'layercake';
2
2
  export { Svg, Html };
3
3
  </script>
4
4
 
5
- <script >import { max, min } from 'd3-array';
5
+ <script>import { max, min } from 'd3-array';
6
6
  import { get } from 'lodash-es';
7
7
  /**
8
8
  * Resolve a value from data based on the accessor type
@@ -1,4 +1,4 @@
1
- <script >import { getContext } from 'svelte';
1
+ <script>import { getContext } from 'svelte';
2
2
  import RectClipPath from './RectClipPath.svelte';
3
3
  const { width, height, padding } = getContext('LayerCake');
4
4
  </script>
@@ -1,4 +1,4 @@
1
- <script >import { createMotionStore } from '../stores/motionStore';
1
+ <script>import { createMotionStore } from '../stores/motionStore';
2
2
  export let cx;
3
3
  export let cy;
4
4
  export let r;
@@ -1,4 +1,4 @@
1
- <script >import { uniqueId } from 'svelte-ux/utils/string';
1
+ <script>import { uniqueId } from 'svelte-ux/utils/string';
2
2
  import ClipPath from './ClipPath.svelte';
3
3
  import Circle from './Circle.svelte';
4
4
  /** Unique id for clipPath */
@@ -1,4 +1,4 @@
1
- <script >import { uniqueId } from 'svelte-ux/utils/string';
1
+ <script>import { uniqueId } from 'svelte-ux/utils/string';
2
2
  /** Unique id for clipPath */
3
3
  export let id = uniqueId('clipPath-');
4
4
  </script>
@@ -1,4 +1,4 @@
1
- <script >/*
1
+ <script>/*
2
2
  TODO:
3
3
  - [ ] Consider becoming LinkLine using d3-path buider https://github.com/d3/d3-path
4
4
  - https://github.com/airbnb/visx/blob/master/packages/visx-shape/src/shapes/link/line/LinkHorizontalLine.tsx
@@ -1,4 +1,4 @@
1
- <script >import { getContext } from 'svelte';
1
+ <script>import { getContext } from 'svelte';
2
2
  import { createMotionStore } from '../stores/motionStore';
3
3
  const { width, height } = getContext('LayerCake');
4
4
  /**
@@ -1,4 +1,4 @@
1
- <script >import { getContext } from 'svelte';
1
+ <script>import { getContext } from 'svelte';
2
2
  import { get } from 'svelte/store';
3
3
  import Circle from './Circle.svelte';
4
4
  import Line from './Line.svelte';
@@ -1,4 +1,4 @@
1
- <script >import { getContext } from 'svelte';
1
+ <script>import { getContext } from 'svelte';
2
2
  import { isScaleBand } from '../utils/scales';
3
3
  import Rect from './Rect.svelte';
4
4
  export let data;
@@ -1,4 +1,4 @@
1
- <script >/*
1
+ <script>/*
2
2
  * TODO
3
3
  * - [ ] Support step curves (center like scaleBand())
4
4
  * - [ ] Support multiple values (threshold, stacks, etc)
@@ -1,4 +1,4 @@
1
- <script >import { createMotionStore } from '../stores/motionStore';
1
+ <script>import { createMotionStore } from '../stores/motionStore';
2
2
  export let x1;
3
3
  export let y1;
4
4
  export let x2;
@@ -1,4 +1,4 @@
1
- <script >export let id;
1
+ <script>export let id;
2
2
  export let from;
3
3
  export let via; // TODO: Currently --tw-gradient-via is not the color but the full stops
4
4
  export let to;
@@ -1,4 +1,4 @@
1
- <script >import { link as d3Link, curveBumpX, curveBumpY } from 'd3-shape';
1
+ <script>import { link as d3Link, curveBumpX, curveBumpY } from 'd3-shape';
2
2
  import { interpolatePath } from 'd3-interpolate-path';
3
3
  import { createMotionStore } from '../stores/motionStore';
4
4
  // Properties to override what is used from context
@@ -0,0 +1,27 @@
1
+ <script>import { getContext } from 'svelte';
2
+ import { partition as d3Partition } from 'd3-hierarchy';
3
+ const { data, width, height } = getContext('LayerCake');
4
+ export let orientation = 'horizontal';
5
+ export let size = undefined;
6
+ /**
7
+ * see: https://github.com/d3/d3-hierarchy#tree_nodeSize
8
+ */
9
+ export let padding = undefined;
10
+ /**
11
+ * see: https://github.com/d3/d3-hierarchy#tree_nodeSize
12
+ */
13
+ export let round = undefined;
14
+ let partition;
15
+ $: {
16
+ partition = d3Partition().size(size ?? (orientation === 'horizontal' ? [$height, $width] : [$width, $height]));
17
+ if (padding) {
18
+ partition.padding(padding);
19
+ }
20
+ if (round) {
21
+ partition.round(round);
22
+ }
23
+ }
24
+ $: partitionData = partition($data);
25
+ </script>
26
+
27
+ <slot nodes={partitionData.descendants()} />
@@ -0,0 +1,27 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ declare const __propDef: {
3
+ props: {
4
+ orientation?: 'vertical' | 'horizontal';
5
+ size?: [number, number] | undefined;
6
+ /**
7
+ * see: https://github.com/d3/d3-hierarchy#tree_nodeSize
8
+ */ padding?: number | undefined;
9
+ /**
10
+ * see: https://github.com/d3/d3-hierarchy#tree_nodeSize
11
+ */ round?: boolean | undefined;
12
+ };
13
+ events: {
14
+ [evt: string]: CustomEvent<any>;
15
+ };
16
+ slots: {
17
+ default: {
18
+ nodes: import("d3-hierarchy").HierarchyRectangularNode<unknown>[];
19
+ };
20
+ };
21
+ };
22
+ export declare type PartitionProps = typeof __propDef.props;
23
+ export declare type PartitionEvents = typeof __propDef.events;
24
+ export declare type PartitionSlots = typeof __propDef.slots;
25
+ export default class Partition extends SvelteComponentTyped<PartitionProps, PartitionEvents, PartitionSlots> {
26
+ }
27
+ export {};
@@ -1,4 +1,4 @@
1
- <script >/*
1
+ <script>/*
2
2
  TODO:
3
3
  - [ ] Show path progressively show / animated in on load. Also fix sliding in from left side (at last in from bottom)
4
4
  */
@@ -35,7 +35,7 @@ $: {
35
35
 
36
36
  <path class="path-line" d={$tweened_d} stroke={color} stroke-width={width} {...$$restProps} />
37
37
 
38
- <style >
38
+ <style>
39
39
  .path-line {
40
40
  fill: none;
41
41
  stroke-linejoin: round;
@@ -1,4 +1,4 @@
1
- <script >// https://developer.mozilla.org/en-US/docs/Web/SVG/Element/pattern
1
+ <script>// https://developer.mozilla.org/en-US/docs/Web/SVG/Element/pattern
2
2
  // https://airbnb.io/visx/patterns
3
3
  // https://github.com/airbnb/visx/tree/master/packages/visx-pattern/src/patterns
4
4
  export let id;
@@ -1,4 +1,4 @@
1
- <script >import { getContext } from 'svelte';
1
+ <script>import { getContext } from 'svelte';
2
2
  import { pie as d3pie } from 'd3-shape';
3
3
  import Arc from './Arc.svelte';
4
4
  import Group from './Group.svelte';
@@ -1,4 +1,4 @@
1
- <script >import { getContext } from 'svelte';
1
+ <script>import { getContext } from 'svelte';
2
2
  import Circle from './Circle.svelte';
3
3
  import { isScaleBand } from '../utils/scales';
4
4
  const context = getContext('LayerCake');
@@ -1,4 +1,4 @@
1
- <script >import { createMotionStore } from '../stores/motionStore';
1
+ <script>import { createMotionStore } from '../stores/motionStore';
2
2
  export let x = 0;
3
3
  export let y = 0;
4
4
  export let width;
@@ -1,4 +1,4 @@
1
- <script >import { uniqueId } from 'svelte-ux/utils/string';
1
+ <script>import { uniqueId } from 'svelte-ux/utils/string';
2
2
  import ClipPath from './ClipPath.svelte';
3
3
  import Rect from './Rect.svelte';
4
4
  /** Unique id for clipPath */
@@ -1,4 +1,4 @@
1
- <script >// https://github.com/d3/d3-sankey
1
+ <script>// https://github.com/d3/d3-sankey
2
2
  import { createEventDispatcher, getContext } from 'svelte';
3
3
  import { sankey as d3Sankey, sankeyLeft, sankeyCenter, sankeyRight, sankeyJustify } from 'd3-sankey';
4
4
  const dispatch = createEventDispatcher();
@@ -1,4 +1,4 @@
1
- <script >import { getStringWidth } from '../utils/string';
1
+ <script>import { getStringWidth } from '../utils/string';
2
2
  /*
3
3
  TODO:
4
4
  - [ ] Handle styled text (use <slot /> to measure?)
@@ -1,4 +1,4 @@
1
- <script >/*
1
+ <script>/*
2
2
  See also:
3
3
  - https://observablehq.com/@d3/difference-chart
4
4
  - https://github.com/airbnb/visx/issues/245
@@ -1,4 +1,4 @@
1
- <script >import { getContext, createEventDispatcher } from 'svelte';
1
+ <script>import { getContext, createEventDispatcher } from 'svelte';
2
2
  import { spring } from 'svelte/motion';
3
3
  import { fade } from 'svelte/transition';
4
4
  import { writable } from 'svelte/store';
@@ -1,4 +1,4 @@
1
- <script >import { getContext } from 'svelte';
1
+ <script>import { getContext } from 'svelte';
2
2
  import { tree as d3Tree } from 'd3-hierarchy';
3
3
  const { data, width, height, padding } = getContext('LayerCake');
4
4
  /**
@@ -1,14 +1,10 @@
1
- <script >/**
1
+ <script>/**
2
2
  * TODO:
3
3
  * - [ ] Improve zoomable nested (apply extent ratio? const extentRatio = ($extents.y1 - $extents.y0) / $height;
4
4
  */
5
5
  import { getContext } from 'svelte';
6
- import { tweened } from 'svelte/motion';
7
- import { cubicOut } from 'svelte/easing';
8
6
  import * as d3 from 'd3-hierarchy';
9
- import { scaleLinear } from 'd3-scale';
10
7
  import { group } from 'd3-array';
11
- import RectClipPath from './RectClipPath.svelte';
12
8
  import { aspectTile } from '../utils/treemap';
13
9
  const { data, width, height } = getContext('LayerCake');
14
10
  export let tile = d3.treemapSquarify;
@@ -61,43 +57,16 @@ $: {
61
57
  }
62
58
  }
63
59
  $: root = treemap($data);
60
+ // TODO: Remove selected
64
61
  $: selected = root; // set initial selection
65
- // group nodes by depth so can be rendered lowest to highest
62
+ // group nodes by depth so can be rendered lowest to highest, to stack properly
66
63
  $: nodesByDepth = group(root, (d) => d.depth);
67
- const duration = 800;
68
- const extents = tweened(undefined, { easing: cubicOut, duration });
69
- $: $extents = selected
70
- ? {
71
- x0: selected.x0,
72
- y0: selected.y0,
73
- x1: selected.x1,
74
- y1: selected.y1
75
- }
76
- : {
77
- x0: 0,
78
- y0: 0,
79
- x1: $width,
80
- y1: $height
81
- };
82
- $: xScale = scaleLinear().domain([$extents.x0, $extents.x1]).rangeRound([0, $width]);
83
- $: yScale = scaleLinear().domain([$extents.y0, $extents.y1]).rangeRound([0, $height]);
84
64
  </script>
85
65
 
86
- <RectClipPath width={$width} height={$height}>
87
- {#each Array.from(nodesByDepth) as [depth, nodes]}
88
- <g>
89
- {#each nodes as node, i (nodeKey(node, i))}
90
- <slot
91
- name="node"
92
- {node}
93
- rect={{
94
- x: xScale(node.x0),
95
- y: yScale(node.y0),
96
- width: xScale(node.x1) - xScale(node.x0),
97
- height: yScale(node.y1) - yScale(node.y0)
98
- }}
99
- />
100
- {/each}
101
- </g>
102
- {/each}
103
- </RectClipPath>
66
+ {#each Array.from(nodesByDepth) as [depth, nodes]}
67
+ <g>
68
+ {#each nodes as node, i (nodeKey(node, i))}
69
+ <slot name="node" {node} />
70
+ {/each}
71
+ </g>
72
+ {/each}
@@ -19,12 +19,6 @@ declare const __propDef: {
19
19
  slots: {
20
20
  node: {
21
21
  node: unknown;
22
- rect: {
23
- x: number;
24
- y: number;
25
- width: number;
26
- height: number;
27
- };
28
22
  };
29
23
  };
30
24
  };
@@ -1,4 +1,4 @@
1
- <script >import { getContext } from 'svelte';
1
+ <script>import { getContext } from 'svelte';
2
2
  import { spring } from 'svelte/motion';
3
3
  const { width, height, padding } = getContext('LayerCake');
4
4
  let dragging = false;
@@ -5,6 +5,7 @@ export { default as AxisX } from './AxisX.svelte';
5
5
  export { default as AxisY } from './AxisY.svelte';
6
6
  export { default as Bars } from './Bars.svelte';
7
7
  export { default as Baseline } from './Baseline.svelte';
8
+ export { default as Bounds } from './Bounds.svelte';
8
9
  export { default as Chart } from './Chart.svelte';
9
10
  export { default as ChartClipPath } from './ChartClipPath.svelte';
10
11
  export { default as Circle } from './Circle.svelte';
@@ -18,6 +19,7 @@ export { default as Labels } from './Labels.svelte';
18
19
  export { default as Line } from './Line.svelte';
19
20
  export { default as LinearGradient } from './LinearGradient.svelte';
20
21
  export { default as Link } from './Link.svelte';
22
+ export { default as Partition } from './Partition.svelte';
21
23
  export { default as Path } from './Path.svelte';
22
24
  export { default as Pattern } from './Pattern.svelte';
23
25
  export { default as Pie } from './Pie.svelte';
@@ -28,5 +30,6 @@ export { default as Sankey } from './Sankey.svelte';
28
30
  export { default as Text } from './Text.svelte';
29
31
  export { default as Threshold } from './Threshold.svelte';
30
32
  export { default as Tooltip } from './Tooltip.svelte';
33
+ export { default as Tree } from './Tree.svelte';
31
34
  export { default as Treemap } from './Treemap.svelte';
32
35
  export { default as Zoom } from './Zoom.svelte';
@@ -5,6 +5,7 @@ export { default as AxisX } from './AxisX.svelte';
5
5
  export { default as AxisY } from './AxisY.svelte';
6
6
  export { default as Bars } from './Bars.svelte';
7
7
  export { default as Baseline } from './Baseline.svelte';
8
+ export { default as Bounds } from './Bounds.svelte';
8
9
  export { default as Chart } from './Chart.svelte';
9
10
  export { default as ChartClipPath } from './ChartClipPath.svelte';
10
11
  export { default as Circle } from './Circle.svelte';
@@ -18,6 +19,7 @@ export { default as Labels } from './Labels.svelte';
18
19
  export { default as Line } from './Line.svelte';
19
20
  export { default as LinearGradient } from './LinearGradient.svelte';
20
21
  export { default as Link } from './Link.svelte';
22
+ export { default as Partition } from './Partition.svelte';
21
23
  export { default as Path } from './Path.svelte';
22
24
  export { default as Pattern } from './Pattern.svelte';
23
25
  export { default as Pie } from './Pie.svelte';
@@ -28,5 +30,6 @@ export { default as Sankey } from './Sankey.svelte';
28
30
  export { default as Text } from './Text.svelte';
29
31
  export { default as Threshold } from './Threshold.svelte';
30
32
  export { default as Tooltip } from './Tooltip.svelte';
33
+ export { default as Tree } from './Tree.svelte';
31
34
  export { default as Treemap } from './Treemap.svelte';
32
35
  export { default as Zoom } from './Zoom.svelte';
@@ -1,4 +1,4 @@
1
- <script >import Prism from 'prismjs';
1
+ <script>import Prism from 'prismjs';
2
2
  import 'prism-svelte';
3
3
  export let code = null;
4
4
  export let language = 'svelte';
package/package.json CHANGED
@@ -3,38 +3,38 @@
3
3
  "author": "Sean Lynch <techniq35@gmail.com>",
4
4
  "license": "MIT",
5
5
  "repository": "techniq/layerchart",
6
- "version": "0.4.0",
6
+ "version": "0.5.1",
7
7
  "devDependencies": {
8
8
  "@rollup/plugin-dsv": "^2.0.3",
9
- "@sveltejs/adapter-vercel": "^1.0.0-next.47",
10
- "@sveltejs/kit": "^1.0.0-next.303",
9
+ "@sveltejs/adapter-vercel": "^1.0.0-next.58",
10
+ "@sveltejs/kit": "^1.0.0-next.350",
11
11
  "@tailwindcss/typography": "^0.5.2",
12
- "@types/d3-array": "^3.0.2",
12
+ "@types/d3-array": "^3.0.3",
13
13
  "@types/d3-dsv": "^3.0.0",
14
- "@types/d3-hierarchy": "^3.0.2",
14
+ "@types/d3-hierarchy": "^3.1.0",
15
15
  "@types/d3-sankey": "^0.11.2",
16
16
  "@types/d3-scale": "^4.0.2",
17
- "@types/d3-shape": "^3.0.2",
17
+ "@types/d3-shape": "^3.1.0",
18
18
  "@types/lodash-es": "^4.17.6",
19
- "autoprefixer": "^10.4.4",
20
- "mdsvex": "^0.10.5",
21
- "prettier": "^2.6.1",
22
- "prettier-plugin-svelte": "^2.6.0",
19
+ "autoprefixer": "^10.4.7",
20
+ "mdsvex": "^0.10.6",
21
+ "prettier": "^2.6.2",
22
+ "prettier-plugin-svelte": "^2.7.0",
23
23
  "prism-themes": "^1.9.0",
24
- "svelte": "^3.46.6",
25
- "svelte-check": "^2.4.6",
26
- "svelte-preprocess": "^4.10.4",
27
- "svelte2tsx": "^0.5.6",
28
- "tailwindcss": "^3.0.23",
29
- "tslib": "^2.3.1",
30
- "typescript": "^4.6.3",
24
+ "svelte": "^3.48.0",
25
+ "svelte-check": "^2.7.2",
26
+ "svelte-preprocess": "^4.10.7",
27
+ "svelte2tsx": "^0.5.10",
28
+ "tailwindcss": "^3.1.0",
29
+ "tslib": "^2.4.0",
30
+ "typescript": "^4.7.3",
31
31
  "unist-util-visit": "^4.1.0",
32
32
  "vite-plugin-sveld": "^1.0.3"
33
33
  },
34
34
  "type": "module",
35
35
  "dependencies": {
36
- "@mdi/js": "^6.6.96",
37
- "d3-array": "^3.1.1",
36
+ "@mdi/js": "^6.7.96",
37
+ "d3-array": "^3.1.6",
38
38
  "d3-dsv": "^3.0.1",
39
39
  "d3-hierarchy": "^3.1.2",
40
40
  "d3-interpolate-path": "^2.2.3",
@@ -45,7 +45,7 @@
45
45
  "date-fns": "^2.28.0",
46
46
  "layercake": "^6.1.0",
47
47
  "lodash-es": "^4.17.21",
48
- "svelte-ux": "^0.5.0"
48
+ "svelte-ux": "^0.5.1"
49
49
  },
50
50
  "exports": {
51
51
  "./package.json": "./package.json",
@@ -56,6 +56,7 @@
56
56
  "./components/AxisY.svelte": "./components/AxisY.svelte",
57
57
  "./components/Bars.svelte": "./components/Bars.svelte",
58
58
  "./components/Baseline.svelte": "./components/Baseline.svelte",
59
+ "./components/Bounds.svelte": "./components/Bounds.svelte",
59
60
  "./components/Chart.svelte": "./components/Chart.svelte",
60
61
  "./components/ChartClipPath.svelte": "./components/ChartClipPath.svelte",
61
62
  "./components/Circle.svelte": "./components/Circle.svelte",
@@ -69,6 +70,7 @@
69
70
  "./components/Line.svelte": "./components/Line.svelte",
70
71
  "./components/LinearGradient.svelte": "./components/LinearGradient.svelte",
71
72
  "./components/Link.svelte": "./components/Link.svelte",
73
+ "./components/Partition.svelte": "./components/Partition.svelte",
72
74
  "./components/Path.svelte": "./components/Path.svelte",
73
75
  "./components/Pattern.svelte": "./components/Pattern.svelte",
74
76
  "./components/Pie.svelte": "./components/Pie.svelte",
package/utils/scales.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { tweened, spring } from 'svelte/motion';
1
2
  /**
2
3
  * Implemenation for missing `scaleBand().invert()`
3
4
  *
@@ -8,3 +9,19 @@
8
9
  */
9
10
  export declare function scaleBandInvert(scale: any): (value: any) => any;
10
11
  export declare function isScaleBand(scale: any): boolean;
12
+ /**
13
+ * Animate d3-scale as domain and/or range are updated using tweened store
14
+ */
15
+ export declare function tweenedScale(scale: any, tweenedOptions?: Parameters<typeof tweened>[1]): {
16
+ subscribe: (this: void, run: import("svelte/store").Subscriber<any>, invalidate?: (value?: any) => void) => import("svelte/store").Unsubscriber;
17
+ domain: (values: any) => Promise<void>;
18
+ range: (values: any) => Promise<void>;
19
+ };
20
+ /**
21
+ * Animate d3-scale as domain and/or range are updated using spring store
22
+ */
23
+ export declare function springScale(scale: any, springOptions?: Parameters<typeof spring>[1]): {
24
+ subscribe: (this: void, run: import("svelte/store").Subscriber<any>, invalidate?: (value?: any) => void) => import("svelte/store").Unsubscriber;
25
+ domain: (values: any) => Promise<void>;
26
+ range: (values: any) => Promise<void>;
27
+ };
package/utils/scales.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { derived } from 'svelte/store';
2
+ import { tweened, spring } from 'svelte/motion';
1
3
  /**
2
4
  * Implemenation for missing `scaleBand().invert()`
3
5
  *
@@ -19,3 +21,47 @@ export function scaleBandInvert(scale) {
19
21
  export function isScaleBand(scale) {
20
22
  return typeof scale.bandwidth === 'function';
21
23
  }
24
+ /**
25
+ * Animate d3-scale as domain and/or range are updated using tweened store
26
+ */
27
+ export function tweenedScale(scale, tweenedOptions = {}) {
28
+ const tweenedDomain = tweened(undefined, tweenedOptions);
29
+ const tweenedRange = tweened(undefined, tweenedOptions);
30
+ const tweenedScale = derived([tweenedDomain, tweenedRange], ([domain, range]) => {
31
+ const scaleInstance = scale.domain ? scale : scale(); // support `scaleLinear` or `scaleLinear()` (which could have `.interpolate()` and others set)
32
+ if (domain) {
33
+ scaleInstance.domain(domain);
34
+ }
35
+ if (range) {
36
+ scaleInstance.range(range);
37
+ }
38
+ return scaleInstance;
39
+ });
40
+ return {
41
+ subscribe: tweenedScale.subscribe,
42
+ domain: (values) => tweenedDomain.set(values),
43
+ range: (values) => tweenedRange.set(values)
44
+ };
45
+ }
46
+ /**
47
+ * Animate d3-scale as domain and/or range are updated using spring store
48
+ */
49
+ export function springScale(scale, springOptions = {}) {
50
+ const springDomain = spring(undefined, springOptions);
51
+ const springRange = spring(undefined, springOptions);
52
+ const tweenedScale = derived([springDomain, springRange], ([domain, range]) => {
53
+ const scaleInstance = scale.domain ? scale : scale(); // support `scaleLinear` or `scaleLinear()` (which could have `.interpolate()` and others set)
54
+ if (domain) {
55
+ scaleInstance.domain(domain);
56
+ }
57
+ if (range) {
58
+ scaleInstance.range(range);
59
+ }
60
+ return scaleInstance;
61
+ });
62
+ return {
63
+ subscribe: tweenedScale.subscribe,
64
+ domain: (values) => springDomain.set(values),
65
+ range: (values) => springRange.set(values)
66
+ };
67
+ }