UNPKG

create-gojs-kit

Version:

A CLI for downloading GoJS samples, extensions, and docs

461 lines (419 loc) 18.9 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="A thermometer." /> <meta itemprop="description" content="A thermometer." /> <meta property="og:description" content="A thermometer." /> <meta name="twitter:description" content="A thermometer." /> <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="Thermometer Nodes using Graduated Panels" /> <meta property="og:title" content="Thermometer Nodes using Graduated Panels" /> <meta name="twitter:title" content="Thermometer Nodes using Graduated Panels" /> <meta property="og:image" content="https://gojs.net/latest/assets/images/screenshots/thermometer.png" /> <meta itemprop="image" content="https://gojs.net/latest/assets/images/screenshots/thermometer.png" /> <meta name="twitter:image" content="https://gojs.net/latest/assets/images/screenshots/thermometer.png" /> <meta property="og:url" content="https://gojs.net/latest/samples/thermometer.html" /> <meta property="twitter:url" content="https://gojs.net/latest/samples/thermometer.html" /> <meta name="twitter:card" content="summary_large_image" /> <meta property="og:type" content="website" /> <meta property="twitter:domain" content="gojs.net" /> <title> Thermometer Nodes using Graduated Panels | GoJS Diagramming Library </title> </head> <body> <!-- This top nav is not part of the sample code --> <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="flex flex-col prose"> <div class="w-full max-w-screen-xl mx-auto"> <!-- * * * * * * * * * * * * * --> <!-- Start of GoJS sample code --> <script src="https://cdn.jsdelivr.net/npm/gojs@3.1.0"></script> <div id="allSampleContent" class="p-4 w-full"> <script id="code"> function getMercuryBrush(color) { return new go.Brush('Linear', { 0: color, 0.2: go.Brush.lighten(color), 0.33: 'rgba(255, 255, 255, 1)', 0.5: go.Brush.lighten(color), 0.9: color, 1: go.Brush.darken(color), start: go.Spot.Left, end: go.Spot.Right }); } function getBulbBrush(color) { return new go.Brush('Radial', { 0.0: 'rgba(255, 255, 255, 1)', 0.5: go.Brush.lighten(color), 0.9: color, 1: go.Brush.darken(color), start: new go.Spot(0.3, 0.3) // end: go.Spot.BottomRight, }); } function getStemBrush(color) { return new go.Brush('Linear', { 0: color, 0.2: go.Brush.lighten(color), 0.5: go.Brush.lighten(color), 0.9: color, 1: go.Brush.darken(color), start: go.Spot.Left, end: go.Spot.Right }); } function init() { myDiagram = new go.Diagram('myDiagramDiv', { layout: new go.GridLayout({ isOngoing: false, wrappingColumn: 4 }), 'animationManager.isEnabled': false, 'undoManager.isEnabled': true }); // ResizingTool override: add just one handle, instead of eight myDiagram.toolManager.resizingTool.makeAdornment = function (resizeObj) { // method override must be function, not => return new go.Adornment('Spot', { locationSpot: go.Spot.Center, category: this.name, adornedObject: resizeObj }) .add( new go.Placeholder(), this.makeHandle(resizeObj, go.Spot.Top) ); }; var ORIGINAL_HEIGHT = 400; /* The thermometer node consists of a Spot Panel with 6 children: 0: The BarSpace, which is the main element and 1: The Farenheit scale, on the left 2: The Celsius scale, on the right 3: The shape that represents alcohol or mercury in the thermometer 4: (Cosmetic) The stem that attaches to the bulb 5: (Cosmetic) The bulb The two Graduated Panels use alignmentFocusName to make sure their main Shapes line up with the Spot Panel"s main element, BarSpace. 1|0|2 1|0|2 1|0|2 1|0|2 1|3|2 1|3|2 |4| |5| */ myDiagram.nodeTemplate = new go.Node('Auto', { resizable: true, resizeObjectName: 'BarSpace', locationObjectName: 'Bulb', locationSpot: go.Spot.Center, isShadowed: true, shadowOffset: new go.Point(6, 6), margin: 5 }) .add( new go.Shape('RoundedRectangle', { fill: new go.Brush('Linear', { 0: '#fff', 1: '#eee', start: go.Spot.TopLeft, end: go.Spot.TopRight }) }), new go.Panel('Spot', { padding: 5 }) .add( new go.Shape({ name: 'BarSpace', width: 25, height: ORIGINAL_HEIGHT, strokeWidth: 0, fill: new go.Brush('Linear', { 0: '#a2a19f', 0.33: '#fff', 0.6: '#a2a19f', 0.8: go.Brush.lighten('#a2a19f'), 1: go.Brush.darken('#a2a19f'), start: go.Spot.Left, end: go.Spot.Right }), isShadowed: true, shadowVisible: true, shadowOffset: new go.Point(2, 2), shadowColor: '#eee' }) .bindTwoWay('height'), // Farenheit scale, on the left: new go.Panel('Graduated', { background: 'transparent', graduatedMin: -40, graduatedMax: 80, graduatedTickBase: 0, graduatedTickUnit: 1, alignment: go.Spot.BottomLeft, alignmentFocus: go.Spot.BottomLeft, alignmentFocusName: 'line' }) .bind('graduatedMax', '', data => { if (data.type === 'scaling') return 80; return data.height * 0.3 - 40; }) .add( new go.Shape({ name: 'line', geometryString: 'M0 0 V-' + ORIGINAL_HEIGHT, stroke: 'gray' }) .bind('height'), new go.Shape({ alignmentFocus: go.Spot.Bottom, interval: 2, strokeWidth: 1, geometryString: 'M0 0 V15' }), new go.Shape({ alignmentFocus: go.Spot.Bottom, interval: 10, strokeWidth: 2, geometryString: 'M0 0 V20' }), new go.TextBlock({ interval: 20, font: 'bold 18px sans-serif', alignmentFocus: new go.Spot(1, 0.5, 25, 0) }), // Mark 32 degrees on the farenheit scale: new go.TextBlock({ interval: 16, graduatedFunction: n => n === 32 ? '32—' : '', font: 'bold 12px sans-serif', stroke: 'red', alignmentFocus: new go.Spot(1, 0.5, 22, 0) }) ), // Mercury/alcohol bar, which represents the values of farenheit and celsius new go.Shape({ width: 25, strokeWidth: 0, fill: getMercuryBrush('#797dbe'), alignment: go.Spot.Bottom, alignmentFocus: go.Spot.Bottom }) .bind('fill', 'type', t => { let baseColor = (t === 'scaling') ? 'red' : '#797dbe'; return getMercuryBrush(baseColor); }) // .bind('shadowColor', 'type', t => { // let baseColor = (t === 'scaling') ? 'red' : '#797dbe'; // return go.Brush.lighten(baseColor); // }) // To determine the level, look at both data.farenheit and data.celsius, but prefer celsius .bind('height', '', data => { var thermometerHeight = ORIGINAL_HEIGHT; if (data.type === 'scaling') thermometerHeight = data.height; if (data.celsius !== undefined) { // (celsius + minimum value) / (total celsius range) * height return Math.max(0, ((data.celsius + 40) / 67) * thermometerHeight); } else if (data.farenheit !== undefined) { // (farenheit + minimum value) / (total farenheit range) * height return Math.max(0, ((data.farenheit + 40) / 120) * thermometerHeight); } else { return 0; } }) .bind('maxSize', 'height', h => new go.Size(NaN, h)), // Celsius scale, on the right: new go.Panel('Graduated', { background: 'transparent', // -40 to 27 because we picked -40 to 80 for farenheit, and want them to line up graduatedMin: -40, graduatedMax: 27, graduatedTickBase: 0, graduatedTickUnit: 1, alignment: go.Spot.BottomRight, alignmentFocus: go.Spot.BottomRight, alignmentFocusName: 'line2' }) .bind('graduatedMax', '', data => { if (data.type === 'scaling') return 27; return data.height * 0.1675 - 40; }) .add( new go.Shape({ name: 'line2', geometryString: 'M0 0 V-' + ORIGINAL_HEIGHT, stroke: 'gray' }) .bind('height'), new go.Shape({ interval: 2, strokeWidth: 1, geometryString: 'M0 0 V15' }), new go.Shape({ interval: 10, strokeWidth: 2, geometryString: 'M0 0 V20' }), new go.TextBlock({ interval: 20, textAlign: 'left', font: 'bold 18px sans-serif', alignmentFocus: go.Spot.Left, segmentOffset: new go.Point(0, 25) }) ), // Cosmetic: The stem and bulb new go.Shape({ width: 25, height: 10, strokeWidth: 0, fill: getStemBrush('#797dbe'), alignment: go.Spot.Bottom }) .bind('fill', 'type', t => { let baseColor = (t === 'scaling') ? 'red' : '#797dbe'; return getStemBrush(baseColor); }), new go.Shape('Circle', { name: 'Bulb', width: 55, height: 55, strokeWidth: 0, fill: getBulbBrush('#797dbe'), alignment: go.Spot.Bottom, alignmentFocus: go.Spot.Top, isShadowed: true, shadowVisible: true, shadowOffset: new go.Point(0, 0) }) .bind('fill', 'type', t => { let baseColor = (t === 'scaling') ? 'red' : '#797dbe'; return getBulbBrush(baseColor); }) ) ); // end node template myDiagram.model = new go.GraphLinksModel([ { height: 400, celsius: 20 }, { height: 250, celsius: -10 }, { type: 'scaling', height: 400, farenheit: 22 /*, celsius: 0*/ }, { type: 'scaling', height: 250, farenheit: 68 /*, celsius: 20*/ } ]); } window.addEventListener('DOMContentLoaded', init); </script> <div id="sample"> <div id="myDiagramDiv" style="border: solid 1px black; width: 800px; height: 500px"></div> <p>This sample uses <a href="../intro/graduatedPanels.html">Graduated Panels</a> and <code>Panel.alignmentFocusName</code> to line up thermometer scales.</p> <p> The thermometers are resizable, with two types. For the first two (default), resizing the thermometer reduces or increases the range of the values. For the second two (<code>type: "scaling"</code>), resizing the thermometer keeps the range, and scales the thermometer. </p> </div> </div> <!-- * * * * * * * * * * * * * --> <!-- End of GoJS sample code --> </div> <div id="allTagDescriptions" class="p-4 w-full max-w-screen-xl mx-auto"> <hr/> <h3 class="text-xl">GoJS Features in this sample</h3> <!-- blacklist tags that do not correspond to a specific GoJS feature --> <!-- blacklist tags that do not correspond to a specific GoJS feature --> <h4>Geometry Path Strings</h4> <p> The <b>GoJS</b> <a href="../api/symbols/Geometry.html" target="api">Geometry</a> class controls the "shape" of a <a href="../api/symbols/Shape.html" target="api">Shape</a>, whereas the <a href="../api/symbols/Shape.html#fill" target="api">Shape.fill</a> and <a href="../api/symbols/Shape.html#stroke" target="api">Shape.stroke</a> and other shape properties control the colors and appearance of the shape. For common shape figures, there are predefined geometries that can be used by setting <a href="../api/symbols/Shape.html#figure" target="api">Shape.figure</a>. However one can also define custom geometries. </p> <p> One can construct any Geometry by allocating and initializing a <a href="../api/symbols/Geometry.html" target="api">Geometry</a> of at least one <a href="../api/symbols/PathFigure.html" target="api">PathFigure</a> holding some <a href="../api/symbols/PathSegment.html" target="api">PathSegment</a>s. But you may find that using the string representation of a Geometry is easier to write and save in a database. Use the static method <a href="../api/symbols/Geometry.html#parse" target="api">Geometry.parse</a> or the <a href="../api/symbols/Shape.html#geometryString" target="api">Shape.geometryString</a> property to transform a geometry path string into a <a href="../api/symbols/Geometry.html" target="api">Geometry</a> object. </p> <p> More information can be found in the <a href="../intro/geometry.html">GoJS Intro</a>. </p> <p> <a href="../samples/index.html#geometries">Related samples</a> </p> <hr> </div> </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>