UNPKG

8.76 kBHTMLView Raw
1<!DOCTYPE html>
2<html lang="en">
3<head>
4<meta charset="utf-8"/>
5<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no, viewport-fit=cover"/>
6<meta name="description" content="The Flow PanelLayout arranges panel elements in rows or columns."/>
7<link rel="stylesheet" href="../assets/css/style.css"/>
8<!-- Copyright 1998-2021 by Northwoods Software Corporation. -->
9<title>Flow PanelLayout</title>
10</head>
11
12<body>
13 <!-- This top nav is not part of the sample code -->
14 <nav id="navTop" class="w-full z-30 top-0 text-white bg-nwoods-primary">
15 <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">
16 <div class="md:pl-4">
17 <a class="text-white hover:text-white no-underline hover:no-underline
18 font-bold text-2xl lg:text-4xl rounded-lg hover:bg-nwoods-secondary " href="../">
19 <h1 class="mb-0 p-1 ">GoJS</h1>
20 </a>
21 </div>
22 <button id="topnavButton" class="rounded-lg sm:hidden focus:outline-none focus:ring" aria-label="Navigation">
23 <svg fill="currentColor" viewBox="0 0 20 20" class="w-6 h-6">
24 <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>
25 <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>
26 </svg>
27 </button>
28 <div id="topnavList" class="hidden sm:block items-center w-auto mt-0 text-white p-0 z-20">
29 <ul class="list-reset list-none font-semibold flex justify-end flex-wrap sm:flex-nowrap items-center px-0 pb-0">
30 <li class="p-1 sm:p-0"><a class="topnav-link" href="../learn/">Learn</a></li>
31 <li class="p-1 sm:p-0"><a class="topnav-link" href="../samples/">Samples</a></li>
32 <li class="p-1 sm:p-0"><a class="topnav-link" href="../intro/">Intro</a></li>
33 <li class="p-1 sm:p-0"><a class="topnav-link" href="../api/">API</a></li>
34 <li class="p-1 sm:p-0"><a class="topnav-link" href="https://www.nwoods.com/products/register.html">Register</a></li>
35 <li class="p-1 sm:p-0"><a class="topnav-link" href="../download.html">Download</a></li>
36 <li class="p-1 sm:p-0"><a class="topnav-link" href="https://forum.nwoods.com/c/gojs/11">Forum</a></li>
37 <li class="p-1 sm:p-0"><a class="topnav-link" href="https://www.nwoods.com/contact.html"
38 target="_blank" rel="noopener" onclick="getOutboundLink('https://www.nwoods.com/contact.html', 'contact');">Contact</a></li>
39 <li class="p-1 sm:p-0"><a class="topnav-link" href="https://www.nwoods.com/sales/index.html"
40 target="_blank" rel="noopener" onclick="getOutboundLink('https://www.nwoods.com/sales/index.html', 'buy');">Buy</a></li>
41 </ul>
42 </div>
43 </div>
44 <hr class="border-b border-gray-600 opacity-50 my-0 py-0" />
45 </nav>
46 <div class="md:flex flex-col md:flex-row md:min-h-screen w-full max-w-screen-xl mx-auto">
47 <div id="navSide" class="flex flex-col w-full md:w-48 text-gray-700 bg-white flex-shrink-0"></div>
48 <!-- * * * * * * * * * * * * * -->
49 <!-- Start of GoJS sample code -->
50
51
52 <div class="p-4 w-full">
53<div id="sample">
54 <div id="myDiagramDiv" style="border: solid 1px black; width:100%; height:600px"></div>
55 <p>
56 Each node has a "Flow" PanelLayout below the shape listing a bunch of text values in rows.
57 </p>
58 <p>
59 The context menu shown for each node has three "tabs", each showing some number of shape figures,
60 one of which the user can click to replace the node's shape's figure.
61 These tab panels use a "Flow" PanelLayout to arrange the shapes in columns,
62 by setting <a>PanelLayoutFlow.direction</a> to 90.
63 Note how for a custom <a>PanelLayout</a> one cannot use its name directly,
64 but must construct and initialize an instance of the PanelLayout.
65 </p>
66</div>
67
68<script type="module" id="code">
69 import * as go from "../release/go-module.js";
70 import { PanelLayoutFlow } from "./PanelLayoutFlow.js";
71
72 if (window.goSamples) goSamples(); // init for these samples -- you don't need to call this
73 const $ = go.GraphObject.make; // for conciseness in defining templates
74
75 const myDiagram =
76 $(go.Diagram, "myDiagramDiv",
77 { "undoManager.isEnabled": true });
78
79 myDiagram.nodeTemplate =
80 $(go.Node, "Vertical",
81 $(go.TextBlock,
82 { font: "bold 10pt sans-serif" },
83 new go.Binding("text")),
84 $(go.Shape,
85 {
86 width: 40, height: 40,
87 fill: "white",
88 portId: "",
89 fromSpot: go.Spot.LeftRightSides, toSpot: go.Spot.LeftRightSides
90 },
91 new go.Binding("fill", "color"),
92 new go.Binding("figure").makeTwoWay()),
93 $(go.Panel, "Flow",
94 new go.Binding("itemArray", "values"),
95 {
96 maxSize: new go.Size(40, NaN),
97 background: "transparent",
98 itemTemplate:
99 $(go.Panel,
100 $(go.TextBlock,
101 { font: "9pt sans-serif", margin: new go.Margin(1, 1, 0, 1) },
102 new go.Binding("text", ""))
103 )
104 }
105 )
106 );
107
108 myDiagram.nodeTemplate.contextMenu =
109 $(go.Adornment, "Table",
110 { background: "gray", defaultAlignment: go.Spot.Top, padding: 10 },
111 $(go.Panel, "Vertical",
112 { column: 0, stretch: go.GraphObject.Vertical, defaultStretch: go.GraphObject.Horizontal },
113 makeTabLabel("A Figures", true),
114 makeTabLabel("B Figures"),
115 makeTabLabel("C Figures")
116 ),
117 $(go.RowColumnDefinition, { column: 1, width: 10 }),
118 makeFlowPanel("A Figures", ["Square", "Circle", "RoundedRectangle", "Diamond"], true),
119 makeFlowPanel("B Figures", ["TriangleUp", "TriangleRight", "TriangleDown", "TriangleLeft"]),
120 makeFlowPanel("C Figures", ["LineH", "LineV", "BarH", "BarV", "MinusLine", "PlusLine", "XLine"]),
121 );
122
123 function makeTabLabel(name, selected) {
124 return $(go.TextBlock, name,
125 {
126 margin: new go.Margin(2, 2, 0, 2),
127 mouseEnter: function(e, tb) {
128 var ad = tb.part;
129 if (ad.selectedTextBlock === tb) return;
130 if (ad.selectedTextBlock) { // this keeps a reference to the selected TextBlock
131 ad.selectedTextBlock.background = null;
132 var oldpan = ad.findObject(ad.selectedTextBlock.text);
133 if (oldpan) oldpan.visible = false;
134 }
135 ad.selectedTextBlock = tb;
136 tb.background = "white";
137 var newpan = ad.findObject(tb.text);
138 if (newpan) newpan.visible = true;
139 }
140 });
141 }
142
143 function makeFlowPanel(name, figures, selected) {
144 return $(go.Panel, $(PanelLayoutFlow,
145 { spacing: new go.Size(5, 5), direction: 90 }),
146 {
147 name: name,
148 column: 2,
149 maxSize: new go.Size(NaN, 130),
150 visible: !!selected
151 },
152 figures.map(makeShape)
153 );
154 }
155
156 function makeShape(fig) {
157 return $(go.Shape, fig,
158 {
159 width: 30, height: 30,
160 fill: "white",
161 background: "transparent", // to catch a click anywhere in bounds
162 click: function(e, shape) {
163 var ad = shape.part;
164 e.diagram.commit(function(diag) {
165 diag.model.set(ad.data, "figure", fig);
166 ad.adornedPart.invalidateConnectedLinks();
167 }, "modified figure");
168 }
169 });
170 }
171
172
173 myDiagram.model = new go.GraphLinksModel(
174 [
175 { key: 1, text: "Alpha", color: "lightblue", values: ["A", "B", "C", "D", "E", "F", "G", "H"] },
176 { key: 2, text: "Beta", color: "orange", figure: "Diamond", values: ["I", "J"] },
177 { key: 3, text: "Gamma", color: "lightgreen", figure: "Circle", values: ["123", "456", "7890"] },
178 { key: 4, text: "Delta", color: "pink", figure: "Triangle" }
179 ],
180 [
181 { from: 1, to: 2 },
182 { from: 1, to: 3 },
183 { from: 3, to: 4 },
184 { from: 4, to: 1 }
185 ]);
186
187 window.myDiagram = myDiagram; // Attach to the window for console debugging
188</script>
189 </div>
190 <!-- * * * * * * * * * * * * * -->
191 <!-- End of GoJS sample code -->
192 </div>
193</body>
194<!-- This script is part of the gojs.net website, and is not needed to run the sample -->
195<script src="../assets/js/goSamples.js"></script>
196</html>