layerchart 0.3.1 → 0.3.4
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 +34 -37
- package/components/Treemap.svelte.d.ts +4 -4
- package/package.json +2 -1
- package/utils/hierarchy.d.ts +6 -0
- package/utils/hierarchy.js +13 -0
- 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,27 +34,30 @@ $: 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
|
|
@@ -84,21 +86,16 @@ $: yScale = scaleLinear().domain([$extents.y0, $extents.y1]).rangeRound([0, $hei
|
|
|
84
86
|
{#each Array.from(nodesByHeight) as [height, 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
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"author": "Sean Lynch <techniq35@gmail.com>",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": "techniq/layerchart",
|
|
6
|
-
"version": "0.3.
|
|
6
|
+
"version": "0.3.4",
|
|
7
7
|
"devDependencies": {
|
|
8
8
|
"@sveltejs/adapter-vercel": "^1.0.0-next.47",
|
|
9
9
|
"@sveltejs/kit": "^1.0.0-next.303",
|
|
@@ -91,6 +91,7 @@
|
|
|
91
91
|
"./utils/event": "./utils/event.js",
|
|
92
92
|
"./utils/genData": "./utils/genData.js",
|
|
93
93
|
"./utils/graph": "./utils/graph.js",
|
|
94
|
+
"./utils/hierarchy": "./utils/hierarchy.js",
|
|
94
95
|
"./utils": "./utils/index.js",
|
|
95
96
|
"./utils/math": "./utils/math.js",
|
|
96
97
|
"./utils/path": "./utils/path.js",
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { HierarchyNode } from 'd3-hierarchy';
|
|
2
|
+
/**
|
|
3
|
+
* Find first ancestor matching filter, including node.
|
|
4
|
+
* Similar to `node.find()` (https://github.com/d3/d3-hierarchy#node_find) but checks ancestors instead of descendants
|
|
5
|
+
*/
|
|
6
|
+
export declare function findAncestor<T = any>(node: HierarchyNode<T>, filter: (node: any) => boolean): HierarchyNode<T>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Find first ancestor matching filter, including node.
|
|
3
|
+
* Similar to `node.find()` (https://github.com/d3/d3-hierarchy#node_find) but checks ancestors instead of descendants
|
|
4
|
+
*/
|
|
5
|
+
export function findAncestor(node, filter) {
|
|
6
|
+
while (node) {
|
|
7
|
+
if (filter(node)) {
|
|
8
|
+
return node;
|
|
9
|
+
}
|
|
10
|
+
node = node.parent;
|
|
11
|
+
}
|
|
12
|
+
return null;
|
|
13
|
+
}
|
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
|
+
}
|