JSFiddle - React, Tailwind, and code Playground
by Patricia Warwick
JavaScript
var format = d3.format(",");
var jsonFile = "/sites/default/files/json/25-wards.json";
var viewFile = "/25-ward-postcards-json";
var centered;
if (width <= 800 && height <= 600) { // mobile
mapRatio = .9;
} else { // desktop
mapRatio = 1;
}
var margin = {
top: 0,
left: 10,
bottom: -0,
right: 10
},
width = parseInt(d3.select('#data-div').style('width')),
width = width - margin.left - margin.right,
height = width * mapRatio;
d3.json(jsonFile).then(function(wards, failureCallback) {
d3.json(viewFile).then(function(postcards, failureCallback2) {
var postcardTotals = new Object();
var tip = d3.tip()
.attr('class', 'd3-tip')
.offset([-10, 0])
.html(function(d) {
return wardCounts[0].value[d.properties.SCODE_NAME] + " signed postcards";
})
postcardTotals = d3.nest()
.key(function(d) {
return d.node.event;
})
.rollup(function(v) {
return {
"01": d3.sum(v, function(d) {
return d.node.w1;
}),
"02": d3.sum(v, function(d) {
return d.node.w2;
}),
"03": d3.sum(v, function(d) {
return d.node.w3;
}),
"04": d3.sum(v, function(d) {
return d.node.w4;
}),
"05": d3.sum(v, function(d) {
return d.node.w5;
}),
"06": d3.sum(v, function(d) {
return d.node.w6;
}),
"07": d3.sum(v, function(d) {
return d.node.w7;
}),
"08": d3.sum(v, function(d) {
return d.node.w8;
}),
"09": d3.sum(v, function(d) {
return d.node.w9;
}),
10: d3.sum(v, function(d) {
return d.node.w10;
}),
11: d3.sum(v, function(d) {
return d.node.w11;
}),
12: d3.sum(v, function(d) {
return d.node.w12;
}),
13: d3.sum(v,...