@green-on-grey/ui-kit 1.13.0 → 1.15.0

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.
@@ -11,13 +11,19 @@ export type GraphNode = {
11
11
  muted?: boolean;
12
12
  /** The label shows only on hover, focus or highlight. */
13
13
  hideLabel?: boolean;
14
+ /** With `rows` on the graph: the id of the row of the node and its place in it, ascending left to right. */
15
+ row?: string;
16
+ order?: number;
14
17
  };
18
+ /** A link; `double` draws it as a double line — another layer of links, told apart without colour
19
+ * (FTR.HMR.DEV-0003 R15); it combines with `dashed`. */
15
20
  export type GraphEdge = {
16
21
  source: string;
17
22
  target: string;
18
23
  weight?: number;
19
24
  directed?: boolean;
20
25
  dashed?: boolean;
26
+ double?: boolean;
21
27
  title?: string;
22
28
  };
23
29
  export type GraphSelection = {
@@ -28,6 +34,11 @@ export type GraphSelection = {
28
34
  source: string;
29
35
  target: string;
30
36
  } | null;
37
+ /** A row of the row layout, top to bottom in the order given; the label is drawn at its left. */
38
+ export type GraphRow = {
39
+ id: string;
40
+ label: string;
41
+ };
31
42
  /** A node with its place; the fields of d3-force are spelled out, so the types of the kit need no d3 types. */
32
43
  type Placed = GraphNode & {
33
44
  r: number;
@@ -39,18 +50,52 @@ type Placed = GraphNode & {
39
50
  fx?: number | null;
40
51
  fy?: number | null;
41
52
  };
53
+ type Field = {
54
+ w: number;
55
+ h: number;
56
+ };
57
+ /** The places of the nodes, the size of the field and, in the row layout, the rows with their middle line. */
58
+ type Placement = {
59
+ placed: Placed[];
60
+ field: Field;
61
+ rows?: {
62
+ id: string;
63
+ label: string;
64
+ y: number;
65
+ x: number;
66
+ x2: number;
67
+ }[];
68
+ };
42
69
  /** Ids within `depth` steps of `from`, edges taken both ways. */
43
70
  export declare function neighbours(edges: GraphEdge[], from: string, depth: number): Set<string>;
44
71
  /** Positions of the nodes (exported for the tests): a force layout computed once per data. The start of
45
72
  * d3-force is deterministic, so the same data gives the same picture. */
46
73
  export declare function layout(nodes: GraphNode[], edges: GraphEdge[]): Placed[];
74
+ /** The row layout (FTR.HMR.DEV-0002 R15, exported for the tests): a row per `rows` entry that has nodes, top to
75
+ * bottom in the given order; in a row the nodes by `order`, then id, left to right. A node whose row is not
76
+ * among `rows` goes to a last row without a label. The block is centred in a field at least as big as that of
77
+ * the force layout. */
78
+ export declare function rowLayout(nodes: GraphNode[], rows: GraphRow[]): Placement;
79
+ /** The line of an edge: straight, or in the row layout an arc between two nodes of one row — above when it goes
80
+ * right, below when it goes left, so links both ways do not cover each other. A directed line ends at the
81
+ * circle of the target. */
82
+ export declare function edgeLine(a: Placed, b: Placed, directed: boolean, arcs: boolean): {
83
+ d?: string;
84
+ hit?: string;
85
+ x1: number;
86
+ y1: number;
87
+ x2: number;
88
+ y2: number;
89
+ };
47
90
  /** A graph of nodes and links (FTR.NAB.CMN-0003 R19, FTR.HMR.DEV-0002 R15, R16).
48
91
  * Hovering highlights the neighbours, a click pins the selection; the wheel zooms,
49
- * dragging moves. `focus` highlights a node and its neighbours within `depth`
50
- * steps; `onOpen` is called on a double click or Enter on a node. The kit knows
51
- * nothing of what the nodes are: labels and the legend come from the product.
52
- * The layout runs when `nodes` or `edges` change identity: keep them stable (useMemo). */
53
- export declare function Graph({ nodes, edges, ariaLabel, selected, onSelect, focus, depth, onOpen, legend, nodeLabel }: {
92
+ * dragging the field moves it. `focus` highlights a node and its neighbours within `depth`
93
+ * steps; `onOpen` is called on a double click or Enter on a node. With `rows` the nodes stand in
94
+ * rows (`GraphNode.row`, `order`) instead of the force layout; with `draggable` a node can be moved
95
+ * and a button puts the moved nodes back. The kit knows nothing of what the nodes are: labels,
96
+ * rows and the legend come from the product.
97
+ * The layout runs when `nodes`, `edges` or `rows` change identity: keep them stable (useMemo). */
98
+ export declare function Graph({ nodes, edges, ariaLabel, selected, onSelect, focus, depth, onOpen, legend, nodeLabel, rows, draggable }: {
54
99
  nodes: GraphNode[];
55
100
  edges: GraphEdge[];
56
101
  ariaLabel: string;
@@ -64,5 +109,7 @@ export declare function Graph({ nodes, edges, ariaLabel, selected, onSelect, foc
64
109
  label: string;
65
110
  }[];
66
111
  nodeLabel?: (n: GraphNode) => string;
112
+ rows?: GraphRow[];
113
+ draggable?: boolean;
67
114
  }): import("react").JSX.Element;
68
115
  export {};
package/dist/index.d.ts CHANGED
@@ -4,6 +4,6 @@ export { Button, IconButton } from "./components/Button";
4
4
  export { Tabs } from "./components/Tabs";
5
5
  export { Menu } from "./components/Menu";
6
6
  export { TopBar, type LinkComponent, type TopBarSection } from "./components/TopBar";
7
- export { Graph, neighbours, type GraphNode, type GraphEdge, type GraphSelection } from "./components/Graph";
7
+ export { Graph, neighbours, type GraphNode, type GraphEdge, type GraphSelection, type GraphRow } from "./components/Graph";
8
8
  export { Modal, ToastProvider, useToast, Avatar, Switch, Empty, Loading, useOutside, type ToastSpec } from "./components/ui";
9
9
  export { UIKIT_NS } from "./i18n";