|
| 1 | +<!DOCTYPE html> |
| 2 | +<html> |
| 3 | + <head> |
| 4 | + <title>Swim Gauge</title> |
| 5 | + <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1, shrink-to-fit=no, viewport-fit=cover" /> |
| 6 | + </head> |
| 7 | + <body style="display: flex; justify-content: center; align-items: center; width: 100vw; height: 100vh; margin: 0;"> |
| 8 | + <div id="app" style="display: flex; width: 67%; height: 67%; flex-direction: column;"> |
| 9 | + </div> |
| 10 | + <script src="https://cdn.swimos.org/js/3.10.2/swim-system.js"></script> |
| 11 | + <script> |
| 12 | + |
| 13 | +const app = new swim.HtmlAppView(document.getElementById("app")); |
| 14 | + |
| 15 | +const gaugeCanvas = app.append('div').position('relative').append("canvas"); |
| 16 | + |
| 17 | +const tween = swim.Transition.duration(1000); |
| 18 | + |
| 19 | +/* Gauge View */ |
| 20 | +const gauge = new swim.GaugeView() |
| 21 | + .startAngle(swim.Angle.rad(3 * Math.PI / 4)) |
| 22 | + .sweepAngle(swim.Angle.rad(3 * Math.PI / 2)) |
| 23 | + .dialColor("#cccccc") |
| 24 | + .meterColor("#989898") |
| 25 | + .title(new swim.TextRunView("Foo, Bar, Baz").font("20px sans-serif")) |
| 26 | + .font("14px sans-serif") |
| 27 | + .textColor("#4a4a4a"); |
| 28 | +gaugeCanvas.append(gauge); |
| 29 | + |
| 30 | +const fooDial = new swim.DialView() |
| 31 | + .label("FOO"); |
| 32 | +gauge.setChildView("foo", fooDial); |
| 33 | + |
| 34 | +const barDial = new swim.DialView() |
| 35 | + .label("BAR"); |
| 36 | +gauge.setChildView("bar", barDial); |
| 37 | + |
| 38 | +const bazDial = new swim.DialView() |
| 39 | + .label("BAZ"); |
| 40 | +gauge.setChildView("baz", bazDial); |
| 41 | + |
| 42 | +function updateDial(dial, max, key, value) { |
| 43 | + const v = value.get(key).numberValue(); |
| 44 | + const percent = v / max; |
| 45 | + const legend = key + ": " + (v) + " out of " + max; |
| 46 | + dial.value(v, tween) |
| 47 | + .total(max) |
| 48 | + .meterColor(percent < 0.5 ? "#989898" : percent < 0.9 ? "#4a4a4a" : "#000000", tween); |
| 49 | + dial.label().text(legend); |
| 50 | +} |
| 51 | + |
| 52 | +/* Data Subscriptions */ |
| 53 | +const valueLink = swim.downlinkValue() |
| 54 | + .hostUri("warp://localhost:9001") |
| 55 | + .nodeUri("/unit/master") |
| 56 | + .laneUri("latest") |
| 57 | + .didSet(function (value) { |
| 58 | + updateDial(fooDial, 70, "foo", value); |
| 59 | + updateDial(barDial, 140, "bar", value); |
| 60 | + updateDial(bazDial, 210, "baz", value); |
| 61 | + }) |
| 62 | + .open(); |
| 63 | + |
| 64 | + </script> |
| 65 | + </body> |
| 66 | +</html> |
0 commit comments