function getVegaView(dataToPlot, options) {
const {
interactive,
colorScheme,
color,
shape,
x,
y,
size,
id,
tooltip,
colorDomain,
title,
shapeDomain
} = options;
clusters;
let colorField;
if (computeClusters) {
colorField = vl
.color()
.if("datum.cluster == undefined", vl.value("#ccc7"))
.fieldN(color)
.scale({
domain: colorDomain,
scheme: colorScheme || options.colorSchemeQuantitative
});
} else {
colorField = vl
.color()
.if("datum.cluster == undefined", vl.value("#ccc7"))
.fieldQ(color)
.scale({
domain: colorDomain,
scheme: colorScheme || options.colorSchemeQuantitative
});
}
let base = vl
.markPoint({ opacity: 0.6, filled: true })
.encode(vl.x().fieldQ(x).axis(null), vl.y().fieldQ(y).axis(null))
.data(dataToPlot.filter((d) => d.type !== "keyword"));
let baseWithParams;
if (color) base = base.encode(colorField);
if (size)
base = base.encode(
vl.size().fieldQ(size).scale({ range: options.sizeRange }),
vl.order().fieldQ(size)
);
if (shape) {
let shapeEncoding = vl.shape().fieldN(shape);
if (shapeDomain) {
shapeEncoding = shapeEncoding.scale({ domain: shapeDomain });
}
base = base.encode(shapeEncoding);
}
const boxes = vl
.markRect({ filled: false })
.encode(
vl.x().fieldQ("bbox.minX"),
vl.y().fieldQ("bbox.minY"),
vl.x2().fieldQ("bbox.maxX"),
vl.y2().fieldQ("bbox.maxY")
)
.data(hdbscanClusters);
const keywords = vl
.markText({ fontSize: 8, tooltip: true, opacity: 0.7 })
.encode(vl.x().fieldQ("x"), vl.y().fieldQ("y"), vl.text().fieldN("title"))
.data(dataToPlot.filter((d) => d.type === "keyword"));
const events = "mouseover,pointerover,touchmove,click";
if (interactive) {
const hover = vl
.selectSingle("hover")
.nearest(true)
.on(events)
.clear("none")
.init({ x: [], y: [] });
const drag = vl.selectInterval("drag");
const click = vl
.selectPoint("click")
.fields([id])
.nearest(true)
.on("click")
.init({ id: [] });
const shiftClick = vl
.selectPoint("shiftClick")
.fields([id])
.on("click[event.altKey]")
.toggle("false")
.init({ id: [] });
baseWithParams = base.params(click, hover, drag, shiftClick).encode(
vl
.stroke()
.condition({ param: "click", value: "black", empty: false })
.value(null),
vl.tooltip(tooltip)
);
if (color)
baseWithParams = baseWithParams.encode(
vl
.color()
.if(vl.or(hover, drag), colorField)
.value("grey")
);
}
let chart = vl.layer(
...[
baseWithParams,
clusteringSpace === "Reduced Space" && clusteringType === "HDBScan"
? boxes
: null,
includeKeywords ? keywords : null
].filter((d) => d)
);
return chart.title(title).width(options.width).height(options.height);
}