Published
Edited
Apr 30, 2020
2 forks
Importers
3 stars
Insert cell
Insert cell
Insert cell
Insert cell
data = d3.csv(
"https://raw.githubusercontent.com/info474-s17/m14-layouts/master/exercise-1/data/prepped_data.csv",
d3.autoType
)
Insert cell
render_data_table(data.slice(0, 10))
Insert cell
Insert cell
// Nest by region
nested = d3
.nest()
.key(d => d.region)
.entries(data)
Insert cell
// Transform into a hierarchy (but don't yet specify the sum() function)
hierarchy = d3.hierarchy({ values: nested }, d => d.values)
Insert cell
// Write a function that can compute treemap layout
make_treemap_layout = d3
.treemap()
.round(true)
.tile(d3.treemapResquarify)
.size([width, height])
Insert cell
// Make a color scale for the regions
color = d3
.scaleOrdinal()
.domain(nested.map(d => d.key))
.range(d3.schemeCategory10)
Insert cell
Insert cell
Insert cell
Insert cell
chart.update(metric)
Insert cell
basic_data = _.cloneDeep(hierarchy)
Insert cell
// Draw the visualization
basic_chart = {
make_treemap_layout(basic_data);
const svg = d3
.create("svg")
.attr("width", width)
.attr("height", height);

svg
.selectAll("rect")
.data(hierarchy.leaves())
.join("rect")
.attr("x", d => d.x0)
.attr("width", d => d.x1 - d.x0)
.attr("y", d => d.y0)
.attr("height", d => d.y1 - d.y0)
.style("stroke", "red");

return svg.node();
}
Insert cell
appendix = md`## Appendix`
Insert cell
_ = require("lodash")
Insert cell
d3 = require("d3")
Insert cell
import { select } from "@jashkenas/inputs"
Insert cell
height = 500
Insert cell
import {
displayCaution,
render_data_table,
table_styles
} from "@info474/utilities"
Insert cell
table_styles
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