1.1.2 • Published 11 months ago

editor-creator v1.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

Editor-Creator


npm npm

Editor-Creator is a visual graph editor based on G6 and React​​. It's a tool that provides a visual interface for creating and editing graphs. It can be used for various applications where graph visualization and manipulation is required.

Cover

Installation

$ npm install editor-creator --save

Usage

import React from 'react';
import Editor, { Flow } from 'editor-creator';

const data = {
  nodes: [
    {
      id: '0',
      label: 'Node 1',
      x: 10,
      y: 10,
    },
    {
      id: '1',
      label: 'Node 2',
      x: 20,
      y: 250,
    },
  ],
  edges: [
    {
      label: 'Label',
      source: '0',
      target: '1',
    },
  ],
};

const FlowEditor = () => {
  return (
    <Editor className="editor">
      <Flow
        data={data}
        graphConfig={{
          renderer: 'canvas',
          defaultNode: {
            shape: 'node',
          },
          defaultEdge: {
            shape: 'flowEdge',
          },
          minZoom: 0.1,
          maxZoom: 2,
        }}
        className="editor-flow"
      />
    </Editor>
  );
};

export default FlowEditor;

API

Editor

PropTypeDescription
styleReact.CSSPropertiesThis prop is used to apply CSS styles to the component.
childrenReactElement[]React elements that are going to be rendered inside the component.
classNamestringCSS class name for the component.
onBeforeExecuteCommand (EditorEvent)(e: CommandEvent) => voidEvent handler for before a command is executed.
onAfterExecuteCommand (EditorEvent)(e: CommandEvent) => voidEvent handler for after a command has been executed.

Flow

PropTypeDescription
styleReact.CSSPropertiesThis prop is used to apply CSS styles to the component.
classNamestringCSS class name for the component.
dataFlowDataData required for the flow.
graphConfigPartial<GraphOptions>Configuration options for the graph.
customBehaviorsobjectCustom behaviors to be registered on the graph.
customModes(mode: string, behaviors) => objectFunction to customize the modes of the graph.
GraphReactEventPropsPartial<GraphReactEventProps>Props related to the GraphReact events.

EditorContext

For EditorContextProps:

PropertyTypeDescription
graphGraph | nullThe graph object, which is either an instance of Graph or null.
executeCommand(name: string, params?: object) => voidA function that executes a command with a given name and optional parameters.
commandManagerCommandManagerAn instance of CommandManager which manages the execution of commands.

For EditorPrivateContextProps:

PropertyTypeDescription
setGraph(graph: Graph) => voidA function that sets the graph.
commandManagerCommandManagerAn instance of CommandManager which manages the execution of commands.

Graph

PropDescription
styleOptional. CSS properties to apply to the container div of the GraphComponent.
classNameOptional. Class name(s) to apply to the container div of the GraphComponent.
containerIdRequired. ID to apply to the container div of the GraphComponent. This is also used to get the dimensions for the graph.
dataRequired. Data that represents the nodes and edges of the graph.
parseDataRequired. Function that preprocesses the data before it's passed to the graph.
initGraphRequired. Function that initializes and returns the graph.
setRefRequired. Function that receives a ref to the container div. This ref can be used to manipulate the DOM node directly.
GraphReactEventPropsOptional. Props corresponding to graph events. If a function is passed for any of these props, it will be called when the corresponding event is fired on the graph.

Command

PropDescription
nameRequired. The name of the command that this component will execute when clicked.
classNameOptional. Class name(s) to apply to the Command component. Default is "command".
disabledClassNameOptional. Class name(s) to apply to the Command component when it is disabled. Default is "command-disabled".

ItemPanel

PropDescription
styleOptional. This prop is used to apply CSS styles to the component.
classNameOptional. CSS class name for the component.

Item

PropDescription
styleOptional. CSS Properties to apply to the Item component.
classNameOptional. Class name(s) to apply to the Item component.
typeOptional. The type of the item, either a node or edge. Default is ItemType.Node.
modelRequired. The data model for the node.
childrenOptional. ReactNode(s) to render as children of this component. This can be used to customize the content of the item component.

Plugins

Minimap

FieldDescription
viewportClassNameOptional. The class name of the viewport.
typeOptional. The type of the minimap, can be 'default', 'keyShape', or 'delegate'.
sizeOptional. An array of two numbers to represent the width and height of the minimap respectively.
delegateStyleOptional. The style of the delegate shape.
drawEdgesOptional. A boolean value to determine if the edges should be drawn.
refreshOptional. A boolean value to determine if the minimap should refresh.
paddingOptional. The padding around the viewport.
PluginBaseConfigBase configuration for all G6 plugins.

Usage

import React from 'react';
import Editor, { Flow, Minimap } from 'editor-creator';

const FlowEditor = () => {
  return (
    <Editor className="editor">
      <Flow
        data={data}
        ref={component => {
          if (component) {
            const { graph } = component;
            if (graph && graph.cfg.plugins.length === 0) {
              const minimap = new Minimap({
                size: [230, 120],
                delegateStyle: {
                  fill: '#1890ff40',
                  stroke: '#1890ff40',
                },
                drawEdges: false,
              });

              graph.addPlugin(minimap);

              minimap.updateCanvas();
            }
          }
        }}
        className="editor-flow"
      />
    </Editor>
  );
};

export default FlowEditor;

Grid

Usage

import React from 'react';
import Editor, { Flow, Grid } from 'editor-creator';

const FlowEditor = () => {
  return (
    <Editor className="editor">
      <Flow
        data={data}
        ref={component => {
          if (component) {
            const { graph } = component;
            if (graph && graph.cfg.plugins.length === 0) {
              const grid = new Grid(graph);
              graph.addPlugin(grid);
            }
          }
        }}
        className="editor-flow"
      />
    </Editor>
  );
};

export default FlowEditor;

EditableLabel

Usage

import React from 'react';
import Editor, { Flow, EditableLabel } from 'editor-creator';

const FlowEditor = () => {
  return (
    <Editor className="editor">
      <EditableLabel />
      <Flow data={data} className="editor-flow" />
    </Editor>
  );
};

export default FlowEditor;

Examples

Feel free to experiment with editor-creator directly in your browser to assess its suitability for your project requirements:

Basic Example

The following example shows how to use simple Flow component from the library in your React application.

Edit quirky-architecture-wrdcz8

Advanced Example

The following example shows you a React component that serves as a graphical user interface for managing flows of nodes and edges. This component provides utilities for managing nodes and edges, such as undoing and redoing actions, copying, pasting, removing, and zooming in and out. It also features an interactive minimap and a grid layout for ease of navigation and a context menu for quick access to commands.

Edit ecstatic-forest-2grx8e

1.1.1

11 months ago

1.1.2

11 months ago

1.1.0

1 year ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago