Skip to content

Commit ddf18d4

Browse files
committed
Improve treemap example (text/clip)
1 parent 168b268 commit ddf18d4

1 file changed

Lines changed: 5 additions & 13 deletions

File tree

docs/src/routes/api/charts/treemap/TreemapChart.svelte

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
88
import { ServerChart } from 'layerchart/server';
99
import type { CaptureTarget } from 'layerchart/server';
10-
import { Group, Rect, Text, Treemap } from 'layerchart';
10+
import { Group, Rect, RectClipPath, Text, Treemap } from 'layerchart';
1111
1212
let {
1313
data,
@@ -44,12 +44,7 @@
4444
{height}
4545
padding={{ top: 4, right: 4, bottom: 4, left: 4 }}
4646
>
47-
<Treemap
48-
hierarchy={root}
49-
paddingOuter={4}
50-
paddingInner={4}
51-
paddingTop={20}
52-
>
47+
<Treemap hierarchy={root} paddingOuter={4} paddingInner={4} paddingTop={20}>
5348
{#snippet children({ nodes })}
5449
{#each nodes as node}
5550
{@const nodeWidth = node.x1 - node.x0}
@@ -64,12 +59,9 @@
6459
fillOpacity={node.children ? 0.5 : 1}
6560
rx={5}
6661
/>
67-
<Text
68-
value={node.data.name}
69-
x={4}
70-
y={12}
71-
fill="rgba(0,0,0,0.7)"
72-
/>
62+
<RectClipPath width={nodeWidth} height={nodeHeight}>
63+
<Text value={node.data.name} x={6} y={20} fill="rgba(0,0,0,0.7)" />
64+
</RectClipPath>
7365
</Group>
7466
{/each}
7567
{/snippet}

0 commit comments

Comments
 (0)