Creating a custom button for tree expansion

I saw the other thread on this but the topic of custom buttons is really lacking. I’m trying to create a tree button with a circle (flat looking) and an arrow inside it. That’s it. I started trying to build a button up to implement it and got all sorts of errors. This was my first attempt at just a nothing “give it a try” type of button:

function makeCustomButton() {
var g = go.GraphObject.make;
var button = g(go.Panel, “Auto”,
{
isActionable: true
},
g(go.Shape, “Ellipse”, //the border
{
name: “ButtonBorder”,
height: 16,
width: 16,
fill: null,
stroke: “black”,
strokeWidth: 2
})
)
}

Then I tried to implement it in my template (also couldn’t find any documentation on this so it was just a wild guess…)

), //End of table

g(makeCustomButton(),

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

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

{ visible: true }

)

And then I get the error GraphObject.make requires a class function or class name, not: undefined. This happens during the template initialization and I have no idea what it's referring to (i.e. I have no idea how to call my custom button template).

Thanks!

I think makeCustomButton needs to have
return button;
at the end

Doogal is right, but that’s not a sufficient solution.

GraphObject.make is just a JavaScript function, and it expects its first argument to be a “class” so that it knows what kind of object to construct and initialize. As with all functions, all of its arguments are evaluated. So both of these are OK:
$(go.Node, …)
$(“Button”, …)
but these are not:
$(undefined, …)
$(17, …)
$(2+2, …)
And, similar to what you are doing, this is not valid either:
var pan = new go.Panel(); …
$(pan, …)
That’s because the first argument should not be an Object – GraphObject.make is trying to build a new object.

If you really want to modify an existing GraphObject, you can call GraphObject.setProperties, which will be documented in version 1.5 but exists undocumented in version 1.4. There will also be a Diagram.setProperties as well. But those methods will only work for GraphObjects and Diagrams, whereas the static GraphObject.make function can construct and initialize any Object class (perhaps with some limitations).