@Cr1t wrote:
Hi
I’m trying create a context menu to change the color of a Link this is what I got so far, I’m not sure how to get the color part of the link
function changeColor(e, obj) { myDiagram.commit(function(d) { // get the context menu that holds the button that was clicked var contextmenu = obj.part; var linkdata = contextmenu.data; console.log(nodedata); // compute the next color for the node //var newcolor = "lightblue"; //switch (nodedata.color) { // case "lightblue": newcolor = "lightgreen"; break; // case "lightgreen": newcolor = "lightyellow"; break; // case "lightyellow": newcolor = "orange"; break; // case "orange": newcolor = "lightblue"; break; //} //// modify the node data //// this evaluates data Bindings and records changes in the UndoManager //d.model.set(nodedata, "color", newcolor); }, "changed color"); } //Link Template myDiagram.linkTemplate = $$(go.Link, { layerName: "Background", routing: go.Link.AvoidsNodes, corner: 15, curve: go.Link.JumpGap, reshapable: true, resegmentable: true, contextMenu: // define a context menu for each node $$("ContextMenu", // that has one button $$("ContextMenuButton", $$(go.TextBlock, "Change Color"), { click: changeColor }) // more ContextMenuButtons would go here ) // end Adornment }, new go.Binding("points").makeTwoWay(), $$(go.Shape, { isPanelMain: true, stroke: "#e0e0e0", strokeWidth: 10 }, new go.Binding("stroke", "color", function(c) { return colors[c]; })), $$(go.Shape, { isPanelMain: true, stroke: "white", strokeWidth: 3, name: "PIPE", strokeDashArray: [20, 40] }) );
Posts: 2
Participants: 2