@bruno00o/graph 0.1.0 → 0.3.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 +114 -2
- package/dist/db.d.ts +2 -2
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -1
- package/dist/{mount-graph-BHwq3LOr.js → mount-graph-CzVfiIte.js} +1389 -67
- package/dist/mount-graph-CzVfiIte.js.map +1 -0
- package/dist/{mount-graph-B88WGOQu.d.ts → mount-graph-DQLST9-_.d.ts} +13 -3
- package/dist/query.d.ts +1 -1
- package/dist/react.d.ts +3 -2
- package/dist/react.js +2 -1
- package/dist/react.js.map +1 -1
- package/dist/{types-D6b86Rt1.d.ts → types-BaflHDaf.d.ts} +11 -4
- package/package.json +1 -1
- package/dist/mount-graph-BHwq3LOr.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,9 +1,121 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<a href="https://npmjs.com/package/@bruno00o/graph" target="_parent">
|
|
3
|
+
<img alt="npm version" src="https://img.shields.io/npm/v/@bruno00o/graph.svg" />
|
|
4
|
+
</a>
|
|
5
|
+
<a href="https://npmjs.com/package/@bruno00o/graph" target="_parent">
|
|
6
|
+
<img alt="npm downloads" src="https://img.shields.io/npm/dm/@bruno00o/graph.svg" />
|
|
7
|
+
</a>
|
|
8
|
+
<a href="https://bundlephobia.com/result?p=@bruno00o/graph" target="_parent">
|
|
9
|
+
<img alt="bundle size" src="https://badgen.net/bundlephobia/minzip/@bruno00o/graph" />
|
|
10
|
+
</a>
|
|
11
|
+
<a href="https://github.com/bruno00o/graph/actions/workflows/ci.yml" target="_parent">
|
|
12
|
+
<img alt="CI" src="https://github.com/bruno00o/graph/actions/workflows/ci.yml/badge.svg" />
|
|
13
|
+
</a>
|
|
14
|
+
<a href="./LICENSE" target="_parent">
|
|
15
|
+
<img alt="MIT license" src="https://img.shields.io/npm/l/@bruno00o/graph.svg" />
|
|
16
|
+
</a>
|
|
17
|
+
</div>
|
|
18
|
+
|
|
1
19
|
# @bruno00o/graph
|
|
2
20
|
|
|
3
21
|
Framework-agnostic, typed graph visualization rendered with WebGL2.
|
|
4
22
|
|
|
5
|
-
|
|
23
|
+
- Smooth with 50,000 nodes and 100,000 edges, picking included
|
|
24
|
+
- Declarative marks: map your fields to color, size, labels, arrows and dashes through shared scales, with types inferred from your data
|
|
25
|
+
- Live sources: pass a TanStack DB collection as is, or anything with `subscribeChanges`, and only what changed is redrawn
|
|
26
|
+
- Named states (selection, hover, focus and your own) resolved on the GPU
|
|
27
|
+
- Images and icons clipped to the node shape, corner badges, parallel edges and self loops
|
|
28
|
+
- Drag, pan, zoom, multiple selection and lasso out of the box, plus keyboard navigation announced to screen readers
|
|
29
|
+
- Themed with CSS variables, light and dark
|
|
30
|
+
- A framework-agnostic core with a thin React adapter, plus TanStack DB and TanStack Query integrations
|
|
31
|
+
|
|
32
|
+
> Early development: the API may still change before 1.0.
|
|
33
|
+
|
|
34
|
+
## Install
|
|
35
|
+
|
|
36
|
+
```sh
|
|
37
|
+
pnpm add @bruno00o/graph
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
| Entry point | Contents | Peer dependency |
|
|
41
|
+
| --------------------------- | ---------------------------------------------------------------- | ---------------------- |
|
|
42
|
+
| `@bruno00o/graph` | `defineGraph`, `nodes`, `edges`, `mountGraph` | |
|
|
43
|
+
| `@bruno00o/graph/react` | `<Graph>`, `useGraph`, `useGraphState`, `useGraphEvent` | `react` 19 |
|
|
44
|
+
| `@bruno00o/graph/db` | `persistPositions` for TanStack DB collections | `@tanstack/db` |
|
|
45
|
+
| `@bruno00o/graph/query` | `createExploration` for neighborhoods loaded with TanStack Query | `@tanstack/query-core` |
|
|
46
|
+
| `@bruno00o/graph/theme.css` | Default light and dark theme | |
|
|
47
|
+
|
|
48
|
+
## Quick start
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
import { defineGraph, edges, mountGraph, nodes } from '@bruno00o/graph'
|
|
52
|
+
import '@bruno00o/graph/theme.css'
|
|
53
|
+
|
|
54
|
+
type Item = { id: string; label: string; group: string; weight: number }
|
|
55
|
+
type Link = { id: string; from: string; to: string }
|
|
56
|
+
|
|
57
|
+
const definition = defineGraph({
|
|
58
|
+
marks: [
|
|
59
|
+
edges<Link>(links, { source: 'from', target: 'to', arrow: 'target' }),
|
|
60
|
+
nodes<Item>(items, { color: 'group', size: 'weight', label: 'label' }),
|
|
61
|
+
],
|
|
62
|
+
states: { muted: { opacity: 0.2, label: false } },
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
const graph = mountGraph(container, { definition, ariaLabel: 'Sample graph' })
|
|
66
|
+
|
|
67
|
+
graph.on('click', ({ target }) => {
|
|
68
|
+
if (target?.kind === 'node') graph.view.fit([target.key], { duration: 400 })
|
|
69
|
+
})
|
|
70
|
+
graph.states.set('muted', { nodes: ['n4', 'n7'] })
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
With React:
|
|
74
|
+
|
|
75
|
+
```tsx
|
|
76
|
+
import { defineGraph, edges, nodes } from '@bruno00o/graph'
|
|
77
|
+
import { Graph, useGraphState } from '@bruno00o/graph/react'
|
|
78
|
+
import { useMemo } from 'react'
|
|
79
|
+
|
|
80
|
+
function Hovered() {
|
|
81
|
+
const hovered = useGraphState((state) => state.hovered)
|
|
82
|
+
return <output>{hovered?.kind === 'node' ? String(hovered.key) : ''}</output>
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function SampleGraph({ items, links }: { items: Item[]; links: Link[] }) {
|
|
86
|
+
const definition = useMemo(
|
|
87
|
+
() =>
|
|
88
|
+
defineGraph({
|
|
89
|
+
marks: [
|
|
90
|
+
edges(links, { source: 'from', target: 'to' }),
|
|
91
|
+
nodes(items, { color: 'group', label: 'label' }),
|
|
92
|
+
],
|
|
93
|
+
}),
|
|
94
|
+
[items, links],
|
|
95
|
+
)
|
|
96
|
+
return (
|
|
97
|
+
<Graph definition={definition} ariaLabel="Sample graph" style={{ height: 480 }}>
|
|
98
|
+
<Hovered />
|
|
99
|
+
</Graph>
|
|
100
|
+
)
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
A TanStack DB collection is a live source: pass it to a mark and its changes arrive without a new definition.
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
nodes(itemsCollection, { color: 'group', label: 'label' })
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Examples
|
|
111
|
+
|
|
112
|
+
The [`examples`](./examples) folder holds runnable examples: vanilla and React graphs, images and badges, parallel edges and loops, collaboration across tabs with TanStack DB, and neighborhood exploration with TanStack Query. Run them with `pnpm install && pnpm dev`.
|
|
113
|
+
|
|
114
|
+
## Get Involved
|
|
115
|
+
|
|
116
|
+
- Issues and pull requests are welcome.
|
|
117
|
+
- `pnpm verify` runs lint, types, tests, the build and package checks.
|
|
6
118
|
|
|
7
119
|
## License
|
|
8
120
|
|
|
9
|
-
MIT
|
|
121
|
+
[MIT](./LICENSE)
|
package/dist/db.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { i as GraphInstance } from "./mount-graph-DQLST9-_.js";
|
|
2
|
+
import { _ as Key, d as FieldOf, k as Point } from "./types-BaflHDaf.js";
|
|
3
3
|
import { Collection, MutationFn, Strategy } from "@tanstack/db";
|
|
4
4
|
export interface PersistPositionsOptions<T extends object, TKey extends string | number> {
|
|
5
5
|
readonly collection: Collection<T, TKey>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { A as
|
|
2
|
-
import { C as
|
|
1
|
+
import { A as ResolvedInteraction, B as View, C as NodeImage, D as NumberScale, E as NodeShape, F as SourceSubscription, I as StateStyle, L as StateStyles, M as ScalesOptions, N as SelectMode, O as NumberScaleType, P as SourceChange, R as Style, S as Mark, T as NodeOptions, _ as Key, a as Channel, b as LabelOptions, c as EdgeDash, d as FieldOf, f as FreeState, g as InteractionOptions, h as GraphDefinitionOptions, i as BuiltInState, j as ResolvedTransitions, k as Point, l as EdgeMark, m as GraphDefinition, n as Badge, o as ColorScale, p as GraphData, r as BadgeCorner, s as EdgeArrow, t as Accessor, u as EdgeOptions, v as KeyChannel, w as NodeMark, x as LiveSource, y as KeyFieldOf, z as TransitionOptions } from "./types-BaflHDaf.js";
|
|
2
|
+
import { C as GraphTarget, S as GraphPositionEvent, T as PositionOrigin, _ as GraphEventHandler, a as GraphPositions, b as GraphFocusEvent, c as GraphStates, d as MountGraphOptions, f as ViewOptions, g as GraphDragEvent, h as ElementKeysInput, i as GraphInstance, l as GraphStore, m as ElementKeys, n as GraphElement, o as GraphSelection, p as mountGraph, r as GraphFocus, s as GraphState, t as FitOptions, u as GraphView, v as GraphEventName, w as GraphTargetEvent, x as GraphPointerEvent, y as GraphEvents } from "./mount-graph-DQLST9-_.js";
|
|
3
3
|
export declare function defineGraph<S extends string = never>(options: GraphDefinitionOptions<S>): GraphDefinition<S>;
|
|
4
4
|
export declare function nodes<T>(data: LiveSource<T>, options?: NodeOptions<NoInfer<T>>): NodeMark<T>;
|
|
5
5
|
export declare function nodes<T extends {
|
|
@@ -15,5 +15,5 @@ export declare function edges<T extends {
|
|
|
15
15
|
export declare function edges<T>(data: Iterable<T>, options: EdgeOptions<NoInfer<T>> & {
|
|
16
16
|
readonly key: KeyChannel<NoInfer<T>>;
|
|
17
17
|
}): EdgeMark<T>;
|
|
18
|
-
export { type Accessor, type Badge, type BadgeCorner, type BuiltInState, type Channel, type ColorScale, type EdgeArrow, type EdgeDash, type EdgeMark, type EdgeOptions, type ElementKeys, type ElementKeysInput, type FieldOf, type FitOptions, type FreeState, type GraphData, type GraphDefinition, type GraphDefinitionOptions, type GraphDragEvent, type GraphElement, type GraphEventHandler, type GraphEventName, type GraphEvents, type GraphInstance, type GraphPointerEvent, type GraphPositionEvent, type GraphPositions, type GraphSelection, type GraphState, type GraphStates, type GraphStore, type GraphTarget, type GraphTargetEvent, type GraphView, type InteractionOptions, type Key, type KeyChannel, type KeyFieldOf, type LabelOptions, type LiveSource, type Mark, type MountGraphOptions, type NodeMark, type NodeOptions, type NodeShape, type NumberScale, type NumberScaleType, type Point, type PositionOrigin, type ResolvedInteraction, type ResolvedTransitions, type ScalesOptions, type SelectMode, type SourceChange, type SourceSubscription, type StateStyle, type StateStyles, type Style, type TransitionOptions, type View, type ViewOptions, mountGraph };
|
|
18
|
+
export { type Accessor, type Badge, type BadgeCorner, type BuiltInState, type Channel, type ColorScale, type EdgeArrow, type EdgeDash, type EdgeMark, type EdgeOptions, type ElementKeys, type ElementKeysInput, type FieldOf, type FitOptions, type FreeState, type GraphData, type GraphDefinition, type GraphDefinitionOptions, type GraphDragEvent, type GraphElement, type GraphEventHandler, type GraphEventName, type GraphEvents, type GraphFocus, type GraphFocusEvent, type GraphInstance, type GraphPointerEvent, type GraphPositionEvent, type GraphPositions, type GraphSelection, type GraphState, type GraphStates, type GraphStore, type GraphTarget, type GraphTargetEvent, type GraphView, type InteractionOptions, type Key, type KeyChannel, type KeyFieldOf, type LabelOptions, type LiveSource, type Mark, type MountGraphOptions, type NodeImage, type NodeMark, type NodeOptions, type NodeShape, type NumberScale, type NumberScaleType, type Point, type PositionOrigin, type ResolvedInteraction, type ResolvedTransitions, type ScalesOptions, type SelectMode, type SourceChange, type SourceSubscription, type StateStyle, type StateStyles, type Style, type TransitionOptions, type View, type ViewOptions, mountGraph };
|
|
19
19
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as freeStateNames, r as maxFreeStates, t as mountGraph } from "./mount-graph-
|
|
1
|
+
import { n as freeStateNames, r as maxFreeStates, t as mountGraph } from "./mount-graph-CzVfiIte.js";
|
|
2
2
|
// src/define-graph.ts
|
|
3
3
|
const defaultZoomSpeed = 1;
|
|
4
4
|
const defaultPositionTransition = 120;
|