polly-graph 0.1.3 → 0.1.5
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 +82 -159
- package/dist/index.cjs +314 -299
- package/dist/index.css +221 -32
- package/dist/index.d.cts +30 -3
- package/dist/index.d.ts +30 -3
- package/dist/index.js +304 -299
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -4,14 +4,10 @@ Reusable D3-based graph visualization SDK with configurable nodes, links, labels
|
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* Drag and zoom interactions
|
|
12
|
-
* Arrow markers and relationship visualization
|
|
13
|
-
* Framework-agnostic API
|
|
14
|
-
* Angular and React compatible
|
|
7
|
+
* **Managed Root Architecture**: Provide one host element; the SDK internally manages the SVG canvas and the HTML UI overlay.
|
|
8
|
+
* **Smart Positioning**: Controls and legends use a class-based system (`pg-pos-top-right`) with CSS variable overrides for precision offsets.
|
|
9
|
+
* **Declarative Styling**: Fully customizable node and link aesthetics via style objects.
|
|
10
|
+
* **Animated UI**: Legends feature directional "retraction" animations that sync with their anchor position.
|
|
15
11
|
|
|
16
12
|
---
|
|
17
13
|
|
|
@@ -21,89 +17,46 @@ Reusable D3-based graph visualization SDK with configurable nodes, links, labels
|
|
|
21
17
|
npm install polly-graph
|
|
22
18
|
```
|
|
23
19
|
|
|
24
|
-
No separate D3 installation is required.
|
|
25
|
-
|
|
26
20
|
---
|
|
27
21
|
|
|
28
22
|
## Basic Usage
|
|
29
23
|
|
|
30
24
|
### HTML
|
|
31
|
-
|
|
32
25
|
```html
|
|
33
|
-
<div
|
|
34
|
-
<svg id="graph-container"></svg>
|
|
35
|
-
</div>
|
|
26
|
+
<div id="graph-viewport" style="position: relative; width: 100%; height: 600px;"></div>
|
|
36
27
|
```
|
|
37
28
|
|
|
38
29
|
### TypeScript
|
|
39
|
-
|
|
40
30
|
```ts
|
|
41
|
-
import {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
GraphLink,
|
|
45
|
-
} from 'polly-graph';
|
|
46
|
-
|
|
47
|
-
const container = document.getElementById(
|
|
48
|
-
'graph-container',
|
|
49
|
-
) as SVGSVGElement;
|
|
50
|
-
|
|
51
|
-
const nodes: GraphNode[] = [
|
|
52
|
-
{
|
|
53
|
-
id: 'users',
|
|
54
|
-
label: 'Users',
|
|
55
|
-
style: {
|
|
56
|
-
radius: 24,
|
|
57
|
-
fill: '#7c3aed',
|
|
58
|
-
stroke: '#6d28d9',
|
|
59
|
-
strokeWidth: 2,
|
|
60
|
-
textColor: '#ffffff',
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
id: 'orders',
|
|
65
|
-
label: 'Orders',
|
|
66
|
-
style: {
|
|
67
|
-
radius: 24,
|
|
68
|
-
fill: '#2563eb',
|
|
69
|
-
stroke: '#1d4ed8',
|
|
70
|
-
strokeWidth: 2,
|
|
71
|
-
textColor: '#ffffff',
|
|
72
|
-
},
|
|
73
|
-
},
|
|
74
|
-
];
|
|
75
|
-
|
|
76
|
-
const links: GraphLink[] = [
|
|
77
|
-
{
|
|
78
|
-
source: 'users',
|
|
79
|
-
target: 'orders',
|
|
80
|
-
label: 'has_many',
|
|
81
|
-
style: {
|
|
82
|
-
stroke: '#94a3b8',
|
|
83
|
-
strokeWidth: 2,
|
|
84
|
-
opacity: 1,
|
|
85
|
-
},
|
|
86
|
-
},
|
|
87
|
-
];
|
|
31
|
+
import { createGraph } from 'polly-graph';
|
|
32
|
+
|
|
33
|
+
const viewport = document.getElementById('graph-viewport') as HTMLElement;
|
|
88
34
|
|
|
89
35
|
const graph = createGraph({
|
|
90
|
-
container,
|
|
91
|
-
nodes
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
36
|
+
container: viewport,
|
|
37
|
+
nodes: [
|
|
38
|
+
{
|
|
39
|
+
id: 'n1',
|
|
40
|
+
label: 'Core Service',
|
|
41
|
+
style: {
|
|
42
|
+
radius: 30,
|
|
43
|
+
fill: '#7c3aed',
|
|
44
|
+
stroke: '#5b21b6',
|
|
45
|
+
strokeWidth: 2,
|
|
46
|
+
textColor: '#ffffff',
|
|
47
|
+
fontSize: 12
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
],
|
|
51
|
+
links: [
|
|
52
|
+
{
|
|
53
|
+
source: 'n1',
|
|
54
|
+
target: 'n2',
|
|
55
|
+
style: { stroke: '#94a3b8', strokeWidth: 2, opacity: 0.6 }
|
|
56
|
+
}
|
|
57
|
+
],
|
|
58
|
+
controls: { enabled: true, position: 'top-right' },
|
|
59
|
+
legend: { enabled: true, position: 'bottom-left' }
|
|
107
60
|
});
|
|
108
61
|
|
|
109
62
|
graph.render();
|
|
@@ -111,107 +64,77 @@ graph.render();
|
|
|
111
64
|
|
|
112
65
|
---
|
|
113
66
|
|
|
114
|
-
##
|
|
115
|
-
|
|
116
|
-
```ts
|
|
117
|
-
interaction: {
|
|
118
|
-
hover: {
|
|
119
|
-
enabled: true,
|
|
120
|
-
tooltip: {
|
|
121
|
-
enabled: true,
|
|
122
|
-
theme: 'dark',
|
|
123
|
-
},
|
|
124
|
-
nodeStyle: {
|
|
125
|
-
stroke: '#16a34a',
|
|
126
|
-
strokeWidth: 3,
|
|
127
|
-
opacity: 1,
|
|
128
|
-
},
|
|
129
|
-
},
|
|
130
|
-
}
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
---
|
|
67
|
+
## Styling & Customization
|
|
134
68
|
|
|
135
|
-
|
|
69
|
+
### Node Styles
|
|
70
|
+
Every node can have a unique appearance defined in its `style` object.
|
|
71
|
+
| Property | Type | Description |
|
|
72
|
+
| :--- | :--- | :--- |
|
|
73
|
+
| `radius` | `number` | The size of the node. |
|
|
74
|
+
| `fill` | `string` | Background color (hex/rgb). |
|
|
75
|
+
| `stroke` | `string` | Border color. |
|
|
76
|
+
| `strokeWidth`| `number` | Thickness of the border. |
|
|
77
|
+
| `textColor` | `string` | Label color. |
|
|
136
78
|
|
|
79
|
+
### Link Styles
|
|
80
|
+
Links support custom coloring, thickness, and arrow markers.
|
|
137
81
|
```ts
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
strokeWidth: 4,
|
|
144
|
-
opacity: 1,
|
|
145
|
-
},
|
|
82
|
+
style: {
|
|
83
|
+
stroke: '#cbd5e1',
|
|
84
|
+
strokeWidth: 1.5,
|
|
85
|
+
opacity: 0.8,
|
|
86
|
+
dashed: false // Coming soon
|
|
146
87
|
}
|
|
147
88
|
```
|
|
148
89
|
|
|
149
90
|
---
|
|
150
91
|
|
|
151
|
-
##
|
|
92
|
+
## Positioning Logic
|
|
152
93
|
|
|
153
|
-
|
|
94
|
+
The UI components (Controls & Legend) use a hybrid positioning system.
|
|
154
95
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
<svg #svgRef></svg>
|
|
158
|
-
</div>
|
|
159
|
-
```
|
|
96
|
+
### 1. Corner Anchoring
|
|
97
|
+
Use the `position` property to anchor elements to viewport corners. The SDK applies classes like `.pg-pos-top-right` which handles the layout logic.
|
|
160
98
|
|
|
161
|
-
|
|
99
|
+
Available positions:
|
|
100
|
+
* `top-left`
|
|
101
|
+
* `top-right`
|
|
102
|
+
* `bottom-left`
|
|
103
|
+
* `bottom-right`
|
|
162
104
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
container: this.svgRef.nativeElement,
|
|
166
|
-
nodes,
|
|
167
|
-
links,
|
|
168
|
-
interaction,
|
|
169
|
-
});
|
|
105
|
+
### 2. Custom Offsets
|
|
106
|
+
While the corners provide the anchor, you can use the `offset` object for fine-tuning. This values are passed into CSS variables `--pg-offset-x` and `--pg-offset-y` internally.
|
|
170
107
|
|
|
171
|
-
|
|
108
|
+
```ts
|
|
109
|
+
controls: {
|
|
110
|
+
position: 'top-right',
|
|
111
|
+
offset: { x: 24, y: 24 } // 24px away from the top and right edges
|
|
112
|
+
}
|
|
172
113
|
```
|
|
173
114
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
### Main Exports
|
|
179
|
-
|
|
180
|
-
* `createGraph`
|
|
181
|
-
* `GraphInstance`
|
|
182
|
-
* `GraphNode`
|
|
183
|
-
* `GraphLink`
|
|
184
|
-
* `GraphConfig`
|
|
185
|
-
* `GraphInteractionConfig`
|
|
115
|
+
### 3. Directional Legend Retraction
|
|
116
|
+
The Legend component is aware of its position.
|
|
117
|
+
* If anchored **Left**: It collapses to the left; the toggle icon points **Right** to expand.
|
|
118
|
+
* If anchored **Right**: It collapses to the right; the toggle icon points **Left** to expand.
|
|
186
119
|
|
|
187
120
|
---
|
|
188
121
|
|
|
189
|
-
##
|
|
122
|
+
## Framework Integration
|
|
190
123
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
124
|
+
### Angular
|
|
125
|
+
```ts
|
|
126
|
+
@ViewChild('viewport') viewport!: ElementRef;
|
|
127
|
+
|
|
128
|
+
ngAfterViewInit() {
|
|
129
|
+
this.graph = createGraph({
|
|
130
|
+
container: this.viewport.nativeElement,
|
|
131
|
+
// ... config
|
|
132
|
+
});
|
|
133
|
+
this.graph.render();
|
|
134
|
+
}
|
|
198
135
|
```
|
|
199
136
|
|
|
200
137
|
---
|
|
201
138
|
|
|
202
|
-
## Publish Checklist
|
|
203
|
-
|
|
204
|
-
* Package name available on npm
|
|
205
|
-
* README completed
|
|
206
|
-
* LICENSE added
|
|
207
|
-
* Build succeeds
|
|
208
|
-
* Tests pass
|
|
209
|
-
* npm token configured
|
|
210
|
-
* GitHub workflow passes
|
|
211
|
-
* Repository is public
|
|
212
|
-
|
|
213
|
-
---
|
|
214
|
-
|
|
215
139
|
## License
|
|
216
|
-
|
|
217
|
-
MIT
|
|
140
|
+
MIT
|