UNPKG

38.2 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
7<link rel="stylesheet" href="../assets/css/style.css"/>
8<!-- Copyright 1998-2021 by Northwoods Software Corporation. --> <title> GoJS Graduated Panels -- Northwoods Software </title>
9 <link rel="stylesheet" href="../assets/css/prism.css" />
10 </head>
11 <script>
12
13 window.diagrams = [];
14 window.goCode = function(pre, w, h, parentid, animation) {
15 window.diagrams.push([pre, w, h, parentid, animation]);
16 }
17 </script>
18 <body>
19 <nav id="navTop" class="w-full z-30 top-0 text-white bg-nwoods-primary">
20 <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">
21 <div class="md:pl-4">
22 <a class="text-white hover:text-white no-underline hover:no-underline
23 font-bold text-2xl lg:text-4xl rounded-lg hover:bg-nwoods-secondary " href="../">
24 <h1 class="mb-0 p-1 ">GoJS</h1>
25 </a>
26 </div>
27 <button id="topnavButton" class="rounded-lg sm:hidden focus:outline-none focus:ring" aria-label="Navigation">
28 <svg fill="currentColor" viewBox="0 0 20 20" class="w-6 h-6">
29 <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>
30 <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>
31 </svg>
32 </button>
33 <div id="topnavList" class="hidden sm:block items-center w-auto mt-0 text-white p-0 z-20">
34 <ul class="list-reset list-none font-semibold flex justify-end flex-wrap sm:flex-nowrap items-center px-0 pb-0">
35 <li class="p-1 sm:p-0"><a class="topnav-link" href="../learn/">Learn</a></li>
36 <li class="p-1 sm:p-0"><a class="topnav-link" href="../samples/">Samples</a></li>
37 <li class="p-1 sm:p-0"><a class="topnav-link" href="../intro/">Intro</a></li>
38 <li class="p-1 sm:p-0"><a class="topnav-link" href="../api/">API</a></li>
39 <li class="p-1 sm:p-0"><a class="topnav-link" href="https://www.nwoods.com/products/register.html">Register</a></li>
40 <li class="p-1 sm:p-0"><a class="topnav-link" href="../download.html">Download</a></li>
41 <li class="p-1 sm:p-0"><a class="topnav-link" href="https://forum.nwoods.com/c/gojs/11">Forum</a></li>
42 <li class="p-1 sm:p-0"><a class="topnav-link" href="https://www.nwoods.com/contact.html"
43 target="_blank" rel="noopener" onclick="getOutboundLink('https://www.nwoods.com/contact.html', 'contact');">Contact</a></li>
44 <li class="p-1 sm:p-0"><a class="topnav-link" href="https://www.nwoods.com/sales/index.html"
45 target="_blank" rel="noopener" onclick="getOutboundLink('https://www.nwoods.com/sales/index.html', 'buy');">Buy</a></li>
46 </ul>
47 </div>
48 </div>
49 <hr class="border-b border-gray-600 opacity-50 my-0 py-0" />
50 </nav>
51
52 <div class="md:flex flex-col md:flex-row md:min-h-screen w-full max-w-screen-xl mx-auto">
53
54 <div id="navSide" class="flex flex-col w-full md:w-40 lg:w-48 text-gray-700 bg-white flex-shrink-0">
55 <div class="flex-shrink-0 px-8 py-4">
56 <button id="navButton" class="rounded-lg md:hidden focus:outline-none focus:ring" aria-label="Navigation">
57 <svg fill="currentColor" viewBox="0 0 20 20" class="w-6 h-6">
58 <path id="navOpen" 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>
59 <path id="navClosed" 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>
60 </svg>
61 </button>
62 </div>
63 <nav id="navList" class="min-h-screen hidden md:block sidebar-nav flex-grow px-1 lg:px-4 pb-4 md:pb-0 md:overflow-y-auto break-words">
64 <a href="index.html">Basics</a>
65 <a href="buildingObjects.html">Building Parts</a>
66 <a href="usingModels.html">Using Models</a>
67 <a href="dataBinding.html">Data Binding</a>
68 <a href="react.html">GoJS with React</a>
69 <a href="angular.html">GoJS with Angular</a>
70 <a href="textBlocks.html">TextBlocks</a>
71 <a href="shapes.html">Shapes</a>
72 <a href="pictures.html">Pictures</a>
73 <a href="panels.html">Panels</a>
74 <a href="tablePanels.html">Table Panels</a>
75 <a href="brush.html">Brushes</a>
76 <a href="sizing.html">Sizing Objects</a>
77 <a href="itemArrays.html">Item Arrays</a>
78 <a href="changedEvents.html">Changed Events</a>
79 <a href="transactions.html">Transactions</a>
80 <a href="viewport.html">Coordinates</a>
81 <a href="initialView.html">Initial View</a>
82 <a href="collections.html">Collections</a>
83 <a href="links.html">Links</a>
84 <a href="linkLabels.html">Link Labels</a>
85 <a href="connectionPoints.html">Link Points</a>
86 <a href="ports.html">Ports</a>
87 <a href="nodes.html">Nodes</a>
88 <a href="debugging.html">Debugging</a>
89 <a href="layouts.html">Layouts</a>
90 <a href="trees.html">Trees</a>
91 <a href="subtrees.html">SubTrees</a>
92 <a href="groups.html">Groups</a>
93 <a href="subgraphs.html">SubGraphs</a>
94 <a href="sizedGroups.html">Sized Groups</a>
95 <a href="selection.html">Selection</a>
96 <a href="highlighting.html">Highlighting</a>
97 <a href="animation.html">Animation</a>
98 <a href="toolTips.html">ToolTips</a>
99 <a href="contextmenus.html">Context Menus</a>
100 <a href="events.html">Diagram Events</a>
101 <a href="tools.html">Tools</a>
102 <a href="commands.html">Commands</a>
103 <a href="permissions.html">Permissions</a>
104 <a href="validation.html">Validation</a>
105 <a href="HTMLInteraction.html">HTML Interaction</a>
106 <a href="layers.html">Layers &amp; Z-ordering</a>
107 <a href="palette.html">Palette</a>
108 <a href="overview.html">Overview</a>
109 <a href="resizing.html">Resizing Diagrams</a>
110 <a href="replacingDeleting.html">Replacing and Deleting</a>
111 <a href="buttons.html">Buttons</a>
112 <a href="templateMaps.html">Template Maps</a>
113 <a href="legends.html">Legends and Titles</a>
114 <a href="extensions.html">Extensions</a>
115 <a href="geometry.html">Geometry Strings</a>
116 <a href="grids.html">Grid Patterns</a>
117 <a href="graduatedPanels.html">Graduated Panels</a>
118 <a href="makingImages.html">Diagram Images</a>
119 <a href="makingSVG.html">Diagram SVG</a>
120 <a href="printing.html">Printing</a>
121 <a href="serverSideImages.html">Server-side Images</a>
122 <a href="nodeScript.html">GoJS in Node.js</a>
123 <a href="testing.html">Testing</a>
124 <a href="storage.html">Storage</a>
125 <a href="performance.html">Performance</a>
126 <a href="source.html">Building from Source</a>
127 <a href="platforms.html">Platforms</a>
128 <a href="deployment.html">Deployment</a>
129 </nav>
130 </div>
131 <div class="pt-4 px-2 md:px-0 lg:px-4 pb-16 w-full overflow-hidden">
132
133<h1>Graduated Panels</h1>
134<p>
135 The "Graduated" Panel, <a>Panel,Graduated</a>,
136 draws regular tick marks and/or text labels along the stroke of the main child <a>Shape</a>.
137 Graduated Panels can be considered scales showing a range of values.
138</p>
139<p>
140 For examples of Graduated Panels see the <a href="../samples/timeline.html">Timeline</a>,
141 <a href="../samples/thermometer.html">Thermometer</a>,
142 <a href="../samples/instrumentGauge.html">Instrument Gauge</a>,
143 and <a href="../samples/ruleredDiagram.html">Rulered Diagram</a> samples.
144</p>
145
146<h2 id="SimpleGraduatedPanels">Simple Graduated Panels</h2>
147<p>
148 Similar to Auto and Spot Panels, Graduated Panels should have two or more elements in them.
149 Elements must be either <a>Shape</a>s or <a>TextBlock</a>s.
150 The main Shape element may be declared by setting <a>GraphObject.isPanelMain</a> to true;
151 but no such setting is needed if it is the very first element of the panel.
152 Shapes and TextBlocks, other than the main Shape, basically act as templates for the drawing of each tick mark and label.
153</p>
154<p>
155 Tick mark <a>Shape</a>s within a Graduated Panel should have a measured size, either by setting a <a>GraphObject.desiredSize</a>
156 (or <code>width</code> and <code>height</code> properties), or by setting its <a>Shape.geometry</a>.
157 For basic tick marks drawn normal to the main Shape's path,
158 it is easiest to use a simple vertical line geometry string: <code>M0 0 V10</code>.
159 The height of the geometry will determine the length of the tick mark.
160</p>
161
162<pre class="lang-js" id="graduatedSimple"><code>
163diagram.add(
164 // all Parts are Panels
165 $(go.Part, go.Panel.Graduated, // or "Graduated"
166 $(go.Shape, { geometryString: "M0 0 H400" }), // the main shape, a horizontal line
167 $(go.Shape, { geometryString: "M0 0 V10" }) // a tick mark, a vertical line
168 ));
169</code></pre>
170<script>goCode("graduatedSimple", 500, 100)</script>
171
172<p>
173 Any shape, including custom geometries, can be used as the main Shape or as a tick mark Shape of a Graduated Panel.
174</p>
175<pre class="lang-js" id="graduatedCircle"><code>
176diagram.add(
177 $(go.Part, "Graduated",
178 { background: "transparent" }, // make panel pickable
179 // main shape is a whole circle
180 $(go.Shape, "Circle",
181 { fill: null, desiredSize: new go.Size(150, 150) }),
182 // tick shape is a double line
183 $(go.Shape, { geometryString: "M0 0 V10 M3 0 V10" })
184 ));
185</code></pre>
186<script>goCode("graduatedCircle", 200, 200)</script>
187
188<p>
189 Graduated Panels can also be labeled with TextBlocks denoting the values along the scale.
190 Often, these will be offset from the main stroke using <a>GraphObject.segmentOffset</a>, as one would
191 with Link labels, so that the text does not overlap the main stroke.
192 More detail on placing labels is in the "Appearance" section below.
193</p>
194<pre class="lang-js" id="graduatedLabels"><code>
195diagram.add(
196 $(go.Part, "Graduated",
197 { background: "transparent" }, // make panel pickable
198 $(go.Shape, { geometryString: "M0 0 H400" }), // the main shape
199 $(go.TextBlock, { segmentOffset: new go.Point(0, 12) }) // tick labels
200 ));
201</code></pre>
202<script>goCode("graduatedLabels", 500, 100)</script>
203
204<h2 id="GraduatedPanelProperties">Graduated Panel Properties</h2>
205<p>
206 There are a number of properties that govern the appearance of tick marks and labels.
207</p>
208
209<h3 id="TickMarkValues">Tick Mark Values</h3>
210<p>
211 The graduated values of a Graduated Panel will range on a linear scale from the start of the
212 main shape's stroke to the end of the stroke.
213 The values and frequency of tick marks and labels are governed by a few properties:
214</p>
215<ul>
216 <li><a>Panel.graduatedMin</a>
217 - the minimum value represented on the scale, at the beginning of the stroke of the main shape</li>
218 <li><a>Panel.graduatedMax</a>
219 - the maximum value represented on the scale, at the end of the main shape</li>
220 <li><a>Panel.graduatedTickBase</a>
221 - the value of the "origin" tick mark, the first tick mark if it is the same as graduatedMin</li>
222 <li><a>Panel.graduatedTickUnit</a>
223 - tick marks are positioned at multiples of the graduatedTickUnit added to the graduatedTickBase</li>
224 <li><a>Shape.interval</a>/<a>TextBlock.interval</a>
225 - a multiple of the graduatedTickUnit at which to draw a tick or label</li>
226</ul>
227<p>
228 Graduated Panels can have multiple Shapes as tick marks and multiple TextBlocks as labels,
229 with the interval property controlling at what multiples of the <code>graduatedTickUnit</code> they are drawn.
230 In many of the examples below, larger ticks are drawn at intervals of 4; some have an interval of 5.
231</p>
232
233<p>
234 A <code>graduatedMin</code> of <code>0</code>, <code>graduatedMax</code> of <code>77</code>,
235 <code>graduatedTickBase</code> of <code>0</code>, <code>graduatedTickUnit</code> of <code>2.5</code>,
236 and intervals of 4 result in a scale that might appear as:
237</p>
238<pre class="lang-js" id="graduatedVals1"><code>
239diagram.add(
240 $(go.Part, "Graduated",
241 {
242 graduatedMin: 0, graduatedMax: 77,
243 graduatedTickBase: 0, graduatedTickUnit: 2.5,
244 background: "transparent"
245 },
246 $(go.Shape, { geometryString: "M0 0 H400" }), // the main Shape
247 // a short, frequent tick mark
248 $(go.Shape, { geometryString: "M0 0 V5" }),
249 // a longer tick mark every four ticks
250 $(go.Shape, { geometryString: "M0 0 V10", interval: 4 }),
251 // text label only every four ticks, with a vertical offset
252 $(go.TextBlock, { segmentOffset: new go.Point(0, 12), interval: 4 })
253 ));
254</code></pre>
255<script>goCode("graduatedVals1", 500, 100)</script>
256
257<p>
258 Changing <code>graduatedMin</code> to <code>-23</code> results in:
259</p>
260<pre class="lang-js" id="graduatedVals2"><code>
261diagram.add(
262 $(go.Part, "Graduated",
263 {
264 graduatedMin: -23, graduatedMax: 77,
265 graduatedTickBase: 0, graduatedTickUnit: 2.5,
266 background: "transparent"
267 },
268 $(go.Shape, { geometryString: "M0 0 H400" }), // the main Shape
269 $(go.Shape, { geometryString: "M0 0 V5" }), // short tick mark
270 $(go.Shape, { geometryString: "M0 0 V10", interval: 4 }), // long tick mark
271 $(go.TextBlock, { segmentOffset: new go.Point(0, 12), interval: 4 }) // labels
272 ));
273</code></pre>
274<script>goCode("graduatedVals2", 500, 100)</script>
275<p>
276 The range from the min to the max value (<a>Panel.graduatedRange</a>) has increased from 77 to 100,
277 so the tick marks are closer to each other for the same length main path.
278</p>
279
280<p>
281 Changing <code>graduatedTickBase</code> to <code>1.2</code> results in:
282</p>
283<pre class="lang-js" id="graduatedVals3"><code>
284diagram.add(
285 $(go.Part, "Graduated",
286 {
287 graduatedMin: -23, graduatedMax: 77,
288 graduatedTickBase: 1.2, graduatedTickUnit: 2.5,
289 background: "transparent"
290 },
291 $(go.Shape, { geometryString: "M0 0 H400" }), // the main Shape
292 $(go.Shape, { geometryString: "M0 0 V5" }), // short tick mark
293 $(go.Shape, { geometryString: "M0 0 V10", interval: 4 }), // long tick mark
294 $(go.TextBlock, { segmentOffset: new go.Point(0, 12), interval: 4 }) // labels
295 ));
296</code></pre>
297<script>goCode("graduatedVals3", 500, 100)</script>
298<p>
299 Basically, the "origin" for the scale has shifted slightly, even though the end values remain the same.
300 There will always be a tick mark at the <code>graduatedTickBase</code>
301 if that value is within the range of the graduated scale.
302</p>
303
304<p>
305 Doubling the <code>graduatedTickUnit</code> to <code>5</code> results in:
306</p>
307<pre class="lang-js" id="graduatedVals4"><code>
308diagram.add(
309 $(go.Part, "Graduated",
310 {
311 graduatedMin: -23, graduatedMax: 77,
312 graduatedTickBase: 1.2, graduatedTickUnit: 5,
313 background: "transparent"
314 },
315 $(go.Shape, { geometryString: "M0 0 H400" }),
316 $(go.Shape, { geometryString: "M0 0 V5" }), // short tick mark
317 $(go.Shape, { geometryString: "M0 0 V10", interval: 4 }), // long tick mark
318 $(go.TextBlock, { segmentOffset: new go.Point(0, 12), interval: 4 }) // labels
319 ));
320</code></pre>
321<script>goCode("graduatedVals4", 500, 100)</script>
322<p>
323 Doubling the tick unit halves the number of ticks for the same length path, but again the end values are unchanged.
324</p>
325
326<p>
327 Changing <code>graduatedTickBase</code> back to <code>0</code> and the intervals to <code>5</code> results in:
328</p>
329<pre class="lang-js" id="graduatedVals5"><code>
330diagram.add(
331 $(go.Part, "Graduated",
332 {
333 graduatedMin: -23, graduatedMax: 77,
334 graduatedTickBase: 0, graduatedTickUnit: 5,
335 background: "transparent"
336 },
337 $(go.Shape, { geometryString: "M0 0 H400" }),
338 $(go.Shape, { geometryString: "M0 0 V5" }), // short tick mark
339 $(go.Shape, { geometryString: "M0 0 V10", interval: 5 }), // long tick mark
340 $(go.TextBlock, { interval: 5, segmentOffset: new go.Point(0, 12) })
341 ));
342</code></pre>
343<script>goCode("graduatedVals5", 500, 100)</script>
344
345<p>
346 You can have more than one label. For example, small text that is more frequent than larger text:
347</p>
348<pre class="lang-js" id="graduated2Labels"><code>
349diagram.add(
350 $(go.Part, "Graduated",
351 {
352 graduatedMin: 0, graduatedMax: 140,
353 graduatedTickBase: 0, graduatedTickUnit: 5,
354 background: "transparent"
355 },
356 $(go.Shape, { geometryString: "M0 0 H450" }), // longer line
357 $(go.Shape, { geometryString: "M0 0 V5" }),
358 $(go.Shape, { geometryString: "M0 0 V10", interval: 4 }),
359 // minor label
360 $(go.TextBlock, { interval: 2, segmentOffset: new go.Point(0, 8),
361 stroke: "blue", font: "7pt sans-serif" }),
362 // major label
363 $(go.TextBlock, { interval: 4, segmentOffset: new go.Point(0, 12),
364 stroke: "red", font: "bold 12pt sans-serif" })
365 ));
366</code></pre>
367<script>goCode("graduated2Labels", 500, 100)</script>
368
369<h3 id="TickMarkAppearance">Tick Mark Appearance</h3>
370<p>
371 The appearance of tick marks relative to the main shape path is controlled by a few properties:
372</p>
373<ul>
374 <li><a>Shape.graduatedStart</a>/<a>TextBlock.graduatedStart</a>
375 - the fractional distance along the main stroke at which drawing this tick or label may begin</li>
376 <li><a>Shape.graduatedEnd</a>/<a>TextBlock.graduatedEnd</a>
377 - the fractional distance along the main stroke beyond which it will not draw this tick or label</li>
378 <li><a>GraphObject.alignmentFocus</a>
379 - the spot on the tick or label to align with the calculated path points, defaulting to the top center</li>
380 <li><a>GraphObject.segmentOffset</a>
381 - how much to offset a TextBlock label from the main stroke -- the Y value specifies distance from the path</li>
382 <li><a>GraphObject.segmentOrientation</a>
383 - how to rotate a TextBlock label relative to the main stroke</li>
384</ul>
385<p>
386 Only TextBlock labels should set the <a>GraphObject.segmentOffset</a> or <a>GraphObject.segmentOrientation</a>.
387 They have no impact on the main shape or tick shapes.
388 These GraphObject properties are also commonly used to place Link labels,
389 as seen in the <a href="linkLabels.html">Introduction page on Link labels</a>,
390 and are used by Graduated Panels in a similar manner.
391</p>
392
393<p>
394 Setting <code>graduatedStart</code> and/or <code>graduatedEnd</code> allows for drawing ticks only along part of the main stroke:
395</p>
396<pre class="lang-js" id="graduatedAppr1"><code>
397diagram.add(
398 $(go.Part, "Graduated",
399 $(go.Shape, { geometryString: "M0 0 H400" }),
400 $(go.Shape, { geometryString: "M0 0 V10", graduatedStart: .25, graduatedEnd: .75 })
401 ));
402</code></pre>
403<script>goCode("graduatedAppr1", 500, 100)</script>
404<p>
405 In this case, tick marks are now only drawn in the middle half of the main shape.
406</p>
407
408<p>
409 Setting <code>alignmentFocus</code> to <code>go.Spot.Bottom</code> will cause the ticks to have their bottoms aligned to the main stroke:
410</p>
411<pre class="lang-js" id="graduatedAppr2"><code>
412diagram.add(
413 $(go.Part, "Graduated",
414 $(go.Shape, { geometryString: "M0 0 H400" }),
415 $(go.Shape, { geometryString: "M0 0 V10", alignmentFocus: go.Spot.Bottom })
416 ));
417</code></pre>
418<script>goCode("graduatedAppr2", 500, 100)</script>
419
420<p>
421 Setting <code>alignmentFocus</code> to <code>go.Spot.Center</code> will cause the ticks to be centered across the path:
422</p>
423<pre class="lang-js" id="graduatedAppr21"><code>
424diagram.add(
425 $(go.Part, "Graduated",
426 $(go.Shape, { geometryString: "M0 0 H400" }),
427 $(go.Shape, { geometryString: "M0 0 V10 M0 20 V30", alignmentFocus: go.Spot.Center })
428 ));
429</code></pre>
430<script>goCode("graduatedAppr21", 500, 100)</script>
431<p>
432 Note the gap in the geometry of the shape.
433</p>
434
435<p>
436 Setting <code>segmentOffset</code> for labels can make them more readable near tick marks:
437</p>
438<pre class="lang-js" id="graduatedAppr3"><code>
439diagram.add(
440 $(go.Part, "Graduated",
441 $(go.Shape, { geometryString: "M0 0 H400" }),
442 $(go.Shape, { geometryString: "M0 0 V10" }),
443 // offset to display below ticks
444 $(go.TextBlock, { segmentOffset: new go.Point(0, 12) })
445 ));
446</code></pre>
447<script>goCode("graduatedAppr3", 500, 100)</script>
448
449<p>
450 Setting <code>segmentOrientation</code> for labels can alter the angle at which they are drawn relative to the main stroke:
451</p>
452<pre class="lang-js" id="graduatedAppr4"><code>
453diagram.add(
454 $(go.Part, "Graduated",
455 $(go.Shape, { geometryString: "M0 0 H400" }),
456 $(go.Shape, { geometryString: "M0 0 V10" }),
457 // change the angle of the text
458 $(go.TextBlock, { segmentOrientation: go.Link.OrientMinus90 })
459 ));
460</code></pre>
461<script>goCode("graduatedAppr4", 500, 100)</script>
462<p>
463 Note that the top-center point of each label is exactly at the point along the path for that value.
464</p>
465
466<p>
467 Combining these two properties and re-aligning the tick marks:
468</p>
469<pre class="lang-js" id="graduatedAppr5"><code>
470diagram.add(
471 $(go.Part, "Graduated",
472 $(go.Shape, { geometryString: "M0 0 H400" }),
473 $(go.Shape, { geometryString: "M0 0 V10", alignmentFocus: go.Spot.Bottom }),
474 $(go.TextBlock,
475 {
476 alignmentFocus: go.Spot.Left,
477 segmentOffset: new go.Point(0, -12),
478 segmentOrientation: go.Link.OrientMinus90
479 }
480 )
481 ));
482</code></pre>
483<script>goCode("graduatedAppr5", 500, 100)</script>
484<p>
485 These properties behave similarly to Link labels, in that they respond to the direction of the main stroke.
486 For example, let us turn the main shape so that it goes diagonally down from the top-left to the bottom-right.
487</p>
488<pre class="lang-js" id="graduatedApprDiag"><code>
489diagram.add(
490 $(go.Part, "Graduated",
491 $(go.Shape, { geometryString: "M0 0 L285 285" }),
492 $(go.Shape, { geometryString: "M0 0 V10", alignmentFocus: go.Spot.Bottom }),
493 $(go.TextBlock,
494 {
495 alignmentFocus: go.Spot.Left,
496 segmentOffset: new go.Point(0, -12),
497 segmentOrientation: go.Link.OrientMinus90
498 }
499 )
500 ));
501</code></pre>
502<script>goCode("graduatedApprDiag", 350, 350)</script>
503
504<p>
505 Now let us try a curve:
506</p>
507<pre class="lang-js" id="graduatedApprCurve"><code>
508diagram.add(
509 $(go.Part, "Graduated",
510 $(go.Shape, "Curve1", { desiredSize: new go.Size(285, 285) }),
511 $(go.Shape, { geometryString: "M0 0 V10", alignmentFocus: go.Spot.Bottom }),
512 $(go.TextBlock,
513 {
514 alignmentFocus: go.Spot.Left,
515 segmentOffset: new go.Point(0, -12),
516 segmentOrientation: go.Link.OrientMinus90
517 }
518 )
519 ));
520</code></pre>
521<script>goCode("graduatedApprCurve", 350, 350)</script>
522
523<p>
524 Here's another commonplace configuration:
525</p>
526<pre class="lang-js" id="graduatedApprCurve2"><code>
527diagram.add(
528 $(go.Part, "Graduated",
529 $(go.Shape, { geometryString: "M0 0 A120 120 0 0 1 200 0" }), // an arc
530 $(go.Shape, { geometryString: "M0 0 V10" }),
531 $(go.TextBlock,
532 {
533 segmentOffset: new go.Point(0, 12),
534 segmentOrientation: go.Link.OrientAlong
535 }
536 )
537 ));
538</code></pre>
539<script>goCode("graduatedApprCurve2", 350, 100)</script>
540
541<p>
542 For vertical lines, it's not necessary to rotate the text:
543</p>
544<pre class="lang-js" id="graduatedApprVert"><code>
545diagram.add(
546 $(go.Part, "Graduated",
547 $(go.Shape, { geometryString: "M0 0 V400" }),
548 $(go.Shape, { geometryString: "M0 0 V10", alignmentFocus: go.Spot.Bottom }),
549 $(go.TextBlock,
550 {
551 alignmentFocus: go.Spot.Left,
552 segmentOffset: new go.Point(0, -12)
553 }
554 )
555 ));
556</code></pre>
557<script>goCode("graduatedApprVert", 100, 450)</script>
558
559<p>
560 We can also go from bottom to top:
561</p>
562<pre class="lang-js" id="graduatedApprVertUp"><code>
563diagram.add(
564 $(go.Part, "Graduated",
565 $(go.Shape, { geometryString: "M0 0 V-400" }),
566 $(go.Shape, { geometryString: "M0 0 V10", alignmentFocus: go.Spot.Top }),
567 $(go.TextBlock,
568 {
569 alignmentFocus: go.Spot.Left,
570 segmentOffset: new go.Point(0, 12)
571 }
572 )
573 ));
574</code></pre>
575<script>goCode("graduatedApprVertUp", 100, 450)</script>
576<p>
577 Note how the Geometry goes from 0,0 to 0,-400, because negative Y values are higher on the screen/page.
578 Note how because everything is relative to the path, the tick marks and labels would be on the opposite side,
579 so we have also changed the <code>alignmentFocus</code> and <code>segmentOffset</code> to have opposite values
580 from the previous example.
581</p>
582
583<p>
584 Lastly, any angle specified on a label will be respected if orientation is one of <a>Link.OrientNone</a>,
585 <a>Link.OrientAlong</a>, or <a>Link.OrientUpright</a>. In the case of Along and Upright, the angle will be
586 added to the slope of the main path at the point of the TextBlock.
587</p>
588<pre class="lang-js" id="graduatedApprTxtAngle"><code>
589 diagram.add(
590 $(go.Part, "Spot",
591 $(go.Panel, "Graduated",
592 $(go.Shape, { geometryString: "M0 0 L100 0 100 100 L0 100" }),
593 $(go.Shape, { geometryString: "M0 0 V10" }),
594 $(go.TextBlock,
595 {
596 interval: 5,
597 angle: 45,
598 segmentOffset: new go.Point(0, 12)
599 }
600 )
601 ),
602 $(go.TextBlock, "None")
603 ));
604
605 diagram.add(
606 $(go.Part, "Spot",
607 $(go.Panel, "Graduated",
608 $(go.Shape, { geometryString: "M0 0 L100 0 100 100 L0 100" }),
609 $(go.Shape, { geometryString: "M0 0 V10" }),
610 $(go.TextBlock,
611 {
612 interval: 5,
613 angle: 45,
614 segmentOrientation: go.Link.OrientAlong,
615 segmentOffset: new go.Point(0, 12)
616 }
617 )
618 ),
619 $(go.TextBlock, "Along")
620 ));
621
622 diagram.add(
623 $(go.Part, "Spot",
624 $(go.Panel, "Graduated",
625 $(go.Shape, { geometryString: "M0 0 L100 0 100 100 L0 100" }),
626 $(go.Shape, { geometryString: "M0 0 V10" }),
627 $(go.TextBlock,
628 {
629 interval: 5,
630 angle: 45,
631 segmentOrientation: go.Link.OrientUpright,
632 segmentOffset: new go.Point(0, 12)
633 }
634 )
635 ),
636 $(go.TextBlock, "Upright")
637 ));
638 </code></pre>
639 <script>goCode("graduatedApprTxtAngle", 300, 300)</script>
640 <p>
641 With None, the labels are always 45 degrees. With Along, the labels are always 45 degrees more than the slope.
642 With Upright, the labels are always 45 degrees more than the slope, then rotated upright if necessary.
643 </p>
644
645<h3 id="FunctionalAppearanceProperties">Functional Appearance Properties</h3>
646<p>
647 There are also some functional properties allowing for further customization of the appearance of ticks and labels.
648</p>
649<ul>
650 <li><a>Shape.graduatedSkip</a>/<a>TextBlock.graduatedSkip</a>
651 - an optional function which returns true for values that should be skipped while drawing a particular tick or label</li>
652 <li><a>TextBlock.graduatedFunction</a>
653 - an optional function which converts a value to a string to be displayed at that value -- if not defined, the default returns the value rounded to at most two decimals</li>
654</ul>
655
656<p>
657 Setting <code>graduatedSkip</code> allows for skipping ticks where the supplied function returns true:
658</p>
659<pre class="lang-js" id="graduatedSkip"><code>
660 diagram.add(
661 $(go.Part, "Graduated",
662 $(go.Shape, { geometryString: "M0 0 H400" }),
663 $(go.Shape,
664 { // skip drawing tick at 30
665 graduatedSkip: function (v) { return v === 30; },
666 geometryString: "M0 0 V10"
667 }
668 ),
669 $(go.TextBlock, { segmentOffset: new go.Point(0, 12) })
670 ));
671</code></pre>
672<script>goCode("graduatedSkip", 500, 100)</script>
673
674<p>
675 Setting <code>graduatedFunction</code> allows for changing the way labels are displayed:
676</p>
677<pre class="lang-js" id="graduatedFunc"><code>
678 diagram.add(
679 $(go.Part, "Graduated",
680 $(go.Shape, { geometryString: "M0 0 H400" }),
681 $(go.Shape, { geometryString: "M0 0 V10" }),
682 $(go.TextBlock,
683 { // always display two decimals
684 graduatedFunction: function(val) { return val.toFixed(2); },
685 segmentOffset: new go.Point(0, 12)
686 }
687 )
688 ));
689</code></pre>
690<script>goCode("graduatedFunc", 500, 100)</script>
691
692<h2 id="GraduatedValueComputations">Graduated Value Computations</h2>
693<p>
694 There are some methods available for computing points along graduated paths:
695</p>
696<ul>
697 <li><a>Panel.graduatedPointForValue</a>
698 - returns the Point along the main shape at some value between graduatedMin and graduatedMax in Panel coordinates</li>
699 <li><a>Panel.graduatedValueForPoint</a>
700 - returns the value along the main shape nearest a given Point</li>
701</ul>
702<p>
703 In the following example, the red marker uses a <a>Part.dragComputation</a> function that
704 keeps it along the path of the Graduated Panel using the above functions.
705</p>
706
707<pre class="lang-js" id="graduatedPointValueCalc"><code>
708var gauge =
709 $(go.Part, "Auto",
710 { location: new go.Point(10, 20) },
711 $(go.Shape, { fill: "white" }),
712 $(go.Panel, "Graduated",
713 { name: "SCALE", margin: 10 },
714 $(go.Shape, { name: "PATH", geometryString: "M0 0 A120 120 0 0 1 200 0" }),
715 $(go.Shape, { geometryString: "M0 0 V10" }),
716 $(go.TextBlock,
717 { segmentOffset: new go.Point(0, 12), segmentOrientation: go.Link.OrientAlong })
718 )
719 );
720diagram.add(gauge);
721
722var marker =
723 $(go.Part, "Spot",
724 { locationSpot: go.Spot.Center, selectionAdorned: false },
725 $(go.Shape, "Circle", { fill: "transparent", strokeWidth: 0, cursor: "pointer" }),
726 $(go.Shape, "Circle", { fill: "red", strokeWidth: 0, width: 8, height: 8 }),
727 {
728 dragComputation: function(node, pt) {
729 var scale = gauge.findObject("SCALE");
730 var loc = scale.getLocalPoint(pt);
731 var val = scale.graduatedValueForPoint(loc);
732 var gpt = scale.graduatedPointForValue(val);
733 return scale.getDocumentPoint(gpt);
734 }
735 }
736 );
737diagram.add(marker);
738
739// once everything has been positioned, give the marker its location
740diagram.addDiagramListener("InitialLayoutCompleted", function(e) {
741 var scale = gauge.findObject("SCALE");
742 var gpt = scale.graduatedPointForValue(0);
743 marker.location = scale.getDocumentPoint(gpt);
744});
745</code></pre>
746<script>goCode("graduatedPointValueCalc", 350, 200)</script>
747<p>
748 As you drag the red circle, you will notice that it always stays on the main shape's stroke.
749 The computation converts the point to the panel's coordinate system, computes the closest graduated value,
750 computes the point on the shape geometry for that value, and finally converts it back to document coordinates
751 for use as the marker's location.
752</p>
753<p>
754 Note that for demonstration purposes this example has the marker being a separate Part from the "gauge" Part.
755 A real gauge would have the marker be part of the gauge as an indicator of a particular value, optionally draggable by the user.
756 See some examples at <a href="../samples/controlGauges.html" target="_blank">Instrument Controls: Gauges and Meters</a>.
757</p>
758
759<h2 id="OtherConsiderations">Other Considerations</h2>
760<p>
761 By default, only the main shape of a Graduated Panel can be used to pick the panel.
762 As with Grid Panels, a Graduated Panel should have a non-null <code>background</code> if the entire panel needs to be pickable.
763 You cannot set or bind the <a>Panel.itemArray</a> of a Graduated Panel.
764 You can set and bind properties on tick <a>Shape</a>s and <a>TextBlock</a> labels
765 as you can with any other <a>GraphObject</a> properties.
766</p>
767<pre class="lang-js" id="graduatedBackground"><code>
768diagram.add(
769 $(go.Part, "Graduated", // or "Graduated"
770 { background: "white" },
771 $(go.Shape, { geometryString: "M0 0 H150", stroke: "blue", strokeWidth: 2 }),
772 $(go.Shape, { geometryString: "M0 0 V20", stroke: "blue", strokeDashArray: [2, 2] })
773 ));
774</code></pre>
775<script>goCode("graduatedBackground", 500, 100)</script>
776<p>
777 Events on the tick Shapes and TextBlock labels will be ignored.
778 Rotating the main shape will not rotate the ticks, just as rotating a Spot Panel's main element
779 won't rotate its children. Rotation should generally be done at the Panel level. Another similarity
780 to Spot Panels is that resizing of a Graduated Panel should generally be done on the main shape.
781 TextBlock labels cannot be edited.
782</p>
783 </div>
784 </div>
785
786 <div class="bg-nwoods-primary">
787 <section class="max-w-screen-lg text-white container mx-auto py-2 px-12">
788 <p id="version" class="leading-none mb-2 my-4">GoJS</p>
789 </section>
790 </div><footer class="bg-nwoods-primary text-white">
791 <div class="container max-w-screen-lg mx-auto px-8">
792 <div class="w-full py-6">
793
794 <div class="max-w-screen-lg xl:max-w-screen-xl mx-auto px-4 sm:px-6 md:px-8">
795 <ul class="text-sm font-medium pb-14 sm:pb-20 grid grid-cols-1 sm:grid-cols-3 gap-y-10">
796 <li class="list-none row-span-2">
797 <h2 class="text-base font-semibold tracking-wide">GoJS</h2>
798 <ul class="list-none space-y-4 md:space-y-1 px-0">
799 <li>
800 <a href="../samples/index.html">Samples</a>
801 </li>
802 <li>
803 <a href="../learn/index.html">Learn</a>
804 </li>
805 <li>
806 <a href="../intro/index.html">Intro</a>
807 </li>
808 <li>
809 <a href="../api/index.html">API</a>
810 </li>
811 <li>
812 <a href="../changelog.html">Changelog</a>
813 </li>
814 <li>
815 <a href="https://github.com/NorthwoodsSoftware/GoJS">GitHub</a>
816 </li>
817 </ul>
818 </li>
819 <li class="list-none row-span-2">
820 <h2 class="text-base font-semibold tracking-wide">Support</h2>
821 <ul class="list-none space-y-4 md:space-y-1 px-0">
822 <li>
823 <a href="https://www.nwoods.com/contact.html"
824 target="_blank" rel="noopener" onclick="getOutboundLink('https://www.nwoods.com/contact.html', 'contact');">Contact</a>
825 </li>
826 <li>
827 <a href="https://forum.nwoods.com/c/gojs">Forum</a>
828 </li>
829 <li>
830 <a href="https://www.nwoods.com/app/activate.aspx?sku=gojs">Activate</a>
831 </li>
832 <li>
833 <a href="https://www.nwoods.com/sales/index.html"
834 target="_blank" rel="noopener" onclick="getOutboundLink('https://www.nwoods.com/sales/index.html', 'buy');">Buy</a>
835 </li>
836 <li>
837 <a href="https://www.youtube.com/channel/UC9We8EoX596-6XFjJDtZIDg">Videos</a>
838 </li>
839 </ul>
840 </li>
841 <li class="list-none row-span-2">
842 <h2 class="text-base font-semibold tracking-wide">Company</h2>
843 <ul class="list-none space-y-4 md:space-y-1 px-0">
844 <li>
845 <a href="https://www.nwoods.com">Northwoods</a>
846 </li>
847 <li>
848 <a href="https://www.nwoods.com/about.html">About Us</a>
849 </li>
850 <li>
851 <a href="https://www.nwoods.com/contact.html">Contact Us</a>
852 </li>
853 <li>
854 <a href="https://twitter.com/northwoodsgo">Twitter</a>
855 </li>
856
857 </ul>
858 </li>
859 </ul>
860
861
862 <p class="text-sm text-gray-100 md:mb-6">
863 Copyright 1998-2021 <a class="text-white" href="https://www.nwoods.com">Northwoods Software</a>
864 </p>
865 </div>
866 </div>
867</footer> </body>
868
869<script async src="https://www.googletagmanager.com/gtag/js?id=UA-1506307-5"></script>
870<script>
871 window.dataLayer = window.dataLayer || [];
872 function gtag(){dataLayer.push(arguments);}
873 gtag('js', new Date()); gtag('config', 'UA-1506307-5');
874 var getOutboundLink = function(url, label) {
875 gtag('event', 'click', {
876 'event_category': 'outbound',
877 'event_label': label,
878 'transport_type': 'beacon'
879 });
880 }
881
882 // topnav
883 var topButton = document.getElementById("topnavButton");
884 var topnavList = document.getElementById("topnavList");
885 topButton.addEventListener("click", function() {
886 this.classList.toggle("active");
887 topnavList.classList.toggle("hidden");
888 document.getElementById("topnavOpen").classList.toggle("hidden");
889 document.getElementById("topnavClosed").classList.toggle("hidden");
890 });
891</script>
892 <script src="../assets/js/prism.js"></script>
893 <script src="../release/go.js"></script>
894<script src="../extensions/Figures.js"></script> <script src="../assets/js/goDoc.js"></script>
895 <script>
896 document.addEventListener("DOMContentLoaded", function() {
897 if (window.go) document.getElementById('version').textContent = "GoJS version " + go.version;
898 if (window.goDoc) window.goDoc();
899 var d = window.diagrams;
900 for (var i = 0; i < d.length; i++) {
901 var dargs = d[i];
902 goCodeExecute(dargs[0], dargs[1], dargs[2], dargs[3], dargs[4]);
903 }
904 if (window.extra) window.extra();
905 });
906 </script>
907</html>