-
Notifications
You must be signed in to change notification settings - Fork 0
/
bonus.js
92 lines (87 loc) · 2.22 KB
/
bonus.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/**
* BONUS Solution
* */
function buildGauge(wfreq) {
// Enter the washing frequency between 0 and 180
var level = parseFloat(wfreq) * 20;
// Trig to calc meter point
var degrees = 180 - level;
var radius = 0.5;
var radians = (degrees * Math.PI) / 180;
var x = radius * Math.cos(radians);
var y = radius * Math.sin(radians);
// Path: may have to change to create a better triangle
var mainPath = "M -.0 -0.05 L .0 0.05 L ";
var pathX = String(x);
var space = " ";
var pathY = String(y);
var pathEnd = " Z";
var path = mainPath.concat(pathX, space, pathY, pathEnd);
var data = [
{
type: "scatter",
x: [0],
y: [0],
marker: { size: 12, color: "850000" },
showlegend: false,
name: "Freq",
text: level,
hoverinfo: "text+name"
},
{
values: [50 / 9, 50 / 9, 50 / 9, 50 / 9, 50 / 9, 50 / 9, 50 / 9, 50 / 9, 50 / 9, 50],
rotation: 90,
text: ["8-9", "7-8", "6-7", "5-6", "4-5", "3-4", "2-3", "1-2", "0-1", ""],
textinfo: "text",
textposition: "inside",
marker: {
colors: [
"rgba(0, 105, 11, .5)",
"rgba(10, 120, 22, .5)",
"rgba(14, 127, 0, .5)",
"rgba(110, 154, 22, .5)",
"rgba(170, 202, 42, .5)",
"rgba(202, 209, 95, .5)",
"rgba(210, 206, 145, .5)",
"rgba(232, 226, 202, .5)",
"rgba(240, 230, 215, .5)",
"rgba(255, 255, 255, 0)"
]
},
labels: ["8-9", "7-8", "6-7", "5-6", "4-5", "3-4", "2-3", "1-2", "0-1", ""],
hoverinfo: "label",
hole: 0.5,
type: "pie",
showlegend: false
}
];
var layout = {
shapes: [
{
type: "path",
path: path,
fillcolor: "850000",
line: {
color: "850000"
}
}
],
title: "<b>Belly Button Washing Frequency</b> <br> Scrubs per Week",
height: 500,
width: 500,
xaxis: {
zeroline: false,
showticklabels: false,
showgrid: false,
range: [-1, 1]
},
yaxis: {
zeroline: false,
showticklabels: false,
showgrid: false,
range: [-1, 1]
}
};
var GAUGE = document.getElementById("gauge");
Plotly.newPlot(GAUGE, data, layout);
}