Emanuele Galeotti
Emanuele Galeotti

Reputation: 49

how to disable the automatic center in gojs diagram?

The first click on the diagram causes the automatic positioning of the page in the center of the same, how is it disabled? how can I fix it? I can't find a documentation for these problem. goJs version 2.0.9 we have integrated gojs with angular js these are the functions called after two bees that retrieve nodes and links

$scope.createCustomNode = function () {
            var nodePicture = $scope.make(
                $go.Picture,
                {maxSize: new go.Size(475, 166)},
                new $go.Binding("source", "src")
            )
            var nodeTesxt = $scope.make(
                $go.TextBlock,
                "Default Text",
                new go.Binding("stroke", "color"),
                {margin: 12, font: "21px sans-serif"},
                new $go.Binding('text', 'name')
            )
            var managedEvent = {
                click: function (e, obj) {
                    $scope.nodeClick(obj.part.data.key)
                },
            }
            $scope.diagram.nodeTemplate = $scope.make(
                $go.Node,
                managedEvent,
                new $go.Binding("location", "loc", $go.Point.parse).makeTwoWay($go.Point.stringify),
                'Vertical',
                {background: 'transparent'},
                nodePicture,
                nodeTesxt
            )
        }
        $scope.createCustomLink = function () {
            var linkStyle = $scope.make(
                $go.Shape,
                new go.Binding("stroke", "color"),
                new go.Binding("strokeWidth", "width"),
                new go.Binding("strokeDashArray", "dash")
            )
            var startTextLink = $scope.make(
                $go.TextBlock,
                {font: "18px sans-serif"},
                new $go.Binding('text', 'startLabel'),
                {
                    segmentIndex: 0,
                    segmentFraction: 0.2,
                    segmentOffset: new go.Point(0, -20)
                }
            )
            var endTextLink = $scope.make(
                $go.TextBlock,
                {font: "18px sans-serif"},
                new $go.Binding('text', 'endLabel'),
                {
                    segmentIndex: 0,
                    segmentFraction: 0.8,
                    segmentOffset: new go.Point(0, -20)
                }
            )
            $scope.diagram.linkTemplate = $scope.make(
                $go.Link,
                linkStyle,
                startTextLink,
                endTextLink
            )
        }
        $scope.createDiagram = function () {
            $scope.diagram.model = $scope.model
        }
        $scope.initDiagramParams = function () {
            $scope.diagram = $scope.make($go.Diagram, 'diagram', {
                initialAutoScale: $go.Diagram.Uniform,
                // layout: new $go.ForceDirectedLayout(),
                // layout: new $go.LayeredDigraphLayout(),
                allowCopy: false
            })
            $scope.diagram.addDiagramListener('SelectionMoved', function (e) {
                $scope.nodeDragEnd(e)
            })
        } 

Upvotes: 1

Views: 765

Answers (1)

Walter Northwoods
Walter Northwoods

Reputation: 4106

Try setting Diagram.initialContentAlignment in your Diagram initializations. For example:

$(go.Diagram, . . .,
  {
    initialContentAlignment: go.Spot.TopLeft,
    initialAutoScale: go.Diagram.Uniform,
    layout: . . .
  })

If you do not specify the initialContentAlignment, or the initialDocumentSpot and initialViewportSpot, or the initialPosition, the default behavior in version 2.0 is to center the content in the viewport. The default behavior in version 1.* was to put the content at the top-left of the viewport.

Upvotes: 1

Related Questions