|
7 | 7 | <body style="display: flex; justify-content: center; align-items: center; width: 100vw; height: 100vh; margin: 0;">
|
8 | 8 | <div id="app" style="display: flex; width: 67%; height: 67%; flex-direction: column;">
|
9 | 9 | </div>
|
| 10 | + |
| 11 | + <div> |
| 12 | + <label for="agents">Choose a web agent:</label> |
| 13 | + |
| 14 | + <select name="agents" id="web_agent_select" onchange="update(this.value)"> |
| 15 | + <option value="/unit/master" style = "color:#50e3c2">/unit/master</option> |
| 16 | + <option value="/unit/secondAgent" style = "color:#3c52f0">/unit/secondAgent</option> |
| 17 | + <option value="/unit/thirdAgent" style = "color:#212326">/unit/thirdAgent</option> |
| 18 | + </select> |
| 19 | + </div> |
| 20 | + |
10 | 21 | <script src="https://cdn.swimos.org/js/3.10.2/swim-system.js"></script>
|
11 | 22 | <script>
|
12 | 23 |
|
|
39 | 50 | .label("BAZ");
|
40 | 51 | gauge.setChildView("baz", bazDial);
|
41 | 52 |
|
| 53 | +var colorLow = "#50e3c2"; |
| 54 | +var colorMed = "#359680"; |
| 55 | +var colorHigh = "#1f5c4e" |
| 56 | + |
42 | 57 | function updateDial(dial, max, key, value) {
|
43 | 58 | const v = value.get(key).numberValue();
|
44 | 59 | const percent = v / max;
|
45 | 60 | const legend = key + ": " + (v) + " out of " + max;
|
46 | 61 | dial.value(v, tween)
|
47 | 62 | .total(max)
|
48 |
| - .meterColor(percent < 0.5 ? "#989898" : percent < 0.9 ? "#4a4a4a" : "#000000", tween); |
| 63 | + .meterColor(percent < 0.5 ? colorLow : percent < 0.9 ? colorMed : colorHigh, tween); |
49 | 64 | dial.label().text(legend);
|
50 | 65 | }
|
51 | 66 |
|
| 67 | + |
| 68 | +// switching between web agents |
| 69 | +var agent_URI = "/unit/master"; |
| 70 | + |
52 | 71 | /* Data Subscriptions */
|
53 |
| -const valueLink = swim.downlinkValue() |
| 72 | + |
| 73 | +// runs once |
| 74 | +var valueLink = swim.downlinkValue() |
54 | 75 | .hostUri("warp://localhost:9001")
|
55 |
| - .nodeUri("/unit/master") |
| 76 | + .nodeUri(agent_URI) |
56 | 77 | .laneUri("latest")
|
57 | 78 | .didSet(function (value) {
|
58 | 79 | updateDial(fooDial, 70, "foo", value);
|
|
61 | 82 | })
|
62 | 83 | .open();
|
63 | 84 |
|
| 85 | + |
| 86 | +// update logic runs whenever a new dropdown option is selected |
| 87 | +function update(val) { |
| 88 | + if (valueLink) { |
| 89 | + // close downlink on update |
| 90 | + valueLink.close(); |
| 91 | + |
| 92 | + // update the node URI used in histogramLink to match the selected agent |
| 93 | + agent_URI = document.getElementById('web_agent_select').value; |
| 94 | + console.log(agent_URI); |
| 95 | + |
| 96 | + valueLink = swim.downlinkValue() |
| 97 | + .hostUri("warp://localhost:9001") |
| 98 | + .nodeUri(agent_URI) |
| 99 | + .laneUri("latest") |
| 100 | + .didSet(function (value) { |
| 101 | + updateDial(fooDial, 70, "foo", value); |
| 102 | + updateDial(barDial, 140, "bar", value); |
| 103 | + updateDial(bazDial, 210, "baz", value); |
| 104 | + }) |
| 105 | + .open(); |
| 106 | + |
| 107 | + // switch statement that changes the plot color according to web agent |
| 108 | + switch(agent_URI) { |
| 109 | + case "/unit/secondAgent": |
| 110 | + colorLow = "#3c52f0"; |
| 111 | + colorMed = "#182373"; |
| 112 | + colorHigh = "#0b1347" |
| 113 | + break; |
| 114 | + case "/unit/thirdAgent": |
| 115 | + colorLow = "#d5d9e0"; |
| 116 | + colorMed = "#6d7178"; |
| 117 | + colorHigh = "#000000" |
| 118 | + break; |
| 119 | + default: |
| 120 | + // for master web agent |
| 121 | + colorLow = "#50e3c2"; |
| 122 | + colorMed = "#359680"; |
| 123 | + colorHigh = "#1f5c4e" |
| 124 | + } |
| 125 | + } |
| 126 | +} |
| 127 | + |
64 | 128 | </script>
|
65 | 129 | </body>
|
66 | 130 | </html>
|
0 commit comments