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.6)
.selectAll("path")
.data(data)
.join("path");
polylines
.attr("d", path)
.style("fill", "none")
.style("stroke", d => color(d[colorAttribute]))
.style("opacity", 0.5);
const axes = svg
.append("g")
.selectAll("g")
.data(attributes)
.join("g")
//translate this element to its right position on the x axis
.attr("transform", d => `translate(${x(d)},0)`);
// TODO: add the visual representation of the axes
// source: https://www.d3-graph-gallery.com/graph/parallel_basic.html
axes
.each(function(d) { d3.select(this).call(d3.axisRight(y.get(d))); })
// add axis title
.call(g => g.append("text")
.attr("transform", "rotate(90)")
.style("text-anchor", "left")
.attr("y", 9)
.text(function(d) { return shortAttributeNames.get(d); })
.style("fill", "green"))
.call(g => g.selectAll("text")
.clone(true).lower() //clone and get the lower layer of text as background
.attr("fill", "none")
.attr("stroke-width", 5)
.attr("stroke-linejoin", "round")
.attr("stroke", "white"));
// TODO implement brushing & linking
function updateBrushing() {
// d3.event.selection == activeBrushes without key
if (activeBrushes === null){
polylines.classed("hidden",false);
}
polylines.classed("hidden", d => {
var key = 0;
var value_y = 0;
var active_domain_y = 0;
/*Checks for each attribute whether the polyline should be drawn by checking whether
it is in the active area or not */
for(var i=0; i < attributes.length; i++){
key = attributes[i];
value_y = y.get(key)(d[key]);
active_domain_y /*[y0, y1]*/ = activeBrushes.get(key);
if(active_domain_y != null){
if(value_y < active_domain_y[0] || value_y > active_domain_y[1]) {
return true;
}
}
}
return false;
});
}
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();
}