-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrose.html
180 lines (157 loc) · 4.22 KB
/
rose.html
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<!DOCTYPE html>
<meta charset="utf-8">
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<style>
.chart div {
font: 10px;
text-align: right;
padding: 3px;
margin: 1px;
color: white;
}
.title {
font-size: 20px;
font-weight: 500;
}
.axis path {
display: none;
}
.axis {
stroke: #777;
stroke-dasharray: 5,5;
fill: none;
}
.axis-main{
stroke-dasharray: 0;
}
</style>
<div class="chart"></div>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.js"></script>
<script>
$.ajax({
url: "http://test-compass.openocean.fr/api/point-stat/CUR-ROSE_Point2/get_visu_data/?format=json",
type: "GET",
dataType: 'json',
xhrFields: {
withCredentials: true
},
success: function (json) {
renderR(json);
}
});
function renderR(json) {
// Widths and heights
var wChart = 600;
var hChart = wChart;
var wMargin = 20;
var hMargin = wMargin;
var width = wChart + wMargin * 2;
var hTitle = 50;
var height = hTitle + hChart + hMargin * 2;
var xCenter = wChart / 2 + wMargin;
var yCenter = hChart / 2 + hMargin;
var speedTicks = 5;
var sdat = [];
var labels = [
{"angle": 0, "name": "E"},
{"angle": 45, "name": "S-E"},
{"angle": 90, "name": "S"},
{"angle": 135, "name": "S-W"},
{"angle": 180, "name": "W"},
{"angle": 225, "name": "N-W"},
{"angle": 270, "name": "N"},
{"angle": 315, "name": "N-E"}];
var tdata = json.theta;
var mdata = json.mag;
var metadata = json.visualization;
for (i=0; i<=speedTicks; i++) {
sdat[i] = i;
}
var title = metadata.web["data-legend-0"];
var svg = d3.select(".chart")
.append("svg")
.attr("width", width)
.attr("height", height);
svg.append('g')
.append("text")
.attr("x", width / 2)
.attr("y", hTitle / 2)
.style("text-anchor", "middle")
.attr("class", "title")
.text(title);
var graph = svg.append('g')
.attr('transform', 'translate(0,' + hTitle + ')');
graph.append('g')
.selectAll("circle")
.data(mdata._values[0][0])
.enter()
.append("circle")
.attr("r", "2")
.attr("cx", function(d, i) {
return d * Math.cos((tdata._values[0][0][i] - 90) * Math.PI / 180) * wChart / 2 / speedTicks + xCenter;
})
.attr("cy", function(d, i) {
return d * Math.sin((tdata._values[0][0][i] - 90) * Math.PI / 180) * wChart / 2 / speedTicks + yCenter;
})
.attr("fill", "#7bb0cd");
graph.append('g')
.selectAll("circle")
.data(sdat)
.enter()
.append("circle")
.attr("class", "axis")
.attr("r", function(d) {
return d * wChart / 2 / speedTicks;
})
.attr("cx", xCenter)
.attr("cy", yCenter);
graph.append('g')
.append("circle")
.attr("class", "axis axis-main")
.attr("r", wChart / 2)
.attr("cx", xCenter)
.attr("cy", yCenter)
.style("stroke-width", "2");
graph.append('g')
.selectAll("text")
.data(sdat)
.enter()
.append("text")
.attr("x", function(d) {
return (d * wChart / 2 / speedTicks) * Math.cos(-2) + xCenter;
})
.attr("y", function(d) {
return (d * wChart / 2 / speedTicks) * Math.sin(-2) + yCenter;
})
.style("text-anchor", "middle")
.text(function(d) {return d});
graph.append('g')
.selectAll("line")
.data(labels)
.enter()
.append("line")
.attr("x1",xCenter)
.attr("y1",yCenter)
.attr("x2", function(d) {
return Math.cos(d.angle * Math.PI / 180) * wChart / 2 + xCenter;
})
.attr("y2", function(d) {
return Math.sin(d.angle * Math.PI / 180) * wChart / 2 + yCenter;
})
.attr("class", "axis")
graph.append('g')
.selectAll("line")
.data(labels)
.enter()
.append("text")
.attr("x", function(d) {
return Math.cos((d.angle) * Math.PI / 180) * (wChart / 2 + 10) + xCenter;
})
.attr("y", function(d) {
return Math.sin((d.angle) * Math.PI / 180) * (wChart / 2 + 10) + yCenter + 5;
})
.style("text-anchor", "middle")
.text(function(d) {return d.name});
}
</script>