mxGraph实现按住ctrl键盘拖动图形实现复制图形功能
實現這個功能很easy,僅僅須要重寫moveCells方法就能夠了。以下是源文件里的代碼:
mxGraph.prototype.moveCells = function(cells, dx, dy, clone, target, evt) {clone=evt.ctrlKey;//對。就是這啦!
? if (cells != null && (dx != 0 || dy != 0 || clone || target != null)) { this.model.beginUpdate(); try { if (clone) { cells = this.cloneCells(cells, this.isCloneInvalidEdges()); if (target == null) { target = this.getDefaultParent(); } } this.cellsMoved(cells, dx, dy, !clone && this.isDisconnectOnMove() && this.isAllowDanglingEdges(), target == null); if (target != null) { var index = this.model.getChildCount(target); this.cellsAdded(cells, target, index, null, null, true); } this.fireEvent(new mxEventObject(mxEvent.MOVE_CELLS, 'cells', cells, 'dx', dx, 'dy', dy, 'clone', clone, 'target', target, 'event', evt)); } finally { this.model.endUpdate(); } } return cells; };
是的。實現這個功能的確非常easy。可是往往實際項目中會有不同的需求。比方一個數據庫關系圖,復制一個字段到還有一張表中的時候;選擇了多個圖形而且包含關系線的是時候是否須要復制關系;假設圖形存在子圖形。是否須要一同復制;當前選擇的圖形是不是同意移動/復制。移動進入目標圖形,目標圖形是否同意該操作等等,這些就須要在這種方法區域中進行復雜的推斷。
總結
以上是生活随笔為你收集整理的mxGraph实现按住ctrl键盘拖动图形实现复制图形功能的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 信息图:大数据2016年分析趋势
- 下一篇: HashMap源代码深入剖析