Public
Edited
Mar 21, 2023
Fork of Dashboard
Insert cell
Insert cell
Insert cell
<div style="
background: #fff;
display: grid;
height: ${screen.height / screen.width * 100}vw;
grid-template-areas: 'a b' 'a b' 'a b' 'c c';
grid-gap: 10px;
">
${cell(
htl.html`<div style="grid-area: a; border: solid 1px #ccc;">`,
({width, height}) => {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, 780, 620]);

svg.append("path")
.datum(topojson.merge(tz, tz.objects.Districts.geometries))
.attr("fill", "#e0e0e0")
.attr("d", path);

svg.append("path")
.datum(topojson.mesh(tz, tz.objects.Districts, (a, b) => a !== b))
.attr("fill", "none")
.attr("stroke", "white")
.attr("stroke-linejoin", "round")
.attr("d", path);
svg.append("path")
.datum(topojson.mesh(tz, tz.objects.Districts, (a, b) => a == b))
.attr("fill", "none")
.attr("stroke", "white")
.attr("stroke-linejoin", "round")
.attr("d", path);
const legend = svg.append("g")
.attr("fill", "#777")
.attr("transform", "translate(915,608)")
.attr("text-anchor", "middle")
.style("font", "10px sans-serif")
.selectAll("g")
.data(radius.ticks(4).slice(1))
.join("g");

legend.append("circle")
.attr("fill", "none")
.attr("fill-opacity", 0.3)
.attr("stroke", "#ccc")
.attr("cy", d => -radius(d))
.attr("r",radius);

legend.append("text")
.attr("y", d => -2 * radius(d))
.attr("dy", "1.3em")
.text(radius.tickFormat(4, "s"));

svg.append("g")
.attr("fill", "brown")
.attr("fill-opacity", 0.5)
.attr("stroke", "#fff")
.attr("stroke-width", 0.5)
.selectAll("circle")
.data(data
.filter(d => d.position)
.sort((a, b) => d3.descending(a.value, b.value)))
.join("circle")
.attr("transform", d => `translate(${d.position})`)
.attr("r", d => radius((d.value - 2)*0.1))
.append("title")
.text(d => `${d.title}
${format(d.value)}`);

return svg.node();
}
)}
${cell(
htl.html`<div style="grid-area: b; border: solid 1px #ccc;">`,
({width, height, invalidation}) => StackedAreaChart(unemployment, {
x: d => d.date,
y: d => d.unemployed,
z: d => d.industry,
yLabel: "↑ USD Millions",
width,
height,
invalidation // stop the simulation when the cell is re-run
})
)}
${cell(
htl.html`<div style="grid-area: c; border: solid 1px #ccc;">`,
({width, height}) => LineChart(bei, {
x: d => d.date,
y: d => d.bei,
z: d => d.division,
color: "steelblue",
curve: d3.curveStep,
yLabel: "↑ Uzalishaji (gramu)",
width,
height
})
)}
</div>
Insert cell
import {BarChart} from "@d3/bar-chart"
Insert cell
import {ForceGraph} from "@d3/force-directed-graph"
Insert cell
import {BandChart, temperatures} from "@d3/band-chart"
Insert cell
import {LineChart, bei} from "@quantum/uzalishaji"
Insert cell
import {StackedAreaChart, unemployment,Swatches} from "@quantum/tzdd"
Insert cell
import {tz, format, path, topojson, radius, data} from "@quantum/madini"
Insert cell
Insert cell
function cell(element, initialize) {
let invalidate = () => {};
let invalidation;
let width;
let height;

function resized() {
invalidate();
invalidation = new Promise(resolve => invalidate = resolve);
width = element.clientWidth;
height = element.clientHeight;
const content = initialize({width, height, invalidation});
content.style.position = "absolute";
content.style.width = "100%";
content.style.height = "auto";
if (element.firstChild) element.replaceChild(content, element.firstChild);
else element.appendChild(content);
}

const observer = new ResizeObserver(resized);
observer.observe(element);
Inputs.disposal(element).then(() => {
observer.disconnect();
invalidate();
});

element.style.position = "relative";
return element;
}
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