Convert Figma logo to code with AI

alibaba logoGGEditor

A visual graph editor based on G6 and React

3,411
574
3,411
281

Top Related Projects

11,025

♾ A Graph Visualization Framework in JavaScript.

6,792

mxGraph is a fully client side JavaScript diagramming library

7,735

Visual connectivity for webapps

a super simple, no-nonsense diagramming library written in react that just works

9,978

JavaScript framework for visual programming

4,593

Directed graph layout for JavaScript

Quick Overview

GGEditor is a visual graph editor based on G6 and React. It provides a set of components and APIs for building graph editing applications, including flow charts, mind maps, and organizational charts. GGEditor aims to simplify the process of creating interactive and customizable graph editors for web applications.

Pros

  • Easy integration with React applications
  • Supports multiple graph types (flow charts, mind maps, org charts)
  • Extensive API for customization and interaction
  • Built on top of G6, a powerful graph visualization engine

Cons

  • Limited documentation and examples in English
  • Steep learning curve for advanced customizations
  • Dependency on Ant Design may not suit all project styles
  • Last updated in 2020, potentially outdated or unmaintained

Code Examples

  1. Creating a basic Flow editor:
import GGEditor, { Flow } from 'gg-editor';

const FlowEditor = () => (
  <GGEditor>
    <Flow />
  </GGEditor>
);
  1. Adding custom node types:
import GGEditor, { Flow, RegisterNode } from 'gg-editor';

const CustomNode = () => (
  <RegisterNode
    name="custom-node"
    config={{
      draw(item) {
        const group = item.getGraphicGroup();
        group.addShape('rect', {
          attrs: {
            x: 0,
            y: 0,
            width: 100,
            height: 50,
            fill: '#1890FF',
            radius: 4,
          },
        });
        return group;
      },
    }}
  />
);

const FlowEditor = () => (
  <GGEditor>
    <Flow />
    <CustomNode />
  </GGEditor>
);
  1. Handling editor events:
import GGEditor, { Flow } from 'gg-editor';

const FlowEditor = () => (
  <GGEditor>
    <Flow
      onNodeClick={(e) => {
        console.log('Node clicked:', e.item);
      }}
      onEdgeClick={(e) => {
        console.log('Edge clicked:', e.item);
      }}
    />
  </GGEditor>
);

Getting Started

To use GGEditor in your React project, follow these steps:

  1. Install the package:

    npm install gg-editor
    
  2. Import and use GGEditor components in your React application:

    import React from 'react';
    import GGEditor, { Flow } from 'gg-editor';
    
    const App = () => (
      <div style={{ height: 500 }}>
        <GGEditor>
          <Flow />
        </GGEditor>
      </div>
    );
    
    export default App;
    
  3. Customize the editor by adding more components, registering custom nodes, or handling events as needed.

Competitor Comparisons

11,025

♾ A Graph Visualization Framework in JavaScript.

Pros of G6

  • More versatile and flexible for creating various types of graphs and charts
  • Extensive documentation and examples for easier implementation
  • Larger and more active community, leading to frequent updates and improvements

Cons of G6

  • Steeper learning curve due to its extensive features and options
  • May be overkill for simpler graph editing tasks
  • Requires more manual configuration for specific use cases

Code Comparison

G6:

import G6 from '@antv/g6';

const graph = new G6.Graph({
  container: 'mountNode',
  width: 800,
  height: 600,
});

graph.data(data);
graph.render();

GGEditor:

import GGEditor, { Flow } from 'gg-editor';

<GGEditor>
  <Flow style={{ width: 800, height: 600 }} data={data} />
</GGEditor>

G6 provides a more programmatic approach, allowing fine-grained control over graph creation and rendering. GGEditor, on the other hand, offers a more declarative, React-based implementation, which can be easier to integrate into existing React applications but may offer less flexibility for complex customizations.

6,792

mxGraph is a fully client side JavaScript diagramming library

Pros of mxgraph

  • More mature and feature-rich library with extensive documentation
  • Supports a wider range of diagram types and customization options
  • Larger community and ecosystem, with more examples and third-party resources

Cons of mxgraph

  • Steeper learning curve due to its complexity and extensive API
  • Larger file size and potentially higher performance overhead
  • Less focus on modern web development practices and frameworks

Code Comparison

mxgraph:

var graph = new mxGraph(container);
var parent = graph.getDefaultParent();
graph.getModel().beginUpdate();
try {
  var v1 = graph.insertVertex(parent, null, 'Hello,', 20, 20, 80, 30);
  var v2 = graph.insertVertex(parent, null, 'World!', 200, 150, 80, 30);
  var e1 = graph.insertEdge(parent, null, '', v1, v2);
} finally {
  graph.getModel().endUpdate();
}

GGEditor:

import GGEditor, { Flow } from 'gg-editor';

const data = {
  nodes: [{ id: 'node1', label: 'Node 1' }, { id: 'node2', label: 'Node 2' }],
  edges: [{ source: 'node1', target: 'node2' }],
};

<GGEditor>
  <Flow data={data} />
</GGEditor>

The code comparison shows that mxgraph requires more setup and explicit graph manipulation, while GGEditor offers a more declarative and React-friendly approach to creating diagrams.

7,735

Visual connectivity for webapps

Pros of jsPlumb

  • More mature and widely adopted project with a larger community
  • Supports a broader range of diagram types and use cases
  • Offers both community and commercial versions with extensive documentation

Cons of jsPlumb

  • Steeper learning curve due to its extensive feature set
  • May be overkill for simpler diagram requirements
  • Commercial version required for some advanced features

Code Comparison

GGEditor:

import GGEditor, { Flow } from 'gg-editor';

