default_color = d3.schemeCategory10[0]
plt_color = color_var || default_color
all_vars = [...cont_vars, ...disc_vars]
channels = Object.fromEntries(all_vars.map(k => [k.name, k.name]))
// with a legend, Plot wraps the chart in a <figure>, which gets a bottom margin
// from Bootstrap; the class name lets us remove it so the plots align
viewof scatter = Plot.plot({
className: "scatter",
style: { fontFamily: "var(--sans-serif)" },
inset: 8,
grid: true,
x: { tickFormat: "", label: var_label(x_var) },
y: { label: var_label(y_var) },
color: { legend: true, style: { fontFamily: "var(--sans-serif)" } },
marks: [
Plot.dot(d, {
x: x_var,
y: y_var,
stroke: plt_color,
tip: true,
channels: channels
}),
]
})
viewof x_hist = Plot.plot({
style: { fontFamily: "var(--sans-serif)" },
width: 640/2,
x: { tickFormat: "", label: var_label(x_var) },
y: { grid: true },
marks: [
Plot.rectY(d, Plot.binX({y: "count"}, {x: x_var, fill: plt_color})),
Plot.ruleY([0])
]
})
viewof y_hist = Plot.plot({
style: { fontFamily: "var(--sans-serif)" },
width: 640/2,
x: { label: var_label(y_var) },
y: { grid: true },
marks: [
Plot.rectY(d, Plot.binX({y: "count"}, {x: y_var, fill: plt_color})),
Plot.ruleY([0])
]
})
html`<style>.scatter-figure { margin-bottom: 0; }</style>
<div style="display: flex; flex-wrap: wrap; align-items: flex-end;">
<div style="flex-basis: 25%"> ${viewof y_hist} </div>
<div style="flex-basis: 50%"> ${viewof scatter} </div>
<div style="flex-basis: 25%"> ${viewof x_hist} </div>
</div>`