TextBlock in center of LineDrawing tool

I want to add a textblock in the center of line using LineDrawing tool but after few different ways i tried it is still adding the text at top left corner of the node.


selectionMargin = 5 / 2;

$(

    go.Node,

    {

      reshapable: true, // allow LineReshapingTool to work

      locationObjectName: "LINE",

      locationSpot: new go.Spot(0, 0, selectionMargin, selectionMargin), // account for strokeWidth

      zOrder: 1,

    },

    new go.Binding("location", "loc", go.Point.parse).makeTwoWay(

      go.Point.stringify

    ),

    new go.Binding("resizable", "resizable"),

    {

      rotatable: false,

      rotateObjectName: "LINE",

    },

    new go.Binding("position", "pos", go.Point.parse).makeTwoWay(

      go.Point.stringify

    ),

    $(

      go.Shape,

      {

        name: "LINE",

        margin: 7.5,

        fill: null,

        stroke: "blue",

        strokeWidth: 0.5,

        position: new go.Point(

          selectionMargin - 1 / 2,

          selectionMargin - 1 / 2

        ),

      },

      new go.Binding("geometry", "pts", _makeGeo).makeTwoWay(_saveGeo),

      new go.Binding("stroke", "isSelected", (s) =>

        s ? "#00D1FF" : "#333333"

      ).ofObject(),

      new go.Binding("desiredSize", "size", go.Size.parse).makeTwoWay(

        go.Size.stringify

      )

    ),

    $(go.TextBlock, {

      text: "PIZZA",

      alignment: go.Spot.Center,

      alignmentFocus: go.Spot.Center,

    }),

    $(

      go.Shape, //this shape is for increasing touch area of line tool

      {

        // this shows the actual line, thinner than the transparent shape for selection

        name: "LINE",

        stroke: "#333333",

        opacity: 0,

        strokeWidth: 15,

        position: new go.Point(

          selectionMargin - 1 / 2,

          selectionMargin - 1 / 2

        ),

      }

    )

  )

Your Node is a “Position” Panel, so only the GraphObject.position property will control the position of each element of the node panel. Maybe you want to use a “Spot” Panel type?

It’s probably a bad idea for the Node to have Bindings on both the Part.location and GraphObject.position properties. That might cause a conflict.

Thanks Walter! :D

A post was split to a new topic: Arrowheads on Lines that are not Link paths