function chart_rectangle_data(rectangles_as_arrays, number_columns = 5, text_to_print = "df %>% select(x,z)") {
const numColumns = number_columns;
const numRows = 3;
const cellWidth = width_cell ;
const cellHeight = height_cell ;
const spaceBetweenCells = space_between_cells;
const tot_width = 50 + numColumns * cellWidth + numColumns*(numColumns - 1) * spaceBetweenCells;
const tot_height = numRows * cellHeight + numRows*(numRows ) * spaceBetweenCells;
const zoom = d3.zoom()
.scaleExtent([1, 30])
.on("zoom", zoomed);
const svg = d3.create("svg")
.attr("width", tot_width+140)
.attr("height", tot_height+100)
.attr("viewBox", `0 0 ${tot_width+140} ${tot_height+100}`)
svg.selectAll("rect")
.data(rectangles_as_arrays)
.join("rect")
.attr("x", d => d.x)
.attr("y", d => d.y)
.attr("width", d => d.width)
.attr("height", d => d.height)
.attr("fill", d => d.color)
.attr("opacity", d => d.opacity);
svg.selectAll("text")
.data(rectangles_as_arrays)
.join("text")
.attr("x", d => d.x + d.width / 2)
.attr("y", d => d.y + d.height / 2)
.attr("font-size", 12)
.attr("fill", "#000000")
.attr("text-anchor", "middle")
.attr("dominant-baseline", "middle")
.text(d => (d.text !== undefined && d.text !== null) ? d.text : "");
if (text_to_print == null){
return svg.node();
}
const text = text_to_print ;
const textX = (tot_width / 2) - (text.length * 5);
const textY = 30;
svg.append("text")
.attr("x", 20)
.attr("y", 30)
.attr("font-size", 20)
.attr("fill", "#000000")
.text(text);
return svg.node() ;
function zoomed({transform}) {
svg.attr("transform", transform);
}
function zooming() {
const [x, y] = [0,100];
svg.transition().duration(2500).call(
zoom.transform,
d3.zoomIdentity.translate(tot_width / 2, tot_height / 2).scale(2)
);
}
function reset() {
svg.transition().duration(750).call(
zoom.transform,
d3.zoomIdentity,
d3.zoomTransform(svg.node())
);
}
}