Public
Edited
Jun 23, 2023
2 forks
Insert cell
Insert cell
Insert cell
buildings.get("CTS10")
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
data.stack
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
data.stack
Insert cell
counts = {
let output = []
let params = _.keys(data.stack[0]);

const bin = arr => {
let rng = _.range(0, 100, 2);
return rng.map(d => arr.filter(v => {
let lower = d === 0 ? -1: d;
return (v > lower && v <= d + 2);
}));
}

const translated = data.stack.map(d => {
let sumVals = _.sumBy(Object.entries(d), ([k, v]) => v);
let output = {};
for (const k in d) {
output[k] = d[k] / sumVals * 100;
}
return output;
})

for (const param of params) {
let values = bin(translated.map(d => d[param]));
values = values.map(d => d.length);
output.push({parameter: param, values: values})
}

return output;




}
Insert cell
toPlot = counts[1]
Insert cell
{
// Create an empty SVG with specified width and height.

let height = 300;
let width = 400;
const svg = d3.select(DOM.svg(width, height));

const rScale = d3.scaleSqrt([0, 100], [0, 20]);
const yScale = d3.scaleLinear([0, 100], [0, height / 2]);
const xScale = d3.scaleBand(_.range(0, toPlot.values.length), [50, width - 50]);

const xAxis = svg => svg
.attr("transform", `translate(0,${height / 2})`)
.call(d3.axisBottom(xScale));
// Draw the x and y axes.
svg.append('g').call(xAxis);


// const bars = svg.append("g");

// const bar = bars
// .selectAll("rect")
// .data(toPlot.values)
// .join("rect")
// .attr("fill", "steelblue")
// .attr("y", height / 2)
// .attr("x", (d, i) => xScale(i))
// .attr("height", d => yScale(d))
// .attr("width", xScale.bandwidth())

const dots = svg.append("g");

const dot = dots
.selectAll("circle")
.data(toPlot.values)
.join("circle")
.attr("fill", "steelblue")
.style("mix-blend-mode", "multiply")
.attr("stroke", "none")
// .attr("cx", (d, i) => xScale(i) + xScale.bandwidth() / 2)
.attr("cx", (d, i) => xScale(i))
.attr("cy", height / 2)
.attr("r", d => rScale(d));
return svg.node();
}
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more