Skip to content

Commit

Permalink
📝 docs(common): new inner shape demo
Browse files Browse the repository at this point in the history
  • Loading branch information
萌萌的老胖子 committed Apr 21, 2020
1 parent 4c0519d commit 7abb7d1
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
46 changes: 46 additions & 0 deletions packages/graphin-site/examples/shape/node/demo/CanonicalShape.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* eslint-disable no-undef */
import React from 'react';
import ReactDOM from 'react-dom';
import Graphin, { Utils } from '@antv/graphin';
import '@antv/graphin/dist/index.css'; // 引入Graphin CSS

/**
* Graphin 内置几种预定义的节点样式,您可以根据需要选择合适的样式
*/
const INNER_SHAPES = [
'CanonicalStubNode',
'CanonicalCircleNode',
'CanonicalHexagonNode',
'CanonicalPointNode',
'CanonicalRectNode',
];

const data = Utils.mock(20).random().graphin();
data.nodes = data.nodes.map((node) => {
node.shape = INNER_SHAPES[Math.floor(Math.random() * INNER_SHAPES.length)];
node.style = node.style || {};
// 修改节点大小
node.style.nodeSize = 36;
return node;
});
data.edges = data.edges.map((edge, index) => {
edge.shape = 'CanonicalLineEdge';
edge.style = edge.style || {
line: {},
};
// 设置Edge虚实
edge.style.line.dash = index % 3 === 0 ? [2, 2] : null;
// 设置Edge的宽度
edge.style.line.width = index % 3 === 1 ? 3 : 1;
return edge;
});

const App = () => {
return (
<div>
<Graphin data={data} />
</div>
);
};
const rootElement = document.getElementById('container');
ReactDOM.render(<App />, rootElement);
5 changes: 5 additions & 0 deletions packages/graphin-site/examples/shape/node/demo/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
"filename": "CustomNode.jsx",
"title": "自定义节点",
"screenshot": "https://gw.alipayobjects.com/mdn/rms_975111/afts/img/A*oBwXRrtoXM0AAAAAAAAAAABkARQnAQ"
},
{
"filename": "CanonicalShape.jsx",
"title": "更多内置Shape",
"screenshot": "https://gw.alipayobjects.com/mdn/rms_975111/afts/img/A*oBwXRrtoXM0AAAAAAAAAAABkARQnAQ"
}
]
}

0 comments on commit 7abb7d1

Please sign in to comment.