charts = {
const circleRadius = 20;
const numberOfChannels = pluslifeTestData.testResult.numberOfChannels;
if (numberOfChannels !== 7) {
throw new Error("as far as I know, test cards always have 7 channels 🤔");
}
const values = samples.map(s => s.value);
const times = samples.map(s => s.time);
const colors = d3.quantize(d3.interpolateRainbow, numberOfChannels + 2);
const timeScale = d3.scaleLinear().domain(d3.extent(samples, d => d.time));
const samplesByTimeByChannel = d3.group(samples, d => d.time, d => d.channel);
const samplesByChannel = d3.group(samples, d => d.channel);
const container = d3.create("div")
.style("display", "flex");
const layout = {
card: { width: 240, height: 320 },
graph: {
width: 560,
height: 340,
margin: { top: 30, right: 0, bottom: 50, left: 60 }
}
};
const card = cardSetup(container, layout.card, colors);
const scaleRadius = d3.scaleLinear().domain(d3.extent(values)).range([2, circleRadius]);
const channelPositions = d3.range(7).map((index) => (
getPointOnCircle(120, 200, outerChannelPlacementRadius, outerChannelAngles[index])
));
const { graph, line } = graphSetup(container, layout.graph, samples);
const dasharrayByChannel = d3.range(7).map((index) => {
const lineLength = htl.svg`<path d="${line(samplesByChannel.get(index + 1))}">`.getTotalLength();
return d3.interpolate(`0,${lineLength}`, `${lineLength},${lineLength}`);
});
const circles = card.append("g")
.selectAll("circle")
.data(samplesByTimeByChannel.get(t))
.join("circle")
.attr("cx", ([channel]) => channelPositions[channel - 1].x)
.attr("cy", ([channel]) => channelPositions[channel - 1].y)
.attr("r", ([channel, d]) => scaleRadius(d[0].value))
.attr("fill", ([channel]) => colors[channel - 1])
.attr("opacity", 0.5);
const lines = graph.append("g")
.selectAll("path")
.data(samplesByChannel)
.join("path")
.attr("fill", "none")
.attr("stroke", ([channel]) => colors[channel - 1])
.attr("d", ([channel, d]) => line(d))
.attr("stroke-dasharray", ([channel]) => dasharrayByChannel[channel - 1](timeScale(t)))
.on("mouseover", function (d, i) {
lines.attr("opacity", "0.25");
d3.select(this)
.attr("stroke-width", "2")
.attr("opacity", "1");
})
.on("mouseout", function (d, i) {
lines.attr("stroke-width", "1").attr("opacity", "1");
});
return container.node();
}