UNPKG

gojs

Version:

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

299 lines (285 loc) 14 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"/> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no, viewport-fit=cover"/> <meta name="description" content="An IVR (Interactive Voice Response) diagram showing a call-menu tree with various prompts and responses."/> <link rel="stylesheet" href="../assets/css/style.css"/> <!-- Copyright 1998-2023 by Northwoods Software Corporation. --> <title>IVR Tree</title> </head> <body> <!-- This top nav is not part of the sample code --> <nav id="navTop" class="w-full z-30 top-0 text-white bg-nwoods-primary"> <div class="w-full container max-w-screen-lg mx-auto flex flex-wrap sm:flex-nowrap items-center justify-between mt-0 py-2"> <div class="md:pl-4"> <a class="text-white hover:text-white no-underline hover:no-underline font-bold text-2xl lg:text-4xl rounded-lg hover:bg-nwoods-secondary " href="../"> <h1 class="my-0 p-1 ">GoJS</h1> </a> </div> <button id="topnavButton" class="rounded-lg sm:hidden focus:outline-none focus:ring" aria-label="Navigation"> <svg fill="currentColor" viewBox="0 0 20 20" class="w-6 h-6"> <path id="topnavOpen" fill-rule="evenodd" d="M3 5a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM3 10a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM9 15a1 1 0 011-1h6a1 1 0 110 2h-6a1 1 0 01-1-1z" clip-rule="evenodd"></path> <path id="topnavClosed" class="hidden" fill-rule="evenodd" d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z" clip-rule="evenodd"></path> </svg> </button> <div id="topnavList" class="hidden sm:block items-center w-auto mt-0 text-white p-0 z-20"> <ul class="list-reset list-none font-semibold flex justify-end flex-wrap sm:flex-nowrap items-center px-0 pb-0"> <li class="p-1 sm:p-0"><a class="topnav-link" href="../learn/">Learn</a></li> <li class="p-1 sm:p-0"><a class="topnav-link" href="../samples/">Samples</a></li> <li class="p-1 sm:p-0"><a class="topnav-link" href="../intro/">Intro</a></li> <li class="p-1 sm:p-0"><a class="topnav-link" href="../api/">API</a></li> <li class="p-1 sm:p-0"><a class="topnav-link" href="https://www.nwoods.com/products/register.html">Register</a></li> <li class="p-1 sm:p-0"><a class="topnav-link" href="../download.html">Download</a></li> <li class="p-1 sm:p-0"><a class="topnav-link" href="https://forum.nwoods.com/c/gojs/11">Forum</a></li> <li class="p-1 sm:p-0"><a class="topnav-link" href="https://www.nwoods.com/contact.html" target="_blank" rel="noopener" onclick="getOutboundLink('https://www.nwoods.com/contact.html', 'contact');">Contact</a></li> <li class="p-1 sm:p-0"><a class="topnav-link" href="https://www.nwoods.com/sales/index.html" target="_blank" rel="noopener" onclick="getOutboundLink('https://www.nwoods.com/sales/index.html', 'buy');">Buy</a></li> </ul> </div> </div> <hr class="border-b border-gray-600 opacity-50 my-0 py-0" /> </nav> <div class="md:flex flex-col md:flex-row md:min-h-screen w-full max-w-screen-xl mx-auto"> <div id="navSide" class="flex flex-col w-full md:w-48 text-gray-700 bg-white flex-shrink-0"></div> <!-- * * * * * * * * * * * * * --> <!-- Start of GoJS sample code --> <script src="../release/go.js"></script> <div id="allSampleContent" class="p-4 w-full"> <script src="../extensions/Figures.js"></script> <script id="code"> function init() { // Since 2.2 you can also author concise templates with method chaining instead of GraphObject.make // For details, see https://gojs.net/latest/intro/buildingObjects.html const $ = go.GraphObject.make; // for conciseness in defining templates myDiagram = new go.Diagram("myDiagramDiv", { allowCopy: false, "draggingTool.dragsTree": true, "commandHandler.deletesTree": true, layout: $(go.TreeLayout, { angle: 90, arrangement: go.TreeLayout.ArrangementFixedRoots }), "undoManager.isEnabled": true }); // when the document is modified, add a "*" to the title and enable the "Save" button myDiagram.addDiagramListener("Modified", e => { var button = document.getElementById("SaveButton"); if (button) button.disabled = !myDiagram.isModified; var idx = document.title.indexOf("*"); if (myDiagram.isModified) { if (idx < 0) document.title += "*"; } else { if (idx >= 0) document.title = document.title.slice(0, idx); } }); var bluegrad = $(go.Brush, "Linear", { 0: "#C4ECFF", 1: "#70D4FF" }); var greengrad = $(go.Brush, "Linear", { 0: "#B1E2A5", 1: "#7AE060" }); // each action is represented by a shape and some text var actionTemplate = $(go.Panel, "Horizontal", $(go.Shape, { width: 12, height: 12 }, new go.Binding("figure"), new go.Binding("fill") ), $(go.TextBlock, { font: "10pt Verdana, sans-serif" }, new go.Binding("text") ) ); // each regular Node has body consisting of a title followed by a collapsible list of actions, // controlled by a PanelExpanderButton, with a TreeExpanderButton underneath the body myDiagram.nodeTemplate = // the default node template $(go.Node, "Vertical", new go.Binding("isTreeExpanded").makeTwoWay(), // remember the expansion state for new go.Binding("wasTreeExpanded").makeTwoWay(), // when the model is re-loaded { selectionObjectName: "BODY" }, // the main "BODY" consists of a RoundedRectangle surrounding nested Panels $(go.Panel, "Auto", { name: "BODY" }, $(go.Shape, "Rectangle", { fill: bluegrad, stroke: null } ), $(go.Panel, "Vertical", { margin: 3 }, // the title $(go.TextBlock, { stretch: go.GraphObject.Horizontal, font: "bold 12pt Verdana, sans-serif" }, new go.Binding("text", "question") ), // the optional list of actions $(go.Panel, "Vertical", { stretch: go.GraphObject.Horizontal, visible: false }, // not visible unless there is more than one action new go.Binding("visible", "actions", acts => (Array.isArray(acts) && acts.length > 0)), // headered by a label and a PanelExpanderButton inside a Table $(go.Panel, "Table", { stretch: go.GraphObject.Horizontal }, $(go.TextBlock, "Choices", { alignment: go.Spot.Left, font: "10pt Verdana, sans-serif" } ), $("PanelExpanderButton", "COLLAPSIBLE", // name of the object to make visible or invisible { column: 1, alignment: go.Spot.Right } ) ), // end Table panel // with the list data bound in the Vertical Panel $(go.Panel, "Vertical", { name: "COLLAPSIBLE", // identify to the PanelExpanderButton padding: 2, stretch: go.GraphObject.Horizontal, // take up whole available width background: "white", // to distinguish from the node's body defaultAlignment: go.Spot.Left, // thus no need to specify alignment on each element itemTemplate: actionTemplate // the Panel created for each item in Panel.itemArray }, new go.Binding("itemArray", "actions") // bind Panel.itemArray to nodedata.actions ) // end action list Vertical Panel ) // end optional Vertical Panel ) // end outer Vertical Panel ), // end "BODY" Auto Panel $(go.Panel, // this is underneath the "BODY" { height: 17 }, // always this height, even if the TreeExpanderButton is not visible $("TreeExpanderButton") ) ); // define a second kind of Node: myDiagram.nodeTemplateMap.add("Terminal", $(go.Node, "Spot", $(go.Shape, "Circle", { width: 55, height: 55, fill: greengrad, stroke: null } ), $(go.TextBlock, { font: "10pt Verdana, sans-serif" }, new go.Binding("text") ) ) ); myDiagram.linkTemplate = $(go.Link, go.Link.Orthogonal, { deletable: false, corner: 10 }, $(go.Shape, { strokeWidth: 2 } ), $(go.TextBlock, go.Link.OrientUpright, { background: "white", visible: false, // unless the binding sets it to true for a non-empty string segmentIndex: -2, segmentOrientation: go.Link.None }, new go.Binding("text", "answer"), // hide empty string; // if the "answer" property is undefined, visible is false due to above default setting new go.Binding("visible", "answer", a => a ? true : false) ) ); var nodeDataArray = [ { key: 1, question: "Greeting", actions: [ { text: "Sales", figure: "ElectricalHazard", fill: "blue" }, { text: "Parts and Services", figure: "FireHazard", fill: "red" }, { text: "Representative", figure: "IrritationHazard", fill: "yellow" } ] }, { key: 2, question: "Sales", actions: [ { text: "Compact", figure: "ElectricalHazard", fill: "blue" }, { text: "Mid-Size", figure: "FireHazard", fill: "red" }, { text: "Large", figure: "IrritationHazard", fill: "yellow" } ] }, { key: 3, question: "Parts and Services", actions: [ { text: "Maintenance", figure: "ElectricalHazard", fill: "blue" }, { text: "Repairs", figure: "FireHazard", fill: "red" }, { text: "State Inspection", figure: "IrritationHazard", fill: "yellow" } ] }, { key: 4, question: "Representative" }, { key: 5, question: "Compact" }, { key: 6, question: "Mid-Size" }, { key: 7, question: "Large", actions: [ { text: "SUV", figure: "ElectricalHazard", fill: "blue" }, { text: "Van", figure: "FireHazard", fill: "red" } ] }, { key: 8, question: "Maintenance" }, { key: 9, question: "Repairs" }, { key: 10, question: "State Inspection" }, { key: 11, question: "SUV" }, { key: 12, question: "Van" }, { key: 13, category: "Terminal", text: "Susan" }, { key: 14, category: "Terminal", text: "Eric" }, { key: 15, category: "Terminal", text: "Steven" }, { key: 16, category: "Terminal", text: "Tom" }, { key: 17, category: "Terminal", text: "Emily" }, { key: 18, category: "Terminal", text: "Tony" }, { key: 19, category: "Terminal", text: "Ken" }, { key: 20, category: "Terminal", text: "Rachel" } ]; var linkDataArray = [ { from: 1, to: 2, answer: 1 }, { from: 1, to: 3, answer: 2 }, { from: 1, to: 4, answer: 3 }, { from: 2, to: 5, answer: 1 }, { from: 2, to: 6, answer: 2 }, { from: 2, to: 7, answer: 3 }, { from: 3, to: 8, answer: 1 }, { from: 3, to: 9, answer: 2 }, { from: 3, to: 10, answer: 3 }, { from: 7, to: 11, answer: 1 }, { from: 7, to: 12, answer: 2 }, { from: 5, to: 13 }, { from: 6, to: 14 }, { from: 11, to: 15 }, { from: 12, to: 16 }, { from: 8, to: 17 }, { from: 9, to: 18 }, { from: 10, to: 19 }, { from: 4, to: 20 } ]; // create the Model with the above data, and assign to the Diagram myDiagram.model = new go.GraphLinksModel( { copiesArrays: true, copiesArrayObjects: true, nodeDataArray: nodeDataArray, linkDataArray: linkDataArray }); } window.addEventListener('DOMContentLoaded', init); </script> <div id="sample"> <div id="myDiagramDiv" style="border: solid 1px black; width:100%; height:500px"></div> <p> An <em>IVR tree</em>, or Interactive Voice Response Tree, is typically used by automated answering systems to direct calls to the correct party. This particular example is for a car dealership to route calls. </p> <p> This Interactive Voice Response Tree (IVR tree) has nodes that contain a collapsible list of actions, controlled by a <b>PanelExpanderButton</b>, with a <b>TreeExpanderButton</b> underneath the body. See the <a href="../intro/buttons.html">Intro page on Buttons</a> for more GoJS button information. </p> </div> </div> <!-- * * * * * * * * * * * * * --> <!-- End of GoJS sample code --> </div> </body> <!-- This script is part of the gojs.net website, and is not needed to run the sample --> <script src="../assets/js/goSamples.js"></script> </html>