UNPKG

gojs

Version:

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

240 lines (220 loc) 11.7 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."/> <link rel="stylesheet" href="../assets/css/style.css"/> <!-- Copyright 1998-2023 by Northwoods Software Corporation. --> <title>Thermometer</title> </head> <body> <!-- This top nav is not part of the sample code --> <nav id="navTop" class="w-full z-30 top-0 text-white bg-nwoods-primary"> <div class="w-full container max-w-screen-lg mx-auto flex flex-wrap sm:flex-nowrap items-center justify-between mt-0 py-2"> <div class="md:pl-4"> <a class="text-white hover:text-white no-underline hover:no-underline font-bold text-2xl lg:text-4xl rounded-lg hover:bg-nwoods-secondary " href="../"> <h1 class="my-0 p-1 ">GoJS</h1> </a> </div> <button id="topnavButton" class="rounded-lg sm:hidden focus:outline-none focus:ring" aria-label="Navigation"> <svg fill="currentColor" viewBox="0 0 20 20" class="w-6 h-6"> <path id="topnavOpen" fill-rule="evenodd" d="M3 5a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM3 10a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM9 15a1 1 0 011-1h6a1 1 0 110 2h-6a1 1 0 01-1-1z" clip-rule="evenodd"></path> <path id="topnavClosed" class="hidden" fill-rule="evenodd" d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z" clip-rule="evenodd"></path> </svg> </button> <div id="topnavList" class="hidden sm:block items-center w-auto mt-0 text-white p-0 z-20"> <ul class="list-reset list-none font-semibold flex justify-end flex-wrap sm:flex-nowrap items-center px-0 pb-0"> <li class="p-1 sm:p-0"><a class="topnav-link" href="../learn/">Learn</a></li> <li class="p-1 sm:p-0"><a class="topnav-link" href="../samples/">Samples</a></li> <li class="p-1 sm:p-0"><a class="topnav-link" href="../intro/">Intro</a></li> <li class="p-1 sm:p-0"><a class="topnav-link" href="../api/">API</a></li> <li class="p-1 sm:p-0"><a class="topnav-link" href="https://www.nwoods.com/products/register.html">Register</a></li> <li class="p-1 sm:p-0"><a class="topnav-link" href="../download.html">Download</a></li> <li class="p-1 sm:p-0"><a class="topnav-link" href="https://forum.nwoods.com/c/gojs/11">Forum</a></li> <li class="p-1 sm:p-0"><a class="topnav-link" href="https://www.nwoods.com/contact.html" target="_blank" rel="noopener" onclick="getOutboundLink('https://www.nwoods.com/contact.html', 'contact');">Contact</a></li> <li class="p-1 sm:p-0"><a class="topnav-link" href="https://www.nwoods.com/sales/index.html" target="_blank" rel="noopener" onclick="getOutboundLink('https://www.nwoods.com/sales/index.html', 'buy');">Buy</a></li> </ul> </div> </div> <hr class="border-b border-gray-600 opacity-50 my-0 py-0" /> </nav> <div class="md:flex flex-col md:flex-row md:min-h-screen w-full max-w-screen-xl mx-auto"> <div id="navSide" class="flex flex-col w-full md:w-48 text-gray-700 bg-white flex-shrink-0"></div> <!-- * * * * * * * * * * * * * --> <!-- Start of GoJS sample code --> <script src="../release/go.js"></script> <div id="allSampleContent" class="p-4 w-full"> <script id="code"> function init() { if (window.goSamples) goSamples(); // init for these samples -- you don"t need to call this // Since 2.2 you can also author concise templates with method chaining instead of GraphObject.make // For details, see https://gojs.net/latest/intro/buildingObjects.html const $ = go.GraphObject.make; myDiagram = new go.Diagram("myDiagramDiv", { layout: $(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 $(go.Adornment, "Spot", { locationSpot: go.Spot.Center, category: this.name, adornedObject: resizeObj }, $(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 = $(go.Node, "Spot", { resizable: true, resizeObjectName: "BarSpace", locationObjectName: "Bulb", locationSpot: go.Spot.Center }, $(go.Shape, { name: "BarSpace", width: 25, height: ORIGINAL_HEIGHT, strokeWidth: 0, fill: "rgba(0,0,0,.05)" }, new go.Binding("height").makeTwoWay() ), // Farenheit scale, on the left: $(go.Panel, "Graduated", { background: "white", graduatedMin: -40, graduatedMax: 80, graduatedTickBase: 0, graduatedTickUnit: 1, alignment: go.Spot.BottomLeft, alignmentFocus: go.Spot.BottomLeft, alignmentFocusName: "line" }, new go.Binding("graduatedMax", "", data => { if (data.type === "scaling") return 80; return (data.height * 0.3) - 40; }), $(go.Shape, { name: "line", geometryString: "M0 0 V-" + ORIGINAL_HEIGHT, stroke: "gray" }, new go.Binding("height")), $(go.Shape, { alignmentFocus: go.Spot.Bottom, interval: 2, strokeWidth: 1, geometryString: "M0 0 V15" }), $(go.Shape, { alignmentFocus: go.Spot.Bottom, interval: 10, strokeWidth: 2, geometryString: "M0 0 V20" }), $(go.TextBlock, { interval: 20, font: "22px Georgia", alignmentFocus: new go.Spot(1, 0.5, 20, 0) }), // Mark 32 degrees on the farenheit scale: $(go.TextBlock, { interval: 32, graduatedFunction: n => (n === 32) ? "32—" : "", font: "bold 12px Georgia", stroke: "red", alignmentFocus: new go.Spot(1, 0.5, 20, 0) }) ), // Mercury/alcohol bar, which represents the values of farenheit and celsius $(go.Shape, { width: 25, strokeWidth: 0, fill: "red", alignment: go.Spot.Bottom, alignmentFocus: go.Spot.Bottom, }, new go.Binding('fill', 'type', t => (t === "scaling") ? "dimgray" : "red"), // To determine the level, look at both data.farenheit and data.celsius, but prefer celsius new go.Binding("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; } }), new go.Binding("maxSize", "height", h => new go.Size(NaN, h)) ), // Celsius scale, on the right: $(go.Panel, "Graduated", { background: "white", // -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" }, new go.Binding("graduatedMax", "", data => { if (data.type === "scaling") return 27; return (data.height * 0.1675) - 40; }), $(go.Shape, { name: "line2", geometryString: "M0 0 V-" + ORIGINAL_HEIGHT, stroke: "gray" }, new go.Binding("height")), $(go.Shape, { interval: 2, strokeWidth: 1, geometryString: "M0 0 V15" }), $(go.Shape, { interval: 10, strokeWidth: 2, geometryString: "M0 0 V20" }), $(go.TextBlock, { interval: 20, textAlign: "left", font: "22px Georgia", alignmentFocus: go.Spot.Left, segmentOffset: new go.Point(0, 22) }) ), // Cosmetic: The stem and bulb $(go.Shape, { width: 25, height: 10, strokeWidth: 0, fill: "red", alignment: go.Spot.Bottom }, new go.Binding('fill', 'type', t => (t === "scaling") ? "dimgray" : "red") ), $(go.Shape, "Circle", { name: "Bulb", width: 55, height: 55, strokeWidth: 0, fill: "red", alignment: go.Spot.Bottom, alignmentFocus: go.Spot.Top, }, new go.Binding('fill', 'type', t => (t === "scaling") ? "dimgray" : "red") ) ); // 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> </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>