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();
}