Commit f63e025b by Your Name

enable 下钻

parent 9f565179
#left-control-container { #left-control-container {
opacity: .5;
position: absolute; position: absolute;
top: 50%; top: 50%;
left: 20px; left: 20px;
...@@ -38,6 +39,7 @@ ...@@ -38,6 +39,7 @@
#right-control-container { #right-control-container {
opacity: .5;
position: absolute; position: absolute;
top: 50%; top: 50%;
right: 20px; right: 20px;
......
...@@ -5,6 +5,7 @@ import circle from './circle.93e1.png' ...@@ -5,6 +5,7 @@ import circle from './circle.93e1.png'
import node from './node-bg-select.171e.png' import node from './node-bg-select.171e.png'
import './Relation.css' import './Relation.css'
import { EXPAND_ICON } from './Relation1';
const colors = [ const colors = [
'#BDD2FD', '#BDD2FD',
...@@ -25,11 +26,20 @@ class Relation extends React.Component { ...@@ -25,11 +26,20 @@ class Relation extends React.Component {
// console.debug(this.props?.data) // console.debug(this.props?.data)
} }
componentDidUpdate() { componentDidUpdate(prevProps, _prevState) {
this.graph?.destroy(); const { childData, parentNodeId, data } = this.props;
if (this.props.data) { if (parentNodeId && parentNodeId !== prevProps.parentNodeId) {
this.graph = init(this.elem, this.props.data) const parentData = this.graph?.findDataById(parentNodeId);
if (!parentData.children) {
parentData.children = [];
}
parentData.children = childData;
this.graph?.changeData();
} else if (this.props.data) {
this.graph?.destroy();
this.graph = init(this)(this.elem, this.props.data)
} }
} }
graph = undefined graph = undefined
...@@ -38,11 +48,15 @@ class Relation extends React.Component { ...@@ -38,11 +48,15 @@ class Relation extends React.Component {
render() { render() {
return ( return (
<div ref={ref => this.elem = ref} style={{ width: '100%', height: '100%', overflow: 'hidden', backgroundImage: 'linear-gradient(to bottom left,#2e3b4e,#0d0d13 52%,#0d0d13)' }}> <React.Fragment>
<div ref={ref => this.elem = ref} style={{ width: '100%', height: '100%', backgroundImage: 'linear-gradient(to bottom left,#2e3b4e,#0d0d13 52%,#0d0d13)' }}>
</div>
<div id="left-control-container"></div> <div id="left-control-container"></div>
<div id="right-control-container"></div> <div id="right-control-container"></div>
<div id="bottom-bg-container"></div> <div id="bottom-bg-container"></div>
</div> </React.Fragment>
); );
} }
} }
...@@ -68,7 +82,7 @@ function countDepth(node, _depth = 0) { ...@@ -68,7 +82,7 @@ function countDepth(node, _depth = 0) {
} }
} }
function init(container, data) { const init = (ctx) => function (container, data) {
depthCount = {} depthCount = {}
countDepth(data) countDepth(data)
// console.debug(depthCount) // console.debug(depthCount)
...@@ -150,9 +164,31 @@ function init(container, data) { ...@@ -150,9 +164,31 @@ function init(container, data) {
focusNodes.forEach((fnode) => { focusNodes.forEach((fnode) => {
graph.setItemState(fnode, 'focus', false); // false graph.setItemState(fnode, 'focus', false); // false
}); });
const { item } = evt; const { item, target } = evt;
graph.setItemState(item, 'focus', true); graph.setItemState(item, 'focus', true);
graph.setItemState(item, 'hover', false); graph.setItemState(item, 'hover', false);
const targetType = target.get('type');
const name = target.get('name');
if (targetType === 'marker') { // 响应展开按钮
const model = item.getModel();
if (name === 'add-item') {
const nodeId = item.get('id');
if (model.dbType === 'Dir') {
const children = model.children;
if (!children) {
ctx.props?.loadMoreData(model.dirId || '', nodeId);
}
} else if (model.dbType !== 'Root') {
//通过资产id跳转到资产详情页
// history && history.push(`${ContextPath}/home`);
}
}
} else { // 展示 node 详情
}
}); });
if (typeof window !== 'undefined') if (typeof window !== 'undefined')
...@@ -176,42 +212,42 @@ G6.registerNode( ...@@ -176,42 +212,42 @@ G6.registerNode(
if (depthCount[cfg.depth] > 10) { if (depthCount[cfg.depth] > 10) {
r = 7 r = 7
} }
width1 = r * 3.5 width1 = r * 2.5
width2 = r * 5 width2 = r * 4
if (cfg.depth === 0) { if (cfg.depth === 0) {
root = cfg root = cfg
} }
if (depthCount[cfg.depth] > 10) { // if (depthCount[cfg.depth] > 10) {
group.addShape('image', { group.addShape('image', {
attrs: { attrs: {
x: -width1 / 2, x: -width1 / 2,
y: -width1 / 2, y: -width1 / 2,
width: width1, width: width1,
height: width1, height: width1,
img: circle, img: circle,
}, },
name: 'halo-shape', name: 'halo-shape',
visible: false, visible: false,
}); });
} // }
if (depthCount[cfg.depth] > 10) { // if (depthCount[cfg.depth] > 10) {
group.addShape('image', { group.addShape('image', {
attrs: { attrs: {
x: -width2 / 2, x: -width2 / 2,
y: -width2 / 2, y: -width2 / 2,
width: width2, width: width2,
height: width2, height: width2,
img: node, img: node,
}, },
name: 'focus-shape', name: 'focus-shape',
visible: false, visible: false,
}); });
lineWidth = .8 lineWidth = .8
} // }
const keyShape = group.addShape('circle', { const keyShape = group.addShape('circle', {
attrs: { attrs: {
...@@ -255,7 +291,38 @@ G6.registerNode( ...@@ -255,7 +291,38 @@ G6.registerNode(
}, },
name: 'text-shape', name: 'text-shape',
className: 'text-shape', className: 'text-shape',
}); });
}
const bbox = keyShape.getBBox()
// console.debug(bbox)
if (cfg.dbType === 'Root' || cfg.dbType === 'Dir') {
if (!cfg.children) {
group.addShape('marker', {
attrs: {
x: bbox.maxX + 3,
y: -1,
r: 3,
symbol: EXPAND_ICON,
stroke: '#73d13d',
lineWidth: .7,
cursor: 'pointer',
},
name: 'add-item',
});
}
// else if (cfg?.children?.length > 10) {
// group.addShape('marker', {
// attrs: {
// x: bbox.maxX + 8,
// y: bbox.height >> 1,
// r: 6,
// symbol: cfg.collapsed ? EXPAND_ICON : COLLAPSE_ICON,
// stroke: cfg.collapsed ? '#73d13d' : '#ff4d4f',
// lineWidth: 2,
// }
// });
// }
} }
return keyShape; return keyShape;
......
...@@ -16,7 +16,7 @@ const colors = [ ...@@ -16,7 +16,7 @@ const colors = [
'#FFD6E7', '#FFD6E7',
]; ];
const COLLAPSE_ICON = function COLLAPSE_ICON(x, y, r) { export const COLLAPSE_ICON = function COLLAPSE_ICON(x, y, r) {
return [ return [
['M', x - r, y - r], ['M', x - r, y - r],
['a', r, r, 0, 1, 0, r * 2, 0], ['a', r, r, 0, 1, 0, r * 2, 0],
...@@ -25,7 +25,7 @@ const COLLAPSE_ICON = function COLLAPSE_ICON(x, y, r) { ...@@ -25,7 +25,7 @@ const COLLAPSE_ICON = function COLLAPSE_ICON(x, y, r) {
['L', x + r - 2, y - r], ['L', x + r - 2, y - r],
]; ];
}; };
const EXPAND_ICON = function EXPAND_ICON(x, y, r) { export const EXPAND_ICON = function EXPAND_ICON(x, y, r) {
return [ return [
['M', x - r, y - r], ['M', x - r, y - r],
['a', r, r, 0, 1, 0, r * 2, 0], ['a', r, r, 0, 1, 0, r * 2, 0],
......
...@@ -187,7 +187,7 @@ class MapContent extends React.Component { ...@@ -187,7 +187,7 @@ class MapContent extends React.Component {
} }
return ( return (
<div className='position-relative' style={{ height: '100%' }}> <div className='position-relative' style={{ height: '100%', overflow: 'hidden' }}>
{ {
type==='square' && <> type==='square' && <>
{ {
......
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