1

Using mxGraph version 1.10.1.1

The graph contains a group and a vertex outside the group. Based on an attribute of the vertex how would I go about preventing users from dragging this node into the group?

Listening to mxEvent.CELLS_MOVED doesn't seem to help because the event doesn't get applied to the graph and the target cell does not have the parent group info yet. Unless the event is consumed I suppose.

Is there a simple way to prevent the move from completing or is there a way to roll back the transaction after a condition is met?

sankargorthi
  • 369
  • 3
  • 21

1 Answers1

0

The current implementation I've gone with was to override mxGraphHandler.prototype.mouseUp and check the target and cells before calling moveCells. It works for now, but is not the ideal solution.

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());
        }
    ...
};
sankargorthi
  • 369
  • 3
  • 21