How to use @antv/g6 - 10 common examples

To help you get started, we’ve selected a few @antv/g6 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github antvis / G6 / examples / net / sankey / demo / sankey.js View on Github external
//   draw(cfg, group) {
//     const data = cfg.data;
//     // console.log(data, path(data));
//     const shape = group.addShape('path', {
//       attrs: {
//         stroke: 'rgba(0,0,0,0.1)',
//         lineWidth: Math.max(1, data.dy),
//         path: path(data)
//       }
//     });
//     return shape;
//   }
// },
// 'line');

const graph = new G6.Graph({
  container: 'container',
  width,
  height,
  defaultNode: {
    style: {
      stroke: null
    }
  },
  edgeStateStyles: {
    active: {
      stroke: 'rgba(0,0,0,0.3)'
    }
  }
});
github antvis / G6 / plugins / mds / index.js View on Github external
const Base = require('../base');
const Util = require('@antv/g6').Util;
const Numeric = require('numericjs');

class Mds extends Base {
  getDefaultCfgs() {
    return {
      maxIteration: null,         // 停止迭代的最大迭代数
      center: [ 0, 0 ],           // 布局中心
      linkDistance: 50,           // 默认边长度
      onLayoutEnd() {},           // 布局完成回调
      onTick() {}                 // 每一迭代布局回调
    };
  }
  init() {
    const graph = this.get('graph');
    const onTick = this.get('onTick');
    const tick = () => {
github antvis / Graphin / packages / graphin / src / layout / g6 / dagre.ts View on Github external
const dagreLayout = (data: Data, options: DagreLayoutOption): Data => {
    const source = cloneDeep(data);
    // eslint-disable-next-line new-cap
    const layout = new G6.Layout.dagre({
        type: 'dagre',
        ...options,
    });

    layout.init(source);
    layout.execute();
    return {
        nodes: layout.nodes,
        edges: data.edges,
    };

    // graph.positionsAnimate();
};
export default dagreLayout;
github antvis / G6 / examples / net / layoutMechanism / demo / subgraphLayout.js View on Github external
nodes.forEach(function(node, i) {
    if (i <= 16 && i !== 12) {
      newNodes.push(node);
      newNodeMap.set(node.id, i);
    }
  });
  // add related edges
  edges.forEach(function(edge) {
    const sourceId = edge.source;
    const targetId = edge.target;
    if (newNodeMap.get(sourceId) !== undefined && newNodeMap.get(targetId) !== undefined) {
      newEdges.push(edge);
    }
  });

  const subForceLayout = new G6.Layout.force({
    center: [ nodes[0].x, nodes[0].y ],
    linkDistance: 70,
    preventOverlap: true,
    nodeSize: 20,
    tick: function tick() {
      // the tick function to show the animation of layout process
      graph.refreshPositions();
    }
  });
  subForceLayout.init({
    nodes: newNodes,
    edges: newEdges
  });
  subForceLayout.execute();
}, 1000);
github antvis / Graphin / packages / graphin / src / layout / g6 / radial.ts View on Github external
const radialLayout = (data: Data, options: RadialLayoutOption) => {
    const source = cloneDeep(data);
    // eslint-disable-next-line new-cap
    const layout = new G6.Layout.radial({
        ...options,
    });

    layout.init(source);
    layout.execute();

    return {
        nodes: layout.nodes,
        edges: data.edges,
    };
};
export default radialLayout;
github oam-dev / kubevela / dashboard / src / pages / ApplicationList / ApplicationListDetail / Topology.jsx View on Github external
useEffect(() => {
    if (!graph) {
      graph = new G6.Graph({
        container: 'container',
        width,
        height,
        // translate the graph to align the canvas's center, support by v3.5.1
        fitCenter: true,
        defaultNode: {
          type: 'circle',
          size: [40],
          color: '#5B8FF9',
          style: {
            fill: '#9EC9FF',
            lineWidth: 3,
          },
          labelCfg: {
            style: {
              fill: '#1890ff',
github antvis / G6 / examples / shape / defaultEdges / demo / polyline2.js View on Github external
}, {
    id: '3',
    x: 350,
    y: 250
  }],
  edges: [
  // 配置内置折线的弯折弧度、端点最小距离
    {
      source: '2',
      target: '3'
    }]
};

const width = document.getElementById('container').scrollWidth;
const height = document.getElementById('container').scrollHeight || 500;
const graph = new G6.Graph({
  container: 'container',
  width,
  height,
  defaultNode: {
    style: {
      fill: '#DEE9FF',
      stroke: '#5B8FF9'
    }
  },
  defaultEdge: {
    shape: 'polyline',
    style: {
      radius: 10,
      offset: 30,
      endArrow: true,
      stroke: '#F6BD16'
github OXOYO / X-Flowchart-Vue / src / global / g6 / node / callout.js View on Github external
// 左上
        [ 'M', -width / 2, -height / 2 ],
        // 右上
        [ 'L', width / 2, -height / 2 ],
        // 右下
        [ 'L', width / 2, height / 4 ],
        // 下拐角
        [ 'L', width / 4, height / 4 ],
        [ 'L', 0, height / 2 ],
        [ 'L', 0, height / 4 ],
        // 左下
        [ 'L', -width / 2, height / 4 ],
        [ 'Z' ]
      ]
      const color = cfg.color || Global.defaultNode.color
      const style = Util.mix({}, Global.defaultNode.style, {
        // 节点的位置在上层确定,所以这里仅使用相对位置即可
        x,
        y,
        width,
        height,
        path,
        stroke: color
      }, cfg.style)
      return style
    }
  }
github OXOYO / X-Flowchart-Vue / src / global / g6 / node / step.js View on Github external
// 左上
        [ 'M', -width / 2, -height / 2 ],
        // 右上
        [ 'L', width * 3 / 8, -height / 2 ],
        // 右顶点
        [ 'L', width / 2, 0 ],
        // 右下
        [ 'L', width * 3 / 8, height / 2 ],
        // 左下
        [ 'L', -width / 2, height / 2 ],
        // 左顶点
        [ 'L', -width * 3 / 8, 0 ],
        [ 'Z' ]
      ]
      const color = cfg.color || Global.defaultNode.color
      const style = Util.mix({}, Global.defaultNode.style, {
        // 节点的位置在上层确定,所以这里仅使用相对位置即可
        x,
        y,
        width,
        height,
        path,
        stroke: color
      }, cfg.style)
      return style
    }
  }
github OXOYO / X-Flowchart-Vue / src / global / g6 / node / rounded-rectangle.js View on Github external
// 右上顶点
        [ 'L', width / 2 - r, -height / 2 ],
        // 右上弧
        [ 'Q', width / 2, -height / 2, width / 2, -height / 2 + r ],
        // 右下顶点
        [ 'L', width / 2, height / 2 - r ],
        // 右下弧
        [ 'Q', width / 2, height / 2, width / 2 - r, height / 2 ],
        // 左下顶点
        [ 'L', -width / 2 + r, height / 2 ],
        // 左下弧
        [ 'Q', -width / 2, height / 2, -width / 2, height / 2 - r ],
        [ 'Z' ]
      ]
      const color = cfg.color || Global.defaultNode.color
      const style = Util.mix({}, Global.defaultNode.style, {
        // 节点的位置在上层确定,所以这里仅使用相对位置即可
        x,
        y,
        width,
        height,
        path,
        stroke: color
      }, cfg.style)
      return style
    }
  }