viewof plot1 = {
let data = [{airline: "a", values: []}, {airline: "b", values: []}, {airline: "c", values: []}]
rawData.forEach(function(d) {
data[["a", "b", "c"].indexOf(d.airline)].values.push({date: d.date, price: d.price})
});
let svgPlotContainer = d3.create("svg")
.attr("width", plotVars.plotWidth)
.attr("height", plotVars.plotHeight)
.property("value", []);
svgPlotContainer.append("g")
.attr('class', 'grid')
.call(xAxis)
svgPlotContainer.append("g")
.attr('class', 'grid')
.call(yAxis);
const legend = svgPlotContainer.append("g")
legend.selectAll("legend")
.data([not_included])
.join('rect')
.attr('x', 10)
.attr('y', plotVars.plotHeight - margin.bottom + 12 )
.attr('width', 30)
.attr('height', 20)
.attr('stroke', 'black')
.attr('stroke-width', '2')
.attr('fill', 'green')
.attr('fill-opacity', 0.05)
.attr('stroke', 'green')
.attr('transform', (d,i) => "translate(0," + i * 25 + ")")
legend.selectAll("g")
.data([not_included])
.join('text')
.attr('x', 25)
.attr('y', plotVars.plotHeight - margin.bottom + 10 + 17)
.attr('transform', (d,i) => "translate(0," + i * 25 + ")")
.attr("font-size", "1em")
.attr("fill", "green")
.text(function(d){ return d;})
.attr("text-anchor", "middle")
.attr("font-family", "Montserrat")
svgPlotContainer.append("g")
.selectAll("path")
.data(data)
.join("path")
.attr("class", "data-line") // Class name to be able to access the lines later
.attr("d", d => lineGenerator(d.values)) // Use lineGenerator on d.values
.attr("fill", "none") // Do not fill the area defined by the path
.attr("stroke", 'black'); // Set a color for the line (The maps for color is in 'color')
svgPlotContainer.append("g")
.selectAll("line")
.data([lower,upper])
.join("svg:line")
.attr("x1", margin.left)
.attr("x2", plotVars.plotWidth - margin.right)
.attr("y1", d => yScale(d))
.attr("y2", d => yScale(d))
.attr('stroke', 'green')
.attr('stroke-width', 2)
svgPlotContainer.selectAll("area")
.data([{start: lower, end: upper}])
.join('rect')
.attr('x', margin.left)
.attr('y', d => yScale(d.end))
.attr('width', plotVars.plotWidth - margin.right - margin.left)
.attr('height', d => yScale(d.start) - yScale(d.end))
.attr('fill', 'green')
.attr('fill-opacity', 0.05)
.attr('transform', (d,i) => "translate(0," + i * 25 + ")")
let brushContainer = svgPlotContainer.append("g");
const brush = d3.brush()
.on("start brush end", brushed(svgPlotContainer.selectAll("path.data-line"), svgPlotContainer))
.extent([[margin.left, margin.top], [plotVars.plotWidth - margin.right, plotVars.plotHeight - margin.top]]); // Sets the brushable area [[xMin, yMin], [xMax, yMax]]
brushContainer.call(brush);
return svgPlotContainer.node();
}