forked from zalando/tech-radar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
radar.js
193 lines (174 loc) · 5.67 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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
function init(h,w) {
var radar = new pv.Panel()
.width(w)
.height(h)
.canvas('radar');
// headline
radar.add(pv.Label)
.left(40)
.top(78)
.text("Zalando Tech Radar — 2017.07")
.font("40px sans-serif");
// contact info
radar.add(pv.Label)
.top(875)
.right(40)
.textAlign("right")
.text("Questions? Comments? Ideas?")
.font("28px sans-serif")
.add(pv.Label)
.top(910)
.text("tech-guild-technologists@zalando.de")
.textStyle("blue")
.font("22px monospace")
.add(pv.Label)
.top(940)
.text("#guild-technologists")
.textStyle("blue")
.font("22px monospace");
// legend
radar.add(pv.Dot)
.top(940)
.left(50)
.shape("circle")
.fillStyle("grey")
.strokeStyle("grey")
.size(16)
.anchor("right")
.add(pv.Label)
.text("unchanged")
.textStyle("black")
radar.add(pv.Dot)
.top(940)
.left(126)
.shape("triangle")
.fillStyle("grey")
.strokeStyle("grey")
.size(16)
.angle(45)
.anchor("right")
.add(pv.Label)
.text("changed since last edition (2017.03)")
.textStyle("black");
//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");
// 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)
.textBaseline("top")
.textMargin(40)
.text(function(d) { return d.name; })
.textStyle("#ccc")
.font("bold 40px sans-serif");
//Quadrant Ledgends
var radar_quadrant_ctr=1;
var quadrantFontSize = 18;
var headingFontSize = 14;
var stageHeadingCount = 0;
var lastRadius = 0;
var lastQuadrant='';
var spacer = 16;
var fontSize = 10;
var total_index = 1;
for (var i = 0; i < radar_data.length; i++) {
// quadrant title
if (lastQuadrant != radar_data[i].quadrant) {
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");
}
// re-order the items by radius, in order to logically group by ring
var itemsByStage = _.groupBy(radar_data[i].items, function(item) {
if (item.pc.r <= radar_arcs[0].r) return 0;
if (item.pc.r <= radar_arcs[1].r) return 1;
if (item.pc.r <= radar_arcs[2].r) return 2;
return 3;
});
var offsetIndex = 0;
var midIndex = -1;
for (var stageIndex in itemsByStage) {
if (stageIndex > 0 && _.has(itemsByStage, stageIndex-1)) {
offsetIndex = offsetIndex + itemsByStage[stageIndex-1].length + 1;
}
if ((stageIndex > 1) && (midIndex < 0)) {
midIndex = offsetIndex;
}
var left = radar_data[i].left;
var top = radar_data[i].top + quadrantFontSize + spacer + (stageIndex * headingFontSize) + (offsetIndex * fontSize);
if (stageIndex > 1) {
left = left + 130;
top = top - (2 * headingFontSize) - (midIndex * fontSize);
}
// stage label
radar.add(pv.Label)
.left(left + headingFontSize)
.top(top - headingFontSize / 2)
.text(radar_arcs[stageIndex].name)
.strokeStyle("#ccc")
.fillStyle("#ccc")
.font(headingFontSize + "px Courier New");
// legend label
radar.add(pv.Label)
.left(left)
.top(top)
.strokeStyle(radar_data[i].color)
.fillStyle(radar_data[i].color)
.add(pv.Dot)
.def("i", top)
.data(itemsByStage[stageIndex])
.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;} );
// the blip itself
radar.add(pv.Dot)
.def("active", false)
.data(itemsByStage[stageIndex])
.size(function(d) { return (d.blipSize !== undefined ? d.blipSize : 70); })
.left(function(d) { return polar_to_raster(d.pc.r, d.pc.t)[0]; })
.bottom(function(d) { return polar_to_raster(d.pc.r, d.pc.t)[1]; })
.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();
};