-
Notifications
You must be signed in to change notification settings - Fork 18
/
coffeeMachineView.js
40 lines (33 loc) · 1.18 KB
/
coffeeMachineView.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
google.charts.load('current', {'packages':['gauge']});
/**
* Populates the `planVizDiv` element with the plan visualization of the `finalState`.
* @param {HTMLDivElement} planVizDiv host element on the page
* @param {Plan} plan plan to be visualized
* @param {{variableValue: string, value: number | boolean}[]} finalState final state of the `plan`
* @param {number} displayWidth desired width in pixels
*/
function visualizeStateInDiv(planVizDiv, plan, finalState, displayWidth) {
for (const v of finalState) {
console.log(`${v.variableName}: ${v.value}`);
}
const valueMap = new Map(finalState.map(i => [i.variableName, i.value]));
var data = google.visualization.arrayToDataTable([
['Label', 'Value'],
['water-temperature', valueMap.get('water-temperature')],
['cup-level',
valueMap.get('cup-level')
/ valueMap.get('cup-capacity')
* 100]
]);
var options = {
width: displayWidth, height: displayWidth,
redFrom: 90, redTo: 100,
yellowFrom: 75, yellowTo: 90,
minorTicks: 5
};
var chart = new google.visualization.Gauge(planVizDiv);
chart.draw(data, options);
}
module.exports = {
visualizeStateInDiv: visualizeStateInDiv
};