-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.js
More file actions
224 lines (159 loc) · 4.87 KB
/
Copy pathsetup.js
File metadata and controls
224 lines (159 loc) · 4.87 KB
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
/*global d3, crossndx, barChart, points */
// partially adapted from crossndx's example
var map;
var markers = [];
var ndx;
var val1Dimension;
var val1Grouping;
var val2Dimension;
var val2Grouping;
var charts;
var domCharts;
var latDimension;
var lngDimension;
var idDimension;
var idGrouping;
var map;
var heatmap;
var data;
function init() {
d3.tsv("out.tsv", function (points) {
data = points;
var dateFormat = d3.time.format("%Y-%m-%d %H:%M:%S");
var numberFormat = d3.format(".2f");
var minDate, maxDate;
var numRecords = 0;
points.forEach(function (d) {
++numRecords;
d.dd = dateFormat.parse(d.DateTime); // pre-calculate month for better performance
//console.log(d);
if(minDate==undefined){
minDate = d.dd;
maxDate = d.dd;
}
if( d.dd < minDate ) minDate = d.dd;
if( d.dd > maxDate ) maxDate = d.dd;
d.month = d3.time.month(d.dd);
d.day = d3.time.day(d.dd);
d.week = d3.time.week(d.dd);
d.hour = d3.time.hour(d.dd);
// convert to numeric types
d.FileSize = +d.FileSize;
d.val1 = 0;
d.val2 = 0;
d.lat = +d.lat;
d.lng = +d.lng;
if(d.lat && d.lng){
d.heatMapPoint = new google.maps.LatLng(d.lat, d.lng)
}
});
// init maps
google.maps.visualRefresh = true;
var mapOptions = {
zoom: 2,
streetViewControl: false,
center: new google.maps.LatLng(70, 200),
mapTypeId: google.maps.MapTypeId.SATELLITE
};
map = new google.maps.Map(document.getElementById('map-div'),mapOptions);
function toggleHeatmap() {
heatmap.setMap(heatmap.getMap() ? null : map);
}
function changeGradient() {
var gradient = [
'rgba(0, 255, 255, 0)',
'rgba(0, 255, 255, 1)',
'rgba(0, 191, 255, 1)',
'rgba(0, 127, 255, 1)',
'rgba(0, 63, 255, 1)',
'rgba(0, 0, 255, 1)',
'rgba(0, 0, 223, 1)',
'rgba(0, 0, 191, 1)',
'rgba(0, 0, 159, 1)',
'rgba(0, 0, 127, 1)',
'rgba(63, 0, 91, 1)',
'rgba(127, 0, 63, 1)',
'rgba(191, 0, 31, 1)',
'rgba(255, 0, 0, 1)'
]
heatmap.set('gradient', heatmap.get('gradient') ? null : gradient);
}
// init crossndx
ndx = crossfilter(points);
// var fileSizeDim = ndx.dimension(function (d) {
// return Math.round(d.FileSize/1000000);
// });
// var fileSizeGroup = fileSizeDim.group();
// filesizeHistogram.width(300).height(300)
// .margins({top: 10, right: 50, bottom: 30, left: 40})
// .dimension(fileSizeDim).group(fileSizeGroup)
// .elasticY(true)
// .centerBar(true)
// .gap(1)
// .round(dc.round.floor).alwaysUseRounding(true)
// .x(d3.scale.linear().domain([0, 25])).elasticX(true)
// .colorAccessor(function (d) { return d.key; })
// .colorDomain([0, 10]) //(optional) define color domain to match your data domain if you want to bind data or color
// .renderHorizontalGridLines(true)
// // customize the ndx displayed in the control span
// .filterPrinter(function (ndxs) {
// var ndx = ndxs[0], s = "";
// s += numberFormat(ndx[0]) + "% -> " + numberFormat(ndx[1]) + "%";
// return s;
// });
// filesizeHistogram.xAxis().tickFormat(function (v) { return v + " MB"; });
// filesizeHistogram.yAxis().ticks(5);
// bind map bounds to lat/lng ndx dimensions
latDimension = ndx.dimension(function(p) { return p.lat; });
lngDimension = ndx.dimension(function(p) { return p.lng; });
google.maps.event.addListener(map, 'bounds_changed', function() {
var bounds = this.getBounds();
var northEast = bounds.getNorthEast();
var southWest = bounds.getSouthWest();
// NOTE: need to be careful with the dateline here
lngDimension.filterRange([southWest.lng(), northEast.lng()]);
latDimension.filterRange([southWest.lat(), northEast.lat()]);
// NOTE: may want to debounce here, perhaps on requestAnimationFrame
updateCharts();
});
// dimension and group for looking up currently selected markers
idDimension = ndx.dimension(function(p, i) { return i; });
idGrouping = idDimension.group(function(id) { return id; });
renderAll();
});
}
// Renders the specified chart
function render(method) {
d3.select(this).call(method);
}
// Renders all of the charts
function updateCharts() {
//domCharts.each(render);
}
// set visibility of markers based on crossndx
function updateMarkers() {
var heatMapPoints = [];
var pointIds = idGrouping.all();
for (var i = 0; i < pointIds.length; i++) {
var p = data[i];
if(p.heatMapPoint){heatMapPoints.push(p.heatMapPoint);}
}
var pointArray = new google.maps.MVCArray(heatMapPoints);
if(heatmap) heatmap.setMap(null);
heatmap = new google.maps.visualization.HeatmapLayer({
data: pointArray
});
heatmap.setMap(map);
}
// Whenever the brush moves, re-render charts and map markers
function renderAll() {
dc.renderAll();
updateMarkers();
//updateCharts();
}
window.renderAll = renderAll();
// Reset a particular histogram
window.reset = function(i) {
charts[i].filter(null);
renderAll();
};