@moxa/graph 2.7.6 → 2.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 CHANGED
@@ -6,6 +6,7 @@
6
6
  - [Basic Usage](#basic-usage)
7
7
  - [Graph Control](#graph-control)
8
8
  - [Event Handling](#event-handling)
9
+ - [Developer Guidelines](#developer-guidelines)
9
10
 
10
11
  ## Install
11
12
 
@@ -146,3 +147,175 @@ graph.events.nodeClick.once((e) => { ... });
146
147
  graph.events.beginCreateEdge.on((e) => { ... });
147
148
  graph.events.groupExpanded.off((e) => { ... });
148
149
  ```
150
+
151
+ ## Developer Guidelines
152
+
153
+ This section provides guidelines for developers who want to contribute to or extend the Moxa Graph library.
154
+
155
+ ### Project Structure
156
+
157
+ ```
158
+ libs/graph/
159
+ ├── src/
160
+ │ ├── lib/ # Core functionality
161
+ │ │ ├── behavior/ # Graph behaviors and interactions
162
+ │ │ ├── edge/ # Edge definitions and renderers
163
+ │ │ ├── graph/ # Main graph implementation
164
+ │ │ ├── group/ # Node grouping functionality
165
+ │ │ ├── layout/ # Layout algorithms
166
+ │ │ ├── model/ # Data models and types
167
+ │ │ ├── node/ # Node definitions and renderers
168
+ │ │ ├── plugin/ # Plugin system
169
+ │ │ ├── themes/ # Theming and styling
170
+ │ │ └── utils/ # Utility functions
171
+ │ ├── assets/ # Static assets
172
+ │ ├── styles/ # Global styles
173
+ │ └── stories/ # Storybook examples
174
+ ```
175
+
176
+ ### Development Workflow
177
+
178
+ 1. **Setup Development Environment**
179
+
180
+ ```bash
181
+ # Clone the repository
182
+ git clone <repository-url>
183
+
184
+ # Install dependencies
185
+ pnpm install
186
+
187
+ # Start development server
188
+ pnpm dev
189
+ ```
190
+
191
+ 2. **Building the Library**
192
+
193
+ ```bash
194
+ # Build the library
195
+ pnpm build:graph
196
+
197
+ # Run tests
198
+ pnpm test:graph
199
+ ```
200
+
201
+ ### Extending the Library
202
+
203
+ #### Creating Custom Nodes
204
+
205
+ Custom nodes can be created by extending the base node classes:
206
+
207
+ ```typescript
208
+ import { BaseNode, NodeConfig } from '@moxa/graph';
209
+
210
+ interface CustomNodeConfig extends NodeConfig {
211
+ customProperty: string;
212
+ }
213
+
214
+ class CustomNode extends BaseNode<CustomNodeConfig> {
215
+ render() {
216
+ // Implement custom rendering logic
217
+ const shape = this.createShape('circle', {
218
+ r: 20,
219
+ fill: this.config.customProperty === 'special' ? 'red' : 'blue',
220
+ });
221
+
222
+ return shape;
223
+ }
224
+ }
225
+
226
+ // Register custom node
227
+ graph.registerNode('custom-node', CustomNode);
228
+ ```
229
+
230
+ #### Creating Custom Layouts
231
+
232
+ ```typescript
233
+ import { BaseLayout, LayoutConfig } from '@moxa/graph';
234
+
235
+ class CustomLayout extends BaseLayout {
236
+ layout() {
237
+ // Implement custom layout algorithm
238
+ this.nodes.forEach((node, index) => {
239
+ // Position nodes in a circle
240
+ const angle = (index / this.nodes.length) * Math.PI * 2;
241
+ const radius = 200;
242
+
243
+ node.updatePosition({
244
+ x: Math.cos(angle) * radius + this.width / 2,
245
+ y: Math.sin(angle) * radius + this.height / 2,
246
+ });
247
+ });
248
+ }
249
+ }
250
+
251
+ // Apply custom layout
252
+ graph.changeLayout('custom', {
253
+ /* layout options */
254
+ });
255
+ ```
256
+
257
+ #### Creating Plugins
258
+
259
+ ```typescript
260
+ import { BasePlugin, PluginConfig } from '@moxa/graph';
261
+
262
+ class CustomPlugin extends BasePlugin {
263
+ init() {
264
+ // Setup plugin
265
+ this.graph.events.nodeClick.on(this.handleNodeClick);
266
+ }
267
+
268
+ handleNodeClick = (e) => {
269
+ // Implement custom behavior
270
+ console.log('Node clicked:', e.node.id);
271
+ };
272
+
273
+ destroy() {
274
+ // Clean up
275
+ this.graph.events.nodeClick.off(this.handleNodeClick);
276
+ }
277
+ }
278
+
279
+ // Add plugin to graph
280
+ graph.addPlugin('custom', new CustomPlugin());
281
+ ```
282
+
283
+ ### Best Practices
284
+
285
+ 1. **Performance Considerations**
286
+
287
+ - Use throttling and debouncing for event handlers on large graphs
288
+ - Implement pagination or virtualization for very large datasets
289
+ - Consider using WebGL renderer for graphs with thousands of elements
290
+
291
+ 2. **Accessibility**
292
+
293
+ - Ensure proper contrast ratios in your themes
294
+ - Add ARIA attributes to important interactive elements
295
+ - Support keyboard navigation for critical operations
296
+
297
+ 3. **Testing**
298
+ - Write unit tests for custom components
299
+ - Create visual regression tests for custom node renders
300
+ - Test across different browsers and device sizes
301
+
302
+ ### Troubleshooting
303
+
304
+ Common issues and their solutions:
305
+
306
+ 1. **Graph not rendering properly**
307
+
308
+ - Check if container has proper dimensions
309
+ - Verify data format follows required schema
310
+ - Check browser console for errors
311
+
312
+ 2. **Performance issues with large graphs**
313
+
314
+ - Try different renderers (SVG vs Canvas vs WebGL)
315
+ - Simplify node/edge renderers
316
+ - Use appropriate layout algorithms
317
+
318
+ 3. **Events not firing**
319
+ - Verify event listeners are properly attached
320
+ - Check if event propagation is being stopped
321
+ - Ensure targets exist when attaching listeners