-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.html
162 lines (128 loc) · 4.09 KB
/
map.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
<style>
#map .nyc{
stroke: #000;
fill: #fff;
stroke-width: .2px;
}
.parcels {
fill: black;
}
.bubbles circle {
fill-opacity: 1;
fill: #fa0033;
mix-blend-mode: multiply;
stroke: black;
stroke-width: .5;
}
.tooltip {
font-family: monospace;
font-size: 14px;
line-height: 18px;
color: #fff;
opacity: 1;
position: fixed;
padding: 10px
background: rgba(0, 0, 0, .9);
pointer-events: none;
transition: opacity .2s ease-in-out;
max-width: 300px;
}
.tooltip-hidden {
opacity: 0;
}
</style>
<body>
<div id="map"></div>
<script src='https://d3js.org/d3.v4.js'></script>
<script src="https://d3js.org/topojson.v2.min.js"></script>
<script src='../assets/d3-starterkit.js'></script>
<script>
var tt = d3.select('.dvz-content').append('div.copy-width').append('div.tooltip.tooltip-hidden')
var parseDate = d3.timeParse('%-m/%-d/%-y');
var getYear = d3.timeFormat('%Y');
var formatValue = d3.format('.2s');
var fixBillions = function (val) {
return formatValue(val).replace('G', 'B');
};
// var tt = d3.select('.dvz-content').append('div.copy-width').append('div.tooltip.tooltip-hidden')
var width = 740;
var height = 640;
var radius = d3.scaleSqrt()
.domain([0, 2000000000])
.range([3, 40]);
// var ownCategory = [1, 2, 3, 4, 5, 6, 7, 8];
// var ownColor = ['#fa0033', '#fa7089', '#fa7089', '#fa7089', '#fe9ea4', '#fdcfd7', '#fdcfd7', '#fff0f3'];
// var color = d3.scaleOrdinal()
// .domain(ownCategory)
// .range(ownColor);
var projection = d3.geoAlbers();
var path = d3.geoPath()
.projection(projection);
var svg = d3.select('#map').append('svg')
.attr('width', width)
.attr('height', height);
d3.json('kushnerNYCpoints-topo.json', function (error, topo) {
if (error) throw error;
// console.log(topo.objects.kushnernycpoints.geometries)
var kushProperties = topo.objects.kushnernycpoints.geometries;
kushProperties.forEach(function (d) {
d.properties.date = parseDate(d.properties.docdate);
d.properties.year = +getYear(d.properties.date);
});
// console.log(kushProperties)
var nyc = topojson.feature(topo, topo.objects.nycblocks);
var points = topojson.feature(topo, topo.objects.kushnernycpoints);
projection.fitSize([700, 660], points);
// can't seem to use .center or .transform to give it more padding on top?
svg.append('g')
.attr('class', 'map')
.selectAll('path')
.data(nyc.features)
.enter()
// .each(function(d) { console.log(d) })
.append('path')
.attr('d', path)
.attr('class', 'nyc');
var data = points.features;
console.log(data);
var show = data.filter(function (d) {
return d.properties.year === '2007' || d.properties.year === '2013';
});
console.log(show);
svg.append('g')
.attr('class', 'bubbles')
.selectAll('circle')
.data(data)
// .sort(function(a, b) { return b.properties.pricepaid - a.properties.pricepaid; })
.enter().append('circle')
.attr('transform', function (d) {
return 'translate(' + projection(d.geometry.coordinates) + ')';
})
.attr('r', function (d) {
return radius(d.properties.pricepaid);
})
// .attr('r', 1)
.call(d3.attachTooltip)
.on('mouseover', function (d) {
console.log(d.properties.place);
tt.html(d.properties.place + '<br>' + d.properties.partner + '<br>' + '$' + fixBillions(d.properties.pricepaid)).attr('class', 'tooltip');
})
.on('mouseout', function (d) {
tt.attr('class', 'tooltip-hidden;');
});
});
// TK RESPONSIVE MAP STUFF
// d3.select(window).on('resize', resize);
// function resize() {
// width = parseInt(d3.select('article').style('width'));
// width = $(window).width() * .97;
// height = width/1.85;
// projection
// .scale([width/3.5])
// .translate([width/1,height*1.4]);
// d3.select("article").attr("width",width).attr("height",height);
// d3.select("svg").attr("width",width).attr("height",height);
// d3.selectAll("path").attr('d', path);
// }
</script>
</body>