| | |
| | | import React, {Component} from 'react' |
| | | import PropTypes from 'prop-types' |
| | | import { is, fromJS } from 'immutable' |
| | | import { Popover, Tooltip } from 'antd' |
| | | import { ToolOutlined, DeleteOutlined, FontColorsOutlined, VerticalAlignTopOutlined, VerticalAlignBottomOutlined, SaveOutlined, ZoomInOutlined, ZoomOutOutlined, OneToOneOutlined } from '@ant-design/icons' |
| | | import { Popover, Tooltip, message } from 'antd' |
| | | import { ToolOutlined, DeleteOutlined, FontColorsOutlined, VerticalAlignTopOutlined, VerticalAlignBottomOutlined, SaveOutlined, ZoomInOutlined, ZoomOutOutlined, OneToOneOutlined, DoubleLeftOutlined } from '@ant-design/icons' |
| | | import { Graph, Shape } from '@antv/x6' |
| | | import { Stencil } from '@antv/x6-plugin-stencil' |
| | | import { Transform } from '@antv/x6-plugin-transform' |
| | |
| | | |
| | | state = { |
| | | card: null, |
| | | eventListener: null |
| | | eventListener: null, |
| | | toolunfold: true, |
| | | nodeunfold: true, |
| | | node: null |
| | | } |
| | | |
| | | selectNode = null |
| | | mkGraph = null |
| | | |
| | | UNSAFE_componentWillMount () { |
| | | const { card } = this.props |
| | |
| | | autoResize: true, |
| | | panning: true, |
| | | background: { |
| | | color: '#ffffff', |
| | | color: '#ffffff' |
| | | }, |
| | | mousewheel: { |
| | | enabled: true, |
| | | zoomAtMousePosition: true, |
| | | modifiers: 'ctrl', |
| | | minScale: 0.5, |
| | | maxScale: 5, |
| | | maxScale: 2 |
| | | }, |
| | | connecting: { |
| | | router: 'manhattan', |
| | |
| | | targetMarker: { |
| | | name: 'block', |
| | | width: 12, |
| | | height: 8, |
| | | }, |
| | | }, |
| | | height: 8 |
| | | } |
| | | } |
| | | }, |
| | | zIndex: 0, |
| | | zIndex: 0 |
| | | }) |
| | | }, |
| | | validateConnection({ targetMagnet }) { |
| | | return !!targetMagnet |
| | | }, |
| | | } |
| | | }, |
| | | highlighting: { |
| | | magnetAdsorbed: { |
| | |
| | | args: { |
| | | attrs: { |
| | | fill: '#5F95FF', |
| | | stroke: '#5F95FF', |
| | | }, |
| | | }, |
| | | }, |
| | | }, |
| | | stroke: '#5F95FF' |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }) |
| | | |
| | | // #region 使用插件 |
| | | graph |
| | | .use( |
| | | new Transform({ |
| | | resizing: true, |
| | | rotating: true |
| | | }) |
| | | ) |
| | | .use(new Transform({ |
| | | resizing: true, |
| | | rotating: true |
| | | })) |
| | | .use(new Selection()) |
| | | .use(new Snapline()) |
| | | .use(new Keyboard()) |
| | |
| | | }) |
| | | |
| | | // zoom |
| | | graph.bindKey(['ctrl+1', 'meta+1'], () => { |
| | | const zoom = graph.zoom() |
| | | if (zoom < 1.5) { |
| | | graph.zoom(0.1) |
| | | } |
| | | }) |
| | | graph.bindKey(['ctrl+2', 'meta+2'], () => { |
| | | const zoom = graph.zoom() |
| | | if (zoom > 0.5) { |
| | | graph.zoom(-0.1) |
| | | } |
| | | }) |
| | | // graph.bindKey(['ctrl+1', 'meta+1'], () => { |
| | | // const zoom = graph.zoom() |
| | | // if (zoom < 1.5) { |
| | | // graph.zoom(0.1) |
| | | // } |
| | | // }) |
| | | // graph.bindKey(['ctrl+2', 'meta+2'], () => { |
| | | // const zoom = graph.zoom() |
| | | // if (zoom > 0.5) { |
| | | // graph.zoom(-0.1) |
| | | // } |
| | | // }) |
| | | |
| | | // 控制连接桩显示/隐藏 |
| | | const showPorts = (ports, show) => { |
| | |
| | | }) |
| | | |
| | | // graph.on('cell:click', ({ e, x, y, cell, view }) => { |
| | | |
| | | // cell.attr('body/stroke', "red") |
| | | // }) |
| | | graph.on('node:click', ({ e, x, y, node, view }) => { |
| | | |
| | | this.selectNode = node |
| | | |
| | | this.setState({node: this.selectNode.store.data}) |
| | | }) |
| | | graph.on('edge:click', ({ e, x, y, edge, view }) => { |
| | | |
| | | this.selectNode = edge |
| | | |
| | | this.setState({node: this.selectNode.store.data}) |
| | | |
| | | let trans = document.querySelectorAll('.x6-widget-transform') |
| | | if (trans && trans[0]) { |
| | | trans[0].style.display = 'none' |
| | | } |
| | | }) |
| | | graph.on('blank:click', ({ e, x, y }) => { |
| | | |
| | | this.selectNode = null |
| | | |
| | | this.setState({node: null}) |
| | | }) |
| | | |
| | | |
| | | const r1 = graph.createNode({ |
| | | shape: 'mk-rect', |
| | | label: '开始', |
| | |
| | | shape: 'mk-circle', |
| | | label: '连接' |
| | | }) |
| | | |
| | | |
| | | stencil.load([r1, r2, r3, r4, r5, r6], 'group1') |
| | | |
| | | |
| | | const p1 = graph.createNode({ |
| | | shape: 'mk-ellipse', |
| | | label: 'ellipse' |
| | |
| | | shape: 'mk-star', |
| | | label: '' |
| | | }) |
| | | |
| | | |
| | | stencil.load([p1, p2], 'group2') |
| | | |
| | | this.mkGraph = graph |
| | | } |
| | | |
| | | setTop = () => { |
| | | if (!this.selectNode) { |
| | | message.warning('请选择节点!') |
| | | return |
| | | } |
| | | this.selectNode.toFront() |
| | | } |
| | | |
| | | setBottom = () => { |
| | | if (!this.selectNode) { |
| | | message.warning('请选择节点!') |
| | | return |
| | | } |
| | | // let cells = this.mkGraph.getCells() |
| | | this.selectNode.toBack() |
| | | } |
| | | |
| | | setZoomIn = () => { |
| | | const zoom = this.mkGraph.zoom() |
| | | |
| | | if (zoom < 2) { |
| | | this.mkGraph.zoom(0.1) |
| | | } |
| | | } |
| | | |
| | | setZoomOut = () => { |
| | | const zoom = this.mkGraph.zoom() |
| | | |
| | | if (zoom > 0.5) { |
| | | this.mkGraph.zoom(-0.1) |
| | | } |
| | | } |
| | | |
| | | setZoomInt = () => { |
| | | this.mkGraph.zoomTo(1) |
| | | } |
| | | |
| | | save = () => { |
| | | // let nodes = this.mkGraph.toJSON() |
| | | } |
| | | |
| | | updateComponent = (card) => { |
| | |
| | | } |
| | | |
| | | render() { |
| | | const { card } = this.state |
| | | const { card, toolunfold, nodeunfold, node } = this.state |
| | | let _style = resetStyle(card.style) |
| | | |
| | | return ( |
| | | <div className="menu-scatter-chart-edit-box" style={_style} onClick={this.clickComponent} id={card.uuid}> |
| | | <div className="menu-x6-chart-edit-box" style={_style} onClick={this.clickComponent} id={card.uuid}> |
| | | <Popover overlayClassName="mk-popover-control-wrap" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={ |
| | | <div className="mk-popover-control"> |
| | | <ChartCompileForm config={card} plotchange={this.updateComponent}/> |
| | |
| | | <div className="mk-toolbar"> |
| | | <div className="left-tool"> |
| | | <Tooltip title="置前"> |
| | | <VerticalAlignTopOutlined /> |
| | | <VerticalAlignTopOutlined onClick={this.setTop}/> |
| | | </Tooltip> |
| | | <Tooltip title="置后"> |
| | | <VerticalAlignBottomOutlined /> |
| | | <VerticalAlignBottomOutlined onClick={this.setBottom}/> |
| | | </Tooltip> |
| | | <Tooltip title="保存"> |
| | | <SaveOutlined /> |
| | | <SaveOutlined onClick={this.save}/> |
| | | </Tooltip> |
| | | </div> |
| | | <div className="right-tool"> |
| | | <Tooltip title="放大"> |
| | | <ZoomInOutlined /> |
| | | <ZoomInOutlined onClick={this.setZoomIn}/> |
| | | </Tooltip> |
| | | <Tooltip title="缩小"> |
| | | <ZoomOutOutlined /> |
| | | <ZoomOutOutlined onClick={this.setZoomOut}/> |
| | | </Tooltip> |
| | | <Tooltip title="1:1"> |
| | | <OneToOneOutlined /> |
| | | <OneToOneOutlined onClick={this.setZoomInt}/> |
| | | </Tooltip> |
| | | </div> |
| | | </div> |
| | | <div className="canvas" style={{width: '100%', minHeight: card.plot.height, height: card.plot.height}} id={card.uuid + 'canvas'}> |
| | | <div id={card.uuid + 'stencil'} className="mk-stencil"></div> |
| | | <div id={card.uuid + 'stencil'} className={'mk-stencil ' + (toolunfold ? '' : 'merge')}> |
| | | <div className="tool-control" onClick={() => this.setState({toolunfold: !toolunfold})}> |
| | | <DoubleLeftOutlined /> |
| | | </div> |
| | | </div> |
| | | <div id={card.uuid + 'container'} className="mk-container"></div> |
| | | <div className={'mk-node-edit ' + (nodeunfold ? '' : 'merge')}> |
| | | <div className="tool-control" onClick={() => this.setState({nodeunfold: !nodeunfold})}> |
| | | <DoubleLeftOutlined /> |
| | | </div> |
| | | <div className="header">设置</div> |
| | | {!node ? <div className="empty">未选中</div> : <div></div>} |
| | | </div> |
| | | </div> |
| | | <div className="component-name"> |
| | | <div className="center"> |