| | |
| | | }, |
| | | 'single-node', |
| | | ) |
| | | G6.registerNode( |
| | | 'dice-mind-map-sub', { |
| | | jsx: (cfg) => { |
| | | const width = Util.getTextSize(cfg.label, 14)[0] + 24 |
| | | |
| | | return ` |
| | | <group> |
| | | <rect style={{width: ${width}, height: 22, cursor: pointer}}> |
| | | <text style={{ fontSize: 14, fill: ${cfg.selected ? systemColor : '#000000'}, marginLeft: 12, marginTop: 6, cursor: pointer }}>${cfg.label}</text> |
| | | </rect> |
| | | <rect style={{ fill: ${cfg.color}, width: ${width}, height: 2, x: 0, y: 22, cursor: pointer }} /> |
| | | </group> |
| | | ` |
| | | }, |
| | | getAnchorPoints() { |
| | | return [ |
| | | [0, 0.965], |
| | | [1, 0.965] |
| | | ] |
| | | } |
| | | }, |
| | | 'single-node', |
| | | ) |
| | | G6.registerNode( |
| | | 'dice-mind-map-leaf', { |
| | | jsx: (cfg) => { |
| | |
| | | ev.preventDefault() |
| | | } |
| | | }) |
| | | |
| | | const dataMapTransform = (data) => { |
| | | const changeData = (d, level = 0, color) => { |
| | | const data = { ...d } |
| | | |
| | | switch (level) { |
| | | case 0: |
| | | data.type = 'dice-mind-map-root' |
| | | break |
| | | case 1: |
| | | data.type = 'dice-mind-map-sub' |
| | | break |
| | | default: |
| | | data.type = 'dice-mind-map-leaf' |
| | | break |
| | | } |
| | | |
| | | if (color) { |
| | | data.color = color |
| | | } |
| | | |
| | | if (level === 1 && !d.direction) { |
| | | data.direction = 'right' |
| | | } |
| | | |
| | | if (d.children) { |
| | | data.children = d.children.map((child) => changeData(child, level + 1, data.color)) |
| | | } |
| | | return data |
| | | } |
| | | return changeData(data) |
| | | } |
| | | |
| | | // 缩进文件树 |
| | | G6.registerNode('indentedRoot', { |
| | |
| | | if (item.direction === 'left') { |
| | | item.color = card.plot.leftColor || '#26C281' |
| | | } else { |
| | | item.direction = 'right' |
| | | item.color = card.plot.nodeColor || '#1890ff' |
| | | } |
| | | }) |
| | | |
| | | data.collapsed = false |
| | | data.type = 'dice-mind-map-root' |
| | | |
| | | const collapse = (item) => { |
| | | if (!item.children) return |
| | | |
| | | item.children.forEach(cell => { |
| | | cell.collapsed = card.plot.collapsed === 'true' |
| | | cell.direction = cell.direction || 'right' |
| | | cell.type = 'dice-mind-map-leaf' |
| | | cell.color = cell.color || item.color |
| | | collapse(cell) |
| | | }) |
| | | } |
| | | |
| | | collapse(data) |
| | | } else if (card.plot.subtype === 'indentTree') { |
| | | data.isRoot = true |
| | | data.collapsed = false |
| | |
| | | const { card } = this.state |
| | | const plot = card.plot |
| | | const data = this.getdata() |
| | | const height = getHeight(plot.height) |
| | | |
| | | const graph = new G6.TreeGraph({ |
| | | container: card.uuid + 'canvas', |
| | | width: this.wrap.scrollWidth - 30, |
| | | height: getHeight(plot.height), |
| | | height: height, |
| | | modes: { |
| | | default: [ |
| | | { |
| | |
| | | graph.data(data) |
| | | graph.render() |
| | | graph.fitView() |
| | | |
| | | if (plot.collapsed === 'true') { |
| | | graph.zoomTo(1, { x: 0, y: height / 2 }) |
| | | } |
| | | } |
| | | |
| | | indentrender = () => { |
| | |
| | | const { card } = this.state |
| | | const plot = card.plot |
| | | const data = this.getdata() |
| | | const width = this.wrap.scrollWidth - 30 |
| | | const height = getHeight(plot.height) |
| | | let modes = ['drag-canvas', 'zoom-canvas', 'dice-mindmap'] |
| | | |
| | | if (plot.collapsed === 'true') { |
| | | modes = [{ type: 'collapse-expand' },'drag-canvas', 'zoom-canvas', 'dice-mindmap'] |
| | | } |
| | | |
| | | const tree = new G6.TreeGraph({ |
| | | container: card.uuid + 'canvas', |
| | | width: this.wrap.scrollWidth - 30, |
| | | height: getHeight(plot.height), |
| | | width: width, |
| | | height: height, |
| | | fitView: true, |
| | | layout: { |
| | | type: 'mindmap', |
| | |
| | | }, |
| | | minZoom: 0.5, |
| | | modes: { |
| | | default: ['drag-canvas', 'zoom-canvas', 'dice-mindmap'] |
| | | default: modes |
| | | } |
| | | }) |
| | | |
| | | tree.data(dataMapTransform(data)) |
| | | |
| | | tree.data(data) |
| | | |
| | | tree.render() |
| | | |
| | | if (plot.collapsed === 'true' && plot.dirField) { |
| | | tree.zoomTo(1, { x: width / 2, y: height / 2 }) |
| | | } else if (plot.collapsed === 'true') { |
| | | tree.zoomTo(1, { x: 0, y: height / 2 }) |
| | | } |
| | | } |
| | | |
| | | updateComponent = (card) => { |