{
const [noteMin, noteMax] = d3.extent(notes, d => d.midi);
const [yMin, yMax] = d3.extent(notes, d => d.time);
const xDomain = d3.range(noteMin, noteMax + 1);
const yDomain = [0, yMax];
const xRange = [0, 100];
const yRange = [0, 100];
const xScale = d3.scaleBand(xDomain, xRange);
const yScale = d3.scaleLinear(yDomain, yRange);
const mapped = notes.map(d => {
const top = yScale(d.time);
const bottom = yScale(d.time + d.duration);
const height = Math.abs(top - bottom);
const left = xScale(d.midi);
const right = left + xScale.bandwidth();
const width = Math.abs(left - right);
return {
...d,
top,
bottom,
height,
left,
right,
width
};
});
const rects = mapped.map(d => {
const { top: y, left: x, width, height } = d;
return svg`<rect ${{
x: `${x}%`,
y: `${y}%`,
width: `${width}%`,
height: `${height}%`
}} />`;
});
mutable log = mapped;
return html`<svg style=${{
width: `100%`,
height: `2000px`
}}>${rects}</svg>`;
}