forked from techniq/layerchart
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsoftware-user-flow.svelte
More file actions
111 lines (101 loc) · 2.94 KB
/
software-user-flow.svelte
File metadata and controls
111 lines (101 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<script lang="ts">
import type { ComponentProps } from 'svelte';
import { curveLinear } from 'd3-shape';
import { cubicOut } from 'svelte/easing';
import { slide } from 'svelte/transition';
import { cls } from '@layerstack/tailwind';
import { Chart, Dagre, Group, Layer, Rect, Spline, Text } from 'layerchart';
import DagreControls from '$lib/components/controls/DagreControls.svelte';
import TransformContextControls from '$lib/components/controls/TransformContextControls.svelte';
import ShowControls from '$lib/components/controls/fields/ShowField.svelte';
import { getSoftwareUserFlowGraph } from '$lib/graph.remote';
let data = await getSoftwareUserFlowGraph();
export { data };
let settings = $state({
ranker: 'network-simplex',
direction: 'top-bottom',
align: 'none',
nodeSeparation: 50,
rankSeparation: 50,
edgeSeparation: 10,
edgeLabelPosition: 'center',
edgeLabelOffset: 10,
curve: curveLinear,
arrow: 'triangle'
}) as ComponentProps<typeof DagreControls>['settings'];
let showSettings = $state(false);
</script>
<ShowControls bind:show={showSettings} label="Show Settings" />
<div class="flex gap-2 pt-6">
<Chart
transform={{
mode: 'canvas',
initialScale: 0.75,
initialTranslate: { x: 0, y: -110 },
initialScrollMode: 'scale',
motion: { type: 'tween', duration: 800, easing: cubicOut }
}}
clip
height={700}
>
<TransformContextControls />
<Layer>
<Dagre data={data as any} edges={(d) => d.links} {...settings}>
{#snippet children({ nodes, edges })}
<g class="edges">
{#each edges as edge, i (edge.v + '-' + edge.w)}
<Spline
data={edge.points}
x="x"
y="y"
class="stroke-surface-content opacity-30"
motion="tween"
curve={settings?.curve}
markerEnd={settings.arrow}
/>
<Text
value={edge.label}
x={edge.x}
y={edge.y}
textAnchor="middle"
verticalAnchor="middle"
class="stroke-2 stroke-surface-100"
motion="tween"
/>
{/each}
</g>
<g class="nodes">
{#each nodes as node (node.label)}
<Group x={node.x - node.width / 2} y={node.y - node.height / 2} motion="tween">
<Rect
width={node.width}
height={node.height}
class={cls(
'fill-surface-200 stroke-2 stroke-primary/50',
node.label === 'CLOSED' && 'fill-danger/10 stroke-danger/50',
node.label === 'ESTAB' && 'fill-success/10 stroke-success/50'
)}
rx={10}
/>
<Text
value={node.label}
x={node.width / 2}
y={node.height / 2}
dy={-2}
textAnchor="middle"
verticalAnchor="middle"
class={cls('text-xs pointer-events-none')}
/>
</Group>
{/each}
</g>
{/snippet}
</Dagre>
</Layer>
</Chart>
{#if showSettings}
<div transition:slide={{ axis: 'x' }}>
<DagreControls bind:settings />
</div>
{/if}
</div>