layerchart 0.3.2 → 0.3.5
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/components/Treemap.svelte +37 -40
- package/components/Treemap.svelte.d.ts +4 -4
- package/package.json +1 -1
- package/utils/treemap.d.ts +5 -1
- package/utils/treemap.js +12 -1
|
@@ -8,7 +8,6 @@ import { cubicOut } from 'svelte/easing';
|
|
|
8
8
|
import * as d3 from 'd3-hierarchy';
|
|
9
9
|
import { scaleLinear } from 'd3-scale';
|
|
10
10
|
import { group } from 'd3-array';
|
|
11
|
-
import Group from './Group.svelte';
|
|
12
11
|
import RectClipPath from './RectClipPath.svelte';
|
|
13
12
|
import { aspectTile } from '../utils/treemap';
|
|
14
13
|
const { data, width, height } = getContext('LayerCake');
|
|
@@ -35,32 +34,35 @@ $: tileFunc =
|
|
|
35
34
|
: tile === 'sliceDice'
|
|
36
35
|
? d3.treemapSliceDice
|
|
37
36
|
: tile;
|
|
38
|
-
|
|
39
|
-
$:
|
|
40
|
-
treemap.
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
37
|
+
let treemap;
|
|
38
|
+
$: {
|
|
39
|
+
treemap = d3.treemap().size([$width, $height]).tile(aspectTile(tileFunc, $width, $height));
|
|
40
|
+
if (padding) {
|
|
41
|
+
treemap.padding(padding);
|
|
42
|
+
}
|
|
43
|
+
if (paddingInner) {
|
|
44
|
+
treemap.paddingInner(paddingInner);
|
|
45
|
+
}
|
|
46
|
+
if (paddingOuter) {
|
|
47
|
+
treemap.paddingOuter(paddingOuter);
|
|
48
|
+
}
|
|
49
|
+
if (paddingTop) {
|
|
50
|
+
treemap.paddingTop(paddingTop);
|
|
51
|
+
}
|
|
52
|
+
if (paddingBottom) {
|
|
53
|
+
treemap.paddingBottom(paddingBottom);
|
|
54
|
+
}
|
|
55
|
+
if (paddingLeft) {
|
|
56
|
+
treemap.paddingLeft(paddingLeft);
|
|
57
|
+
}
|
|
58
|
+
if (paddingRight) {
|
|
59
|
+
treemap.paddingRight(paddingRight);
|
|
60
|
+
}
|
|
59
61
|
}
|
|
60
62
|
$: root = treemap($data);
|
|
61
63
|
$: selected = root; // set initial selection
|
|
62
|
-
// group nodes by
|
|
63
|
-
$:
|
|
64
|
+
// group nodes by depth so can be rendered lowest to highest
|
|
65
|
+
$: nodesByDepth = group(root, (d) => d.depth);
|
|
64
66
|
const duration = 800;
|
|
65
67
|
const extents = tweened(undefined, { easing: cubicOut, duration });
|
|
66
68
|
$: $extents = selected
|
|
@@ -81,24 +83,19 @@ $: yScale = scaleLinear().domain([$extents.y0, $extents.y1]).rangeRound([0, $hei
|
|
|
81
83
|
</script>
|
|
82
84
|
|
|
83
85
|
<RectClipPath width={$width} height={$height}>
|
|
84
|
-
{#each Array.from(
|
|
86
|
+
{#each Array.from(nodesByDepth) as [depth, nodes]}
|
|
85
87
|
<g>
|
|
86
88
|
{#each nodes as node}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
height: nodeHeight
|
|
98
|
-
}}
|
|
99
|
-
/>
|
|
100
|
-
</RectClipPath>
|
|
101
|
-
</Group>
|
|
89
|
+
<slot
|
|
90
|
+
name="node"
|
|
91
|
+
{node}
|
|
92
|
+
rect={{
|
|
93
|
+
x: xScale(node.x0),
|
|
94
|
+
y: yScale(node.y0),
|
|
95
|
+
width: xScale(node.x1) - xScale(node.x0),
|
|
96
|
+
height: yScale(node.y1) - yScale(node.y0)
|
|
97
|
+
}}
|
|
98
|
+
/>
|
|
102
99
|
{/each}
|
|
103
100
|
</g>
|
|
104
101
|
{/each}
|
|
@@ -16,13 +16,13 @@ declare const __propDef: {
|
|
|
16
16
|
[evt: string]: CustomEvent<any>;
|
|
17
17
|
};
|
|
18
18
|
slots: {
|
|
19
|
-
|
|
20
|
-
node:
|
|
19
|
+
node: {
|
|
20
|
+
node: unknown;
|
|
21
21
|
rect: {
|
|
22
22
|
x: number;
|
|
23
23
|
y: number;
|
|
24
|
-
width:
|
|
25
|
-
height:
|
|
24
|
+
width: number;
|
|
25
|
+
height: number;
|
|
26
26
|
};
|
|
27
27
|
};
|
|
28
28
|
};
|
package/package.json
CHANGED
package/utils/treemap.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* This custom tiling function adapts the
|
|
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
|
|
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
|
+
}
|