chart = {
const svg = d3.create("svg").attr("viewBox", [0, 0, width, height]);
svg.append("g").call(xAxis);
svg.append("g").call(yAxis);
svg
.append("g")
.attr("class", "remove")
.style("position", "absolute")
.style("z-index", "19")
.style("width", "1px")
.style("height", height)
.attr("stroke", "black");
svg
.append("g")
.attr("stroke-width", 1.5)
.attr("font-family", "sans-serif")
.attr("font-size", 10)
.selectAll("g")
.data(datafiltered)
.join("g")
.attr("transform", d => `translate(${x(d.date)},${y(d.value)})`)
//.attr("transform", d => `translate(100,100)`)
.call(
g =>
g
.append("circle")
.attr("stroke", "steelblue")
.attr("fill", "none")
.attr("r", 3)
/*.filter(function(d) {
return d.value == null;
})
.remove()*/
);
/*.call(g =>
g
.append("text")
.attr("dy", "0.35em")
.attr("x", 7)
.text(d => d.name)*/
/*svg
.append("path")
.datum(data)
.attr("fill", "none")
.attr("stroke", "green")
.attr("stroke-width", 1.5)
.attr("stroke-linejoin", "round")
.attr("stroke-linecap", "round")
.attr("d", line);*/
//median line
svg
.append("path")
.datum(yearlymedian_filtered)
.attr("fill", "none")
.attr("stroke", "darkblue")
.attr("stroke-width", 1.5)
.attr("stroke-linejoin", "round")
.attr("stroke-linecap", "round")
.attr("d", line_median);
//points on the median line
svg
.append("g")
.attr("stroke-width", 1.5)
.attr("font-family", "sans-serif")
.attr("font-size", 10)
.selectAll("g")
.data(yearlymedian_filtered)
.join("g")
.attr("transform", d => `translate(${x_median(d.date)},${y(d.value)})`)
.call(g =>
g
.append("circle")
.attr("stroke", "darkblue")
.attr("fill", "none")
.attr("r", 4)
.filter(function(d) {
return d.value == null;
})
.remove()
);
var ordinal = d3
.scaleOrdinal()
.domain([
"Median Pixel Intensity for a Single Day",
"Annual Median Pixel Intensity"
])
.range(["steelblue", "darkblue"]);
svg
.append("g")
.attr("class", "legendOrdinal")
.attr("transform", "translate(650,20)");
var legendOrdinal = d3Legend
.legendColor()
//d3 symbol creates a path-string, for example
//"M0,-8.059274488676564L9.306048591020996,
//8.059274488676564 -9.306048591020996,8.059274488676564Z"
.shape(
"path",
d3
.symbol()
.type(d3.symbolCircle)
.size(150)()
)
.shapePadding(30)
//use cellFilter to hide the "e" cell
.cellFilter(function(d) {
return d.label !== "e";
})
.scale(ordinal);
svg.select(".legendOrdinal").call(legendOrdinal);
//title
svg
.append("text")
.attr(
"transform",
`translate(${(width + margin.left + margin.right) / 2}, ${margin.top /
2})`
)
//transform title to middle and down so it's in hte right place
.style("text-anchor", "middle")
//center title
.style("font-weight", 700)
//bold text
.text("Blue Band");
//extra information about median and interquartile range
svg
.append("text")
.attr(
"transform",
`translate(${(width + margin.left + margin.right) / 2 - 350}, 490)`
)
//.attr("transform", "rotate(-90)")
/*.attr("y", 0 - margin.left)
.attr("x", 0 - height / 2)
.attr("dy", "1em")*/
.style("text-anchor", "middle")
.style("font-weight", 500)
.text("Median =" + String(median) + ", Interquartile Range = 0.038");
svg
.append("text")
.attr(
"transform",
`translate(${(width + margin.left + margin.right) / 2}, ${margin.top / 2 +
30})`
)
//transform title to middle and down so it's in the right place
.style("text-anchor", "middle")
//center title
.style("font-weight", 700);
//bold text
//.text("Median = 0.034, Interquartile Range = 0.03025");
//y-axis label
svg
.append("text")
//.attr("transform", `translate(${margin.right * 4}, 500)`)
.attr("transform", "rotate(-90)")
.attr("y", margin.left * 0.3)
.attr("x", 0 - height / 2.5)
.attr("dy", "1em")
.style("text-anchor", "middle")
.style("font-weight", 700)
.text("Median Band Intensity");
//x-axis label
svg
.append("text")
.attr(
"transform",
`translate(${(width + margin.left + margin.right) / 2}, ${0.95*height})`
)
//.attr("transform", "rotate(-90)")
/*.attr("y", 0 - margin.left)
.attr("x", 0 - height / 2)
.attr("dy", "1em")*/
.style("text-anchor", "middle")
.style("font-weight", 700)
.text("Year");
/*const brush = d3.brushX().extent([[0, 0], [width, height]]);
// .on("start brush end", brushmoved);
const gBrush = svg
.append("g")
.attr("class", "brush") // we don't know what this line does - if you comment it out, brush still works
.call(brush);*/
return svg.node();
}