UNPKG

gojs

Version:

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

272 lines (255 loc) 12.4 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="TypeScript: Cause-and-effect diagrams using FishboneLayout, also known as Ishikawa or herringbone diagrams."/> <link rel="stylesheet" href="../assets/css/style.css"/> <!-- Copyright 1998-2023 by Northwoods Software Corporation. --> <title>Fishbone Layout</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 --> <div id="allSampleContent" class="p-4 w-full"> <div id="sample"> <div id="myDiagramDiv" style="height:550px;width:100%;border:1px solid black;"></div> <div id="buttons"> <label>Layout:</label> <button id="fishbone">Fishbone</button> <button id="branching">Branching</button> <button id="normal">Normal</button> </div> <p> This sample shows a "fishbone" layout of a tree model of cause-and-effect relationships. This type of layout is often seen in root cause analysis, or RCA. The layout is defined in its own file, as <a href="FishboneLayout.js" target="_blank">FishboneLayout.js</a>. When using FishboneLayout the diagram uses FishboneLink in order to get custom routing for the links. </p> <p> The buttons each set the <a>Diagram.layout</a> within a transaction. </p> </div> <script type="module" id="code"> import * as go from "../release/go-module.js"; import { FishboneLayout, FishboneLink } from './FishboneLayout.js'; if (window.goSamples) window.goSamples(); // init for these samples -- you don't need to call this const $ = go.GraphObject.make; // for conciseness in defining templates const myDiagram = new go.Diagram('myDiagramDiv', // refers to its DIV HTML element by id { isReadOnly: true }); // do not allow the user to modify the diagram // define the normal node template, just some text myDiagram.nodeTemplate = $(go.Node, $(go.TextBlock, new go.Binding('text'), new go.Binding('font', '', convertFont)) ); function convertFont(data) { let size = data.size; if (size === undefined) size = 13; let weight = data.weight; if (weight === undefined) weight = ''; return weight + ' ' + size + 'px sans-serif'; } // This demo switches the Diagram.linkTemplate between the "normal" and the "fishbone" templates. // If you are only doing a FishboneLayout, you could just set Diagram.linkTemplate // to the template named "fishbone" here, and not switch templates dynamically. // define the non-fishbone link template myDiagram.linkTemplateMap.add('normal', $(go.Link, { routing: go.Link.Orthogonal, corner: 4 }, $(go.Shape) )); // use this link template for fishbone layouts myDiagram.linkTemplateMap.add('fishbone', $(FishboneLink, // defined above $(go.Shape) )); // here is the structured data used to build the model const json = { 'text': 'Incorrect Deliveries', 'size': 18, 'weight': 'Bold', 'causes': [ { 'text': 'Skills', 'size': 14, 'weight': 'Bold', 'causes': [ { 'text': 'knowledge', 'weight': 'Bold', 'causes': [ { 'text': 'procedures', 'causes': [ { 'text': 'documentation' } ] }, { 'text': 'products' } ] }, { 'text': 'literacy', 'weight': 'Bold' } ] }, { 'text': 'Procedures', 'size': 14, 'weight': 'Bold', 'causes': [ { 'text': 'manual', 'weight': 'Bold', 'causes': [ { 'text': 'consistency' } ] }, { 'text': 'automated', 'weight': 'Bold', 'causes': [ { 'text': 'correctness' }, { 'text': 'reliability' } ] } ] }, { 'text': 'Communication', 'size': 14, 'weight': 'Bold', 'causes': [ { 'text': 'ambiguity', 'weight': 'Bold' }, { 'text': 'sales staff', 'weight': 'Bold', 'causes': [ { 'text': 'order details', 'causes': [ { 'text': 'lack of knowledge' } ] } ] }, { 'text': 'telephone orders', 'weight': 'Bold', 'causes': [ { 'text': 'lack of information' } ] }, { 'text': 'picking slips', 'weight': 'Bold', 'causes': [ { 'text': 'details' }, { 'text': 'legibility' } ] } ] }, { 'text': 'Transport', 'size': 14, 'weight': 'Bold', 'causes': [ { 'text': 'information', 'weight': 'Bold', 'causes': [ { 'text': 'incorrect person' }, { 'text': 'incorrect addresses', 'causes': [ { 'text': 'customer data base', 'causes': [ { 'text': 'not up-to-date' }, { 'text': 'incorrect program' } ] } ] }, { 'text': 'incorrect dept' } ] }, { 'text': 'carriers', 'weight': 'Bold', 'causes': [ { 'text': 'efficiency' }, { 'text': 'methods' } ] } ] } ] }; function walkJson(obj, arr) { const key = arr.length; obj.key = key; arr.push(obj); const children = obj.causes; if (children) { for (let i = 0; i < children.length; i++) { const o = children[i]; o.parent = key; // reference to parent node data walkJson(o, arr); } } } // build the tree model const nodeDataArray = []; walkJson(json, nodeDataArray); myDiagram.model = new go.TreeModel(nodeDataArray); layoutFishbone(); window.myDiagram = myDiagram; // Attach to the window for console debugging // use FishboneLayout and FishboneLink function layoutFishbone() { myDiagram.startTransaction('fishbone layout'); myDiagram.linkTemplate = myDiagram.linkTemplateMap.getValue('fishbone'); myDiagram.layout = go.GraphObject.make(FishboneLayout, { angle: 180, layerSpacing: 10, nodeSpacing: 20, rowSpacing: 10 }); myDiagram.commitTransaction('fishbone layout'); } // make the layout a branching tree layout and use a normal link template function layoutBranching() { myDiagram.startTransaction('branching layout'); myDiagram.linkTemplate = myDiagram.linkTemplateMap.getValue('normal'); myDiagram.layout = go.GraphObject.make(go.TreeLayout, { angle: 180, layerSpacing: 20, alignment: go.TreeLayout.AlignmentBusBranching }); myDiagram.commitTransaction('branching layout'); } // make the layout a basic tree layout and use a normal link template function layoutNormal() { myDiagram.startTransaction('normal layout'); myDiagram.linkTemplate = myDiagram.linkTemplateMap.getValue('normal'); myDiagram.layout = go.GraphObject.make(go.TreeLayout, { angle: 180, breadthLimit: 1000, alignment: go.TreeLayout.AlignmentStart }); myDiagram.commitTransaction('normal layout'); } document.getElementById("fishbone").onclick = layoutFishbone; document.getElementById("branching").onclick = layoutBranching; document.getElementById("normal").onclick = layoutNormal; </script> </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>