function LineChart(data,data2, {
x = ([x]) => x,
y = ([, y]) => y,
z = ([z]) => z,
a = ([a]) => a,
b = ([b]) => b,
c = ([c]) => c,
d = ([d]) => d,
x2 = ([x2]) => x2,
y2 = ([, y2]) => y2,
z2 = ([z2]) => z2,
a2 = ([a2]) => a2,
b2 = ([b2]) => b2,
c2 = ([c2]) => c2,
d2 = ([d2]) => d2,
title,
title2,
defined,
defined2,
curve = d3.curveLinear,
marginTop = 10,
marginRight = 30,
marginBottom = 30,
marginLeft = 40,
width = 640,
height = 400,
xType = d3.scaleLinear,
xDomain,
xDomain2,
yOffset,
xRange = [marginLeft, width - marginRight],
yType = d3.scaleLinear,
yDomain,
yDomain2,
yRange = [height - marginBottom, marginTop],
color = "currentColor",
strokeWidth = 1.5,
strokeLinejoin = "round",
strokeLinecap = "round",
yFormat,
yLabel,
xLabel,
yLabel2,
xLabel2,
} = {}) {
const X = d3.map(data, x);
const Y = d3.map(data, y);
const O = d3.map(data, d => d);
const I = d3.map(data, (_, i) => i);
const A = d3.map(data, a);
const B = d3.map(data, b);
const C = d3.map(data, c);
const DD = d3.map(data, d);
const X2 = d3.map(data2, x2);
const Y2 = d3.map(data2, y2);
const O2 = d3.map(data2, d => d);
const I2 = d3.map(data2, (_, i) => i);
const A2 = d3.map(data2, a2);
const B2 = d3.map(data2, b2);
const C2 = d3.map(data2, c2);
const DD2 = d3.map(data2, d2);
const Z = d3.map(data, z);
const Z2 = d3.map(data2, z2);
if (defined === undefined) defined = (d, i) => !isNaN(X[i]) && !isNaN(Y[i]);
const D = d3.map(data, defined);
if (defined2 === undefined) defined2 = (d, i) => !isNaN(X2[i]) && !isNaN(Y2[i]);
const D2 = d3.map(data2, defined2);
if (xDomain === undefined) xDomain = d3.extent(X);
if (yDomain === undefined) yDomain = [0, d3.max(Y)];
if (xDomain2 === undefined) xDomain2 = d3.extent(X2);
if (yDomain2 === undefined) yDomain2 = [0, d3.max(Y2)];
const xScale = xType(xDomain, xRange);
const yScale = yType(yDomain, yRange);
const xAxis = d3.axisBottom(xScale).ticks(width / 90).tickSizeOuter(0);
const yAxis = d3.axisLeft(yScale).ticks(height / 25, yFormat);
const xScale2 = xType(xDomain2, xRange);
const yScale2 = yType(yDomain2, yRange);
const xAxis2 = d3.axisBottom(xScale2).ticks(width / 90).tickSizeOuter(0);
const yAxis2 = d3.axisLeft(yScale2).ticks(height / 25, yFormat);
if (title === undefined) {
const formatValue = yScale.tickFormat(100, yFormat);
title = i => `m2 of greenwall ${formatValue(Z[i])}\nEUI kWh/m2 ${formatValue(Y[i])}\nFormaldehyde ppb ${formatValue(A[i])}\nBenzene ppb ${formatValue(B[i])}\nToluene ppb ${formatValue(C[i])}\nCO2ppm ${formatValue(DD[i])}`;
} else {
const O = d3.map(data, d => d);
const T = title;
title = i => T(O[i], i, data);
}
if (title2 === undefined) {
const formatValue = yScale2.tickFormat(100, yFormat);
title2 = i => `m2 of greenwall ${formatValue(Z2[i])}\nEUI kWh/m2 ${formatValue(Y2[i])}\nFormaldehyde ppb ${formatValue(A2[i])}\nBenzene ppb ${formatValue(B2[i])}\nToluene ppb ${formatValue(C2[i])}\nCO2ppm ${formatValue(DD2[i])}`;
} else {
const O2 = d3.map(data2, d => d);
const T2 = title2;
title2 = i => T2(O2[i], i, data2);
}
const line = d3.line()
.defined(i => D[i])
.curve(curve)
.x(i => xScale(X[i]))
.y(i => yScale(Y[i]));
const line2 = d3.line()
.defined(i => D2[i])
.curve(curve)
.x(i => xScale2(X2[i]))
.y(i => yScale2(Y2[i])+yOffset)
const svg = d3.create("svg")
.attr("width", width)
.attr("height", height*2.3)
.attr("viewBox", [0, 0, width, height*2])
.attr("style", "max-width: 100%; height: auto; height: intrinsic;")
.attr("font-family", "sans-serif")
.attr("font-size", 10)
.style("-webkit-tap-highlight-color", "transparent")
.style("overflow", "visible")
.on("pointerenter pointermove", pointermoved)
.on("pointerleave", pointerleft)
.on("touchstart", event => event.preventDefault());
svg.append("g")
.attr("transform", `translate(0,${height - marginBottom})`)
.call(xAxis);
svg.append("g")
.attr("transform", `translate(${marginLeft},0)`)
.call(yAxis)
.call(g => g.select(".domain").remove())
.call(g => g.selectAll(".tick line").clone()
.attr("x2", width - marginLeft - marginRight)
.attr("stroke-opacity", 0.1))
.call(g => g.append("text")
.attr("x", -marginLeft)
.attr("y", 10)
.attr("fill", "currentColor")
.attr("text-anchor", "start")
.attr("font-size", '1.2em')
.text(yLabel))
svg.call(g => g.append("text")
.attr("x", width-marginRight-80)
.attr("y", height+10)
.attr("fill", "currentColor")
.attr("text-anchor", "start")
.attr("font-size", '1.2em')
.text(xLabel));
svg.append("g")
.attr("transform", `translate(0,${height - marginBottom+yOffset})`)
.call(xAxis2);
svg.append("g")
.attr("transform", `translate(${marginLeft},${yOffset})`)
.call(yAxis2)
.call(g => g.select(".domain").remove())
.call(g => g.selectAll(".tick line").clone()
.attr("x2", width - marginLeft - marginRight)
.attr("stroke-opacity", 0.1))
.call(g => g.append("text")
.attr("x", -marginLeft)
.attr("y", 10)
.attr("fill", "currentColor")
.attr("text-anchor", "start")
.attr("font-size", '1.2em')
.text(yLabel))
svg.call(g => g.append("text")
.attr("x", width-marginRight-80)
.attr("y", height+yOffset+10)
.attr("fill", "currentColor")
.attr("text-anchor", "start")
.attr("font-size", '1.2em')
.text(xLabel));
svg.append("path")
.attr("fill", "none")
.attr("stroke", color)
.attr("stroke-width", strokeWidth)
.attr("stroke-linejoin", strokeLinejoin)
.attr("stroke-linecap", strokeLinecap)
.attr("d", line(I));
svg.append("path")
.attr("fill", "none")
.attr("stroke", color)
.attr("stroke-width", strokeWidth)
.attr("stroke-linejoin", strokeLinejoin)
.attr("stroke-linecap", strokeLinecap)
.attr("d", line2(I2));
const tooltip = svg.append("g")
.style("pointer-events", "none");
const tooltip2 = svg.append("g")
.style("pointer-events", "none");
function pointermoved(event) {
pointermoved2(event)
const i = d3.bisectCenter(X, xScale.invert(d3.pointer(event)[0]));
tooltip.style("display", null);
tooltip.attr("transform", `translate(${xScale(X[i])},${yScale(Y[i])})`);
const path = tooltip.selectAll("path")
.data([,])
.join("path")
.attr("fill", "white")
.attr("stroke", "black");
const text = tooltip.selectAll("text")
.data([,])
.join("text")
.call(text => text
.selectAll("tspan")
.data(`${title(i)}`.split(/\n/))
.join("tspan")
.attr("x", 0)
.attr("y", (_, i) => `${i * 1.5}em`)
.attr("font-weight", (_, i) => i ? null : "bold")
.attr("font-size", '1.2em')
.text(d => d));
const {x, y, width: w, height: h} = text.node().getBBox();
text.attr("transform", `translate(${-w / 2},${15 - y})`);
path.attr("d", `M${-w / 2 - 10},5H-5l5,-5l5,5H${w / 2 + 10}v${h + 20}h-${w + 20}z`);
svg.property("value", O[i]).dispatch("input", {bubbles: true});
}
function pointermoved2(event) {
const i2 = d3.bisectCenter(X2, xScale.invert(d3.pointer(event)[0]));
tooltip2.style("display", null);
tooltip2.attr("transform", `translate(${xScale2(X2[i2])},${yScale2(Y2[i2])+yOffset})`);
const path2 = tooltip2.selectAll("path")
.data([,])
.join("path")
.attr("fill", "white")
.attr("stroke", "black");
const text2 = tooltip2.selectAll("text")
.data([,])
.join("text")
.call(text => text
.selectAll("tspan")
.data(`${title2(i2)}`.split(/\n/))
.join("tspan")
.attr("x", 0)
.attr("y", (_, i) => `${i * 1.5}em`)
.attr("font-weight", (_, i) => i ? null : "bold")
.attr("font-size", '1.2em')
.text(d => d));
const {x2, y2, width: w, height: h} = text2.node().getBBox();
text2.attr("transform", `translate(${-w / 2},${25})`);
path2.attr("d", `M${-w / 2 - 10},5H-5l5,-5l5,5H${w / 2 + 10}v${h + 20}h-${w + 20}z`);
svg.property("value", O2[i2]).dispatch("input", {bubbles: true});
}
function pointerleft() {
tooltip.style("display", "none");
svg.node().value = null;
svg.dispatch("input", {bubbles: true});
}
return Object.assign(svg.node(), {value: null});
}