layerchart 0.3.3 → 0.3.6

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.
@@ -19,6 +19,7 @@ export let paddingTop = 0;
19
19
  export let paddingBottom = 0;
20
20
  export let paddingLeft = undefined;
21
21
  export let paddingRight = undefined;
22
+ export let nodeKey = (node, i) => i;
22
23
  export let selected = null;
23
24
  $: tileFunc =
24
25
  tile === 'squarify'
@@ -34,32 +35,35 @@ $: tileFunc =
34
35
  : tile === 'sliceDice'
35
36
  ? d3.treemapSliceDice
36
37
  : tile;
37
- $: treemap = d3.treemap().size([$width, $height]).tile(aspectTile(tileFunc, $width, $height));
38
- $: if (padding) {
39
- treemap.padding(padding);
40
- }
41
- $: if (paddingInner) {
42
- treemap.paddingInner(paddingInner);
43
- }
44
- $: if (paddingOuter) {
45
- treemap.paddingOuter(paddingOuter);
46
- }
47
- $: if (paddingTop) {
48
- treemap.paddingTop(paddingTop);
49
- }
50
- $: if (paddingBottom) {
51
- treemap.paddingBottom(paddingBottom);
52
- }
53
- $: if (paddingLeft) {
54
- treemap.paddingLeft(paddingLeft);
55
- }
56
- $: if (paddingLeft) {
57
- treemap.paddingRight(paddingRight);
38
+ let treemap;
39
+ $: {
40
+ treemap = d3.treemap().size([$width, $height]).tile(aspectTile(tileFunc, $width, $height));
41
+ if (padding) {
42
+ treemap.padding(padding);
43
+ }
44
+ if (paddingInner) {
45
+ treemap.paddingInner(paddingInner);
46
+ }
47
+ if (paddingOuter) {
48
+ treemap.paddingOuter(paddingOuter);
49
+ }
50
+ if (paddingTop) {
51
+ treemap.paddingTop(paddingTop);
52
+ }
53
+ if (paddingBottom) {
54
+ treemap.paddingBottom(paddingBottom);
55
+ }
56
+ if (paddingLeft) {
57
+ treemap.paddingLeft(paddingLeft);
58
+ }
59
+ if (paddingRight) {
60
+ treemap.paddingRight(paddingRight);
61
+ }
58
62
  }
59
63
  $: root = treemap($data);
60
64
  $: selected = root; // set initial selection
61
- // group nodes by height so can be rendered lowest to highest
62
- $: nodesByHeight = group(root, (d) => d.height);
65
+ // group nodes by depth so can be rendered lowest to highest
66
+ $: nodesByDepth = group(root, (d) => d.depth);
63
67
  const duration = 800;
64
68
  const extents = tweened(undefined, { easing: cubicOut, duration });
65
69
  $: $extents = selected
@@ -80,9 +84,9 @@ $: yScale = scaleLinear().domain([$extents.y0, $extents.y1]).rangeRound([0, $hei
80
84
  </script>
81
85
 
82
86
  <RectClipPath width={$width} height={$height}>
83
- {#each Array.from(nodesByHeight) as [height, nodes]}
87
+ {#each Array.from(nodesByDepth) as [depth, nodes]}
84
88
  <g>
85
- {#each nodes as node}
89
+ {#each nodes as node, i (nodeKey(node, i))}
86
90
  <slot
87
91
  name="node"
88
92
  {node}
@@ -10,6 +10,7 @@ declare const __propDef: {
10
10
  paddingBottom?: number;
11
11
  paddingLeft?: any;
12
12
  paddingRight?: any;
13
+ nodeKey?: (node: d3.HierarchyNode<any>, i: number) => any;
13
14
  selected?: any;
14
15
  };
15
16
  events: {
@@ -17,7 +18,7 @@ declare const __propDef: {
17
18
  };
18
19
  slots: {
19
20
  node: {
20
- node: d3.HierarchyRectangularNode<unknown>;
21
+ node: unknown;
21
22
  rect: {
22
23
  x: number;
23
24
  y: number;
package/package.json CHANGED
@@ -3,8 +3,9 @@
3
3
  "author": "Sean Lynch <techniq35@gmail.com>",
4
4
  "license": "MIT",
5
5
  "repository": "techniq/layerchart",
6
- "version": "0.3.3",
6
+ "version": "0.3.6",
7
7
  "devDependencies": {
8
+ "@rollup/plugin-dsv": "^2.0.3",
8
9
  "@sveltejs/adapter-vercel": "^1.0.0-next.47",
9
10
  "@sveltejs/kit": "^1.0.0-next.303",
10
11
  "@tailwindcss/typography": "^0.5.2",
@@ -1,6 +1,10 @@
1
1
  /**
2
- * This custom tiling function adapts the built-in binary tiling function
2
+ * This custom tiling function adapts the tiling function
3
3
  * for the appropriate aspect ratio when the treemap is zoomed-in.
4
4
  * see: https://observablehq.com/@d3/zoomable-treemap#tile and https://observablehq.com/@d3/stretched-treemap
5
5
  */
6
6
  export declare function aspectTile(tile: any, width: any, height: any): (node: any, x0: any, y0: any, x1: any, y1: any) => void;
7
+ /**
8
+ * Show if the node (a) is a child of the selected (b), or any parent above selected
9
+ */
10
+ export declare function isNodeVisible(a: any, b: any): boolean;
package/utils/treemap.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * This custom tiling function adapts the built-in binary tiling function
2
+ * This custom tiling function adapts the tiling function
3
3
  * for the appropriate aspect ratio when the treemap is zoomed-in.
4
4
  * see: https://observablehq.com/@d3/zoomable-treemap#tile and https://observablehq.com/@d3/stretched-treemap
5
5
  */
@@ -14,3 +14,14 @@ export function aspectTile(tile, width, height) {
14
14
  }
15
15
  };
16
16
  }
17
+ /**
18
+ * Show if the node (a) is a child of the selected (b), or any parent above selected
19
+ */
20
+ export function isNodeVisible(a, b) {
21
+ while (b) {
22
+ if (a.parent === b)
23
+ return true;
24
+ b = b.parent;
25
+ }
26
+ return false;
27
+ }