paracoords = {
const svg = d3.create("svg").attr("viewBox", [0, 0, width, height]);
svg
.append("style")
.text("path.hidden { stroke: #000; stroke-opacity: 0.01;}");
let activeBrushes = new Map();
const polylines = svg
.append("g")
.attr("fill", "none")
.attr("stroke-width", 1.5)
.attr("stroke-opacity", 0.4)
.selectAll("path")
.data(data)
.join("path")
.attr("stroke", d => color(d[colorAttribute]))
.attr("d", d => d3.line()
.defined(([, value]) => value != null)
.y(([key, value]) => y.get(key)(value))
.x(([key]) => x(key))
(d3.cross(attributes, [d], (key, d) => [key, d[key]])));
const axes = svg
.append("g")
.selectAll("g")
.data(attributes)
.join("g")
.attr("transform", d => `translate(${x(d)},0)`)
.each(function(d) { d3.select(this).call(d3.axisRight(y.get(d))); })
.call(g => g.append("text")
.attr("x", -1)
.attr("y", 7.5)
.attr("text-anchor", "start")
.attr("fill", "currentColor")
.text(d => shortAttributeNames.get(d)));
function updateBrushing() {
var number_brushes = activeBrushes.size;
if (number_brushes == 0) {
polylines.classed("hidden", d => {return false});
}
else {
polylines.classed("hidden", d => {
var return_value = false;
activeBrushes.forEach((value, key) => {
var y0 = value[0];
var y1 = value[1];
var value_y = y.get(key)(d[key]);
if (value_y <= y1 && value_y >= y0) {
}
else {
return_value=true;
}
});
return return_value;
});
}
}
function brushed(attribute) {
activeBrushes.set(attribute, d3.event.selection);
updateBrushing();
}
function brushEnd(attribute) {
if (d3.event.selection !== null) return;
activeBrushes.delete(attribute);
updateBrushing();
}
const brushes = axes.append("g").call(
d3
.brushY()
.extent([[-10, margin.top], [10, height - margin.bottom]])
.on("brush", brushed)
.on("end", brushEnd)
);
return svg.node();
}