# x6-graph

> 封装x6为组件使用

Latest version **1.0.0** (published 2023-02-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install x6-graph
pnpm add x6-graph
yarn add x6-graph
bun add x6-graph
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2023-02-22 |
| First published | 2023-02-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM |
| Dependencies | 0 |
| Unpacked size | 7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | lloydzhou |
| Maintainers | lloydzhou |
| Keywords | antv, x6, graph, svg, vue, react, typescript |

## Links

- npm: https://www.npmjs.com/package/x6-graph
- Repository: https://github.com/lloydzhou/x6-graph
- Issues: https://github.com/lloydzhou/x6-graph/issues
- npm.io page: https://npm.io/package/x6-graph

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2023-02-22

## README

# x6-graph

封装x6为组件使用

<a href="https://www.npmjs.com/package/x6-graph"><img alt="NPM Package" src="https://img.shields.io/npm/v/x6-graph.svg?style=flat-square"></a>
![npm bundle size](https://img.shields.io/bundlephobia/minzip/x6-graph?style=flat-square)
![npm](https://img.shields.io/npm/dm/x6-graph?style=flat-square)
<a href="/LICENSE"><img src="https://img.shields.io/github/license/lloydzhou/x6-graph?style=flat-square" alt="MIT License"></a>

## install
```
npm install x6-graph
yarn add x6-graph
```

## online demos
### react
[react demo](https://codesandbox.io/s/antv-x6-react-graph-demo-6ere13)

[mindmap demo](https://codesandbox.io/s/x6-hooks-react-mindmap-demo-2t6954?file=/src/App.js)

### vue
[vue demo](https://codesandbox.io/s/x6-hooks-vue-demo-j19slj)


## examples
### react
```
import { Graph, useGraphInstance } from 'x6-graph/react'

const GraphBehavior = () => {
  const graph = useGraphInstance()
  // TODO 这里拿到graph对象处理自己的逻辑（例如使用后端数据初始化画布，增加事件监听...）
  return null
}

function App() {
  const gRef = useRef<X6.Graph | null>(null)
  // 1. Graph组件支持多实例；2. 父组件传递ref
  return (
    <div className="App">
      <Graph grid width={800} height={600} ref={gRef}>
        <GraphBehavior />
      </Graph>
    </div>
  )
}
```

### vue

```
import { Graph, useGraphInstance, contextSymbol } from 'x6-graph/vue'

const GraphBehavior = defineComponent({
  name: 'GraphBehavior',
  inject: [contextSymbol],
  setup() {
    const { graph } = useGraphInstance()
    onMounted(() => {
      // TODO 这里拿到graph对象处理自己的逻辑
      // （例如使用后端数据初始化画布，增加事件监听...）
    })
    onUnmounted(() => {
      // 组件卸载的时候，移除监听等
    })
    return () => null
  }
})

export default defineComponent({
  components: {
    Graph,
    // 可以将不同的业务逻辑拆分到不同的组件里面写成多个Behavior
    GraphBehavior,
  }
})


<template>
  <Graph grid snapline keyboard clipboard :width="600" :height="400">
    <GraphBehavior />
  </Graph>
</template>

```

---
_Source: https://npm.io/package/x6-graph · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