<GGEditor>
  <Flow data={data} />
</GGEditor>

jsPlumb:

import { jsPlumb } from 'jsplumb';

const instance = jsPlumb.getInstance();
instance.connect({
  source: 'element1',
  target: 'element2'
});

Key Differences

  • GGEditor is focused on graph and flow chart editing, while jsPlumb is more versatile for various diagramming needs
  • GGEditor provides a more React-centric approach, whereas jsPlumb is framework-agnostic
  • jsPlumb offers more fine-grained control over connections and their appearance
  • GGEditor includes built-in support for common graph operations like undo/redo, while jsPlumb requires custom implementation

Both libraries have their strengths, with GGEditor being more suitable for quick implementation of graph editors in React applications, and jsPlumb offering more flexibility and control for complex diagramming needs across different frameworks.

a super simple, no-nonsense diagramming library written in react that just works

Pros of react-diagrams

  • More active development and maintenance
  • Extensive documentation and examples
  • Highly customizable with a modular architecture

Cons of react-diagrams

  • Steeper learning curve due to its flexibility
  • Less out-of-the-box functionality compared to GGEditor

Code Comparison

GGEditor:

import GGEditor, { Flow } from 'gg-editor';

<GGEditor>
  <Flow data={data} />
</GGEditor>

react-diagrams:

import createEngine, { DiagramModel } from '@projectstorm/react-diagrams';

const engine = createEngine();
const model = new DiagramModel();
engine.setModel(model);

<DiagramEngine engine={engine} />

Both libraries offer React-based diagramming solutions, but react-diagrams provides more granular control over the diagram elements and behavior. GGEditor offers a more streamlined approach with pre-built components, while react-diagrams requires more setup but allows for greater customization.

react-diagrams is better suited for complex, highly customized diagramming needs, while GGEditor may be more appropriate for simpler use cases or rapid prototyping. The choice between the two depends on the specific requirements of your project and the level of control you need over the diagramming functionality.

9,978

JavaScript framework for visual programming

Pros of Rete

  • More flexible and customizable, allowing for a wider range of graph types and use cases
  • Better documentation and examples, making it easier for developers to get started
  • Larger and more active community, resulting in frequent updates and improvements

Cons of Rete

  • Steeper learning curve due to its flexibility and more complex API
  • Less out-of-the-box functionality, requiring more setup and configuration
  • May require more performance optimization for large-scale graphs

Code Comparison

GGEditor:

import GGEditor, { Flow } from 'gg-editor';

<GGEditor>
  <Flow data={data} />
</GGEditor>

Rete:

import Rete from "rete";
import ReactRenderPlugin from "rete-react-render-plugin";

const editor = new Rete.NodeEditor("demo@0.1.0", container);
editor.use(ReactRenderPlugin);

Summary

GGEditor is a more opinionated and easier-to-use solution for specific graph types, while Rete offers greater flexibility and customization options. GGEditor may be better suited for quick implementations of common graph types, whereas Rete shines in scenarios requiring unique or complex graph structures. The choice between the two depends on the specific requirements of the project and the developer's familiarity with graph editing concepts.

4,593

Directed graph layout for JavaScript

Pros of dagre

  • Lightweight and focused on graph layout algorithms
  • Provides more flexibility for custom rendering and integration
  • Better performance for large graphs due to its specialized nature

Cons of dagre

  • Requires more setup and integration with other libraries for full functionality
  • Less user-friendly for beginners compared to GGEditor's all-in-one approach
  • Limited built-in UI components and interaction features

Code Comparison

GGEditor example:

import GGEditor, { Flow } from 'gg-editor';

const data = {
  nodes: [{ id: 'node1', label: 'Node 1' }],
  edges: []
};

<GGEditor>
  <Flow data={data} />
</GGEditor>

dagre example:

import dagre from 'dagre';

const g = new dagre.graphlib.Graph();
g.setNode("node1", { label: "Node 1", width: 100, height: 30 });
g.setEdge("node1", "node2");
dagre.layout(g);

Summary

GGEditor offers a more comprehensive, user-friendly solution for graph editing with built-in UI components and interactions. dagre, on the other hand, focuses on graph layout algorithms, providing more flexibility and better performance for large graphs but requiring additional setup and integration with other libraries for a complete graph editing experience.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

English | 简体中文

GGEditor

基于 G6 和 React 的可视化图编辑器

GitHub npm npm

安装

npm

npm install gg-editor --save

umd

<script src="https://unpkg.com/gg-editor@${version}/dist/index.js"></script>

使用

流程图

Edit GGEditor - Flow

import GGEditor, { Flow } from 'gg-editor';

const data = {
  nodes: [
    {
      id: '0',
      label: 'Node',
      x: 55,
      y: 55,
    },
    {
      id: '1',
      label: 'Node',
      x: 55,
      y: 255,
    },
  ],
  edges: [
    {
      label: 'Label',
      source: '0',
      target: '1',
    },
  ],
};

<GGEditor>
  <Flow style={{ width: 500, height: 500 }} data={data} />
</GGEditor>;

脑图

Edit GGEditor - Mind

import GGEditor, { Mind } from 'gg-editor';

const data = {
  label: 'Central Topic',
  children: [
    {
      label: 'Main Topic 1',
    },
    {
      label: 'Main Topic 2',
    },
    {
      label: 'Main Topic 3',
    },
  ],
};

<GGEditor>
  <Mind style={{ width: 500, height: 500 }} data={data} />
</GGEditor>;

示例

# 克隆仓库
$ git clone https://github.com/alibaba/GGEditor.git

# 切换目录
$ cd gg-editor

# 安装依赖
$ npm install

# 运行示例
$ npm start

NPM DownloadsLast 30 Days