UNPKG

gojs

Version:

Interactive diagrams, charts, and graphs, such as trees, flowcharts, orgcharts, UML, BPMN, or business diagrams

89 lines (83 loc) 3.88 kB
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Rounded Nodes Consisting of Two Halves</title> <meta name="description" content="Nodes consisting of two Panels, using a RoundedTopRectangle and a RoundedBottomRectangle figure." /> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- Copyright 1998-2020 by Northwoods Software Corporation. --> <script src="../release/go.js"></script> <script src="../extensions/Figures.js"></script> <script src="../extensions/RoundedRectangles.js"></script> <script src="../assets/js/goSamples.js"></script> <!-- this is only for the GoJS Samples framework --> <script id="code"> function init() { if (window.goSamples) goSamples(); // init for these samples -- you don't need to call this var $ = go.GraphObject.make; myDiagram = $(go.Diagram, "myDiagramDiv", { initialScale: 2.0, "undoManager.isEnabled": true }); var NodeInfoSize = new go.Size(50, 25); // controls the size of each half myDiagram.nodeTemplate = $(go.Node, "Spot", { selectionAdorned: false, locationSpot: go.Spot.Center }, $(go.Panel, "Auto", $(go.Shape, "RoundedRectangle", // shown when selected { stroke: "transparent", strokeWidth: 3, spot1: go.Spot.TopLeft, spot2: go.Spot.BottomRight }, new go.Binding("stroke", "isSelected", function(s) { return s ? "dodgerblue" : "transparent"; }).ofObject()), $(go.Panel, $(go.Panel, "Auto", { desiredSize: NodeInfoSize }, $(go.Shape, "RoundedTopRectangle", { fill: "white" }, new go.Binding("fill", "topColor")), $(go.TextBlock, new go.Binding("text", "topText")) ), $(go.Panel, "Auto", { desiredSize: NodeInfoSize }, { position: new go.Point(0, NodeInfoSize.height - 1) }, // overlap the top side of this shape with the bottom side of the top shape $(go.Shape, "RoundedBottomRectangle", { fill: "white" }, new go.Binding("fill", "bottomColor")), $(go.TextBlock, new go.Binding("text", "bottomText")) ) ) ), // decorations... $(go.Shape, "FivePointedStar", { desiredSize: new go.Size(12, 12), fill: "yellow", alignment: new go.Spot(1, 0, -2, 2), opacity: 0.0 }, new go.Binding("opacity", "star", function(v) { return v ? 1.0 : 0.0; })) ); load(); } function load() { myDiagram.model = go.Model.fromJson(document.getElementById("mySavedModel").value); } </script> </head> <body onload="init()"> <div id="sample"> <div id="myDiagramDiv" style="border: solid 1px black; width:100%; height:400px"></div> <p> This defines a node template consisting of a top half and a bottom half. Each half's text and color are data bound. However the size of each node is fixed, so if the text is too long, it will be clipped. </p> <p> The "RoundedTopRectangle" and "RoundedBottomRectangle" figures are defined in <a href="../extensions/RoundedRectangles.js">RoundedRectangles.js</a> in the extensions directory. See also the <a href="roundedGroups.html" target="_blank">Rounded Groups</a> sample. </p> <textarea id="mySavedModel" style="width:100%;height:200px"> { "class": "go.GraphLinksModel", "nodeDataArray": [ { "key": "Alpha", "topText": "A", "topColor": "lightgray", "bottomText": "B", "bottomColor": "green" }, { "key": "Beta", "topText": "C", "bottomText": "D", "bottomColor": "red", "star": true } ], "linkDataArray": [ { "from": "Alpha", "to": "Beta" } ] } </textarea> </div> </body> </html>