Skip to content

Commit 789da1d

Browse files
committed
select web agent by dropdown with color changes
1 parent dad986e commit 789da1d

File tree

1 file changed

+103
-43
lines changed

1 file changed

+103
-43
lines changed

ui/chart.html

Lines changed: 103 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,54 +5,114 @@
55
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1, shrink-to-fit=no, viewport-fit=cover" />
66
</head>
77
<body style="display: flex; justify-content: center; align-items: center; width: 100vw; height: 100vh; margin: 0;">
8+
89
<div id="app" style="display: flex; width: 67%; height: 67%; flex-direction: column;">
910
</div>
11+
12+
<div>
13+
<label for="agents">Choose a web agent:</label>
14+
15+
<select name="agents" id="web_agent_select" onchange="update(this.value)">
16+
<option value="/unit/master" style = "color:#50e3c2">/unit/master</option>
17+
<option value="/unit/secondAgent" style = "color:#3c52f0">/unit/secondAgent</option>
18+
<option value="/unit/thirdAgent" style = "color:#212326">/unit/thirdAgent</option>
19+
</select>
20+
</div>
21+
1022
<script src="https://cdn.swimos.org/js/3.10.2/swim-system.js"></script>
1123
<script>
1224

13-
const app = new swim.HtmlAppView(document.getElementById("app"));
14-
15-
const chartCanvas = app.append('div').position('relative').append("canvas");
16-
17-
const tween = swim.Transition.duration(1000);
18-
19-
/* Chart View */
20-
const chart = new swim.ChartView()
21-
.bottomAxis(swim.AxisView.bottom("time"))
22-
.leftAxis(swim.AxisView.left("0...120"))
23-
.domainColor("#4a4a4a")
24-
.tickMarkColor("#4a4a4a")
25-
.font("12px sans-serif")
26-
.textColor("#4a4a4a");
27-
chartCanvas.append(chart);
28-
29-
const plot = new swim.LineGraphView()
30-
.stroke("#50e3c2")
31-
.strokeWidth(2);
32-
chart.addPlot(plot);
33-
34-
function addToPlot(key, value) {
35-
const time = key.numberValue();
36-
const v = value.get("count").numberValue(0);
37-
plot.insertDatum({x: time, y: v, opacity: void 0});
38-
}
39-
40-
function removeFromPlot(key) {
41-
const time = key.numberValue();
42-
plot.removeDatum(time);
43-
}
44-
45-
const histogramLink = swim.downlinkMap()
46-
.hostUri("warp://localhost:9001")
47-
.nodeUri("/unit/master")
48-
.laneUri("histogram")
49-
.didUpdate(function(key, value) {
50-
addToPlot(key, value);
51-
})
52-
.didRemove(function(key) {
53-
removeFromPlot(key);
54-
})
55-
.open();
25+
const app = new swim.HtmlAppView(document.getElementById("app"));
26+
27+
const chartCanvas = app.append('div').position('relative').append("canvas");
28+
29+
const tween = swim.Transition.duration(1000);
30+
31+
/* Chart View */
32+
const chart = new swim.ChartView()
33+
.bottomAxis(swim.AxisView.bottom("time"))
34+
.leftAxis(swim.AxisView.left("0...120"))
35+
.domainColor("#4a4a4a")
36+
.tickMarkColor("#4a4a4a")
37+
.font("12px sans-serif")
38+
.textColor("#4a4a4a");
39+
chartCanvas.append(chart);
40+
41+
const plot = new swim.LineGraphView()
42+
.stroke("#50e3c2")
43+
.strokeWidth(2);
44+
chart.addPlot(plot);
45+
46+
function addToPlot(key, value) {
47+
const time = key.numberValue();
48+
const v = value.get("count").numberValue(0);
49+
plot.insertDatum({x: time, y: v, opacity: void 0});
50+
}
51+
52+
function removeFromPlot(key) {
53+
const time = key.numberValue();
54+
plot.removeDatum(time);
55+
}
56+
57+
// Allowing for Web Agent selection by html dropdown menu
58+
59+
var agent_URI = "/unit/master";
60+
61+
// runs once
62+
var histogramLink = swim.downlinkMap()
63+
.hostUri("warp://localhost:9001")
64+
.nodeUri(agent_URI)
65+
.laneUri("histogram")
66+
.didUpdate(function(key, value) {
67+
addToPlot(key, value);
68+
})
69+
.didRemove(function(key) {
70+
removeFromPlot(key);
71+
})
72+
.open();
73+
74+
75+
// update logic runs whenever a new dropdown option is selected
76+
function update(val) {
77+
if (histogramLink) {
78+
// close downlink on update
79+
histogramLink.close();
80+
81+
// update the node URI used in histogramLink to match the selected agent
82+
agent_URI = document.getElementById('web_agent_select').value;
83+
console.log(agent_URI);
84+
85+
histogramLink = swim.downlinkMap()
86+
.hostUri("warp://localhost:9001")
87+
.nodeUri(agent_URI)
88+
.laneUri("histogram")
89+
.didUpdate(function(key, value) {
90+
addToPlot(key, value);
91+
})
92+
.didRemove(function(key) {
93+
removeFromPlot(key);
94+
})
95+
.open();
96+
97+
// switch statement that changes the plot color according to web agent
98+
var color = "#50e3c2";
99+
switch(agent_URI) {
100+
case "/unit/secondAgent":
101+
color = "#3c52f0";
102+
break;
103+
case "/unit/thirdAgent":
104+
color = "#212326";
105+
break;
106+
default:
107+
// for master web agent
108+
color = "#50e3c2";
109+
}
110+
plot
111+
.stroke(color);
112+
chart.addPlot(plot);
113+
}
114+
}
115+
56116
</script>
57117
</body>
58118
</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