Socket
Socket
Sign inDemoInstall

@moxa/graph

Package Overview
Dependencies
0
Maintainers
4
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @moxa/graph

### [👉 Documentation](https://moxa.gitlab.io/sw/f2e/one/one-moxa-vizion/?path=/docs/introduction--docs)


Version published
Maintainers
4
Created

Readme

Source

Moxa Graph Library

👉 Documentation

Install

Use npm

npm i @moxa/graph

Use pnpm

pnpm add @moxa/graph

Basic Usage

Graph will be generated on the dom element with the specified id

Create a DOM

<div id="container"></div>

Initialize Graph

You need to provide a json config object to initialize graph instance
The config include all graph settings, please refer to MxGraphConfig

import { MxGraph } from '@moxa/graph';

const graph = new MxGraph({
  renderer: 'svg',
  container: 'container',
  width: 500,
  height: 500,
  data: {
    nodes: [
      {
        id: 'node1',
        config: {
          type: 'circle-node',
          point: { x: 100, y: 50 },
        },
      },
      {
        id: 'node2',
        config: {
          type: 'circle-node',
          point: { x: 100, y: 250 },
        },
      },
      {
        id: 'node3',
        config: {
          type: 'circle-node',
          point: { x: 300, y: 50 },
        },
      },
      {
        id: 'node4',
        config: {
          type: 'circle-node',
          point: { x: 300, y: 250 },
        },
      },
      {
        id: 'node5',
        config: {
          type: 'circle-node',
          point: { x: 200, y: 150 },
        },
      },
    ],
    edges: [
      {
        id: 'edge1',
        source: 'node1',
        target: 'node2',
      },
      {
        id: 'edge2',
        source: 'node1',
        target: 'node5',
      },
      {
        id: 'edge3',
        source: 'node5',
        target: 'node3',
      },
      {
        id: 'edge4',
        source: 'node3',
        target: 'node4',
      },
    ],
  },
});

Graph Control

You can control the presentation and behavior of the graph by calling the MxGraph methods

// Update Graph Data
graph.updateNode({ ... });
graph.updateEdge({ ... });
graph.updateGroup({ ... });

// View Control
graph.zoom();
graph.fitView();
graph.focusItem();

// Change Behaviors
graph.changeBehavior([ ... ], true);

// Change layouts
graph.changeLayout();

// Change Theme
graph.changeTheme();

// Plugin Management
graph.addPlugin({ ... });
graph.updatePlugin({ ... });
graph.removePlugin({ ... });

Event Handling

// Listen Events
graph.events.nodeClick.once((e) => { ... });
graph.events.beginCreateEdge.on((e) => { ... });
graph.events.groupExpanded.off((e) => { ... });

FAQs

Last updated on 10 May 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc