bject, it would be better to // save these on the wireframe object itself. let width = wireframe.rects.reduce( (max, rect) => Math.max(max, rect.x + rect.width), 0 ); let height = wireframe.rects.reduce( (max, rect) => Math.max(max, rect.y + rect.height), 0 ); svg.setAttributeNS(null, "viewBox", `0 0 ${width} ${height}`); svg.style.backgroundColor = this.nscolorToRGB(wireframe.canvasBackground); const DEFAULT_FILL = "color-mix(in srgb, gray 20%, transparent)"; for (let rectObj of wireframe.rects) { // For now we'll skip rects that have an unknown classification, since // it's not clear how we should treat them. if (rectObj.type == "unknown") { continue; } let rectEl = document.createElementNS(SVG_NS, "rect"); rectEl.setAttribute("x", rectObj.x); rectEl.setAttribute("y", rectObj.y); rectEl.setAttribute("width", rectObj.width); rectEl.setAttribute("height", rectObj.height); let fill; switch (rectObj.type) { case "background": { fill = this.nscolorToRGB(rectObj.color); break; } case "image": { fill = rectObj.color ? this.nscolorToRGB(rectObj.color) : DEFAULT_FILL; break; } case "text": { fill = DEFAULT_FILL; break; } } rectEl.setAttribute("fill", fill); svg.appendChild(rectEl); } return svg; }, }; PK