防止将顶点移动到组中

时间:2013-07-08 21:36:15

标签: mxgraph jgraphx

使用mxGraph版本1.10.1.1

图表包含组和组外的顶点。基于顶点的属性,我将如何阻止用户将此节点拖入组中?

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

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

1 个答案:

答案 0 :(得分:0)

我已经使用的当前实现是覆盖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());
        }
    ...
};
相关问题