Published
Edited
Feb 27, 2020
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
set = Array.from(new Set(pyithu_2015_by_township.map(d => d.Political_party)))
.filter(n => n)
.sort()
Insert cell
set_filtered = pyithu_2015_by_township.filter(d => d.Political_party === party)
Insert cell
Insert cell
NLDMarginMap = {
const stroke = vl
.markGeoshape({
stroke: 'black',
strokeWidth: .4,
border: 0
})
.data(vl.topojson(myanmarTownship_min).feature('mm_township'))
.transform(
vl.lookup('properties.TS').from(
vl
.data(set_filtered)
.key('Constituency_number')
.fields('Political_party')
),
vl.lookup('properties.TS').from(
vl
.data(set_filtered)
.key('Constituency_number')
.fields('percent_of_valid_votes')
),
vl.calculate(`datum.percent_of_valid_votes - .5`).as('margin_of_victory')
)
.encode(
vl.tooltip([
vl.fieldN('properties.ST'),
vl.fieldN('properties.TS'),
vl.fieldN('Political_party'),
vl.fieldQ('margin_of_victory')
])
);

const fill = vl
.markGeoshape({
border: 0
})
.data(vl.topojson(myanmarTownship_min).feature('mm_township'))
.transform(
vl.lookup('properties.TS').from(
vl
.data(set_filtered)
.key('Constituency_number')
.fields('Political_party')
),
vl.lookup('properties.TS').from(
vl
.data(set_filtered)
.key('Constituency_number')
.fields('percent_of_valid_votes')
),
vl.calculate(`datum.percent_of_valid_votes - .5`).as('margin_of_victory'),
vl.filter(`datum.margin_of_victory !== -.5`)
)
.encode(
vl
.color({ format: '%' })
.fieldQ('margin_of_victory')
.scale({ scheme: 'redblue', nice: true })
.legend({ titleOrient: 'left', tickCount: 5, format: '%' })
.title('NLD Margin of Victory')
);

return vl
.layer(fill, stroke)
.config({ view: { stroke: null } })
.width(width / 2)
.height(width)
.render();
}
Insert cell
vl.data(pyithu_2015_by_township).filter(`datum.Political_party === "${party}"`)
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

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