Skip to content

Instantly share code, notes, and snippets.

@jugutier
Forked from mbostock/.block
Last active July 10, 2017 14:59
Show Gist options
  • Save jugutier/28e175c2a270a9131d8b91523705da1a to your computer and use it in GitHub Desktop.
Save jugutier/28e175c2a270a9131d8b91523705da1a to your computer and use it in GitHub Desktop.
Box Plots
license: gpl-3.0

A box-and-whisker plot uses simple glyphs that summarize a quantitative distribution with five standard statistics: the smallest value, lower quartile, median, upper quartile, and largest value. This summary approach allows the viewer to easily recognize differences between distributions. Implementation adapted from Mike Bostok. Each box plot reperents a diferent project, for each of them we measure the number of lines in each file, transversing the whole directory structure.

From left to right, projects are:

  1. AlamoFire
  2. EachScape library (m files only)
  3. RxSwift
  4. AFNetworking
(function() {
// Inspired by http://informationandvisualization.de/blog/box-plot
d3.box = function() {
var width = 1,
height = 1,
duration = 0,
domain = null,
value = Number,
whiskers = boxWhiskers,
quartiles = boxQuartiles,
tickFormat = null;
// For each small multiple…
function box(g) {
g.each(function(d, i) {
d = d.map(value).sort(d3.ascending);
var g = d3.select(this),
n = d.length,
min = d[0],
max = d[n - 1];
// Compute quartiles. Must return exactly 3 elements.
var quartileData = d.quartiles = quartiles(d);
// Compute whiskers. Must return exactly 2 elements, or null.
var whiskerIndices = whiskers && whiskers.call(this, d, i),
whiskerData = whiskerIndices && whiskerIndices.map(function(i) { return d[i]; });
// Compute outliers. If no whiskers are specified, all data are "outliers".
// We compute the outliers as indices, so that we can join across transitions!
var outlierIndices = whiskerIndices
? d3.range(0, whiskerIndices[0]).concat(d3.range(whiskerIndices[1] + 1, n))
: d3.range(n);
// Compute the new x-scale.
var x1 = d3.scale.linear()
.domain(domain && domain.call(this, d, i) || [min, max])
.range([height, 0]);
// Retrieve the old x-scale, if this is an update.
var x0 = this.__chart__ || d3.scale.linear()
.domain([0, Infinity])
.range(x1.range());
// Stash the new scale.
this.__chart__ = x1;
// Note: the box, median, and box tick elements are fixed in number,
// so we only have to handle enter and update. In contrast, the outliers
// and other elements are variable, so we need to exit them! Variable
// elements also fade in and out.
// Update center line: the vertical line spanning the whiskers.
var center = g.selectAll("line.center")
.data(whiskerData ? [whiskerData] : []);
center.enter().insert("line", "rect")
.attr("class", "center")
.attr("x1", width / 2)
.attr("y1", function(d) { return x0(d[0]); })
.attr("x2", width / 2)
.attr("y2", function(d) { return x0(d[1]); })
.style("opacity", 1e-6)
.transition()
.duration(duration)
.style("opacity", 1)
.attr("y1", function(d) { return x1(d[0]); })
.attr("y2", function(d) { return x1(d[1]); });
center.transition()
.duration(duration)
.style("opacity", 1)
.attr("y1", function(d) { return x1(d[0]); })
.attr("y2", function(d) { return x1(d[1]); });
center.exit().transition()
.duration(duration)
.style("opacity", 1e-6)
.attr("y1", function(d) { return x1(d[0]); })
.attr("y2", function(d) { return x1(d[1]); })
.remove();
// Update innerquartile box.
var box = g.selectAll("rect.box")
.data([quartileData]);
box.enter().append("rect")
.attr("class", "box")
.attr("x", 0)
.attr("y", function(d) { return x0(d[2]); })
.attr("width", width)
.attr("height", function(d) { return x0(d[0]) - x0(d[2]); })
.transition()
.duration(duration)
.attr("y", function(d) { return x1(d[2]); })
.attr("height", function(d) { return x1(d[0]) - x1(d[2]); });
box.transition()
.duration(duration)
.attr("y", function(d) { return x1(d[2]); })
.attr("height", function(d) { return x1(d[0]) - x1(d[2]); });
// Update median line.
var medianLine = g.selectAll("line.median")
.data([quartileData[1]]);
medianLine.enter().append("line")
.attr("class", "median")
.attr("x1", 0)
.attr("y1", x0)
.attr("x2", width)
.attr("y2", x0)
.transition()
.duration(duration)
.attr("y1", x1)
.attr("y2", x1);
medianLine.transition()
.duration(duration)
.attr("y1", x1)
.attr("y2", x1);
// Update whiskers.
var whisker = g.selectAll("line.whisker")
.data(whiskerData || []);
whisker.enter().insert("line", "circle, text")
.attr("class", "whisker")
.attr("x1", 0)
.attr("y1", x0)
.attr("x2", width)
.attr("y2", x0)
.style("opacity", 1e-6)
.transition()
.duration(duration)
.attr("y1", x1)
.attr("y2", x1)
.style("opacity", 1);
whisker.transition()
.duration(duration)
.attr("y1", x1)
.attr("y2", x1)
.style("opacity", 1);
whisker.exit().transition()
.duration(duration)
.attr("y1", x1)
.attr("y2", x1)
.style("opacity", 1e-6)
.remove();
// Update outliers.
var outlier = g.selectAll("circle.outlier")
.data(outlierIndices, Number);
outlier.enter().insert("circle", "text")
.attr("class", "outlier")
.attr("r", 5)
.attr("cx", width / 2)
.attr("cy", function(i) { return x0(d[i]); })
.style("opacity", 1e-6)
.transition()
.duration(duration)
.attr("cy", function(i) { return x1(d[i]); })
.style("opacity", 1);
outlier.transition()
.duration(duration)
.attr("cy", function(i) { return x1(d[i]); })
.style("opacity", 1);
outlier.exit().transition()
.duration(duration)
.attr("cy", function(i) { return x1(d[i]); })
.style("opacity", 1e-6)
.remove();
// Compute the tick format.
var format = tickFormat || x1.tickFormat(8);
// Update box ticks.
var boxTick = g.selectAll("text.box")
.data(quartileData);
boxTick.enter().append("text")
.attr("class", "box")
.attr("dy", ".3em")
.attr("dx", function(d, i) { return i & 1 ? 6 : -6 })
.attr("x", function(d, i) { return i & 1 ? width : 0 })
.attr("y", x0)
.attr("text-anchor", function(d, i) { return i & 1 ? "start" : "end"; })
.text(format)
.transition()
.duration(duration)
.attr("y", x1);
boxTick.transition()
.duration(duration)
.text(format)
.attr("y", x1);
// Update whisker ticks. These are handled separately from the box
// ticks because they may or may not exist, and we want don't want
// to join box ticks pre-transition with whisker ticks post-.
var whiskerTick = g.selectAll("text.whisker")
.data(whiskerData || []);
whiskerTick.enter().append("text")
.attr("class", "whisker")
.attr("dy", ".3em")
.attr("dx", 6)
.attr("x", width)
.attr("y", x0)
.text(format)
.style("opacity", 1e-6)
.transition()
.duration(duration)
.attr("y", x1)
.style("opacity", 1);
whiskerTick.transition()
.duration(duration)
.text(format)
.attr("y", x1)
.style("opacity", 1);
whiskerTick.exit().transition()
.duration(duration)
.attr("y", x1)
.style("opacity", 1e-6)
.remove();
});
d3.timer.flush();
}
box.width = function(x) {
if (!arguments.length) return width;
width = x;
return box;
};
box.height = function(x) {
if (!arguments.length) return height;
height = x;
return box;
};
box.tickFormat = function(x) {
if (!arguments.length) return tickFormat;
tickFormat = x;
return box;
};
box.duration = function(x) {
if (!arguments.length) return duration;
duration = x;
return box;
};
box.domain = function(x) {
if (!arguments.length) return domain;
domain = x == null ? x : d3.functor(x);
return box;
};
box.value = function(x) {
if (!arguments.length) return value;
value = x;
return box;
};
box.whiskers = function(x) {
if (!arguments.length) return whiskers;
whiskers = x;
return box;
};
box.quartiles = function(x) {
if (!arguments.length) return quartiles;
quartiles = x;
return box;
};
return box;
};
function boxWhiskers(d) {
return [0, d.length - 1];
}
function boxQuartiles(d) {
return [
d3.quantile(d, .25),
d3.quantile(d, .5),
d3.quantile(d, .75)
];
}
})();
Project File Lines
1 1 64
1 2 212
1 3 97
1 4 29
1 5 460
1 6 28
1 7 465
1 8 37
1 9 580
1 10 233
1 11 52
1 12 436
1 13 647
1 14 465
1 15 715
1 16 300
1 17 307
1 18 719
1 19 899
1 20 453
1 21 136
1 22 309
1 23 332
1 24 200
1 25 46
1 26 355
1 27 714
1 28 88
1 29 963
1 30 250
1 31 826
1 32 704
1 33 1204
1 34 483
1 35 483
1 36 1624
1 37 523
1 38 856
1 39 669
1 40 691
1 41 178
1 42 954
2 1 64
2 2 212
2 3 97
2 4 29
2 5 460
2 6 28
2 7 465
2 8 37
2 9 580
2 10 233
2 11 52
2 12 436
2 13 647
2 14 465
2 15 715
2 16 300
2 17 307
2 18 719
2 19 899
2 20 453
2 21 136
2 22 309
2 23 332
2 24 200
2 25 46
2 26 355
2 27 714
2 28 88
2 29 963
2 30 250
2 31 826
2 32 704
2 33 1204
2 34 483
2 35 483
2 36 1624
2 37 523
2 38 856
2 39 669
2 40 691
2 41 178
2 2 50
2 3 49
2 4 45
2 5 51
2 6 51
2 7 85
2 8 51
2 9 32
2 10 98
2 11 36
2 12 28
2 13 59
2 14 30
2 15 30
2 16 70
2 17 52
2 18 25
2 19 38
2 20 73
2 21 114
2 22 40
2 23 91
2 24 36
2 25 37
2 26 43
2 27 16
2 28 16
2 29 43
2 30 30
2 31 61
2 32 40
2 33 42
2 34 40
2 35 71
2 36 104
2 37 169
2 38 161
2 39 19
2 40 19
2 41 36
2 42 535
2 43 46
2 44 28
2 45 35
2 46 57
2 47 45
2 48 30
2 49 40
2 50 40
2 51 88
2 52 75
2 53 39
2 54 47
2 55 62
2 56 30
2 57 40
2 58 81
2 59 332
2 60 39
2 61 363
2 62 197
2 63 110
2 64 36
2 65 83
2 66 44
2 67 98
2 68 45
2 69 76
2 70 74
2 71 48
2 72 56
2 73 87
2 74 53
2 75 82
2 76 72
2 77 53
2 78 358
2 79 56
2 80 41
2 81 36
2 82 36
2 83 21
2 84 36
2 85 113
2 86 34
2 87 32
2 88 39
2 89 230
2 90 268
2 91 37
2 92 52
2 93 287
2 94 269
2 95 221
2 96 50
2 97 381
2 98 381
2 99 18
2 100 126
2 101 13
2 102 229
2 103 80
2 104 195
2 105 25
2 106 199
2 107 133
2 108 399
2 109 41
2 110 18
2 111 30
2 112 75
2 113 33
2 114 44
2 115 148
2 116 457
2 117 56
2 118 606
2 119 90
2 120 879
2 121 614
2 122 2221
2 123 96
2 124 373
2 125 237
2 126 37
2 127 64
2 128 34
2 129 352
2 130 32
2 131 186
2 132 92
2 133 88
2 134 586
2 135 81
2 136 160
2 137 269
2 138 39
2 139 424
2 140 73
2 141 279
2 142 68
2 143 292
2 144 144
2 145 269
2 146 162
2 147 45
2 148 650
2 149 71
2 150 217
2 151 57
2 152 710
2 153 40
2 154 46
2 155 431
2 156 201
2 157 220
2 158 226
2 159 110
2 160 313
2 161 165
2 162 74
2 163 90
2 164 200
2 165 521
2 166 33
2 167 292
2 168 37
2 169 56
2 170 944
2 171 147
2 172 182
2 173 108
2 174 301
2 175 290
2 176 49
2 177 74
2 178 168
2 179 40
2 180 173
2 181 244
2 182 119
2 183 524
2 184 99
2 185 51
2 186 112
2 187 317
2 188 151
2 189 62
2 190 143
2 191 59
2 192 174
2 193 404
2 194 130
2 195 86
2 196 127
2 197 336
2 198 49
2 199 60
2 200 929
2 201 167
2 202 93
2 203 54
2 204 254
2 205 138
2 206 60
2 207 52
2 208 310
2 209 244
2 210 159
2 211 87
2 212 111
2 213 64
2 214 51
2 215 39
2 216 50
2 217 188
2 218 87
2 219 134
2 220 390
2 221 121
2 222 198
2 223 290
2 224 920
2 225 25
2 226 592
2 227 122
2 228 256
2 229 93
2 230 115
2 231 280
2 232 618
2 233 591
2 234 321
2 235 184
2 236 220
2 237 341
2 238 391
2 239 159
2 240 416
2 241 39
2 242 134
2 243 963
2 244 48
2 245 536
2 246 73
2 247 25
2 248 29
2 249 30
2 250 134
2 251 242
2 252 28
2 253 593
2 254 71
2 255 393
2 256 354
2 257 467
2 258 642
2 259 356
2 260 228
2 261 128
2 262 141
2 263 204
2 264 96
2 265 545
2 266 93
2 267 902
2 268 169
2 269 503
2 270 131
2 271 739
2 272 426
2 273 458
2 274 1422
2 275 176
2 276 208
2 277 53
2 278 145
2 279 129
2 280 753
2 281 144
2 282 757
2 283 45
2 284 395
2 285 259
2 286 160
2 287 90
2 288 44
2 289 231
2 290 89
2 291 169
2 292 119
2 293 109
2 294 126
2 295 88
2 296 79
2 297 96
2 298 184
2 299 113
2 300 108
2 301 215
2 302 136
2 303 108
2 304 281
2 305 145
2 306 113
2 307 234
2 308 137
2 309 116
2 310 222
2 311 136
2 312 114
2 313 39
2 314 512
2 315 64
2 316 25
2 317 117
2 318 268
2 319 568
2 320 48
2 321 460
2 322 47
2 323 128
2 324 466
2 325 204
2 326 2362
2 327 57
2 328 143
2 329 59
2 330 141
2 331 262
2 332 90
2 333 124
2 334 146
2 335 54
2 336 346
2 337 51
2 338 486
2 339 35
2 340 130
2 341 186
2 342 64
2 343 92
2 344 122
2 345 83
2 346 469
2 347 36
2 348 68
2 349 51
2 350 162
2 351 19
2 352 43
2 353 63
2 354 72
2 355 31
2 356 377
2 357 28
2 358 26
2 359 79
2 360 360
2 361 217
2 362 405
2 363 284
2 364 112
2 365 285
2 366 219
2 367 111
2 368 83
2 369 272
2 370 306
2 371 563
2 372 138
2 373 772
2 374 148
2 375 323
2 376 123
2 377 53
2 378 315
2 379 66
2 380 264
2 381 65
2 382 800
2 383 81
2 384 800
2 385 262
2 386 340
2 387 135
2 388 532
2 389 48
2 390 157
2 391 492
2 392 58
2 393 259
2 394 64
2 395 197
2 396 31
2 397 99
2 398 159
2 399 47
2 400 154
2 401 333
2 402 507
2 403 945
2 404 168
2 405 813
2 406 66
2 407 220
2 408 140
2 409 638
2 410 77
2 411 271
2 412 132
2 413 31
2 414 303
2 415 42
2 416 186
2 417 57
2 418 204
2 419 36
2 420 273
2 421 71
2 422 244
2 423 186
2 424 617
2 425 87
2 426 133
2 427 167
2 428 297
2 429 698
2 430 298
2 431 690
2 432 877
2 433 298
2 434 797
2 435 871
2 436 877
2 437 34
2 438 194
2 439 69
2 440 272
2 441 160
2 442 303
2 443 36
2 444 120
2 445 36
2 446 122
2 447 58
2 448 139
2 449 56
2 450 108
2 451 109
2 452 257
2 453 21
2 454 63
2 455 217
2 456 99
2 457 191
2 458 102
2 459 196
2 460 305
2 461 47
2 462 150
2 463 47
2 464 216
2 465 222
2 466 131
2 467 113
2 468 197
2 469 75
2 470 500
2 471 65
2 472 97
2 473 56
2 474 119
2 475 108
2 476 207
2 477 94
2 478 138
2 479 162
2 480 286
2 481 188
2 482 238
2 483 724
2 484 121
2 485 195
2 486 359
2 487 59
2 488 223
2 489 121
2 490 447
2 491 36
2 492 74
2 493 354
2 494 76
2 495 151
2 496 63
2 497 123
2 498 41
2 499 13
2 500 35
2 501 92
2 502 140
2 503 865
2 504 103
2 505 272
2 506 142
2 507 576
2 508 42
2 509 128
2 510 202
2 511 426
2 512 118
2 513 296
2 514 24
2 515 183
2 516 37
2 517 77
2 518 121
3 1 84
3 2 187
3 3 26
3 4 112
3 5 152
3 6 21
3 7 66
3 8 105
3 9 34
3 10 105
3 11 160
3 12 133
3 13 212
3 14 83
3 15 30
3 16 131
3 17 231
3 18 85
3 19 72
3 20 22
3 21 21
3 22 78
3 23 110
3 24 46
3 25 242
3 26 24
3 27 21
3 28 66
3 29 105
3 30 34
3 31 33
3 32 96
3 33 91
3 34 311
3 35 264
3 36 41
3 37 127
3 38 161
3 39 45
3 40 20
3 41 80
3 42 134
3 43 70
3 44 88
3 45 28
3 46 23
3 47 35
3 48 47
3 49 53
3 50 532
3 51 245
3 52 110
3 53 103
3 54 15
3 55 46
3 56 29
3 57 29
3 58 98
3 59 34
3 60 47
3 61 39
3 62 104
3 63 46
3 64 43
3 65 41
3 66 42
3 67 96
3 68 35
3 69 39
3 70 47
3 71 42
3 72 31
3 73 28
3 74 26
3 75 89
3 76 94
3 77 292
3 78 105
3 79 47
3 80 79
3 81 45
3 82 34
3 83 60
3 84 27
3 85 34
3 86 45
3 87 27
3 88 37
3 89 136
3 90 139
3 91 70
3 92 37
3 93 32
3 94 33
3 95 45
3 96 104
3 97 91
3 98 27
3 99 420
3 100 41
3 101 103
3 102 40
3 103 26
3 104 60
3 105 36
3 106 83
3 107 45
3 108 33
3 109 104
3 110 32
3 111 21
3 112 10
3 113 147
3 114 54
3 115 1020
3 116 93
3 117 27
3 118 28
3 119 102
3 120 19
3 121 18
3 122 157
3 123 71
3 124 123
3 125 26
3 126 26
3 127 124
3 128 90
3 129 59
3 130 22
3 131 59
3 132 658
3 133 495
3 134 231
3 135 22
3 136 64
3 137 230
3 138 50
3 139 22
3 140 50
3 141 42
3 142 14
3 143 14
3 144 27
3 145 29
3 146 97
3 147 208
3 148 35
3 149 706
3 150 25
3 151 14
3 152 34
3 153 59
3 154 21
3 155 21
3 156 38
3 157 16
3 158 17
3 159 290
3 160 147
3 161 95
3 162 35
3 163 60
3 164 34
3 165 21
3 166 45
3 167 205
3 168 131
3 169 96
3 170 45
3 171 63
3 172 155
3 173 166
3 174 124
3 175 26
3 176 57
3 177 117
3 178 46
3 179 84
3 180 125
3 181 84
3 182 120
3 183 76
3 184 63
3 185 88
3 186 32
3 187 48
3 188 82
3 189 77
3 190 13
3 191 13
3 192 189
3 193 42
3 194 59
3 195 185
3 196 21
3 197 32
3 198 69
3 199 42
3 200 108
3 201 106
3 202 76
3 203 31
3 204 51
3 205 32
3 206 34
3 207 15
3 208 31
3 209 23
3 210 90
3 211 97
3 212 12
3 213 82
3 214 22
3 215 59
3 216 39
3 217 105
3 218 28
3 219 203
3 220 299
3 221 93
3 222 22
3 223 40
3 224 93
3 225 14
3 226 45
3 227 99
3 228 427
3 229 30
3 230 29
3 231 35
3 232 28
3 233 201
3 234 17
3 235 197
3 236 73
3 237 256
3 238 36
3 239 72
3 240 13
3 241 102
3 242 36
3 243 21
3 244 18
3 245 18
3 246 18
3 247 13
3 248 19
3 249 49
3 250 13
3 251 61
3 252 53
3 253 33
3 254 151
3 255 13
3 256 84
3 257 22
3 258 32
3 259 117
3 260 50
3 261 75
3 262 76
3 263 21
3 264 52
3 265 106
3 266 62
3 267 22
3 268 37
3 269 36
3 270 44
3 271 18
3 272 45
3 273 157
3 274 49
3 275 52
3 276 139
3 277 235
3 278 843
3 279 157
3 280 132
3 281 131
3 282 78
3 283 119
3 284 103
3 285 66
3 286 74
3 287 181
3 288 66
3 289 51
3 290 125
3 291 93
3 292 93
3 293 27
3 294 33
3 295 89
3 296 87
3 297 134
3 298 87
3 299 177
3 300 44
3 301 628
3 302 424
3 303 27
3 304 229
3 305 95
3 306 98
3 307 73
3 308 109
3 309 57
3 310 182
3 311 142
3 312 82
3 313 89
3 314 589
3 315 105
3 316 76
3 317 159
3 318 139
3 319 143
3 320 42
3 321 83
3 322 228
3 323 104
3 324 180
3 325 78
3 326 131
3 327 161
3 328 163
3 329 152
3 330 111
3 331 66
3 332 90
3 333 170
3 334 149
3 335 948
3 336 169
3 337 155
3 338 126
3 339 50
3 340 32
3 341 34
3 342 150
3 343 40
3 344 187
3 345 26
3 346 112
3 347 152
3 348 21
3 349 66
3 350 105
3 351 34
3 352 74
3 353 134
3 354 27
3 355 82
3 356 88
3 357 136
3 358 22
3 359 67
3 360 35
3 361 19
3 362 104
3 363 22
3 364 17
3 365 35
3 366 13
3 367 68
3 368 50
3 369 226
3 370 61
3 371 123
3 372 95
3 373 269
3 374 71
3 375 155
3 376 166
3 377 150
3 378 281
3 379 21
3 380 67
3 381 126
3 382 276
3 383 767
3 384 39
3 385 41
3 386 21
3 387 100
3 388 55
3 389 187
3 390 41
3 391 11
3 392 152
3 393 80
3 394 57
3 395 35
3 396 31
3 397 200
3 398 311
3 399 211
3 400 123
3 401 33
3 402 258
3 403 18
3 404 187
3 405 315
3 406 426
3 407 101
3 408 21
3 409 331
3 410 17
3 411 1459
3 412 21
3 413 18
3 414 42
3 415 215
3 416 26
3 417 1866
3 418 108
3 419 18
3 420 25
3 421 56
3 422 94
3 423 296
3 424 437
3 425 145
3 426 637
3 427 2342
3 428 1731
3 429 668
3 430 70
3 431 107
3 432 102
3 433 379
3 434 217
3 435 226
3 436 582
3 437 270
3 438 23
3 439 257
3 440 118
3 441 1132
3 442 110
3 443 645
3 444 134
3 445 3753
3 446 1944
3 447 598
3 448 84
3 449 55
3 450 351
3 451 33
3 452 436
3 453 243
3 454 191
3 455 158
3 456 495
3 457 268
3 458 541
3 459 388
3 460 466
3 461 116
3 462 208
3 463 217
3 464 588
3 465 276
3 466 675
3 467 419
3 468 529
3 469 187
3 470 411
3 471 494
3 472 156
3 473 178
3 474 222
3 475 181
3 476 372
3 477 2009
3 478 830
3 479 13
3 480 133
3 481 66
3 482 105
3 483 59
3 484 24
3 485 168
3 486 1235
3 487 112
3 488 73
3 489 152
3 490 61
3 491 43
3 492 22
3 493 34
3 494 145
3 495 73
3 496 27
3 497 124
3 498 127
3 499 99
3 500 27
3 501 16
3 502 60
3 503 109
3 504 241
3 505 86
3 506 242
3 507 24
3 508 21
3 509 66
3 510 105
3 511 34
3 512 33
3 513 96
3 514 26
3 515 71
3 516 26
3 517 123
3 518 91
3 519 311
3 520 264
3 521 21
3 522 124
3 523 90
3 524 15
3 525 70
3 526 88
3 527 28
3 528 23
3 529 35
3 530 36
3 531 83
3 532 45
3 533 41
3 534 47
3 535 53
3 536 532
3 537 33
3 538 104
3 539 46
3 540 32
3 541 127
3 542 59
3 543 59
3 544 157
3 545 161
3 546 98
3 547 29
3 548 34
3 549 110
3 550 47
3 551 39
3 552 104
3 553 46
3 554 43
3 555 41
3 556 42
3 557 96
3 558 29
3 559 35
3 560 103
3 561 45
3 562 39
3 563 47
3 564 42
3 565 20
3 566 658
3 567 495
3 568 231
3 569 80
3 570 31
3 571 28
3 572 26
3 573 89
3 574 64
3 575 94
3 576 292
3 577 105
3 578 47
3 579 79
3 580 45
3 581 34
3 582 60
3 583 27
3 584 34
3 585 45
3 586 27
3 587 37
3 588 136
3 589 139
3 590 70
3 591 37
3 592 32
3 593 33
3 594 45
3 595 104
3 596 91
3 597 27
3 598 420
3 599 41
3 600 103
3 601 40
3 602 26
3 603 60
3 604 245
3 605 22
3 606 22
3 607 10
3 608 147
3 609 54
3 610 1020
3 611 93
3 612 27
3 613 28
3 614 102
3 615 19
3 616 45
3 617 157
3 618 61
3 619 19
3 620 32
3 621 72
3 622 49
3 623 52
3 624 102
3 625 155
3 626 62
3 627 187
3 628 166
3 629 53
3 630 33
3 631 139
3 632 13
3 633 235
3 634 843
3 635 157
3 636 132
3 637 126
3 638 151
3 639 131
3 640 82
3 641 88
3 642 19
3 643 78
3 644 136
3 645 119
3 646 103
3 647 66
3 648 74
3 649 181
3 650 66
3 651 51
3 652 49
3 653 21
3 654 104
3 655 13
3 656 13
3 657 84
3 658 22
3 659 125
3 660 93
3 661 93
3 662 27
3 663 33
3 664 52
3 665 106
3 666 89
3 667 87
3 668 134
3 669 37
3 670 22
3 671 67
3 672 35
3 673 36
3 674 26
3 675 22
3 676 17
3 677 87
3 678 36
3 679 21
3 680 68
3 681 177
3 682 44
3 683 628
3 684 424
3 685 27
3 686 32
3 687 44
3 688 18
3 689 126
3 690 50
3 691 229
3 692 34
3 693 40
3 694 50
3 695 95
3 696 66
3 697 105
3 698 276
3 699 767
3 700 112
3 701 98
3 702 150
3 703 152
3 704 73
3 705 74
3 706 34
3 707 226
3 708 109
3 709 117
3 710 57
3 711 281
3 712 182
3 713 134
3 714 27
3 715 142
3 716 82
3 717 50
3 718 35
3 719 13
3 720 61
3 721 71
3 722 89
3 723 123
3 724 75
3 725 589
3 726 76
3 727 105
3 728 76
3 729 159
3 730 139
3 731 143
3 732 42
3 733 22
3 734 21
3 735 83
3 736 21
3 737 228
3 738 104
3 739 18
3 740 18
3 741 18
3 742 13
3 743 150
3 744 180
3 745 78
3 746 131
3 747 161
3 748 163
3 749 152
3 750 111
3 751 66
3 752 90
3 753 67
3 754 95
3 755 269
3 756 170
3 757 149
3 758 948
3 759 169
3 760 155
3 761 39
3 762 187
3 763 41
3 764 21
3 765 100
3 766 55
3 767 41
3 768 11
3 769 57
3 770 35
3 771 31
3 772 152
3 773 80
3 774 200
3 775 326
3 776 37
3 777 51
3 778 221
3 779 21
3 780 66
3 781 105
3 782 34
3 783 22
3 784 33
3 785 437
3 786 37
3 787 59
3 788 15
3 789 47
3 790 93
3 791 50
3 792 549
3 793 529
3 794 17
3 795 1459
3 796 44
3 797 1583
3 798 94
3 799 42
3 800 31
3 801 69
3 802 153
3 803 23
3 804 66
3 805 47
3 806 134
3 807 158
3 808 190
3 809 663
3 810 89
3 811 115
3 812 9
3 813 9
3 814 9
3 815 1527
3 816 56
3 817 36
3 818 32
3 819 43
3 820 33
3 821 143
3 822 368
3 823 32
3 824 23
3 825 36
3 826 87
3 827 31
3 828 34
3 829 40
3 830 32
3 831 35
3 832 321
3 833 212
3 834 120
3 835 28
3 836 27
3 837 27
3 838 37
3 839 120
3 840 111
3 841 31
3 842 673
3 843 47
3 844 130
3 845 63
3 846 25
3 847 67
3 848 123
3 849 33
3 850 258
3 851 223
3 852 315
3 853 426
3 854 101
3 855 331
3 856 42
3 857 215
3 858 108
3 859 296
3 860 145
3 861 637
3 862 2342
3 863 1731
3 864 668
3 865 70
3 866 107
3 867 102
3 868 379
3 869 217
3 870 226
3 871 582
3 872 270
3 873 257
3 874 118
3 875 1132
3 876 110
3 877 645
3 878 134
3 879 3753
3 880 1944
3 881 598
3 882 84
3 883 55
3 884 351
3 885 33
3 886 436
3 887 243
3 888 191
3 889 158
3 890 495
3 891 268
3 892 541
3 893 388
3 894 466
3 895 116
3 896 208
3 897 217
3 898 588
3 899 276
3 900 675
3 901 419
3 902 529
3 903 187
3 904 411
3 905 494
3 906 156
3 907 178
3 908 222
3 909 181
3 910 372
3 911 2009
3 912 830
3 913 133
3 914 168
3 915 1235
3 916 73
3 917 61
3 918 43
3 919 145
3 920 73
3 921 127
3 922 99
3 923 21
3 924 18
3 925 18
3 926 18
3 927 25
3 928 56
3 929 13
3 930 59
3 931 24
3 932 27
3 933 23
3 934 60
3 935 109
3 936 241
3 937 124
3 938 16
3 939 86
4 1 304
4 2 372
4 3 41
4 4 213
4 5 263
4 6 154
4 7 344
4 8 479
4 9 1393
4 10 308
4 11 817
4 12 500
4 13 1221
4 14 41
4 15 92
4 16 42
4 17 130
4 18 30
4 19 40
4 20 30
4 21 49
4 22 27
4 23 103
4 24 33
4 25 82
4 26 38
4 27 31
4 28 62
4 29 26
4 30 27
4 31 107
4 32 5
4 33 59
4 34 113
4 35 79
4 36 26
4 37 39
4 38 27
4 39 51
4 40 66
4 41 233
4 42 94
4 43 242
4 44 117
4 45 613
4 46 447
4 47 98
4 48 208
4 49 181
4 50 113
4 51 56
4 52 94
4 53 654
4 54 37
4 55 66
4 56 117
4 57 110
4 58 150
4 59 116
4 60 104
4 61 502
4 62 149
4 63 201
4 64 157
4 65 403
4 66 103
4 67 259
4 68 48
4 69 114
4 70 175
4 71 302
4 72 35
4 73 109
4 74 157
4 75 42
4 76 64
4 77 126
4 78 53
4 79 113
4 80 80
4 81 157
<!DOCTYPE html>
<meta charset="utf-8">
<style>
body {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}
.box {
font: 10px sans-serif;
}
.box line,
.box rect,
.box circle {
fill: #fff;
stroke: #000;
stroke-width: 1.5px;
}
.box .center {
stroke-dasharray: 3,3;
}
.box .outlier {
fill: none;
stroke: #ccc;
}
</style>
<body>
<script src="//d3js.org/d3.v3.min.js"></script>
<script src="box.js"></script>
<script>
var margin = {top: 10, right: 50, bottom: 20, left: 50},
width = 120 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;
var min = Infinity,
max = -Infinity;
var chart = d3.box()
.whiskers(iqr(1.5))
.width(width)
.height(height);
d3.csv("code-distribution.csv", function(error, csv) {
if (error) throw error;
var data = [];
csv.forEach(function(x) {
var e = Math.floor(x.Project - 1),
r = Math.floor(x.File - 1),
s = Math.floor(x.Lines),
d = data[e];
if (!d) d = data[e] = [s];
else d.push(s);
if (s > max) max = s;
if (s < min) min = s;
});
chart.domain([min, max]);
var svg = d3.select("body").selectAll("svg")
.data(data)
.enter().append("svg")
.attr("class", "box")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.bottom + margin.top)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")")
.call(chart);
});
// Returns a function to compute the interquartile range.
function iqr(k) {
return function(d, i) {
var q1 = d.quartiles[0],
q3 = d.quartiles[2],
iqr = (q3 - q1) * k,
i = -1,
j = d.length;
while (d[++i] < q1 - iqr);
while (d[--j] > q3 + iqr);
return [i, j];
};
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment