Search code examples
javascriptgojs

GoJS different ResizingTool for Groups and Nodes


Is it possible to use a different ResizingTool for different node templates? In my case I have a group containing some notes and I want to resize the groups with a custom ResizingTool and the nodes inside the group should use the default ResizingTool.

As far as I can see the resizingTool property can only be set at the diagram itself, so the same tool for everything!?

A hotfix I'm using now is to call the original go.ResizingTool functions in my custom tool depending on a node type condition.


Solution

  • That is one correct approach -- have each override look at the http://gojs.net/latest/api/symbols/ResizingTool.html#adornedObject and decide what to do.

    A similar approach would be to have instances of two different ResizingTools, both the standard one and your custom one, installed as ToolManager.mouseDownTools. You would install your custom, more specific, tool just before the ToolManager.resizingTool in that ToolManager.mouseDownTools list, and you would need to override ResizingTool.canStart so that it would return true only when it's OK and the resize handle is on one of your groups.

    Something like:

    GroupResizingTool.prototype.canStart = function() {
      if (!this.isEnabled) return false;
      var diagram = this.diagram;
      if (diagram === null || diagram.isReadOnly) return false;
      if (!diagram.allowResize) return false;
      if (!diagram.lastInput.left) return false;
    
      var h = this.findToolHandleAt(diagram.firstInput.documentPoint, this.name);
      return (h !== null && h.part.adornedPart instanceof go.Group);
    }
    

    Or maybe your final predicate would check that the adorned Part is of a particular category. Or any other needed discrimination.

    When your custom canStart fails, then the next tool would be the standard ResizingTool, which would operate normally but only on those nodes for which your custom tool did not.