chart = {
const margin = {top: 30, right: 30, bottom: 40, left: 70};
const svg_width = 600;
const svg_height = 700;
const group_width = svg_width - margin.left - margin.right;
const group_height = svg_height - margin.top - margin.bottom;
const svg = d3.create("svg")
.attr("width", svg_width)
.attr("height", svg_height);
const group = svg.append("g")
.attr("transform", `translate(${margin.left},${margin.top})`);
let dimensions = ['Displacement', 'Length', 'Beam', 'Draft', 'Speed', 'Crew'];
const y = {};
for (let i in dimensions) {
let name = dimensions[i];
y[name] = d3.scaleLinear()
.domain(d3.extent(data_cleaned, d => d[name]))
.range([group_height, 0]);
}
let x = d3.scalePoint()
.domain(dimensions)
.range([0, group_width]);
function row2points(row) {
return dimensions.map(dim => [x(dim), y[dim](row[dim])]);
}
group
.selectAll("myPath")
.data(data_cleaned)
.join("path")
.attr("d", row => d3.line()(row2points(row)))
.style("fill", "none")
.style("stroke", d => d.Type === "Battleship" ? "#1f77b4" : d.Type === "Carrier" ? "#ff7f0e" : "#2ca02c")
.style("opacity", 0.5);
group.selectAll("myAxis")
.data(dimensions)
.enter()
.append("g")
.attr("transform", d => `translate(${x(d)}, 0)`)
.each(function(d) { d3.select(this).call(d3.axisLeft(y[d])); })
.append("text")
.style("text-anchor", "middle")
.attr("y", -9)
.text(d => d)
.style("fill", "black");
return svg.node();
}