forked from bdargan/techradar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
radar.js
156 lines (136 loc) · 6.38 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
function init(h,w) {
$('#title').text(document.title);
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;
}
var itemsByStage = _.groupBy(radar_data[i].items, function(item) {return Math.floor(item.pc.r / 100)});
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();
};