UNPKG

gojs

Version:

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

64 lines (63 loc) 2.94 kB
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>State Chart with Draggable Node Labels</title> <meta name="description" content="TypeScript: Allow the user to shift the label of a node." /> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- Copyright 1998-2020 by Northwoods Software Corporation. --> <script src="../samples/assets/require.js"></script> <script src="../assets/js/goSamples.js"></script> <!-- this is only for the GoJS Samples framework --> <script id="code"> function init() { require(["NodeLabelDraggingScript"], function(app) { app.init(); document.getElementById("SaveButton").onclick = app.save; document.getElementById("LoadButton").onclick = app.load; }); } </script> </head> <body onload="init()"> <div id="sample"> <div id="myDiagramDiv" style="background-color: whitesmoke; border: solid 1px black; width: 100%; height: 400px"></div> <p> This sample is a modification of the <a href="../samples/stateChart.html">State Chart</a> sample that makes use of the NodeLabelDraggingTool that is defined in its own file, as <a href="NodeLabelDraggingTool.ts">NodeLabelDraggingTool.ts</a>. </p> <p> Note that after dragging a node label you can move that node and the label maintains the same position relative to the node. That relative position is specified by the <a>GraphObject.alignment</a> property, used by the "Spot" <a>Panel</a>. This sample also saves any changes to that property by means of a TwoWay <a>Binding</a>. </p> <button id="SaveButton">Save</button> <button id="LoadButton">Load</button> Diagram Model saved in JSON format: <br /> <textarea id="mySavedModel" style="width:100%;height:300px"> { "nodeKeyProperty": "id", "nodeDataArray": [ { "id": 0, "loc": "120 120", "text": "Initial" }, { "id": 1, "loc": "330 120", "text": "First down" }, { "id": 2, "loc": "226 376", "text": "First up" }, { "id": 3, "loc": "60 276", "text": "Second down" }, { "id": 4, "loc": "226 226", "text": "Wait" } ], "linkDataArray": [ { "from": 0, "to": 0, "text": "up or timer", "curviness": -20 }, { "from": 0, "to": 1, "text": "down", "curviness": 20 }, { "from": 1, "to": 0, "text": "up (moved)\nPOST", "curviness": 20 }, { "from": 1, "to": 1, "text": "down", "curviness": -20 }, { "from": 1, "to": 2, "text": "up (no move)" }, { "from": 1, "to": 4, "text": "timer" }, { "from": 2, "to": 0, "text": "timer\nPOST" }, { "from": 2, "to": 3, "text": "down" }, { "from": 3, "to": 0, "text": "up\nPOST\n(dblclick\nif no move)" }, { "from": 3, "to": 3, "text": "down or timer", "curviness": 20 }, { "from": 4, "to": 0, "text": "up\nPOST" }, { "from": 4, "to": 4, "text": "down" } ] } </textarea> </div> </body> </html>