We allow the user to change the grid options using preferences. When they save the preferences we update the grid. We are using this code to update the grid:
updateGrid: function() {
var me = this,
make = go.GraphObject.make,
grid,
lines = [],
prefs = Wp.base.util.Session.preferences;
if (prefs.get(‘showGrid’)) {
lines.push(
make(‘Shape’, ‘LineH’, {
stroke: ‘#BEBEBE’,
strokeWidth: 1
}),
make(‘Shape’, ‘LineV’, {
stroke: ‘#BEBEBE’,
strokeWidth: 1
})
);
}
grid = make(‘Panel’, ‘Grid’, {
gridCellSize: new go.Size(prefs.get(‘gridSize’), prefs.get(‘gridSize’))
},
lines
);
me.diagram.startTransaction(‘updateGrid’);
me.diagram.grid = grid;
me.diagram.toolManager.draggingTool.isGridSnapEnabled = prefs.get(‘snapToGridMove’);
me.diagram.toolManager.resizingTool.isGridSnapEnabled = prefs.get(‘snapToGridResize’);
me.diagram.commitTransaction(‘updateGrid’);
},
I have some questions:
-
After running the above code the grid disappears whether it is turned on or off. If it is on, moving the diagram makes it come back. Is there a call I need to make after updating the grid so it shows w/o having to move the diagram?
-
When adding a new node is there a way to make it snap to grid if user has option turned on? I don’t see any options for ClickCreatingTool.
-
Even though my grid stroke is 1 the lines are thicker than 1px. If I zoom with the mouse, sometimes they are 1px and sometimes 2px. My guess this could be something with anti-aliasing. Is there a way to turn this off for just the grid? Even doing 0.5 doesn’t fix it.
Thanks!