Public
Edited
May 22, 2023
Insert cell
Insert cell
import {map as GTOverview} with {data1final as data} from "@d3/world-airports"
Insert cell
GTOverview
Insert cell
import {chart as Attacks} with {latestaggdata as data} from "@d3/bar-chart-race"
Insert cell
Attacks
Insert cell
mutable latestaggdataCopy = [...latestaggdata];
Insert cell
import {chart as Attacks2} with {mutable latestaggdataCopy as data} from "@d3/bar-chart-race"

Insert cell
Attacks2
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
AttackData2= FileAttachment("terroristdata_1990-2020V2.csv").csv()
Insert cell
AttackData2
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Insert cell
Wrangler(AttackData2)
Insert cell
data1 = // To use copied code replace "data" with your own variable
aq.from(AttackData2)
.select('eventid','iyear','country_txt','region_txt','provstate','city','latitude','longitude','attacktype1_txt','targtype1_txt','corp1','target1','natlty1_txt','gname','claimed','weaptype1_txt','nkill','nwound')
.rename({iyear: "year"})
.rename({nkill: "kills"})
.rename({country_txt: "country"})
.rename({provstate: "province/state"})
.rename({nwound: "wounded"})
.rename({region_txt: "region"})
.rename({attacktype1_txt: "attacktype"})
.rename({weaptype1_txt: "weapontype"})
.rename({targtype1_txt: "targettype"})
.rename({natlty1_txt: "nationality"})
.rename({gname: "organisation"})
.filter(d => d["organisation"] !== "Unknown")
.objects() // Uncomment to return an array of objects
Insert cell
data1
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
data1final = aq.from(data1)
.params({
yearStart: new Date(+control_timeRange[0], 0, 1).getFullYear(),
yearEnd: new Date(+control_timeRange[1], 0, 0).getFullYear()
})
.filter ( (d, params) => d["year"] > params.yearStart)
.filter ( (d, params) => d["year"] < params.yearEnd)
.objects()
Insert cell
Insert cell
claimedorganizations = // To use copied code replace "data" with your own variable
aq.from(AttackData2)
.groupby('gname')
.filter(d => op.match(d["claimed"], "1"))
.dedupe('gname')
.objects()
Insert cell
names= new Set(claimedorganizations.map(d => d.gname))
Insert cell
datevalues = Array.from(d3.rollup(claimedorganizationsattacks, ([d]) => d.count, d => +d.iyear, d => d.gname))
.map(([iyear, claimedorganizationsattacks]) => [new Date(iyear), claimedorganizationsattacks])
.sort(([a], [b]) => d3.ascending(a, b))
Insert cell
readyparse= aq.from(claimedorganizationsattacks)
.rename({iyear: "date"})
.rename({gname: "name"})
.rename({count: "value"})
.objects()
Insert cell
datanewest = readyparse.map(row => ({
...row,
date: new Date(`${row.date}-01-01`)
}))
Insert cell
aq.from(readyparse)
.orderby('name', 'date')
.derive({
aggregate_sum: aq.rolling(values => aq.op.sum(values), ['value'])
})
.objects()
Insert cell
rawData = aq.from(claimedorganizationsattacks)
.rename({iyear: "date"})
.rename({gname: "name"})
.rename({count: "value"})

Insert cell
sortedData = rawData.orderby('name', 'date').objects()
Insert cell
aggregatedData = []
Insert cell
sortedData.reduce((accumulator, current) => {
if (accumulator[current.name]) {
current.aggregate_sum = accumulator[current.name] += current.value;
} else {
current.aggregate_sum = accumulator[current.name] = current.value;
}
aggregatedData.push(current);
return accumulator;
}, {})
Insert cell
aggregatedData
Insert cell
newaggdata = aggregatedData.map(row => ({
...row,
date: new Date(`${row.date}-01-01`)
}))
Insert cell
latestaggdata = aq.from(newaggdata)
.select('date','name','aggregate_sum')
.rename({aggregate_sum : "value"})
.orderby('date')
.objects()
Insert cell
import {chart} with {NewData as dataset} from "@johnburnmurdoch/bar-chart-race-the-most-populous-cities-in-the-world"
Insert cell
// To use copied code replace "data" with your own variable
claimedorganizationsattacks = aq.from(data2)
.filter(d => op.match(d["claimed"], "1"))
.groupby('iyear','gname')
.count()
.objects() // Uncomment to return an array of objects
Insert cell
import {toc} from "@nebrius/indented-toc"
Insert cell
import {Wrangler, op} from "@observablehq/data-wrangler"
Insert cell
import {rangeSlider} from '@mootari/range-slider'
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