Published
Edited
Feb 9, 2021
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
Insert cell
Insert cell
Insert cell
margin = ({ top: 10, right: 10, bottom: 20, left: 40 })
Insert cell
x_time = d3
.scaleBand()
.domain(
_.map(
_.values(
iao
.filter(d => d.origin == 'DE300')
.select('date')
.objects()
),
'date'
)
)
.range([width * 0.36 + margin.left, width * 0.9 - margin.right])
.padding(0.3)
Insert cell
xAxis = g => {
const all_dates = _.map(
_.values(
iao
.filter(d => d.origin == 'DE300')
.select('date')
.objects()
),
'date'
);
const max_date = _.max(all_dates);
const min_date = _.min(all_dates);

const axis = d3
.scaleTime()
.domain([min_date, max_date])
.range([width * 0.36 + margin.left, width * 0.9 - margin.right]);

return g
.attr("transform", `translate(0,${450 - margin.bottom})`)
.call(d3.axisBottom(axis).ticks(7))
.append('text')
.attr('transform', `translate(0,${450 - margin.bottom}) rotate(-90)`)
.attr('text-anchor', 'end')
.attr('fill', 'black')
.attr('font-size', '12px')
.text('# trips');
}
Insert cell
bar_plot = function(data, cb_norm) {
embed.vega.timeFormatLocale(locale);
const format = cb_norm === 'normalize' ? '~%' : '.2s';
return vl
.markBar({ width: 6 })
.data(
data
.derive({ sum: d => d.inner + d.adjacent + d.other })
.derive({
Intern: d => d.inner,
Benachbart: d => d.adjacent
})
.derive({
Fern: d => d.other
})
.fold(['Fern', 'Intern', 'Benachbart'], {
as: ['distance', 'trips']
})
.derive({
rel: d => op.round((100 * d.trips) / d.sum) / 100,
order: d =>
op.recode(d.distance, { Intern: 1, Benachbart: 2, Fern: 0 })
})
.select('date', 'distance', 'trips', 'rel')
)
.encode(
vl
.x()
.fieldT("date")
.axis({ titleFont: "Helvetica Neue", title: 'Datum' }),
vl
.y()
.fieldQ("trips")
.stack(cb_norm === 'normalize' ? 'normalize' : true)
.axis({
titleFont: "Helvetica Neue",
format: format,
title: "Anzahl Bewegungen"
}),
vl
.color()
.fieldN('distance')
.sort(tri.order)
.scale({ range: tri.color })
.legend({ title: 'Entfernung' }),
vl.order('order'),
vl
.tooltip()
.field(cb_norm === 'normalize' ? 'rel' : 'trips')
.format(format)
);
}
Insert cell
tri = Object({
order: ['Intern', 'Benachbart', 'Fern'],
color: ['#95c6ed', '#869e80', '#833471']
})
Insert cell
grad_tri02tri2 = [0, .1, .2, .3, .4, .5, .6, .7, .8, .9, 1]
.map(culori.interpolate([tri.color[0], tri.color[2]], 'lch'))
.map(culori.formatHex)
Insert cell
grad_white2tri2 = [.1, .2, .3, .4, .5, .6, .7, .8, .9, 1]
.map(culori.interpolate(['#F6F6F6', tri.color[2]], 'lch'))
.map(culori.formatHex)
Insert cell
tri_scale = d3
.scaleOrdinal()
.domain(['inner', 'adjacent', 'other'])
.range(tri.color)
.unknown("#fff")
Insert cell
Insert cell
patterns = html`<svg height="0" width="0" xmlns="http://www.w3.org/2000/svg" version="1.1">
<defs>
<pattern id="pattern_1" patternUnits="userSpaceOnUse" width="3" height="3" patternTransform="rotate(45)">
<rect fill="${tri.color[1]}" width="100" height="100"/>
<line x1="0" y="0" x2="0" y2="3" stroke="${tri.color[2]}" stroke-width="2" />
</pattern>

<pattern id="pattern_2" patternUnits="userSpaceOnUse" width="3" height="3" patternTransform="rotate(45)">
<rect fill="#d6d6d6" width="100" height="100"/>
<line x1="0" y="0" x2="0" y2="3" stroke="black" stroke-width="2" />
</pattern>
</defs>
</svg>`
Insert cell
Insert cell
Insert cell
Insert cell
iao = aq
.fromCSV(await FileAttachment("iao_ml_20210203.csv").text())
.derive({ other: d => d.total - d.adjacent })
.derive({ adjacent: d => d.adjacent - d.inner })
Insert cell
nuts3 = await FileAttachment('nuts3de@1.json').json()
Insert cell
Insert cell
Insert cell
Insert cell
d3 = require('d3')
Insert cell
topojson = require('topojson')
Insert cell
import { vl } from "@vega/vega-lite-api"
Insert cell
embed = require("vega-embed")
Insert cell
import { aq, op } from '@adrianzachariae/arquero'
Insert cell
_ = require('lodash')
Insert cell
culori = require('culori')
Insert cell
import { checkbox, select, radio } from "@jashkenas/inputs"
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