Published
Edited
May 1, 2019
1 fork
1 star
Insert cell
Insert cell
Insert cell
Insert cell
treemap = data => d3.treemap()
.size([width, height])
.padding(1)
.round(true)
(d3.hierarchy(data)
.sum(d => d.size)
.sort((a, b) => b.height - a.height || b.value - a.value))
Insert cell
Insert cell
format = d3.format(",d")
Insert cell
color = d3.scaleOrdinal().range(d3.schemeCategory10)
Insert cell
Insert cell
Insert cell
Insert cell
crimeData = groupByField(dataTable, 'PrimaryType')
Insert cell
flares = {
return {
name: 'flare',
children: Object.keys(crimeData).map(crimeType => {
return {name: crimeType.toLowerCase(), children: groupChildren(crimeData[crimeType], 'info')};
})
};
}
Insert cell
function groupChildren(arrayData, groupField) {
const groups = {};
arrayData.map(data => {
const info = data[groupField].toLowerCase();
if (!groups[info]) {
groups[info] = [];
}
groups[info].push(data);
});
return Object.keys(groups).map(key => {
return {name: key, size: groups[key].length};
});
}
Insert cell
Insert cell
arrow = require('apache-arrow@0.3.1')
Insert cell
import {loadData} from '@randomfractals/apache-arrow'
Insert cell
import {groupByField} from '@randomfractals/chicago-crimes-by-type'
Insert cell
d3 = require("https://d3js.org/d3.v5.min.js")
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more