-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminard2.html
648 lines (617 loc) · 25.4 KB
/
minard2.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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html> <head>
<title>Minard map in D3</title>
<script src="https://cdn.rawgit.com/eligrey/canvas-toBlob.js/f1a01896135ab378aa5c0118eadd81da55e698d8/canvas-toBlob.js"></script>
<script src="https://cdn.rawgit.com/eligrey/FileSaver.js/e9d941381475b5df8b7d7691013401e171014e89/FileSaver.min.js"></script>
<script src="http://d3js.org/d3.v3.min.js"></script>
</head>
<style>
h1 {
font-family:sans-serif
}
h2 {
font-family:sans-serif
}
.axis path,
.axis line {
fill: none;
stroke: black;
shape-rendering: crispEdges;
}
.axis text {
font-family: sans-serif;
font-size: 11px;
}
text {
font-family: sans-serif;
font-size: 13px;
}
.grid .tick {
stroke: lightgrey;
opacity: 0.7;
}
.grid path {
stroke-width: 0;
}
.grid .tick {
stroke: lightgrey;
opacity: 0.7;
}
.grid path {
stroke-width: 0;
}
body
{
background: #FFFFFA;
}
</style>
<body>
<script src="pathlayout.js"></script>
<script>
//The data, from http://mbostock.github.io/protovis/ex/napoleon.html
//unchanged except for adding the cities with directions as an element.
var napoleon = {};
napoleon.cities =
[{"time": 124.0 ,"num":55.0 },
{"time": 125.3 ,"num":54.7 },
{"time": 126.4 ,"num":54.4 ,dir:-1},
{"time": 126.8 ,"num":54.3 ,dir:-1},
{"time": 127.7 ,"num":55.2 },
{"time": 127.6 ,"num":53.9 ,dir:-1},
{"time": 128.5 ,"num":54.3 ,dir:-1},
{"time": 128.7 ,"num":55.5 },
{"time": 129.2 ,"num":54.4 ,dir:-1},
{"time": 130.2 ,"num":55.3 },
{"time": 130.4 ,"num":54.5 ,dir:-1},
{"time": 130.4 ,"num":53.9 ,dir:-1},
{"time": 132.0 ,"num":54.8 },
{"time": 133.2 ,"num":54.9 },
{"time": 134.3 ,"num":55.2 ,dir:-1},
{"time": 134.4 ,"num":55.5 },
{"time": 136.0 ,"num":55.5 },
{"time": 137.6 ,"num":55.8 },
{"time": 136.6 ,"num":55.3 ,dir:-1},
{"time": 136.5 ,"num":55.0 ,dir:-1}
];
/*
napoleon.temp = [
{lon:37.6, temp:0, date:"18 Oct 1812"},
{lon:36.0, temp:0, date:"24 Oct 1812"},
{lon:33.2, temp:-9, date:"09 Nov 1812"},
{lon:32.0, temp:-21, date:"14 Nov 1812"},
{lon:29.2, temp:-11, date:"24 Nov 1812"},
{lon:28.5, temp:-20, date:"28 Nov 1812"},
{lon:27.2, temp:-24, date:"01 Dec 1812"},
{lon:26.7, temp:-30, date:"06 Dec 1812"},
{lon:25.3, temp:-26, date:"07 Dec 1812"}
];*/
napoleon.army = [
/* Group 1 */
{time:1, num:2, size:45166, dir:1, group:1},
{time:2, num:1, size:43753, dir:1, group:1},
{time:3, num:1, size:43829, dir:1, group:1},
{time:4, num:1, size:46289, dir:1, group:1},
{time:5, num:1, size:49148, dir:1, group:1},
{time:6, num:1, size:49725, dir:1, group:1},
{time:7, num:1, size:50038, dir:1, group:1},
{time:8, num:1, size:50781, dir:1, group:1},
{time:9, num:1, size:51836, dir:1, group:1},
{time:10, num:1, size:51887, dir:1, group:1},
{time:11, num:1, size:53534, dir:1, group:1},
{time:12, num:1, size:53853, dir:1, group:1},
{time:13, num:1, size:54102, dir:1, group:1},
{time:14, num:1, size:54182, dir:1, group:1},
{time:15, num:1, size:54350, dir:1, group:1},
{time:16, num:1, size:54451, dir:1, group:1},
{time:17, num:1, size:58628, dir:1, group:1},
{time:18, num:1, size:58673, dir:1, group:1},
{time:19, num:1, size:58590, dir:1, group:1},
{time:20, num:1, size:59014, dir:1, group:1},
{time:21, num:1, size:58581, dir:1, group:1},
{time:22, num:2, size:58267, dir:1, group:1},
{time:23, num:1, size:52173, dir:1, group:1},
{time:24, num:1, size:51954, dir:1, group:1},
{time:25, num:1, size:51643, dir:1, group:1},
{time:26, num:1, size:51829, dir:1, group:1},
{time:27, num:1, size:51194, dir:1, group:1},
{time:28, num:1, size:50665, dir:1, group:1},
{time:29, num:1, size:49845, dir:1, group:1},
{time:30, num:1, size:49604, dir:1, group:1},
{time:31, num:2, size:49036, dir:1, group:1},
{time:32, num:1, size:46442, dir:1, group:1},
{time:33, num:1, size:45764, dir:1, group:1},
{time:34, num:1, size:44749, dir:1, group:1},
{time:35, num:1, size:44266, dir:1, group:1},
{time:36, num:1, size:43312, dir:1, group:1},
{time:37, num:2, size:41483, dir:1, group:1},
{time:38, num:1, size:75003, dir:1, group:1},
{time:39, num:1, size:75722, dir:1, group:1},
{time:40, num:2, size:75624, dir:1, group:1},
{time:41, num:1, size:69165, dir:1, group:1},
{time:42, num:1, size:69465, dir:1, group:1},
{time:43, num:1, size:69189, dir:1, group:1},
{time:44, num:1, size:68997, dir:1, group:1},
{time:45, num:2, size:68722, dir:1, group:1},
{time:46, num:1, size:34320, dir:1, group:1},
{time:47, num:1, size:35259, dir:1, group:1},
{time:48, num:2, size:38679, dir:1, group:1},
{time:49, num:1, size:36881, dir:1, group:1},
{time:50, num:1, size:36072, dir:1, group:1},
{time:51, num:1, size:35789, dir:1, group:1},
{time:52, num:1, size:35094, dir:1, group:1},
{time:53, num:1, size:33971, dir:1, group:1},
{time:54, num:1, size:33516, dir:1, group:1},
{time:55, num:1, size:33666, dir:1, group:1},
{time:56, num:1, size:33061, dir:1, group:1},
{time:57, num:2, size:32944, dir:1, group:1},
{time:58, num:2, size:20383, dir:1, group:1},
{time:59, num:1, size:18303, dir:1, group:1},
{time:60, num:1, size:18517, dir:1, group:1},
{time:61, num:1, size:18208, dir:1, group:1},
{time:62, num:1, size:28844, dir:1, group:1},
{time:63, num:2, size:58490, dir:1, group:1},
{time:64, num:1, size:52172, dir:1, group:1},
{time:65, num:1, size:50895, dir:1, group:1},
{time:66, num:1, size:49582, dir:1, group:1},
{time:67, num:2, size:47981, dir:1, group:1},
{time:68, num:2, size:44923, dir:1, group:1},
{time:69, num:2, size:41896, dir:1, group:1},
{time:70, num:1, size:33481, dir:1, group:1},
{time:71, num:1, size:32137, dir:1, group:1},
{time:72, num:2, size:30640, dir:1, group:1},
{time:73, num:1, size:28631, dir:1, group:1},
{time:74, num:1, size:28117, dir:1, group:1},
{time:75, num:1, size:27338, dir:1, group:1},
{time:76, num:1, size:31130, dir:1, group:1},
{time:77, num:2, size:29916, dir:1, group:1},
{time:78, num:2, size:26628, dir:1, group:1},
{time:79, num:1, size:21810, dir:1, group:1},
{time:80, num:1, size:20892, dir:1, group:1},
{time:81, num:1, size:19842, dir:1, group:1},
{time:82, num:2, size:18463, dir:1, group:1},
{time:83, num:1, size:21415, dir:1, group:1},
{time:84, num:1, size:20682, dir:1, group:1},
{time:85, num:1, size:19413, dir:1, group:1},
{time:86, num:2, size:18892, dir:1, group:1},
{time:87, num:1, size:11941, dir:1, group:1},
{time:88, num:1, size:10776, dir:1, group:1},
{time:89, num:1, size:10024, dir:1, group:1},
{time:90, num:1, size:9443, dir:1, group:1},
{time:91, num:2, size:8440, dir:1, group:1},
{time:92, num:1, size:3910, dir:1, group:1},
{time:93, num:1, size:3426, dir:1, group:1},
{time:94, num:1, size:2284, dir:1, group:1},
{time:95, num:1, size:2167, dir:1, group:1},
{time:96, num:1, size:1952, dir:1, group:1},
{time:97, num:1, size:1792, dir:1, group:1},
{time:98, num:1, size:1544, dir:1, group:1},
{time:99, num:1, size:1383, dir:1, group:1},
{time:100, num:1, size:1235, dir:1, group:1},
{time:101, num:1, size:1093, dir:1, group:1},
/* Group 2 */
{time:1, num:1, size:25711, dir:1, group:2},
{time:2, num:1, size:25706, dir:1, group:2},
{time:3, num:1, size:25807, dir:1, group:2},
{time:4, num:1, size:25797, dir:1, group:2},
{time:5, num:1, size:25962, dir:1, group:2},
{time:6, num:1, size:25965, dir:1, group:2},
{time:7, num:1, size:26055, dir:1, group:2},
{time:8, num:1, size:30160, dir:1, group:2},
{time:9, num:2, size:29926, dir:1, group:2},
{time:10, num:1, size:29547, dir:1, group:2},
{time:11, num:1, size:29080, dir:1, group:2},
{time:12, num:1, size:28664, dir:1, group:2},
{time:13, num:1, size:28359, dir:1, group:2},
{time:14, num:1, size:28127, dir:1, group:2},
{time:15, num:1, size:27118, dir:1, group:2},
{time:16, num:2, size:27918, dir:1, group:2},
{time:17, num:1, size:25442, dir:1, group:2},
{time:18, num:1, size:27950, dir:1, group:2},
{time:19, num:2, size:27948, dir:1, group:2},
{time:20, num:1, size:28357, dir:1, group:2},
{time:21, num:2, size:28560, dir:1, group:2},
{time:22, num:1, size:26520, dir:1, group:2},
{time:23, num:1, size:29054, dir:1, group:2},
{time:24, num:2, size:29599, dir:1, group:2},
{time:25, num:1, size:31462, dir:1, group:2},
{time:26, num:2, size:32280, dir:1, group:2},
{time:27, num:1, size:33388, dir:1, group:2},
{time:28, num:2, size:34169, dir:1, group:2},
{time:29, num:1, size:31068, dir:1, group:2},
{time:30, num:1, size:31894, dir:1, group:2},
{time:31, num:1, size:32657, dir:1, group:2},
{time:32, num:1, size:33694, dir:1, group:2},
{time:33, num:1, size:34398, dir:1, group:2},
{time:34, num:1, size:34902, dir:1, group:2},
{time:35, num:1, size:35429, dir:1, group:2},
{time:36, num:1, size:36539, dir:1, group:2},
{time:37, num:1, size:42121, dir:1, group:2},
{time:37.9, num:1, size:42121, dir:1, group:2},
{time:38.2, num:1, size:35003, dir:1, group:2},
//{time:38, num:1, size:75003, dir:1, group:2},
//{time:39, num:1, size:75722, dir:1, group:2},
/* Group 3 */
{time:1, num:1, size:26103, dir:1, group:3},
{time:2, num:1, size:26695, dir:1, group:3},
{time:3, num:1, size:27774, dir:1, group:3},
{time:4, num:1, size:28220, dir:1, group:3},
{time:5, num:1, size:28570, dir:1, group:3},
{time:6, num:1, size:28966, dir:1, group:3},
{time:7, num:1, size:29265, dir:1, group:3},
{time:8, num:2, size:30879, dir:1, group:3},
{time:9, num:1, size:29224, dir:1, group:3},
{time:10, num:1, size:29316, dir:1, group:3},
{time:11, num:1, size:29486, dir:1, group:3},
{time:12, num:1, size:29542, dir:1, group:3},
{time:13, num:1, size:29571, dir:1, group:3},
{time:14, num:1, size:29623, dir:1, group:3},
{time:15, num:1, size:29692, dir:1, group:3},
{time:16, num:1, size:29631, dir:1, group:3},
{time:17, num:1, size:29574, dir:1, group:3},
{time:18, num:1, size:29914, dir:1, group:3},
{time:19, num:1, size:30070, dir:1, group:3},
{time:20, num:1, size:30069, dir:1, group:3},
{time:21, num:1, size:29977, dir:1, group:3},
{time:22, num:1, size:29825, dir:1, group:3},
{time:23, num:1, size:29642, dir:1, group:3},
{time:24, num:1, size:29382, dir:1, group:3},
{time:25, num:1, size:29304, dir:1, group:3},
{time:26, num:1, size:29323, dir:1, group:3},
{time:27, num:1, size:29274, dir:1, group:3},
{time:28, num:1, size:29211, dir:1, group:3},
{time:29, num:1, size:29090, dir:1, group:3},
{time:30, num:1, size:28530, dir:1, group:3},
{time:31, num:1, size:28253, dir:1, group:3},
{time:32, num:1, size:27851, dir:1, group:3},
{time:33, num:1, size:27603, dir:1, group:3},
{time:34, num:1, size:27169, dir:1, group:3},
{time:35, num:1, size:26890, dir:1, group:3},
{time:36, num:1, size:26347, dir:1, group:3},
{time:37, num:1, size:25423, dir:1, group:3},
{time:38, num:1, size:24987, dir:1, group:3},
{time:39, num:1, size:24503, dir:1, group:3},
{time:40, num:1, size:24026, dir:1, group:3},
{time:41, num:1, size:25849, dir:1, group:3},
{time:42, num:1, size:25337, dir:1, group:3},
{time:43, num:1, size:24827, dir:1, group:3},
{time:44, num:1, size:24187, dir:1, group:3},
{time:45, num:1, size:23218, dir:1, group:3},
{time:46, num:1, size:22481, dir:1, group:3},
{time:47, num:1, size:21640, dir:1, group:3},
{time:48, num:1, size:20601, dir:1, group:3},
{time:49, num:2, size:19504, dir:1, group:3},
{time:50, num:1, size:16195, dir:1, group:3},
{time:51, num:1, size:15595, dir:1, group:3},
{time:52, num:1, size:14396, dir:1, group:3},
{time:53, num:1, size:13881, dir:1, group:3},
{time:54, num:1, size:13524, dir:1, group:3},
{time:55, num:1, size:13259, dir:1, group:3},
{time:56, num:1, size:12695, dir:1, group:3},
{time:57, num:1, size:12231, dir:1, group:3},
{time:58, num:1, size:11834, dir:1, group:3},
{time:59, num:1, size:11475, dir:1, group:3},
{time:60, num:1, size:10741, dir:1, group:3},
{time:61, num:1, size:10343, dir:1, group:3},
{time:62, num:1, size:10359, dir:1, group:3},
{time:63, num:1, size:10109, dir:1, group:3},
{time:64, num:1, size:9774, dir:1, group:3},
{time:65, num:1, size:9508, dir:1, group:3},
{time:66, num:1, size:9263, dir:1, group:3},
{time:67, num:1, size:10189, dir:1, group:3},
{time:68, num:2, size:9873, dir:1, group:3},
{time:69, num:1, size:9591, dir:1, group:3},
{time:70, num:1, size:9824, dir:1, group:3},
{time:71, num:1, size:9542, dir:1, group:3},
{time:72, num:1, size:8332, dir:1, group:3},
{time:73, num:2, size:8123, dir:1, group:3},
{time:74, num:1, size:6859, dir:1, group:3},
{time:75, num:1, size:6559, dir:1, group:3},
{time:76, num:1, size:7547, dir:1, group:3},
{time:77, num:1, size:7171, dir:1, group:3},
{time:78, num:1, size:7060, dir:1, group:3},
{time:79, num:1, size:5936, dir:1, group:3},
{time:80, num:1, size:5986, dir:1, group:3},
{time:81, num:1, size:5817, dir:1, group:3},
{time:82, num:1, size:5622, dir:1, group:3},
{time:83, num:1, size:5569, dir:1, group:3},
{time:84, num:1, size:5337, dir:1, group:3},
{time:85, num:1, size:5845, dir:1, group:3},
{time:86, num:1, size:5757, dir:1, group:3},
{time:87, num:1, size:5088, dir:1, group:3},
{time:88, num:1, size:5104, dir:1, group:3},
{time:89, num:1, size:5736, dir:1, group:3},
{time:90, num:1, size:5710, dir:1, group:3},
{time:91, num:1, size:5740, dir:1, group:3},
{time:92, num:1, size:5728, dir:1, group:3},
{time:93, num:1, size:5723, dir:1, group:3},
{time:94, num:1, size:5730, dir:1, group:3},
{time:95, num:1, size:5760, dir:1, group:3},
{time:96, num:1, size:6476, dir:1, group:3},
{time:97, num:1, size:6599, dir:1, group:3},
{time:98, num:1, size:6665, dir:1, group:3},
{time:99, num:1, size:6673, dir:1, group:3},
{time:100, num:1, size:6713, dir:1, group:3},
{time:101, num:1, size:6680, dir:1, group:3},
{time:102, num:1, size:6447, dir:1, group:3},
{time:103, num:1, size:6402, dir:1, group:3},
{time:104, num:1, size:8092, dir:1, group:3},
/* Group 4 */
{time:1, num:1, size:8311, dir:1, group:4},
{time:2, num:1, size:7955, dir:1, group:4},
{time:3, num:1, size:7615, dir:1, group:4},
{time:4, num:2, size:7441, dir:1, group:4},
{time:5, num:1, size:4730, dir:1, group:4},
{time:6, num:1, size:4340, dir:1, group:4},
{time:7, num:1, size:4295, dir:1, group:4},
{time:8, num:1, size:4236, dir:1, group:4},
{time:9, num:1, size:4204, dir:1, group:4},
{time:10, num:1, size:4221, dir:1, group:4},
{time:11, num:1, size:4164, dir:1, group:4},
{time:12, num:1, size:4213, dir:1, group:4},
{time:13, num:1, size:4125, dir:1, group:4},
{time:14, num:1, size:4213, dir:1, group:4},
{time:15, num:1, size:4189, dir:1, group:4},
{time:16, num:1, size:4258, dir:1, group:4},
{time:16.9, num:1, size:4258, dir:1, group:4},
//{time:17, num:1, size:58628, dir:1, group:4},
//{time:18, num:1, size:58673, dir:1, group:4},
];
</script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-4871207-9', 'benschmidt.org');
ga('send', 'pageview');
</script>
<!--
<h1>Minard's Map of the Russian Campaign</h1>
<h2>A trail layout demonstration</h2>
<div>This is a demo of how my <a href="http://github.com/bmschmidt/D3-trail">D3 trail layout</a> for <a href="http://d3js.org">D3</a> can reproduce
<a href=http://en.wikipedia.org/wiki/Charles_Joseph_Minard>Minard's map of the retreat of Napoleon's army from Russia</a>.
<p>
The "grouping" elements are being used here to draw several
different paths (by color) simultaneously, and set their width by
the size of Napoleon's army. (From a maximum of 340,000 to an end
value of 4,000: no scale displayed for concision.) Data is taken
from <a href=http://mbostock.github.io/protovis/ex/napoleon.html>here</a>.
<p>This is a reimplementation, not a reimagination,
of Minard's diagram. The only significant addition is the temporal
placement of elements. This helps clarify the most confusing elements of
the original (such as the direction of the temperature graph). All
animation timing is done by purely by D3 transitions. This frees
up color from representing the army's direction:
here the different branches of the French force each have their own
color. Even these minor improvements can only mean, though, that
this has now displaced Minard's original as <em>greatest statistical graphic ever
created.</em> (Unless you really miss the original rivers, I guess.)
</div>
!-->
<script>
var width=1200,height=600;
reload = function() {
d3.selectAll("svg").remove()
d3.select("body").append("svg").attr('width',width).attr('height',height).attr('id','minard')
proj = d3.geo.mercator().translate([width/2,height*(1/2)]).center([2,1.15]).scale(12000)
layout = d3.layout.trail()
.positioner(function(d,i) {
var dshift = 0.26;
if (d.group==1) {
shift = 2.0*dshift;
}
if (d.group==4) {
shift = 1.0*dshift;
if (d.time >=5){
shift = shift*(1+(d.time-5.0)*(d.time-5.0)*0.0058);
}
}
if (d.group==3) {
shift = 4.0*dshift;
}
if (d.group==2) {
shift = 3.0*dshift;
if (d.time >=21){
shift = shift*(1.0-(d.time-21.0)*(d.time-21.0)*0.0008);
}
}
var tslant=0.0;
var vslant=0.0;
var tmp = 0.0;
//if (d.num > 1){
// if (d.size > d.size[i-1]) { //inflow
// tmp = d.size-d.size[i-1]
// d.size = tmp;
// tslant =-0.06;
// vslant = 0.05*Math.pow(-1,d.time);
// } else{ //outflow
// tmp = d.size-d.size[i+1]
// d.size = tmp;
// tslant = 0.06;
// vslant = 0.05*Math.pow(-1,d.time);
// }}
return proj([d.time*0.01+tslant,vslant+shift])
//return proj([d.time*0.01,d.num*0.003+shift])
})
//.positioner(function(d) { console.log(d.group); return proj([d.time*0.01,d.num*0.01+d.group*0.5])})
data = layout
.grouping(function(d) {return d.group})
.data(napoleon.army)
.coordType("xy")
.layout()
//napoleon.army.map(function(d) {console.log( d.size,d.group)})
widthScale =
d3.scale.linear().domain([0,(340000)]).range([0,40])
var lines = d3.select("#minard").selectAll("line").data(data)
color = d3.scale.category10().domain([1,2,3])
var time = 75; //Time to get to Moscow
longs = d3.extent(napoleon.army.map(function(d) {return d.x2}))
negTime = d3.scale.linear().domain(longs).range([0,time])
posTime = d3.scale.linear().domain(longs).range([time,0])
//Define a scale that returns right to left or left to right in time depending on the directionality. Well, not a scale, strictly, since it can't be inverted and so on: but a function that sits on top of scales.
timeScale = function(d,element) {
out = d.dir==-1? time : 0;
lag = d.dir==-1 ? posTime(d[element]) : negTime(d[element]);
return out+lag
}
lines.enter().append("line")
.attr("x1",function(d) {return d.x1})
.attr("y1",function(d) {return d.y1})
.attr("y2",function(d) {return d.y1})
.attr("x2",function(d) {return d.x1})
.style("stroke-width",function(d) {return widthScale((d.size*3))})
.style("stroke",function(d) {return color(d.group)})
.style("opacity",1.0)
.transition()
.ease("linear")//keeps the transition pointed in the right direction
.duration(function(d) {return Math.abs(timeScale(d,'x2') - timeScale(d,'x1'))})
.delay(function(d) { return d3.min([timeScale(d,'x1'),timeScale(d,'x2')]) })
.attr("y2",function(d) {return d.y2})
.attr("x2",function(d) {return d.x2})
.style("stroke-linecap","round")
// now draw individual branches
// 1) massage the army data to only keep the num>1 points
//console.log(napoleon.army);
var branch = (napoleon.army).filter(function(d,i) {
//console.log(i,napoleon.army[i].size,napoleon.army[i+1].size)
var point = [d.time,(d.num),(d.size),(d.dir)];
var point_prev = point;
var point_next = point;
if (i>0){
point_prev = [napoleon.army[i-1].time,(napoleon.army[i-1].num),(napoleon.army[i-1].size)];
}
if (i<napoleon.army.length-1) {
var point_next = [napoleon.army[i+1].time,(napoleon.army[i+1].num),(napoleon.army[i+1].size)];
}
if (d.num > 1){
d.time = point[0];
d.num = point[1];
ldiff = (point[2]-point_prev[2]);
rdiff = (point_next[2]-point_prev[2]);
d.size = Math.max(Math.abs(ldiff),Math.abs(rdiff));
if (Math.abs(ldiff) < Math.abs(rdiff) && (rdiff <0)) { // split
d.dir = 1;
} else if (Math.abs(ldiff) < Math.abs(rdiff) && (rdiff > 0)) { // merge
d.dir = -1;
} else if (Math.abs(ldiff) > Math.abs(rdiff) && (ldiff > 0)) { // merge
d.dir = -1;
} else if (Math.abs(ldiff) > Math.abs(rdiff) && (ldiff < 0)) { // split
d.dir = 1;
} else {
d.dir = 1;
}
//console.log(point_prev[2],point[2],point_next[2]);
if (point[2] > point_prev[2]) { //inflow
d.size = point[2]-point_prev[2];
} else {
d.size = point[2]-point_next[2];
}
// shift to right layout
var dshift = 0.26;
if (d.group==1) {
shift = 2.0*dshift;
}
if (d.group==4) {
shift = 1.0*dshift;
if (d.time >=5){
shift = shift*(1+(d.time-5.0)*(d.time-5.0)*0.0065);
}
}
if (d.group==3) {
shift = 4.0*dshift;
}
if (d.group==2) {
shift = 3.0*dshift;
if (d.time >=21){
shift = shift*(1.0-(d.time-21.0)*(d.time-21.0)*0.00092);
}
}
var tslant=0.0;
var vslant=0.0;
var tmp = 0.0;
d.time = d.time*0.01+tslant;
d.num = d.num*0.003+shift+vslant;
return d;}
});
//console.log(branch);
napoleon.cities = branch.map(function(d,i) {
var point = proj([d.time,(d.num)]);
//console.log(point)
d.x = point[0];
d.y = point[1];
d.dir = d.dir;
d.size = d.size
var endp = proj([d.time+d.dir,d.num+0.25]);
d.xend = endp[0];
d.yend = endp[1];
return d
})
//console.log(napoleon.cities)
var cities = d3
.select("#minard")
.selectAll("g")
.data(napoleon.cities)
cities = cities.enter().append("g")
//.attr("transform",function(d) {
//return "translate(" + d.x + "," + d.y + ")" })
console.log(cities)
circles = cities.append("circle")
.attr('cx',function(d){ return d.x})
.attr('cy',function(d){ return d.y})
.attr('r',2).style("fill","black").style("opacity",0)
//.transition()
//.delay(function(d) {return timeScale(d,'x')}).duration(10).style("opacity",1)
lines2 = cities.append("line")
.attr('x1',function(d){ return d.x})
.attr('y1',function(d){ return d.y})
.attr('x2',function(d){ return (d.x+d.dir*25) } ) //*(1.0+d.dir*0.04))})
.attr('y2',function(d,i){ return (d.y+20*Math.pow(-1,i%2))})
.style("stroke-width",function(d) {return widthScale((d.size*1.5))})
.style("stroke",function(d) {return color(d.group)})
.style("opacity",0.5)
.attr("y2",function(d) {return (d.y+d.dir*20)})
.attr("x2",function(d) {return (d.x+d.dir*25)})
.style("stroke-linecap","round")
// .transition()
// .delay(function(d) {return timeScale(d,'x')}).duration(10).style("opacity",1)
// create x-axis
var xScale = d3.scale.linear()
.domain([0,1.05 ])
.range([0, 700]);
var xAxis = d3.svg.axis()
.scale(xScale)
.orient("top")
.innerTickSize(-height*0.01)
.outerTickSize(0)
.tickPadding(10);
var axes = cities.append("g")
.attr("class", "x axis")
.attr("transform", "translate(180,270)")
.call(xAxis)
.append("text")
.style("font-size",30)
.attr("transform","translate(310,-40)")
.text("\u0394T (\u03A9"+"\u207B"+"\u00B9"+")")
.style("opacity",.15);
axes.select("path").attr("marker-end","url(#arrowhead)")
.style("opacity",1)
.style("stroke","black")
.style("stroke-width",10);
//tmpLayout = d3.layout.trail()
//// start drawing 150 milliseconds before the map gets there: this seems
//// to produce the nicest effect.
//labels = cities.append("text").text(function(d) {return d.name})
// .style("fill","black").attr("transform","translate(5,5)").style("opacity",0).transition()
// .delay(function(d) {return timeScale(d,'x')-150}).duration(1000).style("opacity",1)
//temps = d3.select("#minard").append("g").attr("transform","translate(0,300)")
//tempScale = d3.scale.linear().domain([1,-41]).range([0,200])
//yaxis = d3.svg.axis().orient("right").scale(tempScale)
//grid = temps.append("g")
//.attr("transform","translate(" + proj([37.6,55])[0] + "0)")
}
reload()
</script>
<!--<hr> --!>
<address></address>
<!-- hhmts start --><!--Last modified: Thu Jun 19 10:52:24 EDT 2014 --!> <!-- hhmts end -->
</body> </html>