chart = {
const svg = d3.select(DOM.svg(width, height));
const areaGradient = svg.append("defs")
.append("linearGradient")
.attr("id","areaGradient")
.attr("x1", "0%").attr("y1", "0%")
.attr("x2", "0%").attr("y2", "100%");
areaGradient.append("stop")
.attr("offset", "0%")
.attr("stop-color", '#14979c')
.attr("stop-opacity", 1);
areaGradient.append("stop")
.attr("offset", "25%")
.attr("stop-color", '#64a99a')
.attr("stop-opacity", 1);
areaGradient.append("stop")
.attr("offset", "65%")
.attr("stop-color", '#92bb98')
.attr("stop-opacity", 1);
areaGradient.append("stop")
.attr("offset", "100%")
.attr("stop-color", '#bacd95')
.attr("stop-opacity", 1)
svg.append('rect')
.attr('x', 0)
.attr('y', 0)
.attr('width', width)
.attr('height', height)
.attr('stroke', 'none')
.attr('fill', 'url(#areaGradient)')
let g = svg.append("g").attr("transform", `translate(${(width - w) / 2},0)`);
let nbColor = 12;
let linearGradient = svg
.append("linearGradient")
.attr("id", "Gradient2")
.attr('gradientUnits', "userSpaceOnUse")
.attr("x1", "0")
.attr("x2", "0")
.attr("y1", 0)
.attr("y2", -overlap * y.step());
// linearGradient
// .selectAll("stop")
// .data(d3.range(nbColor))
// .join("stop")
// .attr("offset", (d, i) => `${i / (nbColor - 1)}`)
// .attr("stop-color", (d, i) =>
// interpolator(invertColor ? 1 - i / (nbColor - 1) : i / (nbColor - 1))
// // );
// '#235E8D', // 0
// '#94942e',
// '#1F99BE', //
// '#33B5CB',
// '#45d0b2',
// '#4AB5AA',
// '#76B177',
// '#B6BA71',
//
// '#F0BA5C',
// '#EF8060',
linearGradient
// .selectAll("stop")
// .data([
// {offset: "0%", color: "#EF8060"}, // 最下面
// {offset: "2%", color: "#F0BA5C"},
// // {offset: "12.5%", color: "#F0BA5C"},
// {offset: "15%", color: "#ccd358"},
// {offset: "27.5%", color: "#76B177"},
// {offset: "30%", color: "#45d0b2"},
// {offset: "50.5%", color: "#33B5CB"},
// {offset: "70%", color: "#1F99BE"},
// {offset: "80.5%", color: "#94942e"},
// {offset: "100%", color: "#235E8D"} ])
// .enter().append("stop")
// .attr("offset", function(d) { return d.offset; })
// .attr("stop-color", function(d) { return d.color; });
.selectAll("stop")
.data(d3.range(nbColor))
.join("stop")
.attr("offset", (d, i) => `${i / (nbColor - 1)}`)
.attr("stop-color", (d, i) =>
colorScale1(invertColor ? 1 - i / (nbColor - 1) : i / (nbColor - 1))
);
linearGradient.append("stop")
.attr("offset", "95%")
.attr("stop-color", "#87BE93")
.attr("stop-opacity", 1);
// # zoom function
svg
.append("rect")
.attr("fill", "none")
.attr("pointer-events", "all")
.attr("width", width)
.attr("height", height)
.call(
d3
.zoom()
.scaleExtent([1 / 10, 8])
.on("zoom", zoom)
);
function zoom({ transform }, d) {
g.attr("transform", transform);
}
const serie = g
.append("g")
.selectAll("g")
.data(data)
.enter()
.append("g")
.attr("transform", (d, i) => {
return `translate(0,${y(i)})`;
});
serie
.append("path")
.attr("fill", "#dddddd")
.attr("opacity", 1)
.attr("d", (d, i) => area2(d));
//# gradient fill
serie
.append("path")
.attr("fill", "url(#Gradient2)")
.attr("opacity", opacity)
.attr("d", (d, i) => area(d));
//# shorten the flat area lines
serie
.append("path")
.attr("fill", "none")
.attr("stroke", "#cccccc")
.attr("stroke-width", 1)
.attr("opacity", showline ? 1 : 0)
.attr("d", d => line2(d));
//# THE top path line
serie
.append("path")
.attr("fill", "none")
.attr("stroke-width", 1)
.attr("stroke", lineColor)
.attr("opacity", showline ? 1 : 0)
.attr("d", d => line(d));
return svg.node();
}