Published
Edited
Aug 26, 2021
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() {
function dragstarted() {
d3.select('#svg').select("#dragrect").attr("fill", "grey");
}

function dragged(event, d) {
console.log(event.target)
console.log(event.subject)
console.log(event.sourceEvent)
const xvalue = sticky(event.x);//class="mdl-application__wrapper " margin
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
d3.select('#svg').property("value", jahr);
d3.select('#svg').dispatch("input");

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

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

return d3
.drag()
.container(d3.select(this).childNode)
//.subject('#dragGr')
.on("start", dragstarted)
.on("drag", dragged)
.on("end", dragended);
}
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
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
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

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