|
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 |
|
|
17 | 28 | const tween = swim.Transition.duration(1000);
|
18 | 29 |
|
19 | 30 | /* Pie View */
|
20 |
| -const sliceColors = [swim.Color.parse("#00a6ed"), |
21 |
| - swim.Color.parse("#6acd00"), |
22 |
| - swim.Color.parse("#c200fa")]; |
| 31 | +var color1 = "#50e3c2"; |
| 32 | +var color2 = "#359680"; |
| 33 | +var color3 = "#1f5c4e" |
| 34 | +var sliceColors = [swim.Color.parse(color3), |
| 35 | + swim.Color.parse(color2), |
| 36 | + swim.Color.parse(color1)]; |
23 | 37 | const pie = new swim.PieView()
|
24 | 38 | // .innerRadius("15%")
|
25 | 39 | .outerRadius("25%")
|
26 | 40 | .tickColor("#b7b7b7")
|
27 | 41 | .font("14px sans-serif")
|
28 |
| - .textColor("#4a4a4a"); |
| 42 | + .textColor("#000000"); |
29 | 43 | pieCanvas.append(pie);
|
30 | 44 | const pieIndices = {"foo": 0, "bar": 1, "baz": 2};
|
31 | 45 |
|
32 | 46 | function updateSlice(key, value) {
|
33 | 47 | const v = value.get(key).numberValue();
|
34 | 48 | let slice = pie.getChildView(key);
|
35 | 49 | if (slice) {
|
| 50 | + sliceColor = sliceColors[pieIndices[key]]; |
| 51 | + slice.sliceColor(sliceColor) |
36 | 52 | slice.value(v, tween);
|
37 | 53 | slice.label().text(v);
|
38 | 54 | } else {
|
39 |
| - const sliceColor = sliceColors[pieIndices[key]]; |
| 55 | + var sliceColor = sliceColors[pieIndices[key]]; |
40 | 56 | slice = new swim.SliceView()
|
41 | 57 | .value(v)
|
42 | 58 | .sliceColor(sliceColor)
|
43 | 59 | .label(v.toFixed())
|
44 | 60 | .legend(key);
|
45 |
| - pie.setChildView(key, slice); |
| 61 | + pie.setChildView(key, slice); |
46 | 62 | }
|
47 | 63 | }
|
48 | 64 |
|
| 65 | +// switching between web agents |
| 66 | +var agent_URI = "/unit/master"; |
| 67 | + |
49 | 68 | /* Data Subscriptions */
|
50 |
| -const valueLink = swim.downlinkValue() |
| 69 | +var valueLink = swim.downlinkValue() |
51 | 70 | .hostUri("warp://localhost:9001")
|
52 |
| - .nodeUri("/unit/master") |
| 71 | + .nodeUri(agent_URI) |
53 | 72 | .laneUri("latest")
|
54 | 73 | .didSet(function (value) {
|
55 | 74 | updateSlice("foo", value);
|
|
58 | 77 | })
|
59 | 78 | .open();
|
60 | 79 |
|
| 80 | +// update logic runs whenever a new dropdown option is selected |
| 81 | +function update(val) { |
| 82 | + if (valueLink) { |
| 83 | + // close downlink on update |
| 84 | + valueLink.close(); |
| 85 | + |
| 86 | + // update the node URI used in histogramLink to match the selected agent |
| 87 | + agent_URI = document.getElementById('web_agent_select').value; |
| 88 | + console.log(agent_URI); |
| 89 | + |
| 90 | + // switch statement that changes the plot color according to web agent |
| 91 | + switch(agent_URI) { |
| 92 | + case "/unit/secondAgent": |
| 93 | + color1 = "#7a85d6" |
| 94 | + color2 = "#3c52f0"; |
| 95 | + color3 = "#182373"; |
| 96 | + break; |
| 97 | + case "/unit/thirdAgent": |
| 98 | + color1 = "#d5d9e0"; |
| 99 | + color2 = "#9da4b0" |
| 100 | + color3 = "#6d7178"; |
| 101 | + break; |
| 102 | + default: |
| 103 | + // for master web agent |
| 104 | + color1 = "#50e3c2"; |
| 105 | + color2 = "#359680"; |
| 106 | + color3 = "#1f5c4e" |
| 107 | + } |
| 108 | + sliceColors = [swim.Color.parse(color3), |
| 109 | + swim.Color.parse(color2), |
| 110 | + swim.Color.parse(color1)]; |
| 111 | + |
| 112 | + valueLink = swim.downlinkValue() |
| 113 | + .hostUri("warp://localhost:9001") |
| 114 | + .nodeUri(agent_URI) |
| 115 | + .laneUri("latest") |
| 116 | + .didSet(function (value) { |
| 117 | + updateSlice("foo", value); |
| 118 | + updateSlice("bar", value); |
| 119 | + updateSlice("baz", value); |
| 120 | + }) |
| 121 | + .open(); |
| 122 | + } |
| 123 | + } |
| 124 | + |
61 | 125 | </script>
|
62 | 126 | </body>
|
63 | 127 | </html>
|
0 commit comments