-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
762 lines (609 loc) · 22.9 KB
/
script.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
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
function drawbubble(id,PrivateWork,PublicWork,selfEmployed,FamilyWork){
var salesData=[
{label:"Basic", color:"#3366CC", value: PrivateWork},
{label:"Plus", color:"#DC3912",value :PublicWork},
{label:"Lite", color:"#FF9900", value:selfEmployed},
{label:"Elite", color:"#109618",value:FamilyWork}
];
var svg = d3.select("#det2").append("svg").attr("width",600).attr("height",300);
svg.selectAll("g").remove();
svg.append("g").attr("id","salesDonut");
Donut3D.draw("salesDonut", randomData(), 100, 100, 100, 100, 30,0.3);
function randomData(){
return salesData.map(function(d){
return {label:d.label, value:d.value, color:d.color};});
}
}
function drawcommute(id,drive,carpool,transit,walk,othertransport){
var pieObjects=[
{
key: "drive",
value: drive,
},
{
key: "carpool",
value: carpool,
},
{
key: "transit",
value: transit,
},
{
key: "walk",
value: walk,
},
{
key: "othertransport",
value: othertransport,
}];
for(i=0;i<pieObjects.length;i++){
if (isNaN(pieObjects.value))
pieObjects.value=0;
}
var outerWidth = 300;
var outerHeight = 300;
var margin = { left: 10, top: 10, right: 10, bottom: 10 };
var innerWidth = outerWidth - margin.left - margin.right;
var innerHeight = outerHeight - margin.top - margin.bottom;
var radius = Math.min(innerHeight, innerWidth) /2;
var colorScale = d3.scale.ordinal()
.range(["lightseagreen","khaki","lightsalmon","lightskyblue","lightpink",]);
// select SVG element on the DOM
var svg1 = d3.select("#det4")
.attr("width", outerWidth)
.attr("height", outerHeight);
var arc = d3.svg.arc()
.outerRadius(radius * 0.8)
.innerRadius(radius * 0.5);
var labelArc = d3.svg.arc()
.outerRadius(radius - 50)
.innerRadius(radius - 50);
var pie = d3.layout.pie()
.sort(null)
.value(function (d) {
return d.value;
});
svg1.selectAll("g").remove();
// add group
var group=svg1.append("g").attr("transform", "translate("+outerWidth/2+","+ outerHeight/2+")");;
var slice =group.selectAll(".arc")
.data(pie(pieObjects))
.enter().append("g")
.attr("class", "arc").append("path")
.style("fill", function (d) {
console.log(colorScale(d.data.key))
return colorScale(d.data.key);
}).attr("d",arc);
// slice
var div = d3.select("body").append("div").attr("class", "toolTip");
slice
.on("mousemove", function(d){
div.style("left", d3.event.pageX+10+"px");
div.style("top", d3.event.pageY-25+"px");
div.style("display", "inline-block");
div.html((d.data.key)+"<br>"+(d3.format(".2s")(d.data.value))+"%");
});
slice
.on("mouseout", function(d){
div.style("display", "none");
});
var legendRectSize = radius * 0.05;
var legendSpacing = radius * 0.05;
var legend = group.selectAll('.legend')
.data(colorScale.domain())
.enter()
.append('g')
.attr('class', 'legend')
.attr('transform', function(d, i) {
var height = legendRectSize + legendSpacing;
var offset = height * colorScale.domain().length / 2;
var horz = -8 * legendRectSize;
var vert = i * height - offset;
return 'translate(' + horz + ',' + vert + ')';
});
legend.append('rect')
.attr('width', legendRectSize)
.attr('height', legendRectSize)
.attr('x', 5+legendRectSize + legendSpacing)
.attr('y',(legendRectSize - legendSpacing+legendRectSize/2)-8)
.style('fill', colorScale)
.style('stroke', colorScale);
legend.append('text')
.attr('x', 15+legendRectSize + legendSpacing)
.attr('y', legendRectSize - legendSpacing+legendRectSize/2)
.attr('class', 'legendText')
.text(function(d) { return d; });
}
function drawIncomeToPovertyBarChart(id,professional,service,office,construction,production) {
var professional = parseFloat(professional);
var service = parseFloat(service);
var office = parseFloat(office);
var construction = parseFloat(construction);
var production = parseFloat(production);
var total = professional+service+office+construction+production;
var barObjects = [
{
key: "professional",
value: professional,
percent:professional/total
},
{
key: "service",
value: service,
percent: service/total
},
{
key: "office",
value:office,
percent:office/ total
},
{
key: "construction",
value: construction,
percent: construction / total
},
{
key: "production",
value: production,
percent:production/ total
}];
for(i=0;i<barObjects.length;i++){
if (isNaN(barObjects.value))
barObjects.value=0;
}
/* BEFORE DATA */
// chart size
var outerWidth = 300;
var outerHeight = 300;
var margin = { left: 30, top: 30, right: 20, bottom: 90 };
var innerWidth = outerWidth - margin.left - margin.right;
var innerHeight = outerHeight - margin.top - margin.bottom;
var innerHeightOffset = innerHeight+1;
var xAxisLabelText = "Employment Stream";
var xAxisLabelOffset = 35;
var yAxisLabelText = "% of People";
var yAxisLabelOffset = 10;
/* var tip = d3.tip()
.attr('class', 'd3-tip')
.offset([-10, 0])
.html(function(d) {
return "<strong>Frequency:</strong> <span style='color:red'>" + d.value + "</span>";
})*/
// Select SVG element on the DOM
var SVG = d3.select("#det1").attr("width",outerWidth).attr("height",outerHeight);
// Remove previous line charts
SVG.selectAll("g").remove();
// Bar chart group
var group=SVG.append("g").attr("transform", "translate(" + margin.left + "," + margin.top + ")");
// xAxis Group
var xAxisG=group.append("g").attr('class', 'axis').attr('transform', "translate(0," + innerHeightOffset + ")");
// yAxis Group
var yAxisG= group.append("g").attr('class', 'axis').attr('transform', 'translate(-2,0)');
var xAxisLabel = xAxisG.append("text")
.style("text-anchor", "middle")
.attr("x", innerWidth/2)
.attr("y", xAxisLabelOffset)
.attr("class", "label")
.attr("id","xlabel")
.text(xAxisLabelText)
var yAxisLabel = yAxisG.append("text")
.style("text-anchor", "middle")
.attr("transform", "translate(" + yAxisLabelOffset + "," + (innerHeight/4) + ") rotate(-90)")
.attr("class", "label")
.text(yAxisLabelText);
// create axis scale: Pixel Space
var xOrdinalScale =d3.scale.ordinal().rangeBands([0, innerWidth], 0.05);
var yScale = d3.scale.linear().range([innerHeight, 0]);
// define x and y axis
var xAxis = d3.svg.axis().scale(xOrdinalScale).orient('bottom');
var yAxis = d3.svg.axis().scale(yScale).orient('left').tickFormat(d3.format(".2s"))
.outerTickSize(0);
xOrdinalScale.domain(barObjects.map(function(d) {
return d.key; }));
yScale.domain([0, d3.max(barObjects, function(d) {
return d.value; })]);
xAxisG.call(xAxis).selectAll("text")
.style("text-anchor", "end")
.attr("dx", "-.8em")
.attr("dy", ".15em")
.attr("transform", function(d) {
return "rotate(-65)"
});
d3.select("#xlabel").style("text-anchor", "middle")
.attr("x", innerWidth/2)
.attr("y", 70)
.attr("transform","rotate(1.5)");
// .attr("transform", "translate(" + yAxisLabelOffset + "," + (innerHeight/4) + ") rotate(-90)")
yAxisG.call(yAxis);
// Bind Data
var bars= group.selectAll("rect").data(barObjects);
// Enter
bars.enter().append('rect')
.attr("class", "bar");
// figure out the width of individual bars
var barWidth = innerWidth / 5;
//tip
var div = d3.select("body").append("div").attr("class", "toolTip");
// Update
bars.attr("x", function(d, i) { return i*barWidth})
.attr("y", function(d, i) { return yScale(d.value);})
.attr("width", barWidth)
.attr("height", function(d) { return innerHeight - yScale(d.value); });
bars.on('mouseover',function(d){
div.style("left", d3.event.pageX+10+"px");
div.style("top", d3.event.pageY-25+"px");
div.style("display", "inline-block");
div.html((d.value)+"%");
})
.on('mouseout', function(d){
div.style("display", "none");
});
// Exit
bars.exit().remove();
// console.log("data:"+ data);
}
function valueFormat(d) {
if (d > 1000000000) {
return Math.round(d / 1000000000 * 10) / 10 + "B";
} else if (d > 1000000) {
return Math.round(d / 1000000 * 10) / 10 + "M";
} else if (d > 1000) {
return Math.round(d / 1000 * 10) / 10 + "K";
} else {
return d;
}
}
function drawAllMaps(stateid,state,male,female){
var total = parseInt(male)+parseInt(female)
var pieObjects=[
{
key: "Male",
value: male,
percent: parseInt(male)/total
},
{
key: "Female",
value: female,
percent: parseInt(female) /total
}];
for(i=0;i<pieObjects.length;i++){
if (isNaN(pieObjects.value))
pieObjects.value=0;
}
var outerWidth = 300;
var outerHeight = 300;
var margin = { left: 10, top: 10, right: 10, bottom: 10 };
var innerWidth = outerWidth - margin.left - margin.right;
var innerHeight = outerHeight - margin.top - margin.bottom;
var radius = Math.min(innerHeight, innerWidth) /2;
var colorScale = d3.scale.ordinal()
.range(["darkslateblue","Hotpink"]);
// select SVG element on the DOM
var svg1 = d3.select("#det5")
.attr("width", outerWidth)
.attr("height", outerHeight);
var arc = d3.svg.arc()
.outerRadius(radius * 0.8)
.innerRadius(radius * 0.5);
var labelArc = d3.svg.arc()
.outerRadius(radius - 50)
.innerRadius(radius - 50);
var pie = d3.layout.pie()
.sort(null)
.value(function (d) {
return d.value;
});
svg1.selectAll("g").remove();
// add group
var group=svg1.append("g").attr("transform", "translate("+outerWidth/2+","+ outerHeight/2+")");;
var slice =group.selectAll(".arc")
.data(pie(pieObjects))
.enter().append("g")
.attr("class", "arc").append("path")
.style("fill", function (d) {
console.log(colorScale(d.data.key))
return colorScale(d.data.key);
}).attr("d",arc);
// slice
var div = d3.select("body").append("div").attr("class", "toolTip");
slice
.on("mousemove", function(d){
div.style("left", d3.event.pageX+10+"px");
div.style("top", d3.event.pageY-25+"px");
div.style("display", "inline-block");
div.html((d.data.key)+"<br>"+(d3.format(".2s")(d.data.value))+"("+(d3.format(",.1%")(d.data.percent))+")");
});
slice
.on("mouseout", function(d){
div.style("display", "none");
});
var legendRectSize = radius * 0.05;
var legendSpacing = radius * 0.05;
var legend = group.selectAll('.legend')
.data(colorScale.domain())
.enter()
.append('g')
.attr('class', 'legend')
.attr('transform', function(d, i) {
var height = legendRectSize + legendSpacing;
var offset = height * colorScale.domain().length / 2;
var horz = -8 * legendRectSize;
var vert = i * height - offset;
return 'translate(' + horz + ',' + vert + ')';
});
legend.append('rect')
.attr('width', legendRectSize)
.attr('height', legendRectSize)
.attr('x', 10+legendRectSize + legendSpacing)
.attr('y', (5+legendRectSize - legendSpacing+legendRectSize/2) - 7)
.style('fill', colorScale)
.style('stroke', colorScale);
legend.append('text')
.attr('x', 25+legendRectSize + legendSpacing)
.attr('y', 5+legendRectSize - legendSpacing+legendRectSize/2)
.attr('class', 'legendText')
.text(function(d) { return d; });
}
//Width and height of map
var width = 768;
var height = 500;
// D3 Projection
var projection = d3.geo.albersUsa()
.translate([width/2, height/2]) // translate to center of screen
.scale([1000]); // scale things down so see entire US
// Define path generator
var path = d3.geo.path() // path generator that will convert GeoJSON to SVG paths
.projection(projection); // tell path generator to use albersUsa projection
// Define linear scale for output
var color = d3.scale.linear()
.range(["lightsteelblue","#00BFFF","lightsalmon","lightpink"]);
//Create SVG element and append map to the SVG
var svgContainer = d3.select('#map');
var svg = svgContainer.append("svg")
.attr("width", width)
.attr("height", height);
// Append Div for tooltip to SVG
var div =svgContainer.append("div")
.attr("class", "tooltip")
.style("opacity", 0);
// Load in my states data!
d3.csv("dataquery1.csv", function(data) {
color.domain([0,1,2,3]); // setting the range of the input data
// Load GeoJSON data and merge with states data
d3.json("usstates2.json", function(json) {
// Loop through each state data value in the .csv file
for (var i = 0; i < data.length; i++) {
// Grab State Name
var dataState = data[i].State;
// Grab data value
var dataValue = data[i].TotalPop;
var dataIncome = data[i].Income;
var Male = data[i].Men;
var Female = data[i].Women;
var dataValue = data[i].TotalPop;
var dataHispanic = data[i].Hispanic;
var dataWhite = data[i].White;
var dataBlack = data[i].Black;
var dataNative = data[i].Native;
var dataAsian = data[i].Asian;
var dataPacific = data[i].Pacific;
var dataIncomePerCap = data[i].IncomePerCap;
var dataPoverty = data[i].Poverty;
var dataProfessional = data[i].Professional;
var dataService = data[i].Service;
var dataOffice = data[i].Office;
var dataConstruction = data[i].Construction;
var dataProduction = data[i].Production;
var dataDrive = data[i].Drive;
var dataCarpool = data[i].Carpool;
var dataTransit = data[i].Transit;
var dataWalk = data[i].Walk;
var dataOtherTransport = data[i].OtherTransport;
var dataWorkAtHome = data[i].WorkAtHome;
var dataEmployment = data[i].Employment;
var dataPrivateWork = data[i].PrivateWork;
var dataPublicWork = data[i].PublicWork;
var dataselfEmployed = data[i].selfEmployed;
var dataFamilyWork = data[i].FamilyWork;
var dataUnemployment = data[i].Unemployment;
var dummy= 0;
//console.log(dataValue)
//3D
// Find the corresponding state inside the GeoJSON
for (var j = 0; j < json.features.length; j++) {
var jsonState = json.features[j].properties.name;
if (dataState == jsonState) {
// Copy the data value into the JSON
json.features[j].properties.TotalPop = dataValue;
json.features[j].properties.Income = dataIncome;
json.features[j].properties.Male = Male;
json.features[j].properties.Female = Female;
json.features[j].properties.TotalPop = dataValue;
json.features[j].properties.Hispanic = dataHispanic;
json.features[j].properties.White = dataWhite;
json.features[j].properties.Black = dataBlack;
json.features[j].properties.Asian = dataAsian;
json.features[j].properties.Pacific = dataPacific;
json.features[j].properties.Native = dataNative;
json.features[j].properties.IncomePerCap = dataIncomePerCap;
json.features[j].properties.Poverty = dataPoverty;
json.features[j].properties.Professional = dataProfessional;
json.features[j].properties.Service = dataService;
json.features[j].properties.Construction = dataConstruction;
json.features[j].properties.Office = dataOffice;
json.features[j].properties.Production = dataProduction;
json.features[j].properties.Drive = dataDrive;
json.features[j].properties.Carpool = dataCarpool;
json.features[j].properties.Transit = dataTransit;
json.features[j].properties.Walk = dataWalk;
json.features[j].properties.OtherTransport = dataOtherTransport;
json.features[j].properties.WorkAtHome = dataWorkAtHome;
json.features[j].properties.Employment = dataEmployment;
json.features[j].properties.PrivateWork = dataPrivateWork;
json.features[j].properties.PublicWork = dataPublicWork;
json.features[j].properties.selfEmployed = dataselfEmployed;
json.features[j].properties.FamilyWork = dataFamilyWork;
json.features[j].properties.Unemployment = dataUnemployment;
//console.log(json.features[j].properties.TotalPop)
// Stop looking through the JSON
break;
}
}
}
// Bind the data to the SVG and create one path per GeoJSON feature
svg.selectAll("path")
.data(json.features)
.enter()
.append("path")
.attr("d", path)
.style("stroke", "#fff")
.style("stroke-width", "1")
.style("fill", function(d) {
// Get data value
var value = d.properties.TotalPop;
//console.log(value)
if (value) {
//If value exists…
return color(1);
} else {
//If value is undefined…
return "rgb(213,222,217)";
}
});
queue()
.defer(d3.json, "usstates2.json")
.defer(d3.csv, "dataquery1.csv")
.await(ready);
function ready(error, usstates2, dataquery) {
var pairRateWithId = {};
var pairNameWithId = {};
var pairIncomeWithId = {};
var pairRateWithId = {};
var pairMaleWithId = {};
var pairFemaleWithId = {};
var pairAsianWithId = {};
var pairWhiteWithId = {};
var pairBlackWithId = {};
var pairNativeWithId = {};
var pairPacificWithId = {};
var pairHispanicWithId = {};
var pairIncomePerCapWithId = {};
var pairPovertyWithId = {};
var pairProfessionalWithId = {};
var pairServiceWithId = {};
var pairOfficeWithId = {};
var pairConstructionWithId = {};
var pairProductionWithId = {};
var pairCarpoolWithId = {};
var pairDriveWithId = {};
var pairWalkWithId = {};
var pairTransWithId = {};
var pairOtherTransportWithId = {};
var pairWorkAtHomeWithId = {};
var pairEmploymentWithId = {};
var pairUnemploymentWithId = {};
var pairPublicWorkWithId = {};
var pairPrivateWorkWithId = {};
var pairselfEmployedWithId = {};
var pairFamilyWorkWithId = {};
//Moves selction to front
d3.selection.prototype.moveToFront = function() {
return this.each(function(){
this.parentNode.appendChild(this);
});
};
//Moves selction to back
d3.selection.prototype.moveToBack = function() {
return this.each(function() {
var firstChild = this.parentNode.firstChild;
if (firstChild) {
this.parentNode.insertBefore(this, firstChild);
}
});
};
data.forEach(function(d) {
pairRateWithId[d.id] = +d.TotalPop;
pairNameWithId[d.id] = d.State;
pairIncomeWithId[d.id] = d.Income;
pairRateWithId[d.id] = +d.TotalPop;
pairMaleWithId[d.id] = d.Male;
pairFemaleWithId[d.id] = d.Female;
pairAsianWithId[d.id] = d.Asian;
pairWhiteWithId[d.id] = d.White;
pairBlackWithId[d.id] = d.Black;
pairNativeWithId[d.id] = d.Native;
pairPacificWithId[d.id] = d.Pacific;
pairHispanicWithId[d.id] = d.Hispanic;
pairIncomePerCapWithId[d.id] = d.IncomePerCap;
pairPovertyWithId[d.id] = d.Poverty;
pairProfessionalWithId[d.id] = d.Professional;
pairServiceWithId[d.id] = d.Service;
pairOfficeWithId[d.id] = d.Office;
pairConstructionWithId[d.id] = d.Construction;
pairProductionWithId[d.id] = d.Production;
pairCarpoolWithId[d.id] = d.Carpool;
pairWalkWithId[d.id] = d.Walk;
pairDriveWithId[d.id] = d.Drive;
pairTransWithId[d.id] = d.Transit;
pairOtherTransportWithId[d.id] = d.OtherTransport;
pairWorkAtHomeWithId[d.id] = d.WorkAtHome;
pairEmploymentWithId[d.id] = d.Employment;
pairUnemploymentWithId[d.id] = d.Unemployment;
pairPublicWorkWithId[d.id] = d.PublicWork;
pairPrivateWorkWithId[d.id] = d.PrivateWork;
pairselfEmployedWithId[d.id] = d.selfEmployed;
pairFamilyWorkWithId[d.id] = d.FamilyWork;
//console.log(pairRateWithId[d.id])
});
svg.append("g")
// .attr("class", "county")
.selectAll("path")
.data(json.features)
.enter().append("path")
.attr("d", path)
.style ( "fill" , function (d) {
return color (1);
})
.style("opacity", 0.8)
.on("click", function (d) {
if(dummy==d.id)
{
window.location.reload();
}
dummy=d.id;
//pass id
drawAllMaps(d.id,d.properties.name,d.properties.Male,d.properties.Female);
drawcommute(d.id,d.properties.Drive,d.properties.Carpool,d.properties.Transit,d.properties.Walk,d.properties.OtherTransport);
drawbubble(d.id,d.properties.PrivateWork,d.properties.PublicWork,d.properties.selfEmployed,d.properties.FamilyWork);
drawIncomeToPovertyBarChart(d.id,d.properties.Professional,d.properties.Service,d.properties.Office,d.properties.Construction,d.properties.Production);
d3.selectAll('path').each(function (d) {
//return color (1);
});
})
.on("mouseover", function(d) {
var sel = d3.select(this);
sel.moveToFront();
d3.select(this).style("fill","orange")
d3.select(this).transition().duration(300).style({'opacity': 1, 'stroke': 'black', 'stroke-width': 1.5});
div.transition().duration(300)
.style("opacity", 1)
div.text(pairNameWithId[d.id] + "\n" + "total population:" + valueFormat(pairRateWithId[d.id]) + "\n" + "Avg Income:" + valueFormat(pairIncomeWithId[d.id]))
.style("left", (d3.event.pageX -350) + "px")
.style("top", (d3.event.pageY -30) + "px");
})
.on("mouseout", function() {
var sel = d3.select(this);
sel.moveToBack();
d3.select(this).style("fill",function(d) {
return color(1);
});
d3.select(this)
.transition().duration(300)
.style({'opacity': 0.8, 'stroke': 'white', 'stroke-width': 0});
div.transition().duration(300)
.style("opacity", 0);
})
// Modified Legend Code from Mike Bostock: http://bl.ocks.org/mbostock/3888852
};
});
});