@zsherman/viz 0.0.0-stage → 0.1.1
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/CHANGELOG.md +14 -0
- package/LICENSE +373 -0
- package/README.md +13 -2
- package/THIRD_PARTY_NOTICES.md +79 -0
- package/dist/dom/flow/flow.js +370 -0
- package/dist/dom/flow/flow.styles.js +158 -0
- package/dist/dom/flow/index.js +4 -0
- package/dist/dom/flow/layout.js +51 -0
- package/dist/dom/geo-map/geo-map.js +1037 -0
- package/dist/dom/geo-map/geo-map.styles.js +184 -0
- package/dist/dom/geo-map/geometry.js +231 -0
- package/dist/dom/geo-map/index.js +3 -0
- package/dist/dom/geo-map/types.js +0 -0
- package/dist/dom/geo-map/world.js +15 -0
- package/dist/dom/index.js +6 -0
- package/dist/solid/flow/flow.jsx +180 -0
- package/dist/solid/flow/flow.styles.jsx +158 -0
- package/dist/solid/flow/index.jsx +4 -0
- package/dist/solid/flow/layout.jsx +51 -0
- package/dist/solid/geo-map/geo-map.jsx +698 -0
- package/dist/solid/geo-map/geo-map.styles.jsx +184 -0
- package/dist/solid/geo-map/geometry.jsx +231 -0
- package/dist/solid/geo-map/index.jsx +3 -0
- package/dist/solid/geo-map/types.jsx +0 -0
- package/dist/solid/geo-map/world.jsx +15 -0
- package/dist/solid/index.jsx +6 -0
- package/dist/styles.css +1 -0
- package/dist/types/flow/flow.d.ts +92 -0
- package/dist/types/flow/flow.styles.d.ts +137 -0
- package/dist/types/flow/index.d.ts +6 -0
- package/dist/types/flow/layout.d.ts +47 -0
- package/dist/types/geo-map/geo-map.d.ts +70 -0
- package/dist/types/geo-map/geo-map.styles.d.ts +188 -0
- package/dist/types/geo-map/geometry.d.ts +116 -0
- package/dist/types/geo-map/index.d.ts +4 -0
- package/dist/types/geo-map/types.d.ts +103 -0
- package/dist/types/geo-map/world.d.ts +11 -0
- package/dist/types/index.d.ts +2 -0
- package/docs/api.json +297 -0
- package/docs/flow.md +255 -0
- package/docs/geo-map.md +320 -0
- package/docs/llms.txt +43 -0
- package/docs/search-index.json +64 -0
- package/package.json +66 -4
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/** The map's projection: a flat world (`naturalEarth`, `mercator`, `equirectangular`, `albers`) or a globe (`orthographic`). */
|
|
2
|
+
export type GeoMapProjection = "naturalEarth" | "mercator" | "equirectangular" | "orthographic" | "albers";
|
|
3
|
+
/** How a connection is drawn between its two markers. */
|
|
4
|
+
export type GeoMapArcStyle = "greatCircle" | "quadratic" | "straight";
|
|
5
|
+
/**
|
|
6
|
+
* A marker's or a connection's color: a chart series token (`"chart-1"` … `"chart-8"`), a tone (`"accent"`,
|
|
7
|
+
* `"info"`, `"success"`, `"warning"`, `"danger"`, `"neutral"`), or any CSS color.
|
|
8
|
+
*/
|
|
9
|
+
export type GeoMapColor = "chart-1" | "chart-2" | "chart-3" | "chart-4" | "chart-5" | "chart-6" | "chart-7" | "chart-8" | "accent" | "info" | "success" | "warning" | "danger" | "neutral" | (string & {});
|
|
10
|
+
/** A place on the map. */
|
|
11
|
+
export interface GeoMapMarker<T = unknown> {
|
|
12
|
+
/** Unique among the markers; connections name markers by it. */
|
|
13
|
+
id: string;
|
|
14
|
+
/** What the marker is called: its accessible name and the tooltip's title ("Tokyo"). */
|
|
15
|
+
name: string;
|
|
16
|
+
latitude: number;
|
|
17
|
+
longitude: number;
|
|
18
|
+
/**
|
|
19
|
+
* Markers of one group share a color: groups take `chart-1`, `chart-2`, … in the order they first appear
|
|
20
|
+
* ("server", then "user"). Without groups every marker is `chart-1`.
|
|
21
|
+
*/
|
|
22
|
+
group?: string;
|
|
23
|
+
/** Overrides the group's color. */
|
|
24
|
+
color?: GeoMapColor;
|
|
25
|
+
/** The dot's radius in pixels; it stays this size on screen at any zoom. @defaultValue 5 */
|
|
26
|
+
radius?: number;
|
|
27
|
+
/** A second line for the tooltip and the marker's description for screen readers ("3 servers, healthy"). */
|
|
28
|
+
description?: string;
|
|
29
|
+
/** Your own data, handed back in `onMarkerSelect` and `tooltip`. */
|
|
30
|
+
data?: T;
|
|
31
|
+
}
|
|
32
|
+
/** A line between two markers. */
|
|
33
|
+
export interface GeoMapConnection {
|
|
34
|
+
/** The `id` of the marker it starts at. */
|
|
35
|
+
source: string;
|
|
36
|
+
/** The `id` of the marker it ends at. */
|
|
37
|
+
target: string;
|
|
38
|
+
/** The line's width in pixels; it stays this width on screen at any zoom. @defaultValue 1.5 */
|
|
39
|
+
weight?: number;
|
|
40
|
+
/** The line's color. Defaults to the source marker's color. */
|
|
41
|
+
color?: GeoMapColor;
|
|
42
|
+
/** What the connection carries, after its two ends in its tooltip ("42 ms"). */
|
|
43
|
+
label?: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The land the map draws, as GeoJSON: a FeatureCollection of countries or land polygons (what
|
|
47
|
+
* `topojson.feature` returns). `loadWorld()` gives the default, Natural Earth's countries at 1:110m.
|
|
48
|
+
*/
|
|
49
|
+
export interface GeoMapWorld {
|
|
50
|
+
type: "FeatureCollection";
|
|
51
|
+
features: readonly GeoMapFeature[];
|
|
52
|
+
}
|
|
53
|
+
/** One feature of a `GeoMapWorld`: a country or a land polygon. */
|
|
54
|
+
export interface GeoMapFeature {
|
|
55
|
+
type: "Feature";
|
|
56
|
+
id?: string | number;
|
|
57
|
+
geometry: GeoMapGeometry | null;
|
|
58
|
+
properties?: Record<string, unknown> | null;
|
|
59
|
+
}
|
|
60
|
+
/** A GeoJSON geometry (`Polygon`, `MultiPolygon`, …), coordinates in `[longitude, latitude]` degrees. */
|
|
61
|
+
export interface GeoMapGeometry {
|
|
62
|
+
type: string;
|
|
63
|
+
coordinates?: unknown;
|
|
64
|
+
geometries?: readonly GeoMapGeometry[];
|
|
65
|
+
}
|
|
66
|
+
/** What the map shows now, as the controller and `onViewChange` report it. */
|
|
67
|
+
export interface GeoMapView {
|
|
68
|
+
/** 1 is the whole world; 2 is twice as close. */
|
|
69
|
+
zoom: number;
|
|
70
|
+
/** The place in the middle of the map, `[longitude, latitude]`. */
|
|
71
|
+
center: [number, number];
|
|
72
|
+
}
|
|
73
|
+
/** Drives the map from your own controls. `GeoMap` hands one to `controller` once it mounts. */
|
|
74
|
+
export interface GeoMapController {
|
|
75
|
+
/**
|
|
76
|
+
* Shows every marker (`"markers"`, the default; the whole world when there are none), the whole world
|
|
77
|
+
* (`"world"`), or the markers with these ids, as close as they fit. A globe turns to face them.
|
|
78
|
+
*/
|
|
79
|
+
fit(target?: "markers" | "world" | readonly string[]): void;
|
|
80
|
+
/** Zooms in (above 1) or out (below 1) around the middle of the map. */
|
|
81
|
+
zoomBy(factor: number): void;
|
|
82
|
+
/** Brings a marker (by id) or a place into the middle of the map, keeping the zoom. */
|
|
83
|
+
centerOn(target: string | readonly [longitude: number, latitude: number]): void;
|
|
84
|
+
/** Moves keyboard focus to a marker. */
|
|
85
|
+
focus(id: string): void;
|
|
86
|
+
/** What the map shows now. */
|
|
87
|
+
view(): GeoMapView;
|
|
88
|
+
}
|
|
89
|
+
/** Built-in words (English defaults); also settable for every map through `LocaleProvider`'s `geoMap`. */
|
|
90
|
+
export interface GeoMapLabels {
|
|
91
|
+
/** The map's role, after its label ("map"). */
|
|
92
|
+
map: string;
|
|
93
|
+
/** The markers' list's name. @defaultValue "Locations" */
|
|
94
|
+
markers: string;
|
|
95
|
+
zoomIn: string;
|
|
96
|
+
zoomOut: string;
|
|
97
|
+
/** The button that shows every marker (or the world). @defaultValue "Show all" */
|
|
98
|
+
fit: string;
|
|
99
|
+
/** What + and − announce. @defaultValue (p) => `Zoom ${p}%` */
|
|
100
|
+
zoom: (percent: number) => string;
|
|
101
|
+
/** After a marker's name, when the map has connections. @defaultValue (n) => n === 1 ? "1 connection" : `${n} connections` */
|
|
102
|
+
connections: (count: number) => string;
|
|
103
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The world the GeoMap draws when it isn't given one: Natural Earth's countries at 1:110m (`world-atlas`,
|
|
3
|
+
* TopoJSON, about 100 KB), loaded on demand as a chunk of its own and turned into GeoJSON with
|
|
4
|
+
* `topojson-client`. Natural Earth is public domain; world-atlas and topojson-client are ISC.
|
|
5
|
+
*/
|
|
6
|
+
import type { GeoMapWorld } from "./types.js";
|
|
7
|
+
/**
|
|
8
|
+
* The countries at 1:110m, as GeoJSON. Loads once per page (later calls share the request); call it early
|
|
9
|
+
* to start the load before a map mounts, or pass its result as `worldData` to render land on the server.
|
|
10
|
+
*/
|
|
11
|
+
export declare function loadWorld(): Promise<GeoMapWorld>;
|
package/docs/api.json
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
{
|
|
2
|
+
"geo-map": {
|
|
3
|
+
"components": {
|
|
4
|
+
"GeoMap": {
|
|
5
|
+
"props": [
|
|
6
|
+
{
|
|
7
|
+
"name": "animated",
|
|
8
|
+
"type": "boolean",
|
|
9
|
+
"default": "false",
|
|
10
|
+
"description": "Moves dashes along every connection, from source to target. Still under reduced motion.",
|
|
11
|
+
"required": false,
|
|
12
|
+
"from": "kit"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"name": "arcStyle",
|
|
16
|
+
"type": "\"greatCircle\" | \"quadratic\" | \"straight\"",
|
|
17
|
+
"default": "\"greatCircle\"",
|
|
18
|
+
"description": "How connections are drawn.",
|
|
19
|
+
"required": false,
|
|
20
|
+
"from": "kit"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"name": "center",
|
|
24
|
+
"type": "readonly [longitude: number, latitude: number]",
|
|
25
|
+
"default": "[10, 25]",
|
|
26
|
+
"description": "The place a globe faces first, `[longitude, latitude]`.",
|
|
27
|
+
"required": false,
|
|
28
|
+
"from": "kit"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"name": "connections",
|
|
32
|
+
"type": "readonly GeoMapConnection[]",
|
|
33
|
+
"default": "[]",
|
|
34
|
+
"description": "Lines between markers, by their ids. Ones naming a missing marker are left out.",
|
|
35
|
+
"required": false,
|
|
36
|
+
"from": "kit"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"name": "controller",
|
|
40
|
+
"type": "((controller: GeoMapController) => void)",
|
|
41
|
+
"description": "Receives the map's controller once it mounts: fit, zoom and center from your own controls.",
|
|
42
|
+
"required": false,
|
|
43
|
+
"from": "kit"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"name": "controls",
|
|
47
|
+
"type": "boolean",
|
|
48
|
+
"default": "true",
|
|
49
|
+
"description": "Shows the zoom in, zoom out and Show all buttons (with `interactive`).",
|
|
50
|
+
"required": false,
|
|
51
|
+
"from": "kit"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"name": "defaultSelected",
|
|
55
|
+
"type": "string | null",
|
|
56
|
+
"default": "null",
|
|
57
|
+
"description": "The marker selected at first, when the selection isn't controlled.",
|
|
58
|
+
"required": false,
|
|
59
|
+
"from": "kit"
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"name": "graticule",
|
|
63
|
+
"type": "boolean",
|
|
64
|
+
"default": "false",
|
|
65
|
+
"description": "Draws lines of latitude and longitude every 10°.",
|
|
66
|
+
"required": false,
|
|
67
|
+
"from": "kit"
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
"name": "height",
|
|
71
|
+
"type": "string | number",
|
|
72
|
+
"description": "The map's height (a number is pixels). Without it the map is twice as wide as it is high.",
|
|
73
|
+
"required": false,
|
|
74
|
+
"from": "kit"
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
"name": "highlighted",
|
|
78
|
+
"type": "string | null",
|
|
79
|
+
"description": "A marker whose connections stand out while the rest dim, to control the highlight (from a table row your app hovers, say). Without it the marker under the pointer or the keyboard focus is highlighted.",
|
|
80
|
+
"required": false,
|
|
81
|
+
"from": "kit"
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"name": "initialView",
|
|
85
|
+
"type": "\"markers\" | \"world\"",
|
|
86
|
+
"default": "\"world\"",
|
|
87
|
+
"description": "What the map shows first: the whole world, or every marker as close as they fit (it follows the markers until someone pans or zooms).",
|
|
88
|
+
"required": false,
|
|
89
|
+
"from": "kit"
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
"name": "interactive",
|
|
93
|
+
"type": "boolean",
|
|
94
|
+
"default": "true",
|
|
95
|
+
"description": "Pan and zoom (a flat map) or turn and zoom (a globe) with the pointer, the wheel and the keys.",
|
|
96
|
+
"required": false,
|
|
97
|
+
"from": "kit"
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
"name": "label",
|
|
101
|
+
"type": "string",
|
|
102
|
+
"description": "The map's accessible name: what it shows (\"Servers and users, last hour\").",
|
|
103
|
+
"required": true,
|
|
104
|
+
"from": "kit"
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
"name": "labels",
|
|
108
|
+
"type": "Partial<GeoMapLabels>",
|
|
109
|
+
"description": "Built-in words; also settable for every map through `LocaleProvider`'s `geoMap`.",
|
|
110
|
+
"required": false,
|
|
111
|
+
"from": "kit"
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
"name": "markers",
|
|
115
|
+
"type": "readonly GeoMapMarker<T>[]",
|
|
116
|
+
"default": "[]",
|
|
117
|
+
"description": "The places to mark.",
|
|
118
|
+
"required": false,
|
|
119
|
+
"from": "kit"
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
"name": "onConnectionSelect",
|
|
123
|
+
"type": "((connection: GeoMapConnection) => void)",
|
|
124
|
+
"description": "Runs when a connection is clicked.",
|
|
125
|
+
"required": false,
|
|
126
|
+
"from": "kit"
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
"name": "onMarkerSelect",
|
|
130
|
+
"type": "((marker: GeoMapMarker<T> | null) => void)",
|
|
131
|
+
"description": "Runs when a marker is clicked, or chosen with Enter or Space, with the marker (null when it's chosen again, which clears the selection).",
|
|
132
|
+
"required": false,
|
|
133
|
+
"from": "kit"
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
"name": "projection",
|
|
137
|
+
"type": "\"albers\" | \"equirectangular\" | \"mercator\" | \"naturalEarth\" | \"orthographic\"",
|
|
138
|
+
"default": "\"naturalEarth\"",
|
|
139
|
+
"description": "A flat world or a globe (`\"orthographic\"`).",
|
|
140
|
+
"required": false,
|
|
141
|
+
"from": "kit"
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
"name": "selected",
|
|
145
|
+
"type": "string | null",
|
|
146
|
+
"description": "The selected marker's id, to control the selection. `null` selects none.",
|
|
147
|
+
"required": false,
|
|
148
|
+
"from": "kit"
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
"name": "tooltip",
|
|
152
|
+
"type": "((marker: GeoMapMarker<T>) => Element)",
|
|
153
|
+
"description": "The tooltip's content for a marker. Defaults to its name, description and connection count.",
|
|
154
|
+
"required": false,
|
|
155
|
+
"from": "kit"
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
"name": "worldData",
|
|
159
|
+
"type": "GeoMapWorld",
|
|
160
|
+
"description": "The land, as GeoJSON. Without it the map loads Natural Earth's countries (1:110m) on demand, after it mounts; pass `await loadWorld()` (or your own) to draw land on the server too.",
|
|
161
|
+
"required": false,
|
|
162
|
+
"from": "kit"
|
|
163
|
+
}
|
|
164
|
+
],
|
|
165
|
+
"dataAttributes": [],
|
|
166
|
+
"cssVariables": [],
|
|
167
|
+
"state": []
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
"flow": {
|
|
172
|
+
"components": {
|
|
173
|
+
"Flow": {
|
|
174
|
+
"props": [
|
|
175
|
+
{
|
|
176
|
+
"name": "background",
|
|
177
|
+
"type": "boolean",
|
|
178
|
+
"default": "true",
|
|
179
|
+
"description": "Draws a dot grid behind the graph.",
|
|
180
|
+
"required": false,
|
|
181
|
+
"from": "kit"
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
"name": "children",
|
|
185
|
+
"type": "Element",
|
|
186
|
+
"description": "Extra parts inside the flow (a `Panel`, your own controls).",
|
|
187
|
+
"required": false,
|
|
188
|
+
"from": "kit"
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
"name": "class",
|
|
192
|
+
"type": "string",
|
|
193
|
+
"description": "Classes for the flow's root, after the kit's.",
|
|
194
|
+
"required": false,
|
|
195
|
+
"from": "kit"
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
"name": "controls",
|
|
199
|
+
"type": "boolean",
|
|
200
|
+
"default": "true",
|
|
201
|
+
"description": "Shows the zoom and fit buttons.",
|
|
202
|
+
"required": false,
|
|
203
|
+
"from": "kit"
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
"name": "height",
|
|
207
|
+
"type": "string | number",
|
|
208
|
+
"description": "The flow's height (a number is pixels). Without it the flow is 16:9.",
|
|
209
|
+
"required": false,
|
|
210
|
+
"from": "kit"
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
"name": "label",
|
|
214
|
+
"type": "string",
|
|
215
|
+
"description": "The flow's accessible name: what the graph shows (\"Nightly ETL: 2 of 6 steps failed\").",
|
|
216
|
+
"required": true,
|
|
217
|
+
"from": "kit"
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
"name": "minimap",
|
|
221
|
+
"type": "boolean",
|
|
222
|
+
"default": "false",
|
|
223
|
+
"description": "Shows a minimap in the bottom corner.",
|
|
224
|
+
"required": false,
|
|
225
|
+
"from": "kit"
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
"name": "readOnly",
|
|
229
|
+
"type": "boolean",
|
|
230
|
+
"default": "true",
|
|
231
|
+
"description": "A view of the graph: pan, zoom and select only (no dragging, connecting or deleting), and the wheel scrolls the page (pinch or Ctrl/⌘ + wheel zooms). `false` makes it an editor; set the interaction props (`nodesDraggable`, `nodesConnectable`, …) yourself to mix.",
|
|
232
|
+
"required": false,
|
|
233
|
+
"from": "kit"
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
"name": "style",
|
|
237
|
+
"type": "CSSProperties",
|
|
238
|
+
"description": "Styles for the flow's root, after its `height`.",
|
|
239
|
+
"required": false,
|
|
240
|
+
"from": "kit"
|
|
241
|
+
}
|
|
242
|
+
],
|
|
243
|
+
"dataAttributes": [],
|
|
244
|
+
"cssVariables": [],
|
|
245
|
+
"state": []
|
|
246
|
+
},
|
|
247
|
+
"FlowBackground": {
|
|
248
|
+
"props": [],
|
|
249
|
+
"dataAttributes": [],
|
|
250
|
+
"cssVariables": [],
|
|
251
|
+
"state": []
|
|
252
|
+
},
|
|
253
|
+
"FlowControls": {
|
|
254
|
+
"props": [],
|
|
255
|
+
"dataAttributes": [],
|
|
256
|
+
"cssVariables": [],
|
|
257
|
+
"state": []
|
|
258
|
+
},
|
|
259
|
+
"FlowEdge": {
|
|
260
|
+
"props": [],
|
|
261
|
+
"dataAttributes": [],
|
|
262
|
+
"cssVariables": [],
|
|
263
|
+
"state": []
|
|
264
|
+
},
|
|
265
|
+
"FlowMiniMap": {
|
|
266
|
+
"props": [],
|
|
267
|
+
"dataAttributes": [],
|
|
268
|
+
"cssVariables": [],
|
|
269
|
+
"state": []
|
|
270
|
+
},
|
|
271
|
+
"FlowNode": {
|
|
272
|
+
"props": [],
|
|
273
|
+
"dataAttributes": [],
|
|
274
|
+
"cssVariables": [],
|
|
275
|
+
"state": []
|
|
276
|
+
},
|
|
277
|
+
"BaseEdge": {
|
|
278
|
+
"props": [],
|
|
279
|
+
"dataAttributes": [],
|
|
280
|
+
"cssVariables": [],
|
|
281
|
+
"state": []
|
|
282
|
+
},
|
|
283
|
+
"Handle": {
|
|
284
|
+
"props": [],
|
|
285
|
+
"dataAttributes": [],
|
|
286
|
+
"cssVariables": [],
|
|
287
|
+
"state": []
|
|
288
|
+
},
|
|
289
|
+
"Panel": {
|
|
290
|
+
"props": [],
|
|
291
|
+
"dataAttributes": [],
|
|
292
|
+
"cssVariables": [],
|
|
293
|
+
"state": []
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
package/docs/flow.md
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
# Flow
|
|
2
|
+
|
|
3
|
+
<!-- search: dag, graph, node graph, pipeline, workflow, data flow, flowchart, node editor, xyflow, react flow, dependency graph, lineage -->
|
|
4
|
+
|
|
5
|
+
A pannable, zoomable graph of steps and what moves between them: an ETL pipeline, a deploy's jobs, a service map, a workflow someone builds. It's [@dschz/solid-flow](https://github.com/dsnchz/solid-flow) (xyflow's engine for Solid 2) in the kit's look: step nodes with a status, an icon, a title, a description and meta; edges in the kit's tones that can show data moving; themed background, controls and minimap; and `layoutFlow` to place graphs that arrive without positions. It's read-only by default (pan, zoom and select), and an editor with `readOnly={false}`. It renders on the server when nodes have a `width` and `height`.
|
|
6
|
+
|
|
7
|
+
```tsx
|
|
8
|
+
import { Flow, layoutFlow, type FlowEdgeItem, type FlowNodeItem } from "@zsherman/viz/flow";
|
|
9
|
+
|
|
10
|
+
const nodes: Omit<FlowNodeItem, "position">[] = [
|
|
11
|
+
{ id: "pg", type: "step", width: 200, height: 56, data: { title: "Postgres orders", status: "success", meta: "41s" } },
|
|
12
|
+
{ id: "join", type: "step", width: 200, height: 56, data: { title: "Join and dedupe", status: "running" } },
|
|
13
|
+
{ id: "load", type: "step", width: 200, height: 56, data: { title: "Load to warehouse", status: "pending" } },
|
|
14
|
+
];
|
|
15
|
+
const edges: FlowEdgeItem[] = [
|
|
16
|
+
{ id: "pg-join", source: "pg", target: "join", type: "flow" },
|
|
17
|
+
{ id: "join-load", source: "join", target: "load", type: "flow", data: { flowing: true, tone: "accent" } },
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
<Flow label="Nightly ETL: 1 running" defaultNodes={layoutFlow(nodes, edges)} defaultEdges={edges} height={360} />;
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage guidelines
|
|
24
|
+
|
|
25
|
+
- Use it when the shape of the work matters: what feeds what, what runs side by side, where a failure stops the rest. For steps in order, a Trace (`@zsherman/kit/trace`) reads faster; put the two side by side for a run.
|
|
26
|
+
- Name it with `label`: what the graph is and its state ("Nightly ETL: 2 running, 1 failed").
|
|
27
|
+
- Give every node a `width` and `height`: the server can't measure, `layoutFlow` uses them to place nodes, and the first paint is right.
|
|
28
|
+
- Keep it read-only for views (the default); `readOnly={false}` only where people edit the graph.
|
|
29
|
+
- Say what matters in text too (a failed step in a heading or a list): a graph is hard to read with a screen reader.
|
|
30
|
+
|
|
31
|
+
## Anatomy
|
|
32
|
+
|
|
33
|
+
```tsx
|
|
34
|
+
<Flow
|
|
35
|
+
label="…" // required: the flow's accessible name
|
|
36
|
+
defaultNodes={nodes} defaultEdges={edges} // or nodes={store} edges={store} (createNodeStore, createEdgeStore)
|
|
37
|
+
readOnly // the default: pan, zoom, select
|
|
38
|
+
height={360} // without it the flow is 16:9
|
|
39
|
+
controls // zoom and fit buttons (on by default)
|
|
40
|
+
background // the dot grid (on by default)
|
|
41
|
+
minimap // off by default
|
|
42
|
+
nodeTypes={{ … }} edgeTypes={{ … }} // your own, beside "step" and "flow"
|
|
43
|
+
onNodeClick onSelectionChange … // every solid-flow prop and event
|
|
44
|
+
>
|
|
45
|
+
<Panel position="top-right">…</Panel> // anything inside the flow
|
|
46
|
+
</Flow>
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
What renders: a root `div` (`data-slot="flow"`, `data-readonly` while read-only) around solid-flow's wrapper (`role="application"`, named by `label`) with the viewport, the nodes (`.solid-flow__node`, focusable, `aria-roledescription="node"`), the edges, and the background, controls and minimap. Each step node renders `flow-node` (`data-status`) with `flow-node-icon`, `flow-node-title`, `flow-node-description` and `flow-node-meta`; each kit edge renders `flow-edge` (`data-flowing`).
|
|
50
|
+
|
|
51
|
+
## Step nodes
|
|
52
|
+
|
|
53
|
+
A node with `type: "step"` (the Flow registers it) shows `FlowNodeData`:
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
type FlowStatus = "pending" | "running" | "success" | "warning" | "error";
|
|
57
|
+
|
|
58
|
+
type FlowNodeData = {
|
|
59
|
+
title: string; // the node's name, after its status for screen readers ("Failed: Search index")
|
|
60
|
+
description?: string; // a second line
|
|
61
|
+
status?: FlowStatus; // the status icon and colors, as in a Trace; running shows the kit Spinner
|
|
62
|
+
icon?: IconNode; // an icon of your own (@zsherman/kit/icons) instead of the status icon
|
|
63
|
+
meta?: string; // a short value at the end ("2m 14s")
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
type FlowNodeItem = Node<FlowNodeData, "step">; // with id, position, width, height, …
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Statuses take Trace's icons and colors: pending a dashed circle, running the Spinner and an accent edge, success a check, warning a triangle and a warning edge, error an alert and a danger edge. The status word comes from the locale's `trace.status` (`LocaleProvider`), "Succeeded", "Failed" and so on in English.
|
|
70
|
+
|
|
71
|
+
Handles sit on the sides `layoutFlow` gives the node (`targetPosition`, `sourcePosition`: left and right by default, top and bottom going down). In a read-only flow they're hidden but still anchor the edges.
|
|
72
|
+
|
|
73
|
+
## Edges
|
|
74
|
+
|
|
75
|
+
An edge with `type: "flow"` (the default type for edges without one) is a curve in a tone, with `FlowEdgeData`:
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
type FlowEdgeData = {
|
|
79
|
+
flowing?: boolean; // dashes move source to target (data moving); they stop under reduced motion
|
|
80
|
+
tone?: "neutral" | "accent" | "success" | "warning" | "danger"; // the line's color, neutral by default
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
type FlowEdgeItem = Edge<FlowEdgeData, "flow">; // with id, source, target, label, …
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
solid-flow's built-in edge types (`"default"`, `"straight"`, `"step"`, `"smoothstep"`) work too, in the kit's border color; their `animated: true` stops under reduced motion as well.
|
|
87
|
+
|
|
88
|
+
## Auto layout
|
|
89
|
+
|
|
90
|
+
`layoutFlow(nodes, edges, options)` places nodes that arrive without positions with dagre's layered layout: ranks along the edges, few crossings. It returns new nodes with `position` (top left), `targetPosition` and `sourcePosition`; the input isn't changed.
|
|
91
|
+
|
|
92
|
+
```ts
|
|
93
|
+
interface LayoutFlowOptions {
|
|
94
|
+
direction?: "LR" | "TB"; // left to right (default) or top to bottom
|
|
95
|
+
nodeWidth?: number; // for nodes without width/height (default 200)
|
|
96
|
+
nodeHeight?: number; // (default 56)
|
|
97
|
+
rankGap?: number; // between ranks (default 72)
|
|
98
|
+
nodeGap?: number; // between nodes in a rank (default 24)
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
```tsx
|
|
103
|
+
<Flow
|
|
104
|
+
label="Build graph"
|
|
105
|
+
defaultNodes={layoutFlow(nodes, edges, { direction: "TB", rankGap: 48 })}
|
|
106
|
+
defaultEdges={edges}
|
|
107
|
+
/>
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
To tidy an editable graph, lay out its current nodes and move them:
|
|
111
|
+
|
|
112
|
+
```tsx
|
|
113
|
+
const placed = new Map(layoutFlow([...nodes], [...edges]).map((node) => [node.id, node.position]));
|
|
114
|
+
setNodes((draft) => {
|
|
115
|
+
for (const node of draft) node.position = placed.get(node.id) ?? node.position;
|
|
116
|
+
});
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Editing
|
|
120
|
+
|
|
121
|
+
`readOnly={false}` turns on dragging, connecting and deleting (Backspace), and the wheel zooms. Keep the graph in solid-flow's stores: the flow writes positions and selection onto your rows, and you add the edges people connect in `onConnect`.
|
|
122
|
+
|
|
123
|
+
```tsx
|
|
124
|
+
import {
|
|
125
|
+
type Connection,
|
|
126
|
+
type FlowEdgeTypes,
|
|
127
|
+
type FlowNodeTypes,
|
|
128
|
+
createEdgeStore,
|
|
129
|
+
createNodeStore,
|
|
130
|
+
Flow,
|
|
131
|
+
} from "@zsherman/viz/flow";
|
|
132
|
+
|
|
133
|
+
const [nodes, setNodes] = createNodeStore<FlowNodeTypes>([
|
|
134
|
+
{ id: "a", type: "step", width: 180, height: 48, position: { x: 0, y: 0 }, data: { title: "New signup" } },
|
|
135
|
+
{ id: "b", type: "step", width: 180, height: 48, position: { x: 260, y: 0 }, data: { title: "Send welcome email" } },
|
|
136
|
+
]);
|
|
137
|
+
const [edges, setEdges] = createEdgeStore<FlowEdgeTypes>([{ id: "a-b", source: "a", target: "b", type: "flow" }]);
|
|
138
|
+
|
|
139
|
+
const connect = (c: Connection) =>
|
|
140
|
+
setEdges((draft) => {
|
|
141
|
+
draft.push({ id: `${c.source}-${c.target}`, source: c.source, target: c.target, type: "flow" });
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
<Flow label="Onboarding automation" readOnly={false} nodes={nodes} edges={edges} onConnect={connect} minimap />;
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
To mix (drag but don't connect), set solid-flow's own props after `readOnly`: `nodesDraggable`, `nodesConnectable`, `elementsSelectable`, `deleteKey`, `zoomOnScroll`. Every solid-flow prop and event passes through (`onNodeClick`, `onSelectionChange`, `fitViewOptions`, …); `useSolidFlow()` inside the flow gives its commands (`fitView`, `setCenter`, `addNodes`, …).
|
|
148
|
+
|
|
149
|
+
## Your own nodes and edges
|
|
150
|
+
|
|
151
|
+
`nodeTypes` and `edgeTypes` add to the Flow's (`step`, `flow`). Build them from solid-flow's parts, which this entry re-exports (`Handle`, `Position`, `BaseEdge`, `getBezierPath`, `getSmoothStepPath`, `getStraightPath`, `Panel`, `useSolidFlow`, and the types `Node`, `Edge`, `NodeProps`, `EdgeProps`, `Connection`):
|
|
152
|
+
|
|
153
|
+
```tsx
|
|
154
|
+
import { Flow, Handle, Position, type NodeProps } from "@zsherman/viz/flow";
|
|
155
|
+
|
|
156
|
+
function Gate(props: NodeProps<{ label: string }, "gate">) {
|
|
157
|
+
return (
|
|
158
|
+
<div style={{ padding: "8px 12px", border: "1px dashed var(--sui-border-strong)", "border-radius": "999px" }}>
|
|
159
|
+
<Handle type="target" position={Position.Left} />
|
|
160
|
+
{props.data.label}
|
|
161
|
+
<Handle type="source" position={Position.Right} />
|
|
162
|
+
</div>
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
<Flow label="Release" nodeTypes={{ gate: Gate }} defaultNodes={nodes} defaultEdges={edges} />;
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## Theming
|
|
170
|
+
|
|
171
|
+
`@zsherman/viz/styles.css` carries solid-flow's stylesheet (in the kit's base layer) and maps xyflow's `--xy-*` variables to the kit's tokens inside a Flow: the surface for nodes, controls and the minimap, `--sui-border-strong` for edges, handles and the grid, `--sui-accent` for selection. Override a variable on the Flow, or any token:
|
|
172
|
+
|
|
173
|
+
```css
|
|
174
|
+
[data-slot="flow"] .solid-flow {
|
|
175
|
+
--xy-edge-stroke: var(--sui-text-muted);
|
|
176
|
+
--xy-background-pattern-color: var(--sui-border);
|
|
177
|
+
}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
The parts are exported for a flow you compose yourself on solid-flow's `SolidFlow`: `FlowNode` and `FlowEdge` (register them as types), `FlowBackground` (dots in the border color), `FlowControls` (zoom and fit) and `FlowMiniMap`.
|
|
181
|
+
|
|
182
|
+
## Keyboard and screen readers
|
|
183
|
+
|
|
184
|
+
The flow is an application region named by `label`. Nodes are focusable; solid-flow describes the keys to screen readers and announces selection.
|
|
185
|
+
|
|
186
|
+
| Key | Action |
|
|
187
|
+
| --- | --- |
|
|
188
|
+
| Tab | Moves between nodes (and edges), then the controls |
|
|
189
|
+
| Enter, Space | Selects the focused node |
|
|
190
|
+
| Escape | Clears the selection |
|
|
191
|
+
| Arrow keys | Move the selected nodes (when they're draggable: `readOnly={false}`) |
|
|
192
|
+
| Backspace | Deletes the selection (`readOnly={false}`) |
|
|
193
|
+
|
|
194
|
+
A step node's name says its status first ("Failed: Search index"). Edges aren't named: say in text which steps feed which when it matters.
|
|
195
|
+
|
|
196
|
+
## Gotchas
|
|
197
|
+
|
|
198
|
+
- Nodes without `width` and `height` render on the server without a size and jump once measured; `layoutFlow` falls back to 200 × 56 for them.
|
|
199
|
+
- `defaultNodes`/`defaultEdges` seed the flow once (later changes are ignored); pass stores (`nodes`/`edges`) to change the graph from your code.
|
|
200
|
+
- Node ids must be unique, and every edge's `source` and `target` must name a node.
|
|
201
|
+
- A large graph fits whole at a small zoom (down to 0.1); give it a `minimap`, and zoom in to read.
|
|
202
|
+
|
|
203
|
+
## API reference: `@zsherman/viz/flow`
|
|
204
|
+
|
|
205
|
+
<!-- generated:props:flow (node tooling/props-doc.ts; edit the JSDoc in the source, not this table) -->
|
|
206
|
+
|
|
207
|
+
Generated from the types of `@zsherman/viz/flow`. Each part also takes its element's native and ARIA attributes.
|
|
208
|
+
|
|
209
|
+
#### `Flow`
|
|
210
|
+
|
|
211
|
+
| Prop | Type | Default | Description |
|
|
212
|
+
| --- | --- | --- | --- |
|
|
213
|
+
| `background` | `boolean` | `true` | Draws a dot grid behind the graph. |
|
|
214
|
+
| `children` | `Element` | | Extra parts inside the flow (a `Panel`, your own controls). |
|
|
215
|
+
| `class` | `string` | | Classes for the flow's root, after the kit's. |
|
|
216
|
+
| `controls` | `boolean` | `true` | Shows the zoom and fit buttons. |
|
|
217
|
+
| `height` | `string \| number` | | The flow's height (a number is pixels). Without it the flow is 16:9. |
|
|
218
|
+
| `label` (required) | `string` | | The flow's accessible name: what the graph shows ("Nightly ETL: 2 of 6 steps failed"). |
|
|
219
|
+
| `minimap` | `boolean` | `false` | Shows a minimap in the bottom corner. |
|
|
220
|
+
| `readOnly` | `boolean` | `true` | A view of the graph: pan, zoom and select only (no dragging, connecting or deleting), and the wheel scrolls the page (pinch or Ctrl/⌘ + wheel zooms). `false` makes it an editor; set the interaction props (`nodesDraggable`, `nodesConnectable`, …) yourself to mix. |
|
|
221
|
+
| `style` | `CSSProperties` | | Styles for the flow's root, after its `height`. |
|
|
222
|
+
|
|
223
|
+
#### `FlowBackground`
|
|
224
|
+
|
|
225
|
+
No props beyond the element's attributes.
|
|
226
|
+
|
|
227
|
+
#### `FlowControls`
|
|
228
|
+
|
|
229
|
+
No props beyond the element's attributes.
|
|
230
|
+
|
|
231
|
+
#### `FlowEdge`
|
|
232
|
+
|
|
233
|
+
No props beyond the element's attributes.
|
|
234
|
+
|
|
235
|
+
#### `FlowMiniMap`
|
|
236
|
+
|
|
237
|
+
No props beyond the element's attributes.
|
|
238
|
+
|
|
239
|
+
#### `FlowNode`
|
|
240
|
+
|
|
241
|
+
No props beyond the element's attributes.
|
|
242
|
+
|
|
243
|
+
#### `BaseEdge`
|
|
244
|
+
|
|
245
|
+
No props beyond the element's attributes.
|
|
246
|
+
|
|
247
|
+
#### `Handle`
|
|
248
|
+
|
|
249
|
+
No props beyond the element's attributes.
|
|
250
|
+
|
|
251
|
+
#### `Panel`
|
|
252
|
+
|
|
253
|
+
No props beyond the element's attributes.
|
|
254
|
+
|
|
255
|
+
<!-- /generated:props:flow -->
|