chart = {
const svg = d3.select(DOM.svg(width, height));
svg.append("g").call(xAxis);
svg.append("g").call(yAxis);
var newline = d3
.line()
.defined(d => !(d.TSG_T_Avg < 8))
.x(d => x(new Date(d.time)))
.y(d => y(d.TSG_T_Avg));
var newdata = combinded.map((p, index) =>
index === combinded.length - 1 ? [p] : [p, combinded[index + 1]]
);
var bounds = d3.extent(combinded, d => d.TSG_T_Avg);
var interval = bounds[1] - bounds[0];
console.log(data, newdata, bounds, interval);
var gradientColor = p => {
if (p[0].TSG_T_Avg > p[0].per90 && p[0].TSG_T_Avg < 10.8) {
return "#feb24c";
} else if (p[0].TSG_T_Avg > 10.8) {
return "#f03b20";
} else {
return "steelblue";
}
};
const makeOpacity = d => {
if (d[0].TSG_T_Avg > d[0].per90 && d[0].TSG_T_Avg < 10.8) {
return 1;
} else if (d[0].TSG_T_Avg > 10.8) {
return 1;
} else {
return 1;
}
};
svg
.selectAll('path')
.data(newdata)
.enter()
.append('path')
.attr('d', p => newline(p))
.style("opacity", d => makeOpacity(d))
.attr('stroke', p => gradientColor(p));
return svg.node();
}