{
const width = 840;
const height = 150;
const s = 7;
const sizeSq = s ** 2;
const tickSizeY = 5;
const gridClr = "#e2e2e2";
const hover = {
name: "hover",
select: { type: "point", on: "mouseover", clear: "mouseout" },
views: ["dotLayer"]
};
const dots = {
name: "dotLayer",
mark: { type: "point" },
data: {
values: laureates
},
encoding: {
x: {
field: "awardYear",
type: "temporal",
scale: { domainMin: { year: 1900 } },
title: "Award year →"
},
y: {
field: "genderOffset",
type: "quantitative",
stack: true,
axis: { values: [5, 0, -5, -10] },
title: "← Men · Women →"
},
color: {
field: "gender",
scale: {
domain: ["male", "female"],
range: ["#bfb498", "#dc5a74"]
},
legend: null
},
stroke: {
condition: { value: "#000", param: "hover", empty: false },
value: "#fff"
},
size: {
condition: {
value: sizeSq * 1.2,
param: "hover",
empty: false
},
value: sizeSq
},
order: { condition: { param: "hover", value: 1 }, value: 0 },
tooltip: [
{ field: "name", title: "Name" },
{ field: "category", title: "Category" },
{
field: "awardYear",
title: "Award year",
timeUnit: "year"
}
]
}
};
const rule = {
mark: {
type: "rule",
x: -tickSizeY,
x2: width + tickSizeY
},
data: {
values: [
"We just need an array of length 1 to draw the rule mark once. You can use a string (as in this example), a number, or just an empty object {}."
]
},
encoding: {
y: { datum: 0 }
}
};
const config = {
view: { stroke: null },
font: franklinLight,
title: { fontSize: 25, font: bodoni, offset: 10 },
point: {
filled: true,
strokeWidth: 1,
cursor: "pointer"
},
rule: {
strokeWidth: 0.8
},
axis: {
domain: false,
labelColor: "#808080",
labelFontSize: 14,
labelPadding: 5,
titleFontSize: 15,
titleFontWeight: 400,
titlePadding: 15
},
axisX: {
grid: false,
offset: 10,
tickCount: 10,
tickSize: 2 * tickSizeY,
labelFlush: false,
titleAnchor: "end"
},
axisY: {
labelExpr: "abs(datum.value)",
tickSize: tickSizeY,
gridColor: gridClr,
tickColor: gridClr,
titleY: 0.2 * height
}
};
return render({
width: width,
height: height,
title: "Nobel Prize Laureates",
params: [hover],
layer: [dots, rule],
config: config
});
}