parallel_coordinates = {
var margin = {top: 50, right: 50, bottom: 100, left: 50};
var width = 1100 - margin.left - margin.right;
var height =1000 - margin.top - margin.bottom;
var x = d3.scalePoint().range([0, width]).padding(1),
y = {},
dragging= {};
var line = d3.line(),
axis = d3.axisLeft(),
background,
foreground;
var dimensions = null;
const svg = d3.select(DOM.svg(width + margin.left + margin.right, height+margin.top + margin.bottom));
const svg_adjusted = svg.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
var out = d3.select(output)
out.text(d3.tsvFormat(sample_data));
x.domain(dimensions = d3.keys(sample_data[0]).filter(function(d) {
return (y['Name']=d3.scalePoint()
.range([height,0])
.domain(NMDomain)) && d!="Book Intro Chapter" && d!="Gender" &&
(y['Allegiances']=d3.scalePoint()
.range([height,0])
.domain(ALGDomain))&& d!="GoT" && d!="CoK"&& d!="SoS" && d!="FfC" && d!="DwD" &&(y['Death Year']=d3.scalePoint()
.range([height,0])
.domain(DYDomain)) && (y[d] = d3.scaleLinear()
.domain(d3.extent(sample_data, function(p) { return +p[d]; }))
.range([height, 0]));
}));
background = svg_adjusted.append("g")
.attr("class", "background")
.selectAll("path")
.data(sample_data)
.enter().append("path")
.attr("d", path);
foreground = svg_adjusted.append("g")
.attr("class", "foreground")
.selectAll("path")
.data(sample_data)
.enter().append("path")
.attr("d", path)
.attr('stroke',d=>color(d.Gender));
function position(d) {
var v = dragging[d];
return v == null ? x(d) : v;
}
function transition(g) {
return g.transition().duration(500);
}
const g = svg_adjusted.selectAll(".dimension")
.data(dimensions)
.enter()
.append("g")
.attr("class", "dimension")
.attr("transform", function(d) { return "translate(" + x(d) + ")"; })
.call(d3.drag()
.subject(function(d) { return {x: x(d)}; })
.on("start", function(d) {
dragging[d] = x(d);
background.attr("visibility", "hidden");
})
.on("drag", function(d) {
dragging[d] = Math.min(width, Math.max(0, d3.event.x));
foreground.attr("d", path);
dimensions.sort(function(a, b) { return position(a) - position(b); });
x.domain(dimensions);
g.attr("transform", function(d) { return "translate(" + position(d) + ")"; })
})
.on("end", function(d) {
delete dragging[d];
transition(d3.select(this)).attr("transform", "translate(" + x(d) + ")");
transition(foreground).attr("d", path);
background
.attr("d", path)
.transition()
.delay(500)
.duration(0)
.attr("visibility", null);
}));
g.append("g")
.attr("class", "axis")
.each(function(d) { d3.select(this).call(axis.scale(y[d])); })
.append("text")
.style("text-anchor", "middle")
.attr("y", -9)
.text(function(d) { return d; });
g.append("g")
.attr("class", "brush")
.each(function(d) {
d3.select(this).call(y[d].brush = d3.brushY()
.extent([[-10,-10], [10,height+10]])
.on("brush", brush)
.on("end", brush)
)
})
.selectAll("rect")
.attr("x", -8)
.attr("width", 16);
function path(d) {
return line(dimensions.map(function(p) { return [x(p), y[p](d[p])]; }));
}
function brush() {
var actives = [];
svg.selectAll(".brush")
.filter(function(d) {
y[d].brushSelectionValue = d3.brushSelection(this);
return d3.brushSelection(this);
})
.each(function(d) {
actives.push({
dimension: d,
extent: d3.brushSelection(this).map(y[d].invert)
});
});
var selected = [];
foreground.style("display", function(d) {
return actives.every(function(active) {
let result = active.extent[1] <= d[active.dimension] && d[active.dimension] <= active.extent[0];
if(result)selected.push(d);
return result;
}) ? null : "none";
});
(actives.length>0)? out.text(d3.tsvFormat(selected)):out.text(d3.tsvFormat(sample_data));;
}
function updatepath(){
var str=document.getElementById("searchid").value;
const filteredData= sample_data.filter(row => issubstr(row, str));
foreground.selectAll("path").data(filteredData).transition('update').style("display",null)
}
return svg.node();
}