Skip to content

Commit a2f852d

Browse files
committed
drop down to select web agent, color scheme change updates per agent
1 parent aece681 commit a2f852d

File tree

1 file changed

+72
-8
lines changed

1 file changed

+72
-8
lines changed

ui/pie.html

Lines changed: 72 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@
77
<body style="display: flex; justify-content: center; align-items: center; width: 100vw; height: 100vh; margin: 0;">
88
<div id="app" style="display: flex; width: 67%; height: 67%; flex-direction: column;">
99
</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+
1021
<script src="https://cdn.swimos.org/js/3.10.2/swim-system.js"></script>
1122
<script>
1223

@@ -17,39 +28,47 @@
1728
const tween = swim.Transition.duration(1000);
1829

1930
/* 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)];
2337
const pie = new swim.PieView()
2438
// .innerRadius("15%")
2539
.outerRadius("25%")
2640
.tickColor("#b7b7b7")
2741
.font("14px sans-serif")
28-
.textColor("#4a4a4a");
42+
.textColor("#000000");
2943
pieCanvas.append(pie);
3044
const pieIndices = {"foo": 0, "bar": 1, "baz": 2};
3145

3246
function updateSlice(key, value) {
3347
const v = value.get(key).numberValue();
3448
let slice = pie.getChildView(key);
3549
if (slice) {
50+
sliceColor = sliceColors[pieIndices[key]];
51+
slice.sliceColor(sliceColor)
3652
slice.value(v, tween);
3753
slice.label().text(v);
3854
} else {
39-
const sliceColor = sliceColors[pieIndices[key]];
55+
var sliceColor = sliceColors[pieIndices[key]];
4056
slice = new swim.SliceView()
4157
.value(v)
4258
.sliceColor(sliceColor)
4359
.label(v.toFixed())
4460
.legend(key);
45-
pie.setChildView(key, slice);
61+
pie.setChildView(key, slice);
4662
}
4763
}
4864

65+
// switching between web agents
66+
var agent_URI = "/unit/master";
67+
4968
/* Data Subscriptions */
50-
const valueLink = swim.downlinkValue()
69+
var valueLink = swim.downlinkValue()
5170
.hostUri("warp://localhost:9001")
52-
.nodeUri("/unit/master")
71+
.nodeUri(agent_URI)
5372
.laneUri("latest")
5473
.didSet(function (value) {
5574
updateSlice("foo", value);
@@ -58,6 +77,51 @@
5877
})
5978
.open();
6079

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+
61125
</script>
62126
</body>
63127
</html>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy