Components in tree mapper links

Hi, is it possible to put some component (like a square for example) on the links created in the tree mapper sample. Do you have a sample code to do that?
Thanks in advance

Yes, just add what you want to the Node template.

However you do need to consider keeping the size of what you add to a minimum, since the TreeMapLayout may force the node to be very narrow and/or short.

Thanks Walter. I’m very new with GoJS. Just downloaded and trying to do a proof of concept in order to incorporate this component in our product. Do you have a sample code to add the Node and be able to handle the double click on the “square”?
Thanks in advance.

Here’s a modified node template that adds a Shape and a GraphObject.doubleClick event handler:

    myDiagram.nodeTemplate =
        { background: "rgba(99,99,99,0.2)" },
        new go.Binding("background", "fill"),
        $(go.Shape, "Square", { strokeWidth: 0, width: 10, height: 10 }),
          doubleClick: function(e, obj) {
          toolTip: $(go.Adornment,
                     $(go.TextBlock, new go.Binding("text", "", tooltipString).ofObject())

I highly recommend that you read and then all of the pages of the Introduction,, that apply to the kind of app that you want to create. At least read the first dozen or so pages of the Introduction so that you become familiar with GoJS.

It also would help if you read or searched all of the sample code to find code that you might be able to use.

Thanks Walter!!!

Wait! I misunderstood which sample you were talking about.

I answered assuming you were starting with

But now I realize that you probably are starting with

So are you actually interested in the latter sample? If so, it is very easy to add label(s) to the links: As you can see, my answer to both adding a square Shape and a GraphObject.doubleClick event handler is basically the same for both nodes and links.

Thanks Walter. I’ve realized that I need to create a node instead of a LinkLabel. So I made this function that executes at diagram double click and creates:

  1. a new node (Func) - which I want to be created inside a group called “grupofunct”
  2. a link from a node (3) in the left treeView to the new node (Func)
  3. a link from this new node (Func) to a node (103) in the right treeview.

doubleClick: function(e, obj) {
{ key: “Func”,
modelType: “Auto”,
isGroup: false ,
category:“Functoide” ,
// loc: go.Point.parse(“30 30”)
myDiagram.model.addLinkData({ from: 3, to: ‘Func’,“category”:“Mapping” });
myDiagram.model.addLinkData({ from: ‘Func’, to:103,“category”:“Mapping” });
var nf=myDiagram.findNodeForKey(“grupofunct”);
nf.location=go.Point.parse(“200 200”);


The problem is that the new node (Funct) is created at position -5,-5 and moves my group “grupofunct” to that position.

Could you say what am I doing wrong?


Why do you need to involve any Groups? Do what you are doing, but do not try to add the new node to any group. Position the new node to be at the midpoint of the original link.fromNode.location and link.toNode.location.