create-gojs-kit
Version:
A CLI for downloading GoJS samples, extensions, and docs
1,070 lines (1,012 loc) • 41.6 kB
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"/>
<link rel="preconnect" href="https://rsms.me/">
<link rel="stylesheet" href="../assets/css/style.css">
<!-- Copyright 1998-2025 by Northwoods Software Corporation. -->
<meta itemprop="name" content="Graduated Panels" />
<meta property="og:title" content="Graduated Panels" />
<meta name="twitter:title" content="Graduated Panels" />
<meta property="og:image" content="https://gojs.net/latest/assets/images/fp/defaultCard.png" />
<meta itemprop="image" content="https://gojs.net/latest/assets/images/fp/defaultCard.png" />
<meta name="twitter:image" content="https://gojs.net/latest/assets/images/fp/defaultCard.png" />
<meta property="og:url" content="https://gojs.net/latest/intro/graduatedPanels.html" />
<meta property="twitter:url" content="https://gojs.net/latest/intro/graduatedPanels.html" />
<meta name="twitter:card" content="summary_large_image" />
<meta property="og:type" content="website" />
<meta property="twitter:domain" content="gojs.net" />
<title>
Graduated Panels | GoJS
</title>
<link rel="stylesheet" href="../assets/css/prism.css"/>
</head>
<script>
window.diagrams = [];
window.goCode = function (pre, w, h, parentid, animation) {
window
.diagrams
.push([pre, w, h, parentid, animation]);
}
</script>
<body>
<nav id="navTop" class=" w-full h-[var(--topnav-h)] z-30 bg-white border-b border-b-gray-200">
<div class="max-w-screen-xl mx-auto flex flex-wrap items-start justify-between px-4">
<a class="text-white bg-nwoods-primary font-bold !leading-[calc(var(--topnav-h)_-_1px)] my-0 px-2 text-4xl lg:text-5xl logo"
href="../">
GoJS
</a>
<div class="relative">
<button id="topnavButton" class="h-[calc(var(--topnav-h)_-_1px)] px-2 m-0 text-gray-900 bg-inherit shadow-none md:hidden hover:!bg-inherit hover:!text-nwoods-accent hover:!shadow-none" aria-label="Navigation">
<svg class="h-7 w-7 block" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">
<path d="M3.75 6.75h16.5M3.75 12h16.5m-16.5 5.25h16.5" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
</button>
<div id="topnavList" class="hidden md:block">
<div class="absolute right-0 z-30 flex flex-col items-end rounded border border-gray-200 p-4 pl-12 shadow bg-white text-gray-900 font-semibold
md:flex-row md:space-x-4 md:items-start md:border-0 md:p-0 md:shadow-none md:bg-inherit">
<a href="../learn/">Learn</a>
<a href="../samples/">Samples</a>
<a href="../intro/">Intro</a>
<a href="../api/">API</a>
<a href="../download.html">Download</a>
<a href="https://forum.nwoods.com/c/gojs/11" target="_blank" rel="noopener">Forum</a>
<a id="tc" href="https://nwoods.com/contact.html"
target="_blank" rel="noopener" onclick="getOutboundLink('https://nwoods.com/contact.html', 'contact');">Contact</a>
<a id="tb" href="https://nwoods.com/sales/index.html"
target="_blank" rel="noopener" onclick="getOutboundLink('https://nwoods.com/sales/index.html', 'buy');">Buy</a>
</div>
</div>
</div>
</div>
</nav>
<script>
window.addEventListener("DOMContentLoaded", function () {
// topnav
var topButton = document.getElementById("topnavButton");
var topnavList = document.getElementById("topnavList");
if (topButton && topnavList) {
topButton.addEventListener("click", function (e) {
topnavList
.classList
.toggle("hidden");
e.stopPropagation();
});
document.addEventListener("click", function (e) {
// if the clicked element isn't the list, close the list
if (!topnavList.classList.contains("hidden") && !e.target.closest("#topnavList")) {
topButton.click();
}
});
// set active <a> element
var url = window
.location
.href
.toLowerCase();
var aTags = topnavList.getElementsByTagName('a');
for (var i = 0; i < aTags.length; i++) {
var lowerhref = aTags[i]
.href
.toLowerCase();
if (lowerhref.endsWith('.html'))
lowerhref = lowerhref.slice(0, -5);
if (url.startsWith(lowerhref)) {
aTags[i]
.classList
.add('active');
break;
}
}
}
});
</script>
<div class="sticky top-0 left-0 z-10 px-2 w-full bg-white border-b border-b-gray-200 md:hidden">
<button id="sidenavButton" class="flex p-2 text-gray-900 bg-inherit shadow-none items-center text-sm font-semibold hover:!bg-inherit hover:!text-nwoods-accent hover:!shadow-none" aria-label="Navigation">
<svg class="h-7 w-7 block mr-2" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">
<path d="M3.75 6.75h16.5M3.75 12h16.5m-16.5 5.25h16.5" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
<span>Menu</span>
</button>
</div>
<script>
window.addEventListener("DOMContentLoaded", function () {
// sidenav
var sideButton = document.getElementById("sidenavButton");
var sidenav = document.getElementById("sidenav");
if (sideButton && sidenav) {
sideButton.addEventListener("click", function (e) {
sidenav
.classList
.toggle("hidden");
e.stopPropagation();
});
document.addEventListener("click", function (e) {
// if the clicked element isn't the list, close the list
if (!sidenav.classList.contains("hidden") && !e.target.closest("#sidenavList")) {
sideButton.click();
}
});
}
});
</script>
<div class="flex flex-row md:min-h-screen w-full max-w-screen-xl mx-auto">
<aside id="sidenav"
class="hidden fixed top-0 left-0 z-10 w-full bg-black/10 min-h-screen max-h-screen overflow-x-hidden overflow-y-auto shrink-0
md:block md:sticky md:w-52 md:min-h-0 md:bg-inherit md:border-r md:border-r-gray-200 md:overscroll-auto">
<nav id="sidenavList" class="flex flex-col bg-white w-52 min-h-screen pl-2 pt-4 pb-24 md:w-full md:min-h-0">
<a href="index.html">Basics</a>
<a href="buildingObjects.html">Building Parts</a>
<a href="usingModels.html">Using Models</a>
<a href="dataBinding.html">Data Binding</a>
<a href="react.html">GoJS with React</a>
<a href="svelte.html">GoJS with Svelte</a>
<a href="angular.html">GoJS with Angular</a>
<a href="textBlocks.html">TextBlocks</a>
<a href="shapes.html">Shapes</a>
<a href="pictures.html">Pictures</a>
<a href="panels.html">Panels</a>
<a href="tablePanels.html">Table Panels</a>
<a href="brush.html">Brushes</a>
<a href="sizing.html">Sizing Objects</a>
<a href="itemArrays.html">Item Arrays</a>
<a href="changedEvents.html">Changed Events</a>
<a href="transactions.html">Transactions</a>
<a href="viewport.html">Coordinates</a>
<a href="initialView.html">Initial View</a>
<a href="collections.html">Collections</a>
<a href="links.html">Links</a>
<a href="linkLabels.html">Link Labels</a>
<a href="connectionPoints.html">Link Points</a>
<a href="ports.html">Ports</a>
<a href="nodes.html">Nodes</a>
<a href="typings.html">Typings</a>
<a href="debugging.html">Debugging</a>
<a href="layouts.html">Layouts</a>
<a href="routers.html">Routers</a>
<a href="trees.html">Trees</a>
<a href="subtrees.html">SubTrees</a>
<a href="groups.html">Groups</a>
<a href="subgraphs.html">SubGraphs</a>
<a href="sizedGroups.html">Sized Groups</a>
<a href="selection.html">Selection</a>
<a href="highlighting.html">Highlighting</a>
<a href="theming.html">Theming</a>
<a href="tooltips.html">ToolTips</a>
<a href="contextMenus.html">Context Menus</a>
<a href="events.html">Diagram Events</a>
<a href="tools.html">Tools</a>
<a href="commands.html">Commands</a>
<a href="accessibility.html">Accessibility</a>
<a href="buttons.html">Buttons</a>
<a href="permissions.html">Permissions</a>
<a href="validation.html">Validation</a>
<a href="animation.html">Animation</a>
<a href="HTMLInteraction.html">HTML Interaction</a>
<a href="layers.html">Layers & Z-ordering</a>
<a href="palette.html">Palette</a>
<a href="overview.html">Overview</a>
<a href="replacingDeleting.html">Replacing and Deleting</a>
<a href="templateMaps.html">Template Maps</a>
<a href="legends.html">Legends and Titles</a>
<a href="extensions.html">Extensions</a>
<a href="geometry.html">Geometry Strings</a>
<a href="grids.html">Grid Patterns</a>
<a href="graduatedPanels.html">Graduated Panels</a>
<a href="SVGContext.html">Rendering to SVG</a>
<a href="makingSVG.html">Snapshot to SVG</a>
<a href="makingImages.html">Diagram Images</a>
<a href="printing.html">Printing</a>
<a href="serverSideImages.html">Server-side Images</a>
<a href="nodeScript.html">GoJS in Node.js</a>
<a href="testing.html">Testing</a>
<a href="performance.html">Performance</a>
<a href="platforms.html">Platforms</a>
<a href="deployment.html">Deployment</a>
</nav>
</aside>
<script>
var navList = document.getElementById('sidenavList');
if (navList !== null) {
var url = window.location.href;
var lindex = url.lastIndexOf('/');
url = url
.slice(lindex + 1)
.toLowerCase();
var aTags = navList.getElementsByTagName('a');
var currentindex = -1;
for (var i = 0; i < aTags.length; i++) {
var lowerhref = aTags[i]
.href
.toLowerCase();
if (lowerhref.indexOf('/' + url) !== -1) {
currentindex = i;
aTags[i]
.classList
.add('active');
break;
}
}
}
</script>
<div class="px-4 pb-16 w-full overflow-hidden prose">
<h1>Graduated Panels</h1>
<p>
The "Graduated" Panel, <a>Panel.Graduated</a>, draws regular tick marks and/or text labels along the stroke of the main child <a>Shape</a>. Graduated Panels
can be considered scales showing a range of values.
</p>
<p>
For examples of Graduated Panels see the <a href="../samples/timeline.html">Timeline</a>, <a href="../samples/thermometer.html">Thermometer</a>,
<a href="../samples/instrumentGauge.html">Instrument Gauge</a>, and <a href="../samples/ruleredDiagram.html">Rulered Diagram</a> samples.
</p>
<h2 id="SimpleGraduatedPanels">Simple Graduated Panels</h2>
<p>
Similar to Auto and Spot Panels, Graduated Panels should have two or more elements in them. Elements must be either <a>Shape</a>s or <a>TextBlock</a>s. The
main Shape element may be declared by setting <a>GraphObject.isPanelMain</a> to true; but no such setting is needed if it is the very first element of the
panel. Shapes and TextBlocks, other than the main Shape, basically act as templates for the drawing of each tick mark and label.
</p>
<p>
Tick mark <a>Shape</a>s within a Graduated Panel should have a measured size, either by setting a <a>GraphObject.desiredSize</a> (or <code>width</code> and
<code>height</code> properties), or by setting its <a>Shape.geometry</a>. For basic tick marks drawn normal to the main Shape's path, it is easiest to use a
simple vertical line geometry string: <code>M0 0 V10</code>. The height of the geometry will determine the length of the tick mark.
</p>
<pre class="lang-js" id="graduatedSimple"><code>
diagram.add(
// all Parts are Panels
new go.Part("Graduated")
.add(
new go.Shape({ geometryString: "M0 0 H400" }), // the main shape, a horizontal line
new go.Shape({ geometryString: "M0 0 V10" }) // a tick mark, a vertical line
));
</code></pre>
<script>
goCode('graduatedSimple', 500, 100);
</script>
<p>
Any shape, including custom geometries, can be used as the main Shape or as a tick mark Shape of a Graduated Panel.
</p>
<pre class="lang-js" id="graduatedCircle"><code>
diagram.add(
new go.Part("Graduated",
{ background: "transparent" }) // make panel pickable
.add(
// main shape is a whole circle
new go.Shape("Circle",
{ fill: null, desiredSize: new go.Size(150, 150) }),
// tick shape is a double line
new go.Shape({ geometryString: "M0 0 V10 M3 0 V10" })
));
</code></pre>
<script>
goCode('graduatedCircle', 200, 200);
</script>
<p>
Graduated Panels can also be labeled with TextBlocks denoting the values along the scale. Often, these will be offset from the main stroke using
<a>GraphObject.segmentOffset</a>, as one would with Link labels, so that the text does not overlap the main stroke. More detail on placing labels is in the
"Appearance" section below.
</p>
<pre class="lang-js" id="graduatedLabels"><code>
diagram.add(
new go.Part("Graduated",
{ background: "transparent" }) // make panel pickable
.add(
new go.Shape({ geometryString: "M0 0 H400" }), // the main shape
new go.TextBlock({ segmentOffset: new go.Point(0, 12) }) // tick labels
));
</code></pre>
<script>
goCode('graduatedLabels', 500, 100);
</script>
<h2 id="GraduatedPanelProperties">Graduated Panel Properties</h2>
<p>
There are a number of properties that govern the appearance of tick marks and labels.
</p>
<h3 id="TickMarkValues">Tick Mark Values</h3>
<p>
The graduated values of a Graduated Panel will range on a linear scale from the start of the main shape's stroke to the end of the stroke. The values and
frequency of tick marks and labels are governed by a few properties:
</p>
<ul>
<li><a>Panel.graduatedMin</a> - the minimum value represented on the scale, at the beginning of the stroke of the main shape</li>
<li><a>Panel.graduatedMax</a> - the maximum value represented on the scale, at the end of the main shape</li>
<li><a>Panel.graduatedTickBase</a> - the value of the "origin" tick mark, the first tick mark if it is the same as graduatedMin</li>
<li><a>Panel.graduatedTickUnit</a> - tick marks are positioned at multiples of the graduatedTickUnit added to the graduatedTickBase</li>
<li><a>Shape.interval</a>/<a>TextBlock.interval</a> - a multiple of the graduatedTickUnit at which to draw a tick or label</li>
</ul>
<p>
Graduated Panels can have multiple Shapes as tick marks and multiple TextBlocks as labels, with the interval property controlling at what multiples of the
<code>graduatedTickUnit</code> they are drawn. In many of the examples below, larger ticks are drawn at intervals of 4; some have an interval of 5.
</p>
<p>
A <code>graduatedMin</code> of <code>0</code>, <code>graduatedMax</code> of <code>77</code>, <code>graduatedTickBase</code> of <code>0</code>,
<code>graduatedTickUnit</code> of <code>2.5</code>, and intervals of 4 result in a scale that might appear as:
</p>
<pre class="lang-js" id="graduatedVals1"><code>
diagram.add(
new go.Part("Graduated", {
graduatedMin: 0, graduatedMax: 77,
graduatedTickBase: 0, graduatedTickUnit: 2.5,
background: "transparent"
})
.add(
new go.Shape({ geometryString: "M0 0 H400" }), // the main Shape
// a short, frequent tick mark
new go.Shape({ geometryString: "M0 0 V5" }),
// a longer tick mark every four ticks
new go.Shape({ geometryString: "M0 0 V10", interval: 4 }),
// text label only every four ticks, with a vertical offset
new go.TextBlock( { segmentOffset: new go.Point(0, 12), interval: 4 })
));
</code></pre>
<script>
goCode('graduatedVals1', 500, 100);
</script>
<p>
Changing <code>graduatedMin</code> to <code>-23</code> results in:
</p>
<pre class="lang-js" id="graduatedVals2"><code>
diagram.add(
new go.Part("Graduated", {
graduatedMin: -23, graduatedMax: 77,
graduatedTickBase: 0, graduatedTickUnit: 2.5,
background: "transparent"
})
.add(
new go.Shape({ geometryString: "M0 0 H400" }), // the main Shape
new go.Shape({ geometryString: "M0 0 V5" }), // short tick mark
new go.Shape({ geometryString: "M0 0 V10", interval: 4 }), // long tick mark
new go.TextBlock( { segmentOffset: new go.Point(0, 12), interval: 4 }) // labels
));
</code></pre>
<script>
goCode('graduatedVals2', 500, 100);
</script>
<p>
The range from the min to the max value (<a>Panel.graduatedRange</a>) has increased from 77 to 100, so the tick marks are closer to each other for the same
length main path.
</p>
<p>
Changing <code>graduatedTickBase</code> to <code>1.2</code> results in:
</p>
<pre class="lang-js" id="graduatedVals3"><code>
diagram.add(
new go.Part("Graduated", {
graduatedMin: -23, graduatedMax: 77,
graduatedTickBase: 1.2, graduatedTickUnit: 2.5,
background: "transparent"
})
.add(
new go.Shape({ geometryString: "M0 0 H400" }), // the main Shape
new go.Shape({ geometryString: "M0 0 V5" }), // short tick mark
new go.Shape({ geometryString: "M0 0 V10", interval: 4 }), // long tick mark
new go.TextBlock( { segmentOffset: new go.Point(0, 12), interval: 4 }) // labels
));
</code></pre>
<script>
goCode('graduatedVals3', 500, 100);
</script>
<p>
Basically, the "origin" for the scale has shifted slightly, even though the end values remain the same. There will always be a tick mark at the
<code>graduatedTickBase</code>
if that value is within the range of the graduated scale.
</p>
<p>
Doubling the <code>graduatedTickUnit</code> to <code>5</code> results in:
</p>
<pre class="lang-js" id="graduatedVals4"><code>
diagram.add(
new go.Part("Graduated", {
graduatedMin: -23, graduatedMax: 77,
graduatedTickBase: 1.2, graduatedTickUnit: 5,
background: "transparent"
})
.add(
new go.Shape({ geometryString: "M0 0 H400" }),
new go.Shape({ geometryString: "M0 0 V5" }), // short tick mark
new go.Shape({ geometryString: "M0 0 V10", interval: 4 }), // long tick mark
new go.TextBlock( { segmentOffset: new go.Point(0, 12), interval: 4 }) // labels
));
</code></pre>
<script>
goCode('graduatedVals4', 500, 100);
</script>
<p>
Doubling the tick unit halves the number of ticks for the same length path, but again the end values are unchanged.
</p>
<p>
Changing <code>graduatedTickBase</code> back to <code>0</code> and the intervals to <code>5</code> results in:
</p>
<pre class="lang-js" id="graduatedVals5"><code>
diagram.add(
new go.Part("Graduated", {
graduatedMin: -23, graduatedMax: 77,
graduatedTickBase: 0, graduatedTickUnit: 5,
background: "transparent"
})
.add(
new go.Shape({ geometryString: "M0 0 H400" }),
new go.Shape({ geometryString: "M0 0 V5" }), // short tick mark
new go.Shape({ geometryString: "M0 0 V10", interval: 5 }), // long tick mark
new go.TextBlock({ interval: 5, segmentOffset: new go.Point(0, 12) })
));
</code></pre>
<script>
goCode('graduatedVals5', 500, 100);
</script>
<p>
You can have more than one label. For example, small text that is more frequent than larger text:
</p>
<pre class="lang-js" id="graduated2Labels"><code>
diagram.add(
new go.Part("Graduated", {
graduatedMin: 0, graduatedMax: 140,
graduatedTickBase: 0, graduatedTickUnit: 5,
background: "transparent"
})
.add(
new go.Shape({ geometryString: "M0 0 H450" }), // longer line
new go.Shape({ geometryString: "M0 0 V5" }),
new go.Shape({ geometryString: "M0 0 V10", interval: 4 }),
// minor label
new go.TextBlock({
interval: 2, segmentOffset: new go.Point(0, 8),
stroke: "blue", font: "7pt sans-serif"
}),
// major label
new go.TextBlock({
interval: 4, segmentOffset: new go.Point(0, 12),
stroke: "red", font: "bold 12pt sans-serif"
})
));
</code></pre>
<script>
goCode('graduated2Labels', 500, 100);
</script>
<h3 id="TickMarkAppearance">Tick Mark Appearance</h3>
<p>
The appearance of tick marks relative to the main shape path is controlled by a few properties:
</p>
<ul>
<li>
<a>Shape.graduatedStart</a>/<a>TextBlock.graduatedStart</a> - the fractional distance along the main stroke at which drawing this tick or label may begin
</li>
<li>
<a>Shape.graduatedEnd</a>/<a>TextBlock.graduatedEnd</a> - the fractional distance along the main stroke beyond which it will not draw this tick or label
</li>
<li><a>GraphObject.alignmentFocus</a> - the spot on the tick or label to align with the calculated path points, defaulting to the top center</li>
<li><a>GraphObject.segmentOffset</a> - how much to offset a TextBlock label from the main stroke -- the Y value specifies distance from the path</li>
<li><a>GraphObject.segmentOrientation</a> - how to rotate a TextBlock label relative to the main stroke</li>
</ul>
<p>
Only TextBlock labels should set the <a>GraphObject.segmentOffset</a> or <a>GraphObject.segmentOrientation</a>. They have no impact on the main shape or tick
shapes. These GraphObject properties are also commonly used to place Link labels, as seen in the
<a href="linkLabels.html">Introduction page on Link labels</a>, and are used by Graduated Panels in a similar manner.
</p>
<p>
Setting <code>graduatedStart</code> and/or <code>graduatedEnd</code> allows for drawing ticks only along part of the main stroke:
</p>
<pre class="lang-js" id="graduatedAppr1"><code>
diagram.add(
new go.Part("Graduated")
.add(
new go.Shape({ geometryString: "M0 0 H400" }),
new go.Shape({ geometryString: "M0 0 V10", graduatedStart: .25, graduatedEnd: .75 })
));
</code></pre>
<script>
goCode('graduatedAppr1', 500, 100);
</script>
<p>
In this case, tick marks are now only drawn in the middle half of the main shape.
</p>
<p>
Setting <code>alignmentFocus</code> to <code>go.Spot.Bottom</code> will cause the ticks to have their bottoms aligned to the main stroke:
</p>
<pre class="lang-js" id="graduatedAppr2"><code>
diagram.add(
new go.Part("Graduated")
.add(
new go.Shape({ geometryString: "M0 0 H400" }),
new go.Shape({ geometryString: "M0 0 V10", alignmentFocus: go.Spot.Bottom })
));
</code></pre>
<script>
goCode('graduatedAppr2', 500, 100);
</script>
<p>
Setting <code>alignmentFocus</code> to <code>go.Spot.Center</code> will cause the ticks to be centered across the path:
</p>
<pre class="lang-js" id="graduatedAppr21"><code>
diagram.add(
new go.Part("Graduated")
.add(
new go.Shape({ geometryString: "M0 0 H400" }),
new go.Shape({ geometryString: "M0 0 V10 M0 20 V30", alignmentFocus: go.Spot.Center })
));
</code></pre>
<script>
goCode('graduatedAppr21', 500, 100);
</script>
<p>
Note the gap in the geometry of the shape.
</p>
<p>
Setting <code>segmentOffset</code> for labels can make them more readable near tick marks:
</p>
<pre class="lang-js" id="graduatedAppr3"><code>
diagram.add(
new go.Part("Graduated")
.add(
new go.Shape({ geometryString: "M0 0 H400" }),
new go.Shape({ geometryString: "M0 0 V10" }),
// offset to display below ticks
new go.TextBlock({ segmentOffset: new go.Point(0, 12) })
));
</code></pre>
<script>
goCode('graduatedAppr3', 500, 100);
</script>
<p>
Setting <code>segmentOrientation</code> for labels can alter the angle at which they are drawn relative to the main stroke:
</p>
<pre class="lang-js" id="graduatedAppr4"><code>
diagram.add(
new go.Part("Graduated")
.add(
new go.Shape({ geometryString: "M0 0 H400" }),
new go.Shape({ geometryString: "M0 0 V10" }),
// change the angle of the text
new go.TextBlock({ segmentOrientation: go.Orientation.Minus90 })
));
</code></pre>
<script>
goCode('graduatedAppr4', 500, 100);
</script>
<p>
Note that the top-center point of each label is exactly at the point along the path for that value.
</p>
<p>
Combining these two properties and re-aligning the tick marks:
</p>
<pre class="lang-js" id="graduatedAppr5"><code>
diagram.add(
new go.Part("Graduated")
.add(
new go.Shape({ geometryString: "M0 0 H400" }),
new go.Shape({ geometryString: "M0 0 V10", alignmentFocus: go.Spot.Bottom }),
new go.TextBlock({
alignmentFocus: go.Spot.Left,
segmentOffset: new go.Point(0, -12),
segmentOrientation: go.Orientation.Minus90
})
));
</code></pre>
<script>
goCode('graduatedAppr5', 500, 100);
</script>
<p>
These properties behave similarly to Link labels, in that they respond to the direction of the main stroke. For example, let us turn the main shape so that it
goes diagonally down from the top-left to the bottom-right.
</p>
<pre class="lang-js" id="graduatedApprDiag"><code>
diagram.add(
new go.Part("Graduated")
.add(
new go.Shape({ geometryString: "M0 0 L285 285" }),
new go.Shape({ geometryString: "M0 0 V10", alignmentFocus: go.Spot.Bottom }),
new go.TextBlock({
alignmentFocus: go.Spot.Left,
segmentOffset: new go.Point(0, -12),
segmentOrientation: go.Orientation.Minus90
})
));
</code></pre>
<script>
goCode('graduatedApprDiag', 350, 350);
</script>
<p>
Now let us try a curve:
</p>
<pre class="lang-js" id="graduatedApprCurve"><code>
diagram.add(
new go.Part("Graduated")
.add(
new go.Shape("Curve1", { desiredSize: new go.Size(285, 285) }),
new go.Shape({ geometryString: "M0 0 V10", alignmentFocus: go.Spot.Bottom }),
new go.TextBlock({
alignmentFocus: go.Spot.Left,
segmentOffset: new go.Point(0, -12),
segmentOrientation: go.Orientation.Minus90
})
));
</code></pre>
<script>
goCode('graduatedApprCurve', 350, 350);
</script>
<p>
Here's another commonplace configuration:
</p>
<pre class="lang-js" id="graduatedApprCurve2"><code>
diagram.add(
new go.Part("Graduated")
.add(
new go.Shape({ geometryString: "M0 0 A120 120 0 0 1 200 0" }), // an arc
new go.Shape({ geometryString: "M0 0 V10" }),
new go.TextBlock({
segmentOffset: new go.Point(0, 12),
segmentOrientation: go.Orientation.Along
})
));
</code></pre>
<script>
goCode('graduatedApprCurve2', 350, 100);
</script>
<p>
For vertical lines, it's not necessary to rotate the text:
</p>
<pre class="lang-js" id="graduatedApprVert"><code>
diagram.add(
new go.Part("Graduated")
.add(
new go.Shape({ geometryString: "M0 0 V400" }),
new go.Shape({ geometryString: "M0 0 V10", alignmentFocus: go.Spot.Bottom }),
new go.TextBlock({
alignmentFocus: go.Spot.Left,
segmentOffset: new go.Point(0, -12)
})
));
</code></pre>
<script>
goCode('graduatedApprVert', 100, 450);
</script>
<p>
We can also go from bottom to top:
</p>
<pre class="lang-js" id="graduatedApprVertUp"><code>
diagram.add(
new go.Part("Graduated")
.add(
new go.Shape({ geometryString: "M0 0 V-400" }),
new go.Shape({ geometryString: "M0 0 V10", alignmentFocus: go.Spot.Top }),
new go.TextBlock({
alignmentFocus: go.Spot.Left,
segmentOffset: new go.Point(0, 12)
})
));
</code></pre>
<script>
goCode('graduatedApprVertUp', 100, 450);
</script>
<p>
Note how the Geometry goes from 0,0 to 0,-400, because negative Y values are higher on the screen/page. Note how because everything is relative to the path,
the tick marks and labels would be on the opposite side, so we have also changed the <code>alignmentFocus</code> and <code>segmentOffset</code> to have
opposite values from the previous example.
</p>
<p>
Lastly, any angle specified on a label will be respected if orientation is one of <a>Orientation.None</a>, <a>Orientation.Along</a>, or
<a>Orientation.Upright</a>. In the case of Along and Upright, the angle will be added to the slope of the main path at the point of the TextBlock.
</p>
<pre class="lang-js" id="graduatedApprTxtAngle"><code>
diagram.add(
new go.Part("Spot")
.add(
new go.Panel("Graduated")
.add(
new go.Shape({ geometryString: "M0 0 L100 0 100 100 L0 100" }),
new go.Shape({ geometryString: "M0 0 V10" }),
new go.TextBlock({
interval: 5,
angle: 45,
segmentOffset: new go.Point(0, 12)
})
),
new go.TextBlock( "None")
));
diagram.add(
new go.Part("Spot")
.add(
new go.Panel("Graduated")
.add(
new go.Shape({ geometryString: "M0 0 L100 0 100 100 L0 100" }),
new go.Shape({ geometryString: "M0 0 V10" }),
new go.TextBlock({
interval: 5,
angle: 45,
segmentOrientation: go.Orientation.Along,
segmentOffset: new go.Point(0, 12)
})
),
new go.TextBlock( "Along")
));
diagram.add(
new go.Part("Spot")
.add(
new go.Panel("Graduated")
.add(
new go.Shape({ geometryString: "M0 0 L100 0 100 100 L0 100" }),
new go.Shape({ geometryString: "M0 0 V10" }),
new go.TextBlock({
interval: 5,
angle: 45,
segmentOrientation: go.Orientation.Upright,
segmentOffset: new go.Point(0, 12)
})
),
new go.TextBlock( "Upright")
));
</code></pre>
<script>
goCode('graduatedApprTxtAngle', 300, 300);
</script>
<p>
With None, the labels are always 45 degrees. With Along, the labels are always 45 degrees more than the slope. With Upright, the labels are always 45 degrees
more than the slope, then rotated upright if necessary.
</p>
<h3 id="FunctionalAppearanceProperties">Functional Appearance Properties</h3>
<p>
There are also some functional properties allowing for further customization of the appearance of ticks and labels.
</p>
<ul>
<li>
<a>Shape.graduatedSkip</a>/<a>TextBlock.graduatedSkip</a> - an optional function which returns true for values that should be skipped while drawing a
particular tick or label
</li>
<li>
<a>TextBlock.graduatedFunction</a> - 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>
</ul>
<p>
Setting <code>graduatedSkip</code> allows for skipping ticks where the supplied function returns true:
</p>
<pre class="lang-js" id="graduatedSkip"><code>
diagram.add(
new go.Part("Graduated")
.add(
new go.Shape({ geometryString: "M0 0 H400" }),
new go.Shape({
// skip drawing tick at 30
graduatedSkip: v => v === 30,
geometryString: "M0 0 V10"
}),
new go.TextBlock({ segmentOffset: new go.Point(0, 12) })
));
</code></pre>
<script>
goCode('graduatedSkip', 500, 100);
</script>
<p>
Setting <code>graduatedFunction</code> allows for changing the way labels are displayed:
</p>
<pre class="lang-js" id="graduatedFunc"><code>
diagram.add(
new go.Part("Graduated")
.add(
new go.Shape({ geometryString: "M0 0 H400" }),
new go.Shape({ geometryString: "M0 0 V10" }),
new go.TextBlock({
// always display two decimals
graduatedFunction: val => val.toFixed(2),
segmentOffset: new go.Point(0, 12)
})
));
</code></pre>
<script>
goCode('graduatedFunc', 500, 100);
</script>
<h2 id="GraduatedValueComputations">Graduated Value Computations</h2>
<p>
There are some methods available for computing points along graduated paths:
</p>
<ul>
<li><a>Panel.graduatedPointForValue</a> - returns the Point along the main shape at some value between graduatedMin and graduatedMax in Panel coordinates</li>
<li><a>Panel.graduatedValueForPoint</a> - returns the value along the main shape nearest a given Point</li>
</ul>
<p>
In the following example, the red marker uses a <a>Part.dragComputation</a> function that keeps it along the path of the Graduated Panel using the above
functions.
</p>
<pre class="lang-js" id="graduatedPointValueCalc"><code>
const gauge =
new go.Part("Auto", { location: new go.Point(10, 20) })
.add(
new go.Shape({ fill: "white" }),
new go.Panel("Graduated", { name: "SCALE", margin: 10 })
.add(
new go.Shape({ name: "PATH", geometryString: "M0 0 A120 120 0 0 1 200 0" }),
new go.Shape({ geometryString: "M0 0 V10" }),
new go.TextBlock({
segmentOffset: new go.Point(0, 12),
segmentOrientation: go.Orientation.Along
})
)
);
diagram.add(gauge);
const marker =
new go.Part("Spot", {
locationSpot: go.Spot.Center,
selectionAdorned: false,
dragComputation: (node, pt) => {
const scale = gauge.findObject("SCALE");
const loc = scale.getLocalPoint(pt);
const val = scale.graduatedValueForPoint(loc);
const gpt = scale.graduatedPointForValue(val);
return scale.getDocumentPoint(gpt);
}
})
.add(
new go.Shape("Circle", { fill: "transparent", strokeWidth: 0, cursor: "pointer" }),
new go.Shape("Circle", { fill: "red", strokeWidth: 0, width: 8, height: 8 }),
);
diagram.add(marker);
// once everything has been positioned, give the marker its location
diagram.addDiagramListener("InitialLayoutCompleted", e => {
const scale = gauge.findObject("SCALE");
const gpt = scale.graduatedPointForValue(0);
marker.location = scale.getDocumentPoint(gpt);
});
</code></pre>
<script>
goCode('graduatedPointValueCalc', 350, 200);
</script>
<p>
As you drag the red circle, you will notice that it always stays on the main shape's stroke. The computation converts the point to the panel's coordinate
system, computes the closest graduated value, computes the point on the shape geometry for that value, and finally converts it back to document coordinates
for use as the marker's location.
</p>
<p>
Note that for demonstration purposes this example has the marker being a separate Part from the "gauge" Part. A real gauge would have the marker be part of
the gauge as an indicator of a particular value, optionally draggable by the user. See some examples at
<a href="../samples/controlGauges.html" target="_blank">Instrument Controls: Gauges and Meters</a>.
</p>
<h2 id="OtherConsiderations">Other Considerations</h2>
<p>
By default, only the main shape of a Graduated Panel can be used to pick the panel. As with Grid Panels, a Graduated Panel should have a non-null
<code>background</code> if the entire panel needs to be pickable. You cannot set or bind the <a>Panel.itemArray</a> of a Graduated Panel. You can set and bind
properties on tick <a>Shape</a>s and <a>TextBlock</a> labels as you can with any other <a>GraphObject</a> properties.
</p>
<pre class="lang-js" id="graduatedBackground"><code>
diagram.add(
new go.Part("Graduated", { background: "white" })
.add( // or "Graduated"
new go.Shape({ geometryString: "M0 0 H150", stroke: "blue", strokeWidth: 2 }),
new go.Shape({ geometryString: "M0 0 V20", stroke: "blue", strokeDashArray: [2, 2] })
));
</code></pre>
<script>
goCode('graduatedBackground', 500, 100);
</script>
<p>
Events on the tick Shapes and TextBlock labels will be ignored. Rotating the main shape will not rotate the ticks, just as rotating a Spot Panel's main
element won't rotate its children. Rotation should generally be done at the Panel level. Another similarity to Spot Panels is that resizing of a Graduated
Panel should generally be done on the main shape. TextBlock labels cannot be edited.
</p>
</div>
</div>
<footer class="bg-white text-gray-900 border-t border-t-gray-200">
<div class="w-full max-w-screen-lg mx-auto px-4 py-6">
<p id="version" class="text-xs text-gray-900 m-0"></p>
<div class="text-sm px-0 mb-4 grid grid-cols-2 sm:grid-cols-3 gap-y-10">
<div>
<h2 class="text-base font-semibold text-nwoods-primary">GoJS</h2>
<ul class="list-none space-y-4 md:space-y-1 px-0">
<li>
<a href="../samples/index.html">Samples</a>
</li>
<li>
<a href="../learn/index.html">Learn</a>
</li>
<li>
<a href="../intro/index.html">Intro</a>
</li>
<li>
<a href="../api/index.html">API</a>
</li>
<li>
<a href="../changelog.html">Changelog</a>
</li>
<li>
<a href="https://github.com/NorthwoodsSoftware/GoJS" target="_blank" rel="noopener">GitHub</a>
</li>
</ul>
</div>
<div>
<h2 class="text-base font-semibold text-nwoods-primary">Support</h2>
<ul class="list-none space-y-4 md:space-y-1 px-0">
<li>
<a href="https://nwoods.com/contact.html"
target="_blank" rel="noopener" onclick="getOutboundLink('https://nwoods.com/contact.html', 'contact');">Contact</a>
</li>
<li>
<a href="https://forum.nwoods.com/c/gojs" target="_blank" rel="noopener">Forum</a>
</li>
<li>
<a href="https://nwoods.com/app/activate.aspx?sku=gojs" target="_blank" rel="noopener">Activate</a>
</li>
<li>
<a href="https://nwoods.com/sales/index.html"
target="_blank" rel="noopener" onclick="getOutboundLink('https://nwoods.com/sales/index.html', 'buy');">Buy</a>
</li>
<li>
<a href="https://nwoods.com/register.html" target="_blank" rel="noopener">Register</a>
</li>
</ul>
</div>
<div>
<h2 class="text-base font-semibold text-nwoods-primary">Company</h2>
<ul class="list-none space-y-4 md:space-y-1 px-0">
<li>
<a target="_blank" href="https://nwoods.com" target="_blank" rel="noopener">Northwoods</a>
</li>
<li>
<a target="_blank" href="https://nwoods.com/about.html" target="_blank" rel="noopener">About Us</a>
</li>
<li>
<a target="_blank" href="https://nwoods.com/contact.html" target="_blank" rel="noopener">Contact Us</a>
</li>
<li>
<a target="_blank" href="https://nwoods.com/consulting.html" target="_blank" rel="noopener">Consulting</a>
</li>
<li>
<a target="_blank" href="https://twitter.com/northwoodsgo" target="_blank" rel="noopener">Twitter</a>
</li>
</ul>
</div>
</div>
<p class="text-sm text-gray-900 md:mb-6">
Copyright 1998-2025 <a href="https://nwoods.com">Northwoods Software</a>
</p>
</div>
</footer>
</body>
<script async src="https://www.googletagmanager.com/gtag/js?id=G-S5QK8VSK84"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', 'G-S5QK8VSK84');
var getOutboundLink = function (url, label) {
gtag('event', 'click', {
'event_category': 'outbound',
'event_label': label,
'transport_type': 'beacon'
});
}
const params = new URL(document.location).searchParams
let a = params.get('a');
if (a) localStorage.setItem('a', a);
a = localStorage.getItem('a');
if (a) {
const links = [...document.body.getElementsByTagName("a")].filter((l) => l.href.includes('nwoods.com'));
for (const l of links) {
const url = new URL(l.href);
url.searchParams.set('a', a);
l.href = url;
}
}
</script>
<script src="../assets/js/prism.js"></script>
<script src="https://cdn.jsdelivr.net/npm/gojs@3.1.0"></script>
<script src="../extensions/Figures.js"></script>
<script src="../assets/js/goDoc.js"></script>
<script>
document.addEventListener("DOMContentLoaded", function () {
if (window.go)
document
.getElementById('version')
.textContent = "GoJS version " + go.version;
if (window.goDoc)
window.goDoc();
var d = window.diagrams;
for (var i = 0; i < d.length; i++) {
var dargs = d[i];
goCodeExecute(dargs[0], dargs[1], dargs[2], dargs[3], dargs[4]);
}
if (window.extra)
window.extra();
}
);
</script>
</html>