-
Notifications
You must be signed in to change notification settings - Fork 294
/
radar.js
173 lines (150 loc) · 6.86 KB
/
radar.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
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
function init(h,w) {
$('#title').text(document.title).width(w);
var radar = new pv.Panel()
.width(w)
.height(h)
.canvas('radar')
// arcs
radar.add(pv.Dot)
.data(radar_arcs)
.left(w/2)
.bottom(h/2)
.radius(function(d){return d.r;})
.strokeStyle("#ccc")
.anchor("top")
.add(pv.Label).text(function(d) { return d.name;});
//quadrant lines -- vertical
radar.add(pv.Line)
.data([(h/2-radar_arcs[radar_arcs.length-1].r),h-(h/2-radar_arcs[radar_arcs.length-1].r)])
.lineWidth(1)
.left(w/2)
.bottom(function(d) {return d;})
.strokeStyle("#bbb");
//quadrant lines -- horizontal
radar.add(pv.Line)
.data([(w/2-radar_arcs[radar_arcs.length-1].r),w-(w/2-radar_arcs[radar_arcs.length-1].r)])
.lineWidth(1)
.bottom(h/2)
.left(function(d) {return d;})
.strokeStyle("#bbb");
// blips
// var total_index=1;
// for (var i = 0; i < radar_data.length; i++) {
// radar.add(pv.Dot)
// .def("active", false)
// .data(radar_data[i].items)
// .size( function(d) { return ( d.blipSize !== undefined ? d.blipSize : 70 ); })
// .left(function(d) { var x = polar_to_raster(d.pc.r, d.pc.t)[0];
// //console.log("name:" + d.name + ", x:" + x);
// return x;})
// .bottom(function(d) { var y = polar_to_raster(d.pc.r, d.pc.t)[1];
// //console.log("name:" + d.name + ", y:" + y);
// return y;})
// .title(function(d) { return d.name;})
// .cursor( function(d) { return ( d.url !== undefined ? "pointer" : "auto" ); })
// .event("click", function(d) { if ( d.url !== undefined ){self.location = d.url}})
// .angle(Math.PI) // 180 degrees in radians !
// .strokeStyle(radar_data[i].color)
// .fillStyle(radar_data[i].color)
// .shape(function(d) {return (d.movement === 't' ? "triangle" : "circle");})
// .anchor("center")
// .add(pv.Label)
// .text(function(d) {return total_index++;})
// .textBaseline("middle")
// .textStyle("white");
// }
//Quadrant Ledgends
var radar_quadrant_ctr=1;
var quadrantFontSize = 18;
var headingFontSize = 14;
var stageHeadingCount = 0;
var lastRadius = 0;
var lastQuadrant='';
var spacer = 6;
var fontSize = 10;
var total_index = 1;
//TODO: Super fragile: re-order the items, by radius, in order to logically group by the rings.
for (var i = 0; i < radar_data.length; i++) {
//adjust top by the number of headings.
if (lastQuadrant != radar_data[i].quadrant) {
radar.add(pv.Label)
.left( radar_data[i].left )
.top( radar_data[i].top )
.text( radar_data[i].quadrant )
.strokeStyle( radar_data[i].color )
.fillStyle( radar_data[i].color )
.font(quadrantFontSize + "px sans-serif");
lastQuadrant = radar_data[i].quadrant;
}
// group items by stage based on how far they are from each arc
var itemsByStage = _.groupBy(radar_data[i].items, function(item) {
for(var arc_i = 0; arc_i < radar_arcs.length; arc_i++) {
if (item.pc.r < radar_arcs[arc_i].r)
{
return arc_i;
}
}
return 0;
});
// In the case where a quadrant doesn't have an item, group_by will return undefined
// To avoid this, fill in the blanks with an empty array
for (var j=0;j<radar_arcs.length;++j) {
if (!itemsByStage[j]) itemsByStage[j] = [];
}
var offsetIndex = 0;
for (var stageIdx in _(itemsByStage).keys()) {
if (stageIdx > 0) {
offsetIndex = offsetIndex + itemsByStage[stageIdx-1].length + 1;
console.log("offsetIndex = " + itemsByStage[stageIdx-1].length, offsetIndex );
}
radar.add(pv.Label)
.left( radar_data[i].left + headingFontSize )
.top( radar_data[i].top + quadrantFontSize + spacer + (stageIdx * headingFontSize) + (offsetIndex * fontSize) )
.text( radar_arcs[stageIdx].name)
.strokeStyle( '#cccccc' )
.fillStyle( '#cccccc')
.font(headingFontSize + "px Courier New");
radar.add(pv.Label)
.left( radar_data[i].left )
.top( radar_data[i].top + quadrantFontSize + spacer + (stageIdx * headingFontSize) + (offsetIndex * fontSize) )
.strokeStyle( radar_data[i].color )
.fillStyle( radar_data[i].color )
.add( pv.Dot )
.def("i", radar_data[i].top + quadrantFontSize + spacer + (stageIdx * headingFontSize) + spacer + (offsetIndex * fontSize) )
.data(itemsByStage[stageIdx])
.top( function() { return ( this.i() + (this.index * fontSize) );} )
.shape( function(d) {return (d.movement === 't' ? "triangle" : "circle");})
.cursor( function(d) { return ( d.url !== undefined ? "pointer" : "auto" ); })
.event("click", function(d) { if ( d.url !== undefined ){self.location = d.url}})
.size(fontSize)
.angle(45)
.anchor("right")
.add(pv.Label)
.text(function(d) {return radar_quadrant_ctr++ + ". " + d.name;} );
radar.add(pv.Dot)
.def("active", false)
.data(itemsByStage[stageIdx])
.size( function(d) { return ( d.blipSize !== undefined ? d.blipSize : 70 ); })
.left(function(d) { var x = polar_to_raster(d.pc.r, d.pc.t)[0];
//console.log("name:" + d.name + ", x:" + x);
return x;})
.bottom(function(d) { var y = polar_to_raster(d.pc.r, d.pc.t)[1];
//console.log("name:" + d.name + ", y:" + y);
return y;})
.title(function(d) { return d.name;})
.cursor( function(d) { return ( d.url !== undefined ? "pointer" : "auto" ); })
.event("click", function(d) { if ( d.url !== undefined ){self.location = d.url}})
.angle(Math.PI) // 180 degrees in radians !
.strokeStyle(radar_data[i].color)
.fillStyle(radar_data[i].color)
.shape(function(d) {return (d.movement === 't' ? "triangle" : "circle");})
.anchor("center")
.add(pv.Label)
.text(function(d) {return total_index++;})
.textBaseline("middle")
.textStyle("white");
}
}
radar.anchor('radar');
radar.render();
};