-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.html
1531 lines (1344 loc) · 60.3 KB
/
index.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
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en-us">
<head>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-81478188-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-81478188-1');
</script>
<meta charset="UTF-8">
<title>Interactive Map: Taipei's Income Distribution</title>
<style>
#map{ width: 100%; height: 100vh;}
div {
font-family: "Noto Sans TC", "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;;
}
div.legend {
position: absolute;
text-align: left;
width: 330px;
height: 60px;
left: 5%;
top: 79px;
padding: 2px;
font: 12px "Noto Sans TC";
background: rgba(255,255,255,0.6);
border: 0px;
border-radius: 4px;
pointer-events: none;
}
div.title {
position: absolute;
text-align: left;
color: #558C89;
font-size: 1.5rem;
left: 5%;
top: 10px;
padding: 10px;
border: 0px;
border-radius: 4px;
background: rgba(255,255,255,0.6);
}
div.tooltip {
position: absolute;
text-align: center;
width: 100px;
height: 50px;
padding: 5.5px 2px;
font: 14px sans-serif;
background: white;
border: 0px;
border-radius: 5px;
pointer-events: none;
}
div#mapcontrol {
position: absolute;
text-align: left;
left: 5%;
top: 143px;
font-size: 0.7rem;
width: 6.5rem;
padding: 0.01rem;
border: 0px;
border-radius: 4px;
background: rgba(255,255,255,0.6);
white-space: pre;
}
div.story {
position: absolute;
text-align: left;
left: 50%;
-ms-transform: translateX(-50%);
-webkit-transform: translate(-50%,0);
transform: translate(-50%,0);
bottom: 5rem;
width: 18rem;
height: 7.5rem;
padding: 0.55rem 1rem;
font-size: 0.75rem;
background: rgba(255,255,255,0.75);
border: 0px;
border-radius: 8px;
white-space: pre;
}
div.distname {
position: absolute;
text-align: center;
width: 5rem;
height: 1.3rem;
padding: 0.05rem;
font-size: 0.8rem;
background: rgba(255,255,255,0.75);
border: 0px;
border-radius: 2px;
}
.arrow {
position: absolute;
left: 45%;
-ms-transform: translateX(-50%);
-webkit-transform: translate(-50%,0);
transform: translate(-50%,0);
bottom: 0.5rem;
width: 5rem;
height: 2rem;
}
#exit {
position: absolute;
right: 6px;
top: 4px;
width: 15px;
height: 15px;
}
#boxplot {
width: 30%;
height: 90%;
}
#side {
max-width: 50%;
float:left;
margin-right:2%;
}
.axis path,
.axis line {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}
.chart1legend text {
font-weight: 400;
font-size: 0.7rem;
}
.meantext, .mediantext, .q1text, .q3text {
font-weight: 400;
font-size: 0.7rem;
opacity: 0;
}
@media screen and (min-width: 64em) {
#side {
max-width: 50%; }
#chart1 {
width: 60vw;
height: 45vh;}
.x.axis text {
font-weight: 400;
font-size: 0.7rem;
}
.y.axis text {
font-weight: 400;
font-size: 0.8rem;
} }
@media screen and (min-width: 42em) and (max-width: 64em) {
#side {
max-width: 100%;
clear: left; }
#chart1 {
width: 100vw;
height: 45vh;
clear: left; }
.x.axis text {
font-weight: 400;
font-size: 0.5rem;
}
.y.axis text {
font-weight: 400;
font-size: 0.6rem;
} }
@media screen and (max-width: 42em) {
#side {
max-width: 100%;
min-width: 100%;
clear: left; }
#chart1 {
width: 100vw;
height: 45vh;
clear: left; }
.x.axis text {
font-weight: 400;
font-size: 0.5rem;
}
.y.axis text {
font-weight: 400;
font-size: 0.6rem;
} }
/* The switch - the box around the slider */
.switch {
position: relative;
display: inline-block;
width: 1.6rem;
height: 0.8rem;
}
/* Hide default HTML checkbox */
.switch input {display:none;}
/* The slider */
.sliderround {
position: absolute;
cursor: pointer;
top: 0.2rem;
left: 0.15rem;
right: 0;
bottom: 0;
background-color: #ccc;
-webkit-transition: .4s;
transition: .4s;
border-radius: 1rem;
}
.sliderround:before {
position: absolute;
content: "";
height: 0.65rem;
width: 0.65rem;
left: 0.0008rem;
bottom: 0.015rem;
background-color: white;
-webkit-transition: .4s;
transition: .4s;
border-radius: 50%;
}
input:checked + .sliderround {
background-color: #74AFAD;
}
input:focus + .sliderround {
box-shadow: 0 0 1px #74AFAD;
}
input:checked + .sliderround:before {
-webkit-transform: translateX(0.9rem);
-ms-transform: translateX(0.9rem);
transform: translateX(0.9rem);
}
</style>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<meta property="og:image" content="https://raw.githubusercontent.com/missmoss/taipei-stat-mrt/gh-pages/front.png"/>
<meta property="og:description" content="On two sides of a wall, the residents' incomes can differ by ten times. This map reveals the geographical distribution of how much people earn in Taipei."/>
<link rel="stylesheet" type="text/css" href="stylesheets/normalize.css" media="screen"/>
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' 'type='text/css'/>
<link rel="stylesheet" type="text/css" href="stylesheets/stylesheet.css" media="screen"/>
<link rel="stylesheet" type="text/css" href="stylesheets/github-light.css" media="screen"/>
<link rel="stylesheet" href="https://npmcdn.com/[email protected]/dist/leaflet.css" />
<link rel="stylesheet" type="text/css" href="stylesheets/jquery.fullPage.css" />
<script src="https://npmcdn.com/[email protected]/dist/leaflet.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.3/leaflet.js"></script>
<script src="https://code.jquery.com/jquery-1.12.0.min.js"></script>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script src="https://d3js.org/d3.v3.min.js"></script>
<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript" src="stylesheets/scrolloverflow.min.js"></script>
<script type="text/javascript" src="stylesheets/jquery.fullPage.js"></script>
</head>
<body>
<div id="fullpage">
<div class="section">
<section class="main-content" id="front-page">
<img src="front.png" id="side" style="margin-right:2%;"/>
<h1>Interactive Map: <br>Taipei's Income Distribution</h1>
<p>Written, Designed and Developed by <a href="https://github.com/missmoss">@missmoss</a>
<br>Special Thanks to <a href="https://www.facebook.com/Cicadatatw/">Cicadata TW</a>, <a href="https://www.facebook.com/TalkEcon/">Talkecon</a></p>
<p>Incomes on both sides of a wall can differ by ten times. This map reveals the geographical distribution of how much people earn in Taipei.</p>
<p>(Recommend to read on computer for better browsing experiences)</p>
<p><a href="zh.html" id="smaller">中文(Traditional Chinese)</a></p>
</section>
</div>
<div class="section">
<section class="main-content">
<p>It's 11pm on Saturday night. The lights are still on at a law firm on Dunhua South Road. Lawyer C and his colleagues have been preparing for an upcoming crucial court session for weeks. In C's windowless cellular office, it's hard to notice day transitioning into night. Here, the only thing that changes is the to-do list on the desk.</p>
<p>"I can't finish all this work without overtime," the two-year-practice lawyer told me, "On weekends, I'm either in the office or working at home with my laptop and documents."</p>
<p>Clocking up to 90 work hours per week, C has a salary people would envy. He earned 1 million NTD (33k USD) in his first practice year at age 25. However, in C's hometown, Nanhu Village in Neihu District, his annual salary falls just short of the median income of the village. That is, half of the tax units (think of them as households) there each has a higher annual income than C.</p>
<p>Taiwan's white-collar workers view an annual income of 1 million NTD (33k USD) as an achievement. Yet such an income is only middle-class. More than 25% households in Taipei earn less than 0.4 million NTD (13k USD) yearly. Such an income is hardly enough for one to live in Taipei, let alone a whole family.</p>
<p>In the Greater Taipei Area, the geographical distribution of income can help us better understand the differences among districts. Through statistics, we can seek answers to such questions as: <b>Where do high-income people live? What are the differences within particular districts?</b></p>
</section>
</div>
<div class="section">
<div id="map">
</div>
</div>
<div class="section">
<section class="main-content">
<h2>A world divided by the wall</h2>
<p>Among the ordinary five-to-seven-floor apartment buildings common in Taipei, there are several buildings hidden behind high walls and surrounded by tall trees in a lane of Mingsheng East Road. The overall look is one of mystery.</p>
<p>These buildings are located in Dongcheng Village, Songshan Dist. The data from Financial Data Center reveals some clues:</p>
<table id="no-more-tables">
<thead>
<tr>
<th>District</th>
<th>Village</th>
<th>Total Income of the Village</th>
<th>Tax Unit</th>
<th>Average</th>
<th>First Quartile</th>
<th>Midian</th>
<th>Third Quartile</th>
<th>Standard Deviation</th>
</tr>
</thead>
<tbody>
<tr>
<td data-title="District">Songshan</td>
<td data-title="Village">Dongcheng</td>
<td data-title="Total Income of the Village">9836m</td>
<td data-title="Tax Unit">917</td>
<td data-title="Average">1.07m</td>
<td data-title="First Quartile">0.47m</td>
<td data-title="Midian">0.9m</td>
<td data-title="Third Quartile">1.8m</td>
<td data-title="Standard Deviation">261760.57</td>
</tr>
</tbody>
</table>
<blockquote>
<h4>Tax Unit</h4>
<p>A tax unit is a group of individuals who pay tax as a unit (usually parents and children or spouses). One can also pay tax alone. Our data is based on tax units. Hence, we don't know if the income comes from one single person or is the total from multiple family members. We can consider a tax unit as a co-living group, with those in the group sharing both income and expenditure.</p>
</blockquote>
<p>Ordering all tax units in Dongcheng Village from small to large by their incomes, and finding the record exactly in the 25%, 50%, and 75% percentile, we get the first quartile, median and third quartile.</p>
<p>From the data above, we know the residents of Dongcheng Village in the 0-25% percentile earn 0-0.5 million NTD (0-17k USD) yearly. The median income of Dongcheng Village is 0.9 million NTD (30k USD). This ranks it 37th out of 456 villages in Taipei; the placement is a decent one, but not at the top. The third quantile pulls in 1.8 million NTD (60k USD) a year. It ranks 59, still far from the top tiers.</p>
<h2>The Insane Amount of Income Behind the Wall</h2>
<p>Dongcheng Village seems ordinary – as the buildings surrounded by trees are – when it comes to income distribution in Taipei.</p>
<p>However, the average (as compared to median) income in the village has long occupied the No. 1 spot in Taipei and even the whole of Taiwan for years. In the 2014 statistics, the village's average income is an amazing 10.7 million NTD (0.36 million USD)!</p>
<p><b>The average income of Dongcheng Village is far from its median, and also much higher in terms of multiples than its third quantile. This suggests that there are one or more taxpayers who earn an insane amount of money yearly.</b></p>
<p>We can derive a simple estimate of the amount. Let's assume all tax units in the 0-25% quantile each earn 0.5 million NTD (17k USD), those in the 25-50% quantile each earn 0.9 million NTD (30k USD), and those in the 50-75% bracket each earn 1.8 million NTD (60k USD). For the 75-100% quantile, let's assume a 20 million NTD (0.67 million USD) figure. We then have the total income of the village minus the previously assumed amount of income. Dividing this figure by a pre-set number of tax units gives us the annual income of the super-earners in Dongcheng Village.</p>
<h3>Assumption 1: 10 hyper income tax units</h3>
<table id="no-more-tables">
<thead>
<tr>
<th>Income Group</br>Assumed Income</th>
<th>25%</br>0.47m</th>
<th>50%</br>0.9m</th>
<th>75%</br>1.8m</th>
<th>100%</br>20m</th>
<th>Hyper Income Units</th>
</tr>
</thead>
<tbody>
<tr>
<td data-title="Income Group">Units</td>
<td data-title="25%">230</td>
<td data-title="50%">230</td>
<td data-title="75%">230</td>
<td data-title="100%">217</td>
<td data-title="Hyper Income Units">10</td>
</tr>
<tr>
<td data-title="Income Group">Group Total Income</td>
<td data-title="25%">110m</td>
<td data-title="50%">215m</td>
<td data-title="75%">418m</td>
<td data-title="100%">4340m</td>
<td data-title="Hyper Income">4754m</td>
</tr>
<tr>
<td data-title="Hyper Income Units"><b>Average Income of Each Unit</b></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td><font color="#558C89">~470m</font></td>
</tr>
</tbody>
</table>
<h3>Assumption 2: 50 hyper income tax units</h3>
<table id="no-more-tables">
<thead>
<tr>
<th>Income Group</br>Assumed Income</th>
<th>25%</br>0.47m</th>
<th>50%</br>0.9m</th>
<th>75%</br>1.8m</th>
<th>100%</br>20m</th>
<th>Hyper Income Units</th>
</tr>
</thead>
<tbody>
<tr>
<td data-title="Income Group">Units</td>
<td data-title="25%">230</td>
<td data-title="50%">230</td>
<td data-title="75%">230</td>
<td data-title="100%">177</td>
<td data-title="Hyper Income Units">50</td>
</tr>
<tr>
<td data-title="Income Group">Group Total Income</td>
<td data-title="25%">110m</td>
<td data-title="50%">215m</td>
<td data-title="75%">418m</td>
<td data-title="100%">3540m</td>
<td data-title="Hyper Income Units">5554m</td>
</tr>
<tr>
<td data-title="Hyper Income Units"><b>Average Income of Each Unit</b></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td><font color="#558C89">~110m</font></td>
</tr>
</tbody>
</table>
<p>As a result, the mysterious super-earners must each have an annual income of at least 100 million NTD (3 million USD). The real number should be more since we overestimated other tax units' income. If we examine the numbers in detail, we can find the combined income of the other tax units would be slightly less than that of the super-earners.</p>
<h2>Where is the wealthy neighborhood?</h2>
<p>How many villages in Taipei have such similarly huge income inequality?</p>
<div id="chart1">
</div>
<p>Figure 1. Income Inequality Within District</p>
<p>In Figure 1, we plot the statistics of the top 10 villages by average income. We can see what these villages are and how the average income in each differs from its median and third quantile.</p>
<h2>10%?1%?0.1%?</h2>
<p>We may imagine that the commonly thought wealthy districts, such as Daan District in the central of Taipei, are home to the top 10% of wealthy people, to be specific, the top 10% earners. The villages with super-high average income have the top 1% wealthy people. Where do such rich people live? Everyone is curious about the answer to that question. Through mapping and statistics, we can try to understand the geographical distribution of high-income people.</p>
<p>Besides satisfying the curiosity about where rich people live, we have more questions based on the explorations above: Are wealth persons' incomes stable? What's the difference between their income sources and those of average people? Do these differences tell us anything? In the following research, we will continue to explore these questions through financial and available tax data. If we find anything interesting, we will share it.</p>
</section>
<section class="main-content">
<hr>
<h3>Interactive Map: Taipei's Income Distribution</h3>
<p>A heat map of 2014 median annual income of villages in Taipei and New Taipei City. The darker the shade of pink, the higher the median income; the more green, the lower the median income. The median statistics merely give us a general view of the geographical distribution. They cannot show the complete distribution among all households, nor reveal the differences in households. In addition, it does not factor in those residents who did not register their tax status.</p>
<p>The tax data released by Financial Data Center takes a while to process and check so there is usually a two-year delay. This project was originally developed in 2016 and used data that was updated at that time, i.e., data from 2014. Income distribution has changed significantly since then, and we will try to explore and share new findings when we have access to more recent data!</p>
<h3>Data Sources</h3>
Tax Data: </br>2014/<a href="http://www.fia.gov.tw/ct.asp?xItem=3451&ctNode=668&mp=1">Financial Data Center of Minstry of Finance</a> <a href="https://github.com/leeneil">、@leeneil</a> at <a href="https://github.com/cicadatatw>@cicadatatw">@cicadatatw</a>'s <a href="https://github.com/cicadatatw/taiwan-income-by-village"> pdf/csv convertion</a></br>
2012/<a href="http://data.gov.tw/">Open Data Gov Taiwan</a>: <a href="http://data.gov.tw/node/17983">Taipei</a>、<a href="http://data.gov.tw/node/17975">New Taipei</a></br>
MRT Station Location: <a href="https://github.com/repeat" class="user-mention">@repeat</a> <a href="https://github.com/repeat/taipei-metro-stations">taipei-metro-stations</a>
<h3>Derived from</h3>
<a href="http://missmoss.github.io/taipei-mrt-viz/">A Day in Taipei Metro</a></br>
<footer class="site-footer">
<span class="site-footer-owner"><a href="https://github.com/missmoss/taipei-stat-mrt">Taipei Income Map</a> is produced by <a href="https://github.com/missmoss"> @missmoss</a></span>
<span class="site-footer-credits">This page is a <a href="https://pages.github.com">GitHub Pages</a> which is edited from <a href="https://twitter.com/jasonlong">Jason Long</a>'s <a href="https://github.com/jasonlong/cayman-theme">Cayman theme</a>。Special thanks to Miss Monday、Wu-Hsi、Duckling、Yoyo、Nan、Kn、TalkEcon authors for help and discussion in project development.</span>
</footer>
</section>
</div>
</div>
<script>
var subdist, interactive, stationName, firstTime = false, exit = false;
$(document).ready(function() {
$('#fullpage').fullpage({
// scrolling
scrollOverflow: true,
// for mobile
scrollHorizontally: true,
// event
afterLoad: function(anchorLink, index){
var loadedSection = $(this);
//using index
if ( index === 3 && firstTime === false ) {
firstTime = true;
storyTeller();
}
},
onLeave: function(index, nextIndex, direction){
if ( index === 1 ) {
directionArrow.remove();
} else if ( index === 3 ) {
exit = true;
distname.style("opacity", 0);
tooltip.style("opacity", 0);
subdist.style("opacity", 0.475);
story.remove();
interactive();
}
},
})
});
/* Set up Leaflet.js map */
var northEast = L.latLng(25.3,122),
southWest = L.latLng(24.7,121.258),
bounds = L.latLngBounds(southWest, northEast);
/* CARTODB BASEMAP */
var carto = L.tileLayer('http://{s}.basemaps.cartocdn.com/light_nolabels/{z}/{x}/{y}.png', {
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, © <a href="http://cartodb.com/attributions">CartoDB</a>',
subdomain: 'abcd'
});
var satellite = L.tileLayer('http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', {
attribution: 'Tiles © Esri — Source: Esri, i-cubed, USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the GIS User Community'
});
var map = L.map('map', {
scrollWheelZoom: false,
doubleClickZoom: false,
center: [25.045,121.547],
zoom: 13,
zoomControl: false,
maxBounds: bounds
});
//add zoom control with your options
L.control.zoom({
position:'topright'
}).addTo(map);
map.addLayer(carto);
/* Initialize the SVG layer */
map._initPathRoot()
/* Set up svg and some elements for charts */
/* svg1 for Heatmap */
/* We simply pick up the SVG from the map object */
var directionArrow = d3.select("body")
.append("div")
.attr("class", "arrow")
.append("svg");
setTimeout(function() {
directionArrow
.append("path")
.attr("d", "m0,0L30,25L60,0L60,7L30,32L0,7z")
.attr("fill", "#d0d0d0")
.attr("transform", "translate(0, -20)")
.transition()
.duration(500)
.attr("transform", "translate(0, 0)");
directionArrow
.append("text")
.attr("x", 65)
.attr("y", 0)
.attr("fill", "#d0d0d0")
.style("font-size", "1rem")
.text("Scroll Down to Next Page")
.transition()
.duration(500)
.attr("y", 17);
}, 1000);
var svg1 = d3.select("#map").select("svg");
g = svg1.append("g");
var title = d3.select("#map").append("div")
.attr("class", "title");
title.text("Taipei Income Map");
var legend = d3.select("#map").append("div")
.attr("class", "legend");
var mapcontrol = d3.select("#map").append("div")
.attr("id", "mapcontrol");
var label1 = d3.select("#mapcontrol")
.append("div")
.append("label")
.attr("class", "switch")
.text(" MRT Line");
label1.append("input")
.attr("type", "checkbox")
.attr("checked", true)
.attr("id", "mrtline");
label1.append("div")
.attr("class", "sliderround");
var label2 = d3.select("#mapcontrol")
.append("div")
.append("label")
.attr("class", "switch")
.text(" MRT Station");
label2.append("input")
.attr("type", "checkbox")
.attr("id", "station");
label2.append("div")
.attr("class", "sliderround");
var label3 = d3.select("#mapcontrol")
.append("div")
.append("label")
.attr("class", "switch")
.text(" Satellite");
label3.append("input")
.attr("type", "checkbox")
.attr("id", "satellite");
label3.append("div")
.attr("class", "sliderround");
d3.select("#satellite").on("change", changeMap);
function changeMap() {
var check = this.checked;
if (check === true) {
map.removeLayer(carto);
map.addLayer(satellite);
stationName.attr("fill", "white");
} else {
map.removeLayer(satellite);
map.addLayer(carto);
stationName.attr("fill", "black");
}
}
var tooltip = d3.select("body").append("div")
.attr("class", "tooltip")
.style("opacity", 0);
var distname = d3.select("body").append("div")
.attr("class", "distname")
.style("opacity", 0);
var svg2 = d3.select(map.getPanes().overlayPane).append("svg"),
g2 = svg2.append("g").attr("class", "dist");
g3 = svg2.append("g").attr("class", "station");
var story = d3.select("#map").append("div")
.attr("class", "story");
function numberWithCommas(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
d3.json("twnsub3.json", function(collection) {
var incomeMedian = collection.features.map(function(item) {
return parseInt(item.properties.INCOME_MEDIAN);
}
)
var extent = d3.extent(incomeMedian),
middle = (extent[0]+extent[1])/2;
var fillColor = d3.scale.linear()
.domain([extent[0], middle, extent[1]])
//.range(["#7CFFDE", "#5468E8", "#E84374"]);
.range(["#52FFB0", "#5468E8", "#E84374"]);
//.range(["#00A388", "#FFF457", "#E8518E"]);
var fillOpacity = d3.scale.linear()
.domain(extent)
//.range(["#52FFB0", "#5468E8", "#E84374"]);
.range([0.35, 0.55]);
//legend
var legendData = [300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200];
var rectWidth = 27;
legend = legend.append("svg").attr("width", rectWidth*12);
legend.append("text")
.attr("x", 5)
.attr("y", 18)
.attr("fill", "#6C6C6C")
.style("font-size", 14)
.text("Median Annual Income of Village in Taipei");
legend.selectAll(".legend")
.data(legendData)
.enter()
.append("rect")
.attr("x", function(d,i) { return 10+rectWidth*i; })
.attr("y", 25)
.attr("width", rectWidth)
.attr("height", 10)
.attr("fill", function(d) { return fillColor(d); })
.style("opacity", 0.4);
legend.selectAll(".legendtext")
.data(legendData)
.enter()
.append("text")
.attr("text-anchor", "start")
.attr("x", function(d,i) { return 5+rectWidth*i; })
.attr("y", 50)
.attr("fill", "#6C6C6C")
.text(function(d) { return d/1000;});
legend.append("text")
.attr("text-anchor", "start")
.attr("x", rectWidth*10+3)
.attr("y", 49)
.attr("fill", "#6C6C6C")
.text("m NTD");
var transform = d3.geo.transform({point: projectPoint}),
path = d3.geo.path().projection(transform);
subdist = g2.selectAll(".subdist")
.data(collection.features)
.enter().append("path")
.attr("stroke", "white")
.attr("stroke-width", 0.5)
.attr("class", function(d) { return d.properties.TOWN; }) //class=中正區/大安區/松山區...etc
.attr("id", function(d) { return d.properties.VILLAGE; }) //id=華城里/政大里/龍門里...etc
.attr("fill", function(d) {
// Get data value
var value = d.properties.INCOME_MEDIAN;
if (value) {
//If value exists…
return fillColor(value);
} else {
//If value is undefined…
return "white";
}
})
.style("opacity", 0.475);
interactive = function () {
subdist.on("mouseover", function(d) {
d3.select(this)
.style("opacity", 0.85);
tooltip.transition()
.duration(200)
.style("opacity", 0.9);
tooltip.text(function () {
return d.properties.TOWN+'\n'+
d.properties.VILLAGE+'\n'+
numberWithCommas(d.properties.INCOME_MEDIAN)+',000 NTD';
})
.style("left", (d3.event.pageX) + "px")
.style("top", (d3.event.pageY - 28) + "px");
})
.on("click", function(d) {
d3.select(this)
.style("opacity", 0.85);
tooltip.transition()
.duration(200)
.style("opacity", 0.9);
tooltip.text(function () {
return d.properties.TOWN+'\n'+
d.properties.VILLAGE+'\n'+
numberWithCommas(d.properties.INCOME_MEDIAN)+',000 NTD';
})
.style("left", (d3.event.pageX) + "px")
.style("top", (d3.event.pageY - 28) + "px");
})
.on("mouseout", function(d) {
d3.select(this)
.style("opacity", 0.475)
tooltip.transition()
.duration(500)
.style("opacity", 0);
});
}
//d3 code stolen from http://bost.ocks.org/mike/leaflet/#init
map.on("viewreset", reset);
reset();
function reset() {
var topobounds = path.bounds(collection),
topLeft = topobounds[0],
bottomRight = topobounds[1];
svg2.attr("width", bottomRight[0] - topLeft[0])
.attr("height", bottomRight[1] - topLeft[1])
.style("left", topLeft[0] + "px")
.style("top", topLeft[1] + "px");
g2.attr("transform", "translate(" + -topLeft[0] + "," + -topLeft[1] + ")");
subdist.attr("d", path);
}
function projectPoint(x, y) {
var point = map.latLngToLayerPoint(new L.LatLng(y, x));
this.stream.point(point.x, point.y);
}
});
//twnsublatlng.json Village_NLSC_121_1050219 25.0853403,121.4231634
d3.csv("taipei.csv", function(data) {
var transform = d3.geo.transform({point: projectPoint}),
d3path = d3.geo.path().projection(transform);
function projectPoint(x, y) {
var point = map.latLngToLayerPoint(new L.LatLng(x, y));
this.stream.point(point.x, point.y);
}
var lines = {
"1":{
color: "brown",
geoLineString: {
type: "LineString",
coordinates: []
}},
"2": {
color: "red",
geoLineString: {
type: "LineString",
coordinates: []
}},
"3": {
color: "green",
geoLineString: {
type: "LineString",
coordinates: []
}},
"4": {
color: "orange",
geoLineString: {
type: "LineString",
coordinates: []
}},
"4-1": {
color: "orange",
geoLineString: {
type: "LineString",
coordinates: []
}},
"5": {
color: "blue",
geoLineString: {
type: "LineString",
coordinates: []
}},
"n": {
color: "red",
geoLineString: {
type: "LineString",
coordinates: []
}},
"s": {
color: "green",
geoLineString: {
type: "LineString",
coordinates: []
}}
};
data.forEach(function(d) {
lines[d.line_no].geoLineString.coordinates.push(
[parseFloat(d.lat), parseFloat(d.lon)]);
});
var keys = d3.keys(lines).filter(function(key, d) {
return key;
});
var lines2 = [];
keys.forEach(function(key) {
var tmpdata = lines[key];
tmpdata['line_no'] = key;
lines2.push(tmpdata);
});
var linePath = g.selectAll(".lineConnect")
.data(lines2)
.enter()
.append("path")
.attr("class", "lineConnect")
.attr("id", function(d) {return d.line_no; })
.attr("stroke", function(d) { return d.color; })
.attr("stroke-width", 1.5)
.attr("fill", "None")
.style("opacity", 1)
.attr("d", function(d) { return d3path(d.geoLineString); });
d3.select("#mrtline").on("change", switchLine);
function switchLine() {
var check = this.checked;
if (check === true) {
linePath.style("opacity", 1);
} else {
linePath.style("opacity", 0);
}
}
var stations = g.selectAll(".circle")
.data(data)
.enter()
.append("circle")
.attr("r", 3.5)
.attr("cx", function(d) { return map.latLngToLayerPoint(new L.LatLng(d.lat, d.lon)).x;})
.attr("cy", function(d) { return map.latLngToLayerPoint(new L.LatLng(d.lat, d.lon)).y;})
.attr("class", "circle")
.attr("stroke", function(d) { return lines[d.line_no].color; } )
.attr("stroke-width", 1.5)
.attr("fill", "#fff")
.style("opacity", 0);
stationName = g2.selectAll(".station-name")
.data(data)
.enter()
.append("text")
.attr("class", "station-name")
.attr("id", function(d) { return d.id; })
.attr("fill", "black")
.style("font-size", 10)
.text(function(d) { return d.name; } )
.style("opacity", 0);
map.on("viewreset", updateMap);
updateMap();
d3.select("#station").on("change", switchStation);
function switchStation() {
var check = this.checked;
if (check === true) {
stations.style("opacity", 1);
stationName.style("opacity", 1);
} else {
stations.style("opacity", 0);
stationName.style("opacity", 0);
}
}
function updateMap() {
linePath.attr("d", function(d) { return d3path(d.geoLineString); });
stationName.attr("transform", function(d) {
d.x = map.latLngToLayerPoint(new L.LatLng(d.lat, d.lon)).x+7.5;
d.y = map.latLngToLayerPoint(new L.LatLng(d.lat, d.lon)).y+2;
return "translate("+d.x +","+d.y +")rotate(-20)";
});
stations.attr("cx", function(d) { return map.latLngToLayerPoint(new L.LatLng(d.lat, d.lon)).x;})
.attr("cy", function(d) { return map.latLngToLayerPoint(new L.LatLng(d.lat, d.lon)).y;});
}
}); //end of d3.csv("taipei.csv")
function storyTeller() {
// start
var i = 0,
r = $.Deferred();
var storyData = [
{ type: 0, pan: [25.0656575,121.5896828], selector: "sub", target: "寶湖里", text: "#1 Baohu Village, Neihu, Taipei\nMedian Income: 1.24m NTD (41.3k USD)\nMajor Property: Villa House\nHousing Price: Villa 30-50m NTD (1-1.6m USD)"},
{ type: 0, pan: [24.9896,121.59], selector: "sub", target: "政大里", text: "#2 Chengda Village, Wenshan, Taipei\nMedian Income: 1.23m NTD (41k USD)\nMajor Property: Villa House\nHousing Price: House 40m NTD (1.3m USD),\n Apartment 0.7m NTD(23k USD)/35.6 sq ft" },
{ type: 0, pan: [24.9263674,121.4975], selector: "sub", target: "華城里", text: "#3 Huacheng Village, Xindian, New Taipei City\nMedian Income:1.2m NTD (40k USD)\nMajor Property: Villa House\nHousing Price: Villa 30-50m NTD (1-1.6m USD)" },
{ type: 2, pan: [25.045,121.547], center: [[25.0292997,121.5030736], [25.0263064,121.5263363], [25.0645017,121.4959642], [25.0601717,121.5417976], [25.0287132,121.5548065], [25.0294912,121.4803741]], selector: "dist", target: ["中正區", "大安區", "大同區", "松山區", "信義區", "萬華區"], text: "In the central area of Taipei, Zongcheng, Daan, Datong, Songshan and Xinyi Districts have a relatively consistent color within each district. This means income distribution is comparatively even in the five districts. " },
{ type: 3, pan: [25.045,121.547], center: [[24.991582, 121.572439], [25.088473, 121.593980], [25.06,121.532]], selector: "dist", target: ["文山區", "內湖區", "中山區"], text: "Wenshan, Neihu and Zongshan Districts each have one or several villages with distinctly high median income, suggests inequality within each district." },
{ type: 0, pan: [25.045,121.547], center: [25.0263064,121.5263363], selector: "none", target: "", text: "Now, it's your time exploring the map!\nOr scroll down for more stories." }
]
function storyLine() {
var type = storyData[i].type,
pan = storyData[i].pan,
center = storyData[i].center,
target = storyData[i].target,
text = storyData[i].text,
selector;
if (storyData[i].selector === "sub") {
selector = "#";
} else if (storyData[i].selector === "dist") {
selector = ".";
} else {
selector = "";
}
if (type === 0) {
type0();
} else if (type === 1) {
type1();
} else if (type === 2) {
type2();
} else if (type === 3) {
type3();
}
story.text(text);
var exitBtn = story.append("svg")
.attr("id", "exit")
.append("path")
.attr("class", "btn")
.attr("d", "m0,0L5,5L10,10L5,5L0,10L5,5L10,0L5,5z")
.attr("stroke-width", 4)
.attr("stroke", "#d0d0d0")
.attr("transform", "translate(4,4)")
.on("mouseover", function(){
d3.select(this)
.attr("stroke", "#74AFAD");
})
.on("mouseout", function(){
d3.select(this)
.attr("stroke", "#d0d0d0");
})
.on("click", function() {
exit = true;
distname.style("opacity", 0);
tooltip.style("opacity", 0);