@petrarca/sonnet-graph 0.6.0 → 0.8.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.
- package/README.md +89 -118
- package/dist/index.d.ts +354 -33
- package/dist/index.js +1534 -636
- package/dist/index.js.map +1 -1
- package/package.json +6 -4
package/README.md
CHANGED
|
@@ -1,35 +1,33 @@
|
|
|
1
1
|
# @petrarca/sonnet-graph
|
|
2
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
|
-
---
|
|
3
|
+
Property-graph visualization for the Petrarca Sonnet component library. The
|
|
4
|
+
state and the transformations are renderer-independent; Cytoscape and Reagraph
|
|
5
|
+
are two implementations of the drawing surface, switched at runtime
|
|
6
|
+
([ADR-0004](../../docs/adr/0004-graph-rendering-is-renderer-agnostic.md)).
|
|
7
|
+
|
|
8
|
+
## What it provides
|
|
9
|
+
|
|
10
|
+
**A viewer.** `GraphVisualizer` draws the graph through the active renderer,
|
|
11
|
+
with selection, focus mode, hide and show, and expansion.
|
|
12
|
+
`GraphRendererProvider` holds the choice and reports changes so a host can
|
|
13
|
+
persist it; `ActionPanel` shows the selected element and its actions.
|
|
14
|
+
|
|
15
|
+
**An accessible list.** Both renderers draw outside the DOM, so `GraphA11yList`
|
|
16
|
+
mirrors the selectable elements as buttons driving the same selection store,
|
|
17
|
+
`sr-only` by default and displayable as an outline panel.
|
|
18
|
+
|
|
19
|
+
**Stores and transforms.** `createGraphDataStore`, `createGraphFilterStore`,
|
|
20
|
+
`createGraphExplorationStore`, `createSelectionStore`, `createGraphFocusStore`
|
|
21
|
+
and `createActionPanelStore`, plus `enrichNodes`, `enrichEdges`,
|
|
22
|
+
`normalizeGraph` and the palette builders. The consumer creates the stores, so
|
|
23
|
+
two graph views in one application are isolated.
|
|
24
|
+
|
|
25
|
+
**Two editors.** `GraphModelEditor` authors the metamodel -- node types, edge
|
|
26
|
+
types, relations -- as a graph over a controlled `value`. The `graph-edit`
|
|
27
|
+
surface (`GraphEditToolbar`, `NodeFormSheet`, `EdgeFormSheet`,
|
|
28
|
+
`DeleteNodeDialog`) edits the instance data, writing through a
|
|
29
|
+
`GraphMutationPort` you implement and reading schemas from a
|
|
30
|
+
`GraphSchemaProvider` you supply. Nothing here does I/O of its own.
|
|
33
31
|
|
|
34
32
|
## Install
|
|
35
33
|
|
|
@@ -37,108 +35,81 @@ preparing raw graph data before passing it to stores.
|
|
|
37
35
|
pnpm add @petrarca/sonnet-graph
|
|
38
36
|
```
|
|
39
37
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
38
|
+
| Peer | Range | Needed for |
|
|
39
|
+
|---|---|---|
|
|
40
|
+
| `react`, `react-dom` | `>=19` | Everything |
|
|
41
|
+
| `lucide-react` | `>=0.300` | Toolbar and panel icons |
|
|
42
|
+
| `cytoscape` | `>=3` | The Cytoscape renderer |
|
|
43
|
+
| `cytoscape-cola`, `cytoscape-cise`, `cytoscape-cxtmenu`, `cytoscape-dagre`, `cytoscape-elk`, `cytoscape-fcose`, `cytoscape-klay` | `>=1` to `>=3` | Cytoscape layouts and the context menu |
|
|
44
|
+
| `reagraph` | `>=4` | The Reagraph renderer |
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
**The renderer peers are declared optional, and are not optional in practice.**
|
|
47
|
+
Both renderers and all seven Cytoscape plugins are statically imported at
|
|
48
|
+
module scope, so `peerDependenciesMeta.optional` only stops your package manager
|
|
49
|
+
warning at install time. Omit any one of the nine and importing
|
|
50
|
+
`GraphVisualizer` fails; there is no supported subset.
|
|
47
51
|
|
|
48
|
-
|
|
52
|
+
The plugin specifiers must also resolve from your own `node_modules`. If your
|
|
53
|
+
bundler resolves this package from anywhere else -- a linked checkout, a build
|
|
54
|
+
output outside the project, any alias pointing elsewhere -- resolution starts
|
|
55
|
+
from that location and there is nothing to find. Alias all seven plugin
|
|
56
|
+
specifiers to your own `node_modules`; a partial list fails on whichever one was
|
|
57
|
+
left out, when the renderer first mounts. The configuration is in
|
|
58
|
+
[getting started](docs/usage/getting-started.md).
|
|
49
59
|
|
|
50
|
-
|
|
51
|
-
pnpm add cytoscape # Cytoscape.js renderer
|
|
52
|
-
pnpm add reagraph # Reagraph (3D/WebGL) renderer
|
|
53
|
-
```
|
|
60
|
+
## Usage
|
|
54
61
|
|
|
55
|
-
|
|
56
|
-
both `cytoscape` and `reagraph` are required even if your app only uses one renderer.
|
|
57
|
-
|
|
58
|
-
### Cytoscape layout plugins (optional)
|
|
59
|
-
|
|
60
|
-
Install the layout algorithms you need. All are optional — the graph works
|
|
61
|
-
without them but with fewer layout options:
|
|
62
|
-
|
|
63
|
-
```bash
|
|
64
|
-
pnpm add cytoscape-fcose # Force-directed, compound graph
|
|
65
|
-
pnpm add cytoscape-cola # Constraint-based
|
|
66
|
-
pnpm add cytoscape-dagre # DAG / hierarchical
|
|
67
|
-
pnpm add cytoscape-elk # Eclipse Layout Kernel
|
|
68
|
-
pnpm add cytoscape-cise # Circular layout
|
|
69
|
-
pnpm add cytoscape-klay # KLay hierarchical
|
|
70
|
-
pnpm add cytoscape-cxtmenu # Context menu extension
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
### Local development with SONNET_UI_LOCAL=1
|
|
74
|
-
|
|
75
|
-
When resolving `@petrarca/sonnet-graph` from the local dist (via Vite aliases),
|
|
76
|
-
the Cytoscape plugins must also be aliased to the consumer's `node_modules` —
|
|
77
|
-
Vite cannot find them relative to the dist file. Add to your `sonnet-aliases.ts`:
|
|
78
|
-
|
|
79
|
-
```ts
|
|
80
|
-
const nm = path.resolve(baseDir, "node_modules");
|
|
81
|
-
// ...
|
|
82
|
-
"cytoscape-fcose": path.resolve(nm, "cytoscape-fcose"),
|
|
83
|
-
"cytoscape-cola": path.resolve(nm, "cytoscape-cola"),
|
|
84
|
-
"cytoscape-dagre": path.resolve(nm, "cytoscape-dagre"),
|
|
85
|
-
"cytoscape-elk": path.resolve(nm, "cytoscape-elk"),
|
|
86
|
-
"cytoscape-cise": path.resolve(nm, "cytoscape-cise"),
|
|
87
|
-
"cytoscape-klay": path.resolve(nm, "cytoscape-klay"),
|
|
88
|
-
"cytoscape-cxtmenu": path.resolve(nm, "cytoscape-cxtmenu"),
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
See `sonnet-ui-starter/sonnet-aliases.ts` for a complete reference implementation.
|
|
92
|
-
|
|
93
|
-
---
|
|
94
|
-
|
|
95
|
-
## Basic usage
|
|
62
|
+
Create the stores once, never in a render body, and give the container a height.
|
|
96
63
|
|
|
97
64
|
```tsx
|
|
98
65
|
import {
|
|
99
|
-
GraphVisualizer,
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
GraphStoresContext,
|
|
103
|
-
createGraphDataStore,
|
|
104
|
-
createGraphFilterStore,
|
|
105
|
-
createGraphExplorationStore,
|
|
106
|
-
createSelectionStore,
|
|
107
|
-
createGraphFocusStore,
|
|
108
|
-
enrichNodes,
|
|
109
|
-
enrichEdges,
|
|
110
|
-
buildColorPalette,
|
|
111
|
-
type RawGraphNode,
|
|
112
|
-
type RawGraphEdge,
|
|
113
|
-
type WorkspaceStores,
|
|
66
|
+
GraphRendererProvider, GraphStoresContext, GraphVisualizer,
|
|
67
|
+
createGraphDataStore, createGraphExplorationStore, createGraphFilterStore,
|
|
68
|
+
createGraphFocusStore, createSelectionStore, type WorkspaceStores,
|
|
114
69
|
} from "@petrarca/sonnet-graph";
|
|
115
70
|
|
|
116
|
-
|
|
71
|
+
const graphData = createGraphDataStore();
|
|
72
|
+
const graphFilter = createGraphFilterStore();
|
|
73
|
+
const selection = createSelectionStore();
|
|
74
|
+
|
|
75
|
+
// WorkspaceStores has exactly these four members. The focus store is a
|
|
76
|
+
// dependency of the exploration store, which requires its deps object.
|
|
117
77
|
const stores: WorkspaceStores = {
|
|
118
|
-
graphData
|
|
119
|
-
graphFilter
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
78
|
+
graphData,
|
|
79
|
+
graphFilter,
|
|
80
|
+
selection,
|
|
81
|
+
graphExploration: createGraphExplorationStore({
|
|
82
|
+
graphData,
|
|
83
|
+
selection,
|
|
84
|
+
graphFilter,
|
|
85
|
+
graphFocus: createGraphFocusStore(),
|
|
86
|
+
expandNode: async () => ({ nodes: [], edges: [], has_more: false }),
|
|
87
|
+
getNodes: async () => [],
|
|
88
|
+
}),
|
|
123
89
|
};
|
|
124
90
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
</GraphRendererProvider>
|
|
135
|
-
</GraphStoresContext.Provider>
|
|
136
|
-
);
|
|
137
|
-
}
|
|
91
|
+
const GraphView = () => (
|
|
92
|
+
<GraphStoresContext.Provider value={stores}>
|
|
93
|
+
<GraphRendererProvider defaultRenderer="cytoscape">
|
|
94
|
+
<div className="h-[600px] w-full">
|
|
95
|
+
<GraphVisualizer />
|
|
96
|
+
</div>
|
|
97
|
+
</GraphRendererProvider>
|
|
98
|
+
</GraphStoresContext.Provider>
|
|
99
|
+
);
|
|
138
100
|
```
|
|
139
101
|
|
|
140
|
-
|
|
102
|
+
## Documentation
|
|
103
|
+
|
|
104
|
+
- [Usage guides](docs/usage/index.md) -- getting started,
|
|
105
|
+
[stores and data](docs/usage/stores-and-data.md),
|
|
106
|
+
[exploration and selection](docs/usage/exploration-and-selection.md),
|
|
107
|
+
[accessibility](docs/usage/accessibility.md), and both editors:
|
|
108
|
+
[model](docs/usage/model-editing.md) and
|
|
109
|
+
[instance](docs/usage/instance-editing.md).
|
|
110
|
+
- [Design docs](docs/design/index.md) -- the renderer boundary and both editors.
|
|
111
|
+
- [Workspace documentation](../../docs/README.md) -- how the packages layer.
|
|
141
112
|
|
|
142
113
|
## License
|
|
143
114
|
|
|
144
|
-
See [LICENSE.md](../../LICENSE.md).
|
|
115
|
+
Apache 2.0. See [LICENSE.md](../../LICENSE.md).
|