Published
Edited
Aug 30, 2022
4 forks
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// when the map selections change, update the line chart
aktualisierungJ = viewof jahr.updateLines(data_line)
Insert cell
// when the year changes in the line chart, update the map fill colors
aktualisierungG = viewof gem_sel.updateMapFill(jahr)
Insert cell
function drag(svg) {
function dragstarted() {
svg.select("#dragrect").attr("fill", "grey");
}

function dragged(event, d) {
const xvalue = sticky(event.x + 400);
const jahr = Math.round(xScale.invert(xvalue));

console.log(jahr);
// emit an input event to tell Observable that there's a new value for chart
svg.property("value", jahr);
svg.dispatch("input");

d3.select(this).attr("transform", `translate(${xvalue},0)`);
d3.select("#dragYear").text("\u25C0 " + jahr + " \u25B6");
}

function dragended() {
svg.select("#dragrect").attr("fill", "whitesmoke");
}

return d3
.drag()
.on("start", dragstarted)
.on("drag", dragged)
.on("end", dragended);
}
Insert cell
colorScaleOrd = d3.scaleOrdinal()
.range(d3.schemeDark2)
.unknown('dimgrey');
Insert cell
Insert cell
Insert cell
Insert cell
widthNow = d3.min([width, 768])
Insert cell
heightMap = 320
Insert cell
margin = ({ top: 15, right: 25, bottom: 30, left: 35 })
Insert cell
height = 750 - margin.top - margin.bottom
Insert cell
heightChart = 180
Insert cell
id = "GDE_ID"
Insert cell
padding = 10
Insert cell
mapSize = [widthNow, heightMap]
Insert cell
projectionMap = d3
.geoIdentity()
.reflectY(true)
.fitExtent([[padding, padding], mapSize.map(d => d - padding)], mapData)
Insert cell
pathMap = d3.geoPath(projectionMap)
Insert cell
xAxis = (g) =>
g
.attr("transform", `translate(0,${heightChart - margin.bottom + 10})`)
.call(d3.axisBottom(xScale).tickFormat((d) => d.toString()))
Insert cell
xScale = d3
.scaleLinear()
.range([margin.left, widthNow - margin.right])
.domain(yearExt)
Insert cell
yMaxLine = d3.max([
5,
d3.max(data_line.data_sel, (data_raum) =>
d3.max(data_raum.ALLE_JAHRE, (d) => +data_raum.ALLE_WERTE[d])
)
])
Insert cell
yMaxTot = 10
Insert cell
colorScale = d3
.scaleThreshold()
.range(d3.schemeGnBu[8])
.domain([0.5, 1, 1.5, 2, 3, 5, 10, 15])
.unknown("lightgrey")
Insert cell
d3.schemeBuGn[3]
Insert cell
d3.interpolateMagma[8]
Insert cell
Insert cell
parseYear = d3.timeParse("%Y")
Insert cell
formatYear = d3.timeFormat("%Y")
Insert cell
Insert cell
xScale.range()[0]
Insert cell
sticky = function (x) {
let stickyX = d3.max([d3.min([xScale.range()[1], x]), xScale.range()[0]]);
stickyX = xScale(Math.round(xScale.invert(stickyX)));

return stickyX;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
import {legend, swatches} from "@d3/color-legend"
Insert cell
Insert cell
Insert cell
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