|
2 | 2 | <html> |
3 | 3 | <head> |
4 | 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" /> |
| 5 | + <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1, maximum-scale=1, user-scalable=0, shrink-to-fit=no, viewport-fit=cover"> |
6 | 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> |
| 7 | + <body swim-theme style="position: fixed; display: flex; justify-content: center; align-items: center; width: 100vw; height: 100vh; margin: 0;"> |
| 8 | + <script src="https://cdn.swimos.org/js/3.11.1/swim-system.js"></script> |
| 9 | + <script src="https://cdn.swimos.org/js/3.11.1/swim-toolkit.js"></script> |
11 | 10 | <script> |
12 | 11 |
|
13 | | -const app = new swim.HtmlAppView(document.getElementById("app")); |
| 12 | +const bodyView = swim.HtmlView.fromNode(document.body); |
14 | 13 |
|
15 | | -const gaugeCanvas = app.append('div').position('relative').append("canvas"); |
| 14 | +const containerView = bodyView.append("div").display("flex").width("67%").height("67%").touchAction("none").userSelect("none"); |
| 15 | + |
| 16 | +const canvasView = swim.CanvasView.create() |
| 17 | + .mouseEventsEnabled(true) |
| 18 | + .pointerEventsEnabled(true) |
| 19 | + .touchEventsEnabled(true) |
| 20 | + .touchAction("manipulation"); |
16 | 21 |
|
17 | | -const tween = swim.Transition.duration(1000); |
18 | 22 |
|
19 | 23 | /* Gauge View */ |
20 | | -const gauge = new swim.GaugeView() |
| 24 | +const gaugeView = canvasView.append(swim.GaugeView) |
| 25 | + .innerRadius(swim.Length.pct(25)) |
21 | 26 | .startAngle(swim.Angle.rad(3 * Math.PI / 4)) |
22 | 27 | .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 | 28 | .font("14px sans-serif") |
27 | | - .textColor("#4a4a4a"); |
28 | | -gaugeCanvas.append(gauge); |
| 29 | + .title(swim.TextRunView.fromAny("Foo, Bar, Baz").font("20px sans-serif")) |
| 30 | + .font("14px sans-serif") |
| 31 | + .textColor("#4a4a4a") |
| 32 | + .on("pointerover", function (event) { |
| 33 | + if (event.targetView instanceof swim.DialView) { |
| 34 | + event.targetView.modifyMood(swim.Feel.default, [[swim.Feel.secondary, 1]], true); |
| 35 | + } |
| 36 | + }) |
| 37 | + .on("pointerout", function (event) { |
| 38 | + if (event.targetView instanceof swim.DialView) { |
| 39 | + event.targetView.modifyMood(swim.Feel.default, [[swim.Feel.secondary, void 0]], true); |
| 40 | + } |
| 41 | + }); |
29 | 42 |
|
30 | | -const fooDial = new swim.DialView() |
31 | | - .label("FOO"); |
32 | | -gauge.setChildView("foo", fooDial); |
| 43 | +const fooDial = gaugeView.append(swim.DialView, "FOO"); |
33 | 44 |
|
34 | | -const barDial = new swim.DialView() |
35 | | - .label("BAR"); |
36 | | -gauge.setChildView("bar", barDial); |
| 45 | +const barDial = gaugeView.append(swim.DialView, "BAR"); |
37 | 46 |
|
38 | | -const bazDial = new swim.DialView() |
39 | | - .label("BAZ"); |
40 | | -gauge.setChildView("baz", bazDial); |
| 47 | +const bazDial = gaugeView.append(swim.DialView, "BAZ"); |
41 | 48 |
|
42 | 49 | function updateDial(dial, max, key, value) { |
43 | 50 | const v = value.get(key).numberValue(); |
44 | 51 | const percent = v / max; |
45 | 52 | 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); |
| 53 | + const timing = swim.Easing.linear.withDuration(1000); |
| 54 | + dial.value(percent, timing); |
| 55 | + dial.label(legend); |
50 | 56 | } |
51 | 57 |
|
52 | 58 | /* Data Subscriptions */ |
|
61 | 67 | }) |
62 | 68 | .open(); |
63 | 69 |
|
| 70 | +containerView.append(canvasView); |
| 71 | + |
64 | 72 | </script> |
65 | 73 | </body> |
66 | 74 | </html> |
0 commit comments