-
Notifications
You must be signed in to change notification settings - Fork 3
/
mapa.html
787 lines (616 loc) · 31.5 KB
/
mapa.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<link rel="shortcut icon" href="ico/favicon.png">
<title>Mapa</title>
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<link href="vendor/bootswatch/bootstrap.min.css" rel="stylesheet">
<link href="vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet">
<link href="vendor/jquery-custom-scrollbar/jquery.mCustomScrollbar.css" rel="stylesheet" type="text/css" />
<script src="vendor/bootstrap/js/bootstrap.min.js"></script>
<script src="vendor/momentjs/moment-with-langs.min.js"></script>
<script src="http://d3js.org/d3.v3.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/lodash.js/1.0.0-rc.3/lodash.underscore.min.js"></script>
<script src="vendor/jquery-custom-scrollbar/jquery.mCustomScrollbar.concat.min.js"></script>
<script src="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.js"></script>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.css" />
<link rel="stylesheet" href="vendor/leaflet-zoomslider/L.Control.Zoomslider.css" />
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
<link rel="stylesheet" href="vendor/leaflet-zoomslider/L.Control.Zoomslider.ie.css" />
<![endif]-->
<script src="vendor/leaflet-zoomslider/L.Control.Zoomslider.js"></script>
<link href="css/mapa.css" rel="stylesheet">
<link href="css/sticky-footer.css" rel="stylesheet">
</head>
<body>
<div id="wrap">
<div class="container-fluid">
<div class="main-padder">
<div class="row">
<div class="filtros">
<h5 class="titulo-color">Filtros <small>- Click para activar</small></h5>
<button id="limpiar-filtros" class="btn btn-xs btn-block"><i class="fa fa-undo"></i> Limpiar filtros</button>
<div id="scroll-filtros">
<h6>Distritos</h6>
<div id="distritos-togglers">
<div class="distritos-row">
<button data-id="7" type="button">Sur</button>
<button data-id="4" type="button">Norte</button>
<button data-id="6" type="button">Oeste</button>
</div>
<div class="distritos-row">
<button data-id="3" type="button">Centro</button>
<button data-id="5" type="button">Noroeste</button>
<button data-id="8" type="button">Sudoeste</button>
</div>
</div>
<h6>Comisarías</h6>
<div id="comisarias-togglers">
<button data-id="28" type="button">1</button>
<button data-id="20" type="button">2</button>
<button data-id="13" type="button">Sub 2</button>
<button data-id="31" type="button">3</button>
<button data-id="29" type="button">4</button>
<button data-id="15" type="button">5</button>
<button data-id="8" type="button">6</button>
<button data-id="30" type="button">7</button>
<button data-id="10" type="button">8</button>
<button data-id="23" type="button">10</button>
<button data-id="14" type="button">11</button>
<button data-id="6" type="button">12</button>
<button data-id="3" type="button">13</button>
<button data-id="5" type="button">14</button>
<button data-id="16" type="button">15</button>
<button data-id="21" type="button">16</button>
<button data-id="24" type="button">17</button>
<button data-id="7" type="button">18</button>
<button data-id="4" type="button">19</button>
<button data-id="11" type="button">Sub 19</button>
<button data-id="18" type="button">20</button>
<button data-id="22" type="button">Sub 20</button>
<button data-id="12" type="button">21</button>
<button data-id="17" type="button">Sub 21</button>
<button data-id="25" type="button">Sub 22</button>
<button data-id="19" type="button">Sub 24</button>
<button data-id="26" type="button">30</button>
<button data-id="27" type="button">32</button>
<button data-id="9" type="button">33</button>
</div>
</div>
</div>
<div class="col-sm-12 mapa-y-filtros">
<div class="top-bar-wrapper">
<div class="top-bar">
<div class="autoplay-wrapper">
<button id="autoplay" title="Animar el rango de fechas" class="btn btn-primary"><i class="fa fa-play"></i> Reproducir</button><br>
</div>
<h5 class="titulo-color">Mapa <small>- Hacé click en los puntos para más detalles.</small></h5>
<div>
<h4><span id="filtros-fechadesde">16 de Junio</span> <small>al</small> <span id="filtros-fechahasta">23 de Noviembre</span> <small>-</small> <span id="cantidad-puntos"></span> <small>homicidios</small> <small>-</small> <span id="porcentaje">55</span>% <small>del total</small></h4>
<h5 id="textoFiltros"></h5>
</div>
</div>
</div>
<div id='map' data-source="mapa.json"></div>
<div class="bottom-bar-wrapper">
<div class="bottom-bar">
<div id="timeline"></div>
<h5 class="titulo-color">Línea de Tiempo <small>- Seleccioná un área "pintando" en la línea del tiempo para filtrar por fecha, o arrastrando los extremos grises.</small></h5>
</div>
</div>
</div>
</div>
<script type="text/html" id="sideTemplate">
<h4><img src="images/cruz.png" style="height: 16px"> <%- victimas %></h4>
<h5><img src="images/fecha.png" style="height: 16px"> <%- fecha %></h5>
<h5><img src="images/map-pin.png" style="height: 16px"> <%- direccion %></h5>
<h5><img src="images/comisaria.png" style="height: 16px"> <%- comisaria %></h5>
<p><img src="images/arma.png" style="height: 16px"> <%- resumen %></p>
<a href="<%- link %>" target="_blank"><i class="fa fa-external-link"></i> Nota en LaCapital.com.ar</a>
<div class="alert alert-info">
Leyenda:<br><br>
AF : Arma de fuego<br>
AB : Arma blanca<br>
OC : Objeto contundente
</div>
</script>
<script type="text/javascript">
nro_comisaria = {
"28": "1",
"20": "2",
"13": "sub2",
"31": "3",
"29": "4",
"15": "5",
"8": "6",
"30": "7",
"10": "8",
"23": "10",
"14": "11",
"6": "12",
"3": "13",
"5": "14",
"16": "15",
"21": "16",
"24": "17",
"7": "18",
"4": "19",
"11": "sub19",
"18": "20",
"22": "sub20",
"12": "21",
"17": "sub21",
"25": "sub22",
"19": "sub24",
"26": "30",
"27": "32",
"9": "33"
}
moment.lang("es");
var d3map = {};
var TOTAL_PUNTOS = 214; //hardcodeado por ahora
var DEBUG_LEVEL = false;
d3map.brush = null;
d3map.cantidadPuntos = 0;
d3map.fechaInicio = new Date(2013, 0, 1, 0, 0, 0, 0);
d3map.fechaFin = new Date(2013, 11, 31, 23, 59, 59, 0);
d3map.cursorAutoPlay = moment(d3map.fechaInicio).add('days', 1).toDate();
d3map.enAutoPlay = false;
d3map.layers = {
"comisarias": [],
"distritos": []
};
d3map.log = function(msg, debugLevel) {
var debugLevelValue = {
"info": 1,
"warning": 2,
"all": 3
}
if (debugLevelValue[DEBUG_LEVEL] >= debugLevelValue[debugLevel]) {
console.log(msg);
}
}
d3map.autoplay = function() {
d3map.limpiarFiltros();
d3map.enAutoPlay = true;
d3map.cursorAutoPlay = d3map.fechaInicio;
$("#autoplay").off("click");
$("#autoplay").html("<i class='fa fa-stop'></i> Detener");
$("#autoplay").on("click", function() {
d3map.stop();
})
d3map.autoPlayInterval = setInterval(
function() {
d3map.cursorAutoPlay = moment(d3map.cursorAutoPlay).add('days', 1).toDate();
if (d3map.cursorAutoPlay > d3map.fechaFin) {
d3map.stop();
return;
}
d3map.brush.extent([d3map.fechaInicio, d3map.cursorAutoPlay]);
d3.select('.brush').call(d3map.brush);
d3map.mostrarPuntosFiltrados();
d3map.actualizarTextoFiltros();
var s = d3map.brush.extent();
$("#filtros-fechadesde").html(moment(s[0]).format("D [de] MMMM"));
$("#filtros-fechahasta").html(moment(s[1]).format("D [de] MMMM"));
}
, 25
);
}
d3map.stop = function() {
if (d3map.enAutoPlay) {
$("#autoplay").off("click");
$("#autoplay").html("<i class='fa fa-play'></i> Reproducir");
$("#autoplay").on("click", function() {
d3map.autoplay();
})
clearInterval(d3map.autoPlayInterval);
d3map.enAutoPlay = false;
}
}
d3map.limpiarFiltros = function() {
$(".filtros .active").removeClass("active");
d3map.mostrarPuntosFiltrados();
d3map.actualizarTextoFiltros();
}
d3map.actualizarTextoFiltros = function() {
var seleccionadas = [];
$("#comisarias-togglers button").each(function() {
if ($(this).hasClass("active")) {
seleccionadas.push($(this).html());
}
});
var spanComisarias = $("<span/>");
spanComisarias.attr("id", "filtro-comisarias")
if (seleccionadas.length > 0) {
spanComisarias.html(seleccionadas.join(", "));
}
$("#filtro-comisarias").remove();
$("#textoFiltros").append(spanComisarias);
$("#cantidad-puntos").html(d3map.cantidadPuntos);
$("#porcentaje").html(Math.floor((d3map.cantidadPuntos / TOTAL_PUNTOS) * 100));
};
d3map.obtenerFechaPunto = function(d) {
return d3.time.format("%d/%m/%y").parse(d.properties.fecha);
}
d3map.mostrarDistritosFiltrados = function() {
d3map.log("Mostrando distritos filtrados", "info");
var distritosSeleccionados = obtenerDistritosSeleccionados();
var rangoFechas = d3map.brush.extent();
var seleccionados = [];
$("#distritos-togglers button").each(function() {
if ($(this).hasClass("active")) {
seleccionados.push($(this).data("id"));
}
});
var selection = d3.selectAll("#svg-distritos path").classed("selected", function (d) {
return !!(seleccionados.indexOf(d.properties.cartodb_id) > -1);
});
}
d3map.mostrarComisariasFiltradas = function() {
var comisariasSeleccionadas = obtenerComisariasSeleccionadas();
var rangoFechas = d3map.brush.extent();
var seleccionadas = [];
$("#comisarias-togglers button").each(function() {
if ($(this).hasClass("active")) {
seleccionadas.push($(this).data("id"));
}
});
var selection = d3.selectAll("#svg-comisarias path").classed("selected", function (d) {
return !!(seleccionadas.indexOf(d.properties.cartodb_id) > -1);
});
}
d3map.mostrarPuntosFiltrados = function() {
d3map.log("Mostrando puntos", "info");
var comisariasSeleccionadas = obtenerComisariasSeleccionadas();
var rangoFechas = d3map.brush.extent();
d3map.mostrarComisariasFiltradas();
d3map.mostrarDistritosFiltrados();
var selection = d3.selectAll("#svg-puntos path.circle").classed("selected", function (d) {
var fechaPunto = d3map.obtenerFechaPunto(d);
var enFecha = rangoFechas[0] <= fechaPunto && fechaPunto <= rangoFechas[1];
var enComisaria = false;
var nro = d.properties.comisaria.replace("ª", "");
if (comisariasSeleccionadas.length > 0) {
var indiceEnArray = comisariasSeleccionadas.indexOf(nro);
if (indiceEnArray > -1) {
enComisaria = true;
}
} else {
enComisaria = true;
}
return enFecha && enComisaria;
});
d3map.cantidadPuntos = selection.filter(".selected")[0].length;
}
function obtenerComisariasSeleccionadas() {
var seleccionadas = [];
$("#comisarias-togglers button").each(function() {
if ($(this).hasClass("active")) {
seleccionadas.push(nro_comisaria[$(this).data("id")]);
}
});
return seleccionadas;
}
function obtenerDistritosSeleccionados() {
var seleccionadas = [];
$("#distritos-togglers button").each(function() {
if ($(this).hasClass("active")) {
seleccionadas.push($(this).data("id"));
}
});
return seleccionadas;
}
function main() {
var extent, scale,
classes = 9,
reverse = false;
container = L.DomUtil.get('map');
var tpl = document.getElementById("sideTemplate").text;
var map = new L.Map('map', {
zoomControl: false,
center: [-32.9598, -60.6423],
zoom: 13,
zoomAnimation: false
});
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors',
maxZoom: 17
}).addTo(map);
$("#distritos-togglers button").on("click", function() {
d3map.stop();
var seleccionados = [];
if($(this).hasClass("active")) {
$(this).removeClass("active");
} else {
$(this).addClass("active");
}
$("#distritos-togglers button").each(function() {
if ($(this).hasClass("active")) {
seleccionados.push($(this).data("id"));
}
});
d3map.mostrarPuntosFiltrados();
d3map.actualizarTextoFiltros();
});
$("#comisarias-togglers button").on("click", function() {
d3map.stop();
var seleccionados = [];
if($(this).hasClass("active")) {
$(this).removeClass("active");
} else {
$(this).addClass("active");
}
$("#comisarias-togglers button").each(function() {
if ($(this).hasClass("active")) {
seleccionados.push($(this).data("id"));
}
});
d3map.mostrarPuntosFiltrados();
d3map.actualizarTextoFiltros();
});
function agregarCapaComisarias() {
// Agregar la capa SVG para las comisarías a Leaflet
d3map.layers['comisarias']['svg'] = d3.select(map.getPanes().overlayPane).append("svg").attr("id", "svg-comisarias");
d3map.layers['comisarias']['g'] = d3map.layers['comisarias']['svg'].append("g").attr("class", "leaflet-zoom-hide");
d3.json("comisarias.geojson", function(collection) {
// Dibuja los puntos sobre el mapa de Leaflet con D3.js
var transform = d3.geo.transform({point: projectPoint});
d3map.layers['comisarias']['collection'] = collection;
d3map.layers['comisarias']['path'] = d3.geo.path().projection(transform);
// Obtener los puntos y asignar una clase
d3map.layers['comisarias']['features'] = d3map.layers['comisarias']['g'].selectAll("path")
.data(collection.features)
.enter()
.append("path")
.attr("class", "area-comisaria");
// Use Leaflet to implement a D3 geometric transformation.
function projectPoint(x, y) {
var point = map.latLngToLayerPoint(new L.LatLng(y, x));
this.stream.point(point.x, point.y);
}
map.on("viewreset", resetCapasSVG);
});
}
function agregarCapaDistritos() {
// Agregar la capa SVG para las comisarías a Leaflet
d3map.layers['distritos']['svg'] = d3.select(map.getPanes().overlayPane).append("svg").attr("id", "svg-distritos");
d3map.layers['distritos']['g'] = d3map.layers['distritos']['svg'].append("g").attr("class", "leaflet-zoom-hide");
d3.json("distritos.json", function(collection) {
// Dibuja los puntos sobre el mapa de Leaflet con D3.js
var transform = d3.geo.transform({point: projectPoint});
d3map.layers['distritos']['collection'] = collection;
d3map.layers['distritos']['path'] = d3.geo.path().projection(transform);
// Obtener los puntos y asignar una clase
d3map.layers['distritos']['features'] = d3map.layers['distritos']['g'].selectAll("path")
.data(collection.features)
.enter()
.append("path")
.attr("class", "area-distrito");
// Use Leaflet to implement a D3 geometric transformation.
function projectPoint(x, y) {
var point = map.latLngToLayerPoint(new L.LatLng(y, x));
this.stream.point(point.x, point.y);
}
map.on("viewreset", resetCapasSVG);
});
}
agregarCapaComisarias();
agregarCapaDistritos();
// Reposition the SVG to cover the features.
function resetCapasSVG() {
d3map.layers['comisarias']['bounds'] = d3map.layers['comisarias']['path'].bounds(d3map.layers['comisarias']['collection']);
var topLeft = d3map.layers['comisarias']['bounds'][0],
bottomRight = d3map.layers['comisarias']['bounds'][1];
d3map.layers['comisarias']['svg'].attr("width", bottomRight[0] - topLeft[0])
.attr("height", bottomRight[1] - topLeft[1])
.style("left", topLeft[0] + "px")
.style("top", topLeft[1] + "px");
d3map.layers['comisarias']['g'].attr("transform", "translate(" + -topLeft[0] + "," + -topLeft[1] + ")");
d3map.layers['comisarias']['features'].attr("d", d3map.layers['comisarias']['path']);
// Distritos
d3map.layers['distritos']['bounds'] = d3map.layers['distritos']['path'].bounds(d3map.layers['distritos']['collection']);
var topLeftDistritos = d3map.layers['distritos']['bounds'][0],
bottomRightDistritos = d3map.layers['distritos']['bounds'][1];
d3map.layers['distritos']['svg'].attr("width", bottomRightDistritos[0] - topLeftDistritos[0])
.attr("height", bottomRightDistritos[1] - topLeftDistritos[1])
.style("left", topLeftDistritos[0] + "px")
.style("top", topLeftDistritos[1] + "px");
d3map.layers['distritos']['g'].attr("transform", "translate(" + -topLeftDistritos[0] + "," + -topLeftDistritos[1] + ")");
d3map.layers['distritos']['features'].attr("d", d3map.layers['distritos']['path']);
if (d3map.pathPuntos) {
d3map.boundsPuntos = d3map.pathPuntos.bounds(d3map.collectionPuntos);
var topLeft = d3map.boundsPuntos[0],
bottomRight = d3map.layers['comisarias']['bounds'][1];
svg.attr("width", bottomRight[0] - topLeft[0])
.attr("height", bottomRight[1] - topLeft[1])
.style("left", topLeft[0] + "px")
.style("top", topLeft[1] + "px");
g.attr("transform", "translate(" + -topLeft[0] + "," + -topLeft[1] + ")");
d3map.featurePuntos.attr("d", d3map.pathPuntos);
}
}
// Agregar la capa SVG para los puntos a Leaflet
var svg = d3.select(map.getPanes().overlayPane).append("svg").attr("id", "svg-puntos"),
g = svg.append("g").attr("class", "leaflet-zoom-hide");
d3.json("homicidios.json", function(collection) {
// Dibuja los puntos sobre el mapa de Leaflet con D3.js
var transform = d3.geo.transform({point: projectPoint});
d3map.collectionPuntos = collection;
d3map.pathPuntos = d3.geo.path().projection(transform).pointRadius(function (d) {
return 10; // TODO: Implementar radio según zoom del mapa
});
// Obtener los puntos y asignar una clase
d3map.featurePuntos = g.selectAll("#svg-puntos path.circle")
.data(collection.features)
.enter()
.append("path")
.attr("class", "circle");
// Listener para el click en un punto del mapa
d3map.featurePuntos.on("click", function (d, i) {
L.DomEvent.stopPropagation(d3.event);
var data = {
fecha: d.properties.fecha,
direccion: d.properties.direccion,
victimas: d.properties.victimas,
resumen: d.properties.resumen,
comisaria: d.properties.comisaria,
link: d.properties.link
};
document.getElementById('sidebar-padder').innerHTML = _.template(tpl, data);
$("#sidebar").fadeIn();
});
// Use Leaflet to implement a D3 geometric transformation.
function projectPoint(x, y) {
var point = map.latLngToLayerPoint(new L.LatLng(y, x));
this.stream.point(point.x, point.y);
}
var chart = timeseries_chart()
.x(d3map.obtenerFechaPunto).xLabel("Fecha")
.y(get_quantity).yLabel("Casos")
.brushmove(on_brush);
d3.select("#timeline").datum(collection.features).call(chart);
function on_brush(brush) {
d3map.stop();
if (brush) {
d3map.brush = brush;
}
var s = brush.extent();
$("#filtros-fechadesde").html(moment(s[0]).format("D [de] MMMM"));
$("#filtros-fechahasta").html(moment(s[1]).format("D [de] MMMM"));
d3map.mostrarPuntosFiltrados();
d3map.actualizarTextoFiltros();
}
function get_quantity(d) {
return 69; // Tamaño de la barra en la línea de tiempo, arbitrario, en realidad acá podriamos contar la cantidad de casos en una fecha
}
function timeseries_chart() {
var margin = { top: 20, right: 20, bottom: 20, left: 20 },
width = 610,
height = 40;
var x = d3.time.scale()
.domain([d3map.fechaInicio, d3map.fechaFin])
.range([0, width]),
y = d3.scale.linear(),
x_label = "X", y_label = "Y";
d3map.brush = d3.svg.brush()
.x(x)
.extent([d3map.fechaInicio, d3map.fechaFin])
.on("brush", _brushmove);
d3map.mostrarPuntosFiltrados();
d3map.actualizarTextoFiltros();
var get_x = no_op,
get_y = no_op;
function translateMonth() {
}
function timeseries(selection) {
selection.each(function (d) {
x.range([0, width]);
y.range([height, 0]);
var series = d3.select(this).append("svg").attr("id", "mapa-timeseries")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g").attr("id", "date-brush")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
var x_axis = series.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height / 2 + ")")
.style("stroke", "#eee");
var y_axis = series.append("g")
.attr("class", "y axis");
series.append("clipPath")
.attr("id", "clip")
.append("rect")
.attr("width", width - 1)
.attr("height", height - .25)
.attr("transform", "translate(1,0)");
series.append("g")
.attr("class", "brush")
.call(d3map.brush)
.selectAll("rect")
.attr("height", height)
.style("fill", '#ffee44')
.attr("opacity", 0.6);
x.domain(d3.extent(d, get_x));
x_axis.call(d3.svg.axis().tickFormat(function(d) {
return moment(d).format("MMM");
}).scale(x).orient("bottom"));
y.domain(d3.extent(d, get_y));
y_axis.call(d3.svg.axis().scale(y).orient("left"));
series.append("g").attr("class", "timeseries")
.attr("clip-path", "url(#clip)")
.selectAll("rect")
.data(d).enter()
.append("rect") // Deberían ser barras, más altas si hay más de un caso en ese día... veremos.
.style("stroke", '#0022aa')
.style("stroke-width", .5)
.style("fill", '#0077dd')
.attr("opacity", .8)
.attr("width", 3)
.attr("height", 10)
.attr("transform", function (d) {
return "translate(" + x(get_x(d)) + "," + ((height / 2) - 5) + ")";
});
});
}
timeseries.x = function (accessor) {
if (!arguments.length) return get_x;
get_x = accessor;
return timeseries;
};
timeseries.y = function (accessor) {
if (!arguments.length) return get_y;
get_y = accessor;
return timeseries;
};
timeseries.xLabel = function (label) {
if (!arguments.length) return x_label;
x_label = label;
return timeseries;
}
timeseries.yLabel = function (label) {
if (!arguments.length) return y_label;
y_label = label;
return timeseries;
}
timeseries.brushmove = function (cb) {
if (!arguments.length) return brushmove;
brushmove = cb;
return timeseries;
};
function _brushmove() {
brushmove.call(null, d3map.brush);
}
function no_op() {}
return timeseries;
}
resetCapasSVG();
}); // D3.json fin
$("#cerrar-sidebar").on("click", function () {
$("#sidebar").fadeOut();
});
$("#comisarias-togglers").mCustomScrollbar({
theme: "dark-thick"
});
$("#autoplay").on("click", function() {
d3map.autoplay();
});
$("#limpiar-filtros").on("click", function() {
d3map.limpiarFiltros();
});
};
window.onload = main;
</script>
</div> <!-- main-padder -->
</div> <!-- container -->
</div> <!-- wrap -->
</body>
</html>