Commit 5007c1df by zhaochengxiang

资产预览树

parent f583cde4
...@@ -5,37 +5,13 @@ let graph = null; ...@@ -5,37 +5,13 @@ let graph = null;
const globalFontSize = 20; const globalFontSize = 20;
const maxTextWidth = 160; const maxTextWidth = 160;
const COLLAPSE_ICON = function COLLAPSE_ICON(x, y, r) {
return [
['M', x - r, y - r],
['a', r, r, 0, 1, 0, r * 2, 0],
['a', r, r, 0, 1, 0, -r * 2, 0],
['M', x + 2 - r, y - r],
['L', x + r - 2, y - r],
];
};
const EXPAND_ICON = function EXPAND_ICON(x, y, r) {
return [
['M', x - r, y - r],
['a', r, r, 0, 1, 0, r * 2, 0],
['a', r, r, 0, 1, 0, -r * 2, 0],
['M', x + 2 - r, y - r],
['L', x + r - 2, y - r],
['M', x, y - 2 * r + 2],
['L', x, y - 2],
];
};
class PreviewTree extends React.Component { class PreviewTree extends React.Component {
componentDidMount() { componentDidMount() {
const { type, loadMoreData } = this.props; const container = document.getElementById('preview-tree');
const container = document.getElementById('container');
if (!container) return;
const width = container.scrollWidth; const width = container.scrollWidth;
const height = container.scrollHeight || 500; const height = container.scrollHeight || 300;
G6.registerNode( G6.registerNode(
'tree-node', 'tree-node',
...@@ -50,7 +26,7 @@ class PreviewTree extends React.Component { ...@@ -50,7 +26,7 @@ class PreviewTree extends React.Component {
}, },
}); });
const content = (cfg.text||'').replace(/(.{19})/g, '$1\n'); const content = (cfg.label||'').replace(/(.{19})/g, '$1\n');
const text = group.addShape('text', { const text = group.addShape('text', {
attrs: { attrs: {
...@@ -100,7 +76,7 @@ class PreviewTree extends React.Component { ...@@ -100,7 +76,7 @@ class PreviewTree extends React.Component {
}); });
graph = new G6.TreeGraph({ graph = new G6.TreeGraph({
container: 'container', container: 'preview-tree',
width, width,
height, height,
maxZoom: 1, maxZoom: 1,
...@@ -185,22 +161,19 @@ class PreviewTree extends React.Component { ...@@ -185,22 +161,19 @@ class PreviewTree extends React.Component {
const { data } = this.props; const { data } = this.props;
if(graph && data){ if(graph && data){
console.log('data', data);
graph.data(data); graph.data(data);
graph.render(); graph.render();
graph.fitView(); graph.fitView();
} }
} }
componentDidUpdate(prevProps, prevState){ componentDidUpdate(prevProps, prevState) {
this.layoutGraph(); this.layoutGraph();
} }
render() { render() {
return ( return (
<div id='container' style={{ width: '100%', height: '100%' }} /> <div id='preview-tree' style={{ width: '100%', height: '100%' }} />
); );
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment