differencePlot_1 = (dataArray, width, height, options) => {
const svg = d3.select(DOM.svg(width, height));
const chart = svg
.append("g")
.attr("transform", `translate(${margin},${margin})`)
.datum(dataArray);
let W = width - 2 * margin,
H = height - 2 * margin;
const xDomain = d3.extent(dataArray, d => d.date);
const yDomain = [
d3.min(dataArray, d => Math.min(d.value0, d.value1)),
d3.max(dataArray, d => Math.max(d.value0, d.value1))
];
const xScale = d3
.scaleTime()
.domain(xDomain)
.range([0.5, W - 0.5])
.nice();
const yScale = d3
.scaleLinear()
.domain(yDomain)
.range([H - 0.5, 0.5])
.nice();
const positiveAreaGenerator = d3
.area()
.curve(curveType)
.defined(d => d.value0 > d.value1)
.x(d => xScale(d.date))
.y0(d => yScale(d.value1))
.y1(d => yScale(d.value0));
const negativeAreaGenerator = d3
.area()
.curve(curveType)
.defined(d => d.value0 <= d.value1)
.x(d => xScale(d.date))
.y0(d => yScale(d.value0))
.y1(d => yScale(d.value1));
const line0Generator = d3
.line()
.curve(curveType)
.x(d => xScale(d.date))
.y(d => yScale(d.value0));
const line1Generator = d3
.line()
.curve(curveType)
.x(d => xScale(d.date))
.y(d => yScale(d.value1));
chart
.append("path")
.attr("d", negativeAreaGenerator)
.style("stroke", "none")
.style("fill", diffColors[0]);
chart
.append("path")
.attr("d", positiveAreaGenerator)
.style("stroke", "none")
.style("fill", diffColors[1]);
addPaths(
chart,
xScale,
yScale,
[
dataArray.map(d => [d.date, d.value0]),
dataArray.map(d => [d.date, d.value1])
],
options
);
if (options && options.legends)
addLegend(chart, options.legends, [
[
xScale(dataArray[dataArray.length - 1].date),
yScale(dataArray[dataArray.length - 1].value0)
],
[
xScale(dataArray[dataArray.length - 1].date),
yScale(dataArray[dataArray.length - 1].value1)
]
]);
addAxesWithGridLines(chart, xScale, yScale, W, H);
return svg.node();
}