chartElem = Plot.plot({
height: 540,
margin: 0,
projection: {
type: "azimuthal-equal-area",
domain: europeGeo,
inset: 16
},
length: { domain: [0, 1], range: [5, 200] },
marks: [
() =>
svg`
<defs>
<filter id="outline">
<feMorphology in="SourceAlpha" result="DILATED" operator="dilate" radius="0.5"></feMorphology>
<feFlood flood-color="#fff" flood-opacity="1" result="FLOOD"></feFlood>
<feComposite in="FLOOD" in2="DILATED" operator="in" result="OUTLINE"></feComposite>
<feMerge>
<feMergeNode in="OUTLINE" />
<feMergeNode in="SourceGraphic" />
</feMerge>
</filter>
</defs>
`,
Plot.frame({ fill: "#f7fbfd" }),
Plot.geo(worldGeo, {
fill: "#fff",
strokeWidth: 0.5,
stroke: "#cdcdcd"
}),
// lean map
Plot.geo(europeGeo, {
fill: (d) => {
if (election2019Lean[d.id] < 0) {
return "#c01717";
} else {
return "#2b4b8e";
}
},
fillOpacity: (d) => {
return Math.abs(election2019Lean[d.id]) / maxSeatsCountry.get(d.id);
},
//fill: "#fff",
stroke: "#535353",
strokeWidth: 0.5
}),
// data map
/*
Plot.geo(europeGeo, {
fill: (d) => {
const red = electionDiffGroup[0];
const blue = electionDiffGroup[1];
const green = electionDiffGroup[2];
if (red[d.id] > blue[d.id]) {
return "#c01717";
} else {
return "#2b4b8e";
}
},
fillOpacity: (d) => {
const red = election2019Grouped[0];
const blue = election2019Grouped[1];
const green = election2019Grouped[2];
if (red[d.id] > blue[d.id]) {
return Math.abs(red[d.id]) / maxSeatsCountry.get(d.id);
} else {
return Math.abs(blue[d.id]) / maxSeatsCountry.get(d.id);
}
},
//fill: "#fff",
stroke: "#535353",
strokeWidth: 0.5
}),*/
Plot.vector(
europeGeo.features,
Plot.centroid({
anchor: "start",
length: (d) => {
const red = electionDiffGroup[0];
const blue = electionDiffGroup[1];
const green = electionDiffGroup[2];
if (red[d.id] > blue[d.id]) {
return Math.abs(red[d.id]) / maxSeatsCountry.get(d.id);
} else {
return Math.abs(blue[d.id]) / maxSeatsCountry.get(d.id);
}
},
stroke: (d) => {
const red = electionDiffGroup[0];
const blue = electionDiffGroup[1];
const green = electionDiffGroup[2];
if (red[d.id] > blue[d.id]) {
return "#c01717";
} else {
return "#2b4b8e";
}
},
rotate: (d) => {
const red = electionDiffGroup[0];
const blue = electionDiffGroup[1];
const green = electionDiffGroup[2];
if (red[d.id] > blue[d.id]) {
return -60;
} else {
return 60;
}
},
strokeWidth: 4,
imageFilter: "url(#outline)"
})
)
]
})