Drag Creating Tool (Extend to Include go.Picture)

Is there a way to extend the DragCreatingTool to draw a picture box and ensure that the picture box consumes the entire bounding rectangle?

You don’t have to customize the tool. All you have to do is create a new node template that uses a Picture instead of its current template (an auto panel that has a shape and a textblock)

        nodeTemplate:
          $(go.Node, "Position",
            { resizable: true, resizeObjectName: 'pic' },
            new go.Binding("position", "pos", go.Point.parse).makeTwoWay(go.Point.stringify),
            // temporarily put selected nodes in Foreground layer
            new go.Binding("layerName", "isSelected", function(s) { return s ? "Foreground" : ""; }).ofObject(),
            $(go.Picture,
              {
                // TODO: Specify an image source either here or via data binding
                minSize: new go.Size(60, 20),
                desiredSize: new go.Size(60, 20),
                name: 'pic',
                background: 'red'
              },
              new go.Binding("desiredSize", "size", go.Size.parse).makeTwoWay(go.Size.stringify)
            )
          ),

Here’s an example: http://codepen.io/simonsarris/pen/ORJbyz?editors=1010

The binding on desiredSize was what I was missing. I will give that a try. Thanks

Note that, for Picture, you have to set a binding on desiredSize and also set some default desired size, even though it will get a new value right away. This is a necessary workaround in 1.6 (and is fixed in the current Alpha and is not an issue in 1.7).

Simon,

Many thanks for the feedback. I am able to load an image into an image control now. But for some reason when I save my diagram model and then reload, my picture control does not contain the image. I looked at the JSON string and I can see the image data saved as Base64 encoded. Any ideas.

BTW. Here is the JSON representation of my Diagram.model.

{ “class”: “go.GraphLinksModel”,
“nodeDataArray”: [ {“category”:“picture”, “color”:"#99ccff", “key”:-1, “pos”:"-716.03125 -234.515625", “loc”:"-716.03125 -234.515625", “element”:{“src”:“data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB8AAAAUCAIAAAD6C3GtAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAdUSURBVEhLDZL7V9IJGsb5C3bn1GwzY5tToDDeQJCLXL4gchURRREFFRTFC4jcLwJfEFAxb2glGkY6ZZepsfKKpqZJVlvajFluZW3XbXaac3Y6uzOzs82ecTnn8+N7nvd9n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HIJi2F86Ak4pCMGwpmHZK1TtV22L1+1LI5BE7Z5VP2insD1odh56pfudGv+euA4fWIfUoveHXK9WLU+fJL8MkJM2SjszK2NmLk3+tRRr3l69213wTUC46SRyHzSqs8ZjDilM67ZLF3+tuZjhfnezYG7G8vHd0+6Xs/F969M/7L0siCt2ZryPbdudb7veo1X+X2Mf3zEUeMnbDl/+zVPbPG0bqtAAAAAElFTkSuQmCC”}} ],
“linkDataArray”: []}

Instead of data-binding the Picture.element, data bind the source.

This example loads that data: http://codepen.io/simonsarris/pen/mAdWVy?editors=1010

But I changed the data to use “src” directly and put a data binding on Picture:

new go.Binding("source", "src"),

Instead of using element.