【问题标题】:Prevent a vertex from being moved into a group防止顶点被移动到组中
【发布时间】:2013-07-08 21:36:15
【问题描述】:

使用 mxGraph 版本 1.10.1.1

该图包含一个组和组外的一个顶点。基于顶点的属性,我将如何防止用户将该节点拖入组中?

收听 mxEvent.CELLS_MOVED 似乎没有帮助,因为事件没有应用于图表,并且目标单元格还没有父组信息。我想除非事件被消耗掉。

是否有一种简单的方法可以阻止移动完成,或者有没有一种方法可以在满足条件后回滚事务?

【问题讨论】:

    标签: mxgraph jgraphx


    【解决方案1】:

    我使用的当前实现是覆盖mxGraphHandler.prototype.mouseUp 并在调用moveCells 之前检查目标和单元格。它目前有效,但不是理想的解决方案。

    mxGraphHandler.prototype.mouseUp = function(sender, me) {
        var hasRestricted = false;
        if (!me.isConsumed()) {
            var graph = this.graph;
            ...
    
        if (graph.isSplitEnabled() && graph.isSplitTarget(target, this.cells, me.getEvent())) {
            graph.splitEdge(target, this.cells, null, dx, dy);
        } else {
            // Check if this.target is a group and if this.cells contain the restricted cells
            if (this.target.getAttribute('type') !== 'relevantType' || this.cells.indexOf('restrictedVertexType') === -1) {
                this.moveCells(this.cells, dx, dy, clone, this.target, me.getEvent());
            }
        ...
    };
    

    【讨论】:

      猜你喜欢
      • 2018-09-15
      • 2023-03-30
      • 2022-11-01
      • 2017-05-30
      • 1970-01-01
      • 2015-08-25
      • 1970-01-01
      • 2010-10-28
      • 1970-01-01
      相关资源
      最近更新 更多