1.4.1 • Published 5 months ago

@ant-design/graphs v1.4.1

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

@ant-design/graphs

A React relation graphs component library, based on G6.

npm npm GitHub stars npm License

Case

✨ Features

  • Easy to use
  • TypeScript

📦 Installation

$ npm install @ant-design/graphs

🔨 Usage

import React from 'react';
import { DecompositionTreeGraph } from '@ant-design/graphs';

const DemoDecompositionTreeGraph = () => {
  const data = {
    id: 'A0',
    value: {
      title: '订单金额',
      items: [
        {
          text: '3031万',
        },
      ],
    },
    children: [
      {
        id: 'A1',
        value: {
          title: '华南',
          items: [
            {
              text: '1152万',
            },
            {
              text: '占比',
              value: '30%',
            },
          ],
        },
        children: [
          {
            id: 'A11',
            value: {
              title: '广东',
              items: [
                {
                  text: '1152万',
                },
                {
                  text: '占比',
                  value: '30%',
                },
              ],
            },
          },
          {
            id: 'A12',
            value: {
              title: '广西',
              items: [
                {
                  text: '1152万',
                },
                {
                  text: '占比',
                  value: '30%',
                },
              ],
            },
          },
          {
            id: 'A13',
            value: {
              title: '海南',
              items: [
                {
                  text: '1152万',
                },
                {
                  text: '占比',
                  value: '30%',
                },
              ],
            },
          },
        ],
      },
      {
        id: 'A2',
        value: {
          title: '华北',
          items: [
            {
              text: '595万',
            },
            {
              text: '占比',
              value: '30%',
              icon: 'https://gw.alipayobjects.com/zos/antfincdn/iFh9X011qd/7797962c-04b6-4d67-9143-e9d05f9778bf.png',
            },
          ],
        },
      },
    ],
  };

  const config = {
    data,
    behaviors: ['drag-canvas', 'zoom-canvas', 'drag-node'],
    nodeCfg: {
      title: {
        style: (cfg) => {
          return {
            fill: cfg?.value?.title === '青年' ? 'yellow' : '#fff',
          };
        },
      },
      items: {
        containerStyle: {
          fill: '#fff',
        },
        style: (cfg, group, type) => {
          const styles = {
            value: {
              fill: '#52c41a',
            },
            text: {
              fill: '#aaa',
            },
            icon: {
              width: 10,
              height: 10,
            },
          };
          return styles[type];
        },
      },
      nodeStateStyles: {
        hover: {
          stroke: '#1890ff',
          lineWidth: 2,
        },
      },
      style: {
        radius: [2, 2, 2, 2],
      },
    },
    markerCfg: (cfg) => {
      const { children } = cfg;
      return {
        show: children?.length,
      };
    },
  };

  return <DecompositionTreeGraph {...config} />;
};

export default DemoDecompositionTreeGraph;

📜 Document & API

See chart API for details. Common props:

// Graph 通用配置
export interface CommonConfig extends GraphContainerConfig {
  data: Datum;
  /** 是否缩放节点大小自适应容器 */
  autoFit?: boolean;

  /** 是否将图平移到中心位置 */
  fitCenter?: boolean;

  width?: number;
  height?: number;
  pixelRatio?: number;

  /** 不同组件 layout 有差别,参考对应组件文档 */
  layout?: any;

  /** 边配置 */
  edgeCfg?: EdgeCfg;

  /** 节点配置 */
  nodeCfg?: NodeCfg;

  /** marker 配置 */
  markerCfg?: IMarkerCfg;

  /** 迷你地 */
  minimapCfg?: MiniMapConfig;

  /** 交互组件 */
  toolbarCfg?: ToolbarCfg;

  /** 提示 */
  tooltipCfg?: TooltipCfg;

  /** 交互行为 */
  behaviors?: string[];

  /** 是否开启动画 */
  animate?: boolean;

  /**
   * @title 是否自定义布局
   * @description 开启后,layout 失效,使用 data 里面的 x/y 进行数据布局
   * @example
   * ```ts
   *  {
   *   id: '-3',
   *   x: 100,
   *   y: 100,
   *   value: {
   *     title: '来源页面A',
   *     items: [
   *       {
   *         text: '曝光PV',
   *         value: '10.30万',
   *         icon: 'https://gw.alipayobjects.com/zos/antfincdn/iFh9X011qd/7797962c-04b6-4d67-9143-e9d05f9778bf.png',
   *       },
   *     ],
   *   },
   *  },
   * ```
   * @default false
   */
  customLayout?: boolean;

  /** 图表渲染完成回调 */
  onReady?: (graph: IGraph) => void;
}

🤝 How to Contribute

Your contributions are always welcome! Please Do have a look at the issues first.

📧 Contact us

DingTalk group number: 44788198.

License

MIT

1.4.1

5 months ago

1.4.1-beta.0

10 months ago

1.4.0

1 year ago

1.3.9

1 year ago

1.3.8

1 year ago

1.3.7

1 year ago

1.5.0-beta.0

1 year ago

1.3.6

1 year ago

1.3.5

1 year ago

1.3.4

1 year ago

1.3.3

1 year ago

1.3.2

2 years ago

1.3.3-beta.1

1 year ago

1.3.2-beta.1

2 years ago

1.3.3-beta.0

1 year ago

1.3.3-beta.3

1 year ago

1.3.3-beta.2

1 year ago

1.3.2-beta.0

2 years ago

1.3.1

2 years ago

1.3.1-beta.1

2 years ago

1.2.9-beta.1

2 years ago

1.2.8

2 years ago

1.2.7-beta.0

2 years ago

1.2.7

2 years ago

1.2.6

2 years ago

1.2.7-beta.1

2 years ago

1.2.5

2 years ago

1.2.4

2 years ago

1.3.0

2 years ago

1.3.0-alpha.1

2 years ago

1.2.0

2 years ago

1.2.3

2 years ago

1.1.4

2 years ago

1.2.2

2 years ago

1.1.3

2 years ago

1.2.1

2 years ago

1.1.1

2 years ago

1.1.2

2 years ago

1.1.0

2 years ago

1.0.4-beta.0

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0-beta.3

2 years ago