Skip to content

Commit

Permalink
feat: add update-node demos
Browse files Browse the repository at this point in the history
  • Loading branch information
pomelo-nwu committed Jan 28, 2021
1 parent 850199f commit a404154
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 115 deletions.
99 changes: 0 additions & 99 deletions packages/graphin/docs/render/index.md

This file was deleted.

2 changes: 2 additions & 0 deletions packages/graphin/docs/render/update/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ nav:
order: 1
---

## 节点更新

<code src='./node.tsx'>
67 changes: 51 additions & 16 deletions packages/graphin/docs/render/update/node.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,72 @@
import React from 'react';
import Graphin, { Utils, Behaviors, GraphinContext } from '@antv/graphin';
import Graphin, { Utils, GraphinContext } from '@antv/graphin';
import { ContextMenu } from '@antv/graphin-components';
import iconLoader from '@antv/graphin-icons';

const icons = Graphin.registerFontFamily(iconLoader);

const { FitView } = Behaviors;
const { Menu } = ContextMenu;

const data = Utils.mock(5).circle().graphin();
const data = Utils.mock(4).circle().graphin();
const layout = {
type: 'concentric',
minNodeSpacing: 50,
type: 'graphin-force',
preset: {
type: 'random',
},
};

const UpdateNode = () => {
const { graph } = React.useContext(GraphinContext);
const handleChange = (option, item) => {
console.log(option, item);
// 方法一:直接更新,不持久化到数据中
graph.updateItem(item.id, {
style: {
// @ts-ignore
label: {
value: 'rename',
if (item.id === 'node-0') {
graph.updateItem(item.id, {
style: {
// @ts-ignore
label: {
value: 'node-0: update keyshape size,fill,stroke',
},
keyshape: {
size: 80,
stroke: '#ff9f0f',
fill: '#ff9f0ea6',
},
},
});
}
if (item.id === 'node-1') {
graph.updateItem(item.id, {
style: {
// @ts-ignore
label: {
value: 'update label offset/ color',
offset: [100, 0],
position: 'right',
fill: 'red',
},
},
keyshape: {
size: 80,
});
}
if (item.id === 'node-2') {
graph.updateItem(item.id, {
style: {
// @ts-ignore
label: {
value: 'update icon to home',
},
icon: {
type: 'font',
fontFamily: 'graphin',
value: icons.home,
},
},
},
});
});
}
};
return (
<ContextMenu bindType="node">
<Menu bindType="node" options={[{ name: 'RENAME' }]} onChange={handleChange} />
<Menu bindType="node" options={[{ name: 'update' }]} onChange={handleChange} />
</ContextMenu>
);
};
Expand All @@ -39,7 +75,6 @@ export default () => {
return (
<div>
<Graphin data={data} layout={layout}>
<FitView />
<UpdateNode />
</Graphin>
</div>
Expand Down

0 comments on commit a404154

Please sign in to comment.