I want to add snap to grid to my diagrams. The default for gridSnapCellSpot seems to be center, but that doesn’t look good in my case. So I changed it to TopLeft but that has no effect at all.
My Code:
var draggingTool = diagram.toolManager.draggingTool;
draggingTool.isGridSnapEnabled = true;
draggingTool.gridSnapCellSpot = go.Spot.TopLeft;
draggingTool.gridSnapCellSize = new go.Size(20, 20);
isGridSnapEnabled and gridSnapCellSize both work, but gridSnapCellSpot does not. Do you have any idea why?
I use GoJS version 1.6.7.
I’m not sure what behavior you are getting and how you would prefer it to work. Some tiny screenshots would have been useful.
The DraggingTool’s snapping behavior is for moving the node’s Node.location to the nearest grid point, as determined by the DraggingTool.gridSnapCellSpot. You have tried changing this property, but what is the value of Node.locationSpot? What spot of the node do you want to line up with what spot in each grid cell?
Ok, I didn’t know of Node.locationSpot. I tried using DraggingTool.gridSnapCellSpot for that but I was only moving the grid with that option.
Setting locationSpot in my node style template gets me what I need.
I have another question about the grid:
These settings are only for the dragging tool but it would be nice if the TreeLayout would consider the grid settings as well. Is there a way?
If the nodes are sized the same as a grid cell or a multiple, and if the spacing is also a grid cell or multiple, I think that you can make it work.
If you want the spacing to be smaller than a grid cell, then the nodes will need to be smaller than a multiple of the grid cell by the spacing size. This might be trickier to setup.
Ok, spacing is no problem. The nodes with fixed sizes are also no problem. But how do I get dynamic sizes to a multiple of the grid size? Resizing is disabled so the automatic sizing has to do it. Until now, I only have a max width defined.
Any idea?
The circle is 40 wide. layerSpacing is also 40. You can see, that the next element is already off a few pixels.
I think without native grid support for layouts, this won’t work very well.