Published
Edited
Feb 25, 2019
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
data = {return {'nodes': nodeNames, 'links': nodeLinks}}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
crimeData = groupByField(dataTable, 'PrimaryType')
Insert cell
locationData = groupByField(dataTable, 'LocationDescription')
Insert cell
assaults = groupChildren(crimeData['ASSAULT'], 'location')
Insert cell
crimeByLocation = Object.keys(crimeData)
.map(crimeType => {
return {
'crimeType': crimeType.toLowerCase(),
'locations': groupChildren(crimeData[crimeType], 'location'),
'count': crimeData[crimeType].length
};
})
.sort((a, b) => b.count - a.count)
Insert cell
nodeNames = crimeByLocation
.slice(0, 10) // top 10 crimes
.map(crime => {
return {'name': crime.crimeType.toLowerCase()};
})
.concat(Object.keys(locationData)
.map(location => {
return {'name': location.toLowerCase(), 'count': locationData[location].length};
})
.sort((a, b) => b.count - a.count)
.slice(0, 10) // top 10 locations
)
Insert cell
Insert cell
function groupByField(data, groupField) {
let groupData, location, results = {};
const dateFilter = arrow.predicate.custom(i => {
const date = toDate(data.getColumn('Date').get(i));
return (date.getMonth() <= 6); // through June
}, b => 1);
data.filter(dateFilter)
.scan((index) => {
const groupFieldData = groupData(index);
const groupArray = results[groupFieldData];
if (!groupArray) {
results[groupFieldData] = [];
}
const dataRecord = {};
dataRecord[groupField] = groupFieldData;
dataRecord['location'] = location(index);
results[groupFieldData].push(dataRecord);
}, (batch) => {
groupData = arrow.predicate.col(groupField).bind(batch);
location = arrow.predicate.col('LocationDescription').bind(batch);
});
return results;
}
Insert cell
Insert cell
dataTable = loadData(dataUrl).then(buffer => arrow.Table.from(new Uint8Array(buffer)))
Insert cell
import {loadData, toDate} from '@randomfractals/apache-arrow'
Insert cell
import {groupChildren} from '@randomfractals/chicago-crimes-sunburst'
Insert cell
arrow = require('apache-arrow@0.3.1')
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