Skip to content

Commit

Permalink
fix:add label shape parseAttr
Browse files Browse the repository at this point in the history
  • Loading branch information
pomelo-nwu committed Jan 26, 2021
1 parent 9da0e36 commit 727011d
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 4 deletions.
4 changes: 4 additions & 0 deletions packages/graphin/docs/render/element/node.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ nav:
## 基本介绍

<code src='./demos/node.tsx'>

## DefaultNode

<code src='./demos/defaultNode.tsx'>
11 changes: 11 additions & 0 deletions packages/graphin/docs/render/update/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
title: 更新元素
group:
path: /render
nav:
title: Graphin
path: /graphin
order: 1
---

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

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

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

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',
},
keyshape: {
size: 80,
},
},
});
};
return (
<ContextMenu bindType="node">
<Menu bindType="node" options={[{ name: 'RENAME' }]} onChange={handleChange} />
</ContextMenu>
);
};

export default () => {
return (
<div>
<Graphin data={data} layout={layout}>
<FitView />
<UpdateNode />
</Graphin>
</div>
);
};
11 changes: 7 additions & 4 deletions packages/graphin/src/shape/graphin-circle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,11 @@ const parseAttr = (
delete schema.fill; // 如果是图片类型,需要删除fill
}
}
if (itemShapeName === 'label') {
schema.text = value;
}

Object.keys(schema).forEach(key => {
Object.keys(schema).forEach((key) => {
if (schema[key] === undefined) {
delete schema[key];
}
Expand Down Expand Up @@ -204,7 +207,7 @@ export default () => {
}

// badges 会存在多个的情况
badges.forEach(badge => {
badges.forEach((badge) => {
const {
type,
position,
Expand Down Expand Up @@ -328,13 +331,13 @@ export default () => {
const status = item._cfg?.states || [];

try {
Object.keys(initStateStyle).forEach(statusKey => {
Object.keys(initStateStyle).forEach((statusKey) => {
if (name === statusKey) {
if (value) {
setStatusStyle(shapes, initStateStyle[statusKey], parseAttr); // 匹配到status就改变
} else {
setStatusStyle(shapes, initialStyle, parseAttr); // 没匹配到就重置
status.forEach(key => {
status.forEach((key) => {
// 如果cfg.status中还有其他状态,那就重新设置回来
setStatusStyle(shapes, initStateStyle[key], parseAttr);
});
Expand Down

0 comments on commit 727011d

Please sign in to comment.