How antvis/x6 works
Main Components
• Core Graph Engine (packages/x6): This is the central module which handles graph rendering, modeling (nodes, edges, ports), the MVC pattern (data/model vs. view), event handling, and rendering.
• Common Utility Library (packages/x6-common): Contains shared algorithms, DOM manipulation utilities, math/geometry support, and helper functions.
• Domain-Specific Packages:
– Geometry (packages/x6-geometry): Performs geometric calculations such as computing node positions, curves, paths, and more.
– Plugin Packages (e.g., x6-plugin-clipboard, x6-plugin-dnd, x6-plugin-export, etc.): Extend the core functionalities by adding interactive features and behaviors.
– Devtool Package (packages/x6-devtool): Supplies debugging utilities, devtools integration, and a dedicated UI panel to inspect or troubleshoot the graph.
Relationships and Interactions
• The Core Graph Engine (the “heart” of the project) is responsible for maintaining the graph data model and triggering events. It interacts with the:
– Rendering layer that updates the visual presentation based on changes in state.
– Registry system that holds definitions of nodes, edges, connectors, and various tools.
– Event system that notifies plugin modules and external components of changes and user interactions.
• Extension plugins subscribe to the graph’s events and extend functionalities (for example, enabling drag&drop or custom interaction logic).
• The framework-specific packages build on the core engine by wrapping it with UI components and patterns that are idiomatic to React, Angular, or Vue.
• The design is plugin-based and modular so that additional functionality can be added without modifying the core engine.
Architectural Patterns and Design Principles
• MVC / Data-Driven Architecture: The engine separates the “model” (graph data and configuration) from the “view” (rendering and UI) so developers can focus on business logic.
• Event-Driven Communication: All components (core, plugins, UI frameworks) interact through a robust event system to handle user interactions and state changes.
• Modularity & Extensibility: Each package is designed as an independent module (with defined TypeScript interfaces) allowing for plug-and-play integration.
• Adaptability for Different Frontend Frameworks: With dedicated adapters (Angular, React, Vue), the engine is optimized to work seamlessly in different environments.