Public
Edited
Apr 22
Insert cell
Insert cell
Insert cell
Insert cell
html`<svg width="200" height="200">
<circle cx="100" cy="100" r="75" style="fill:green;"></circle>
<circle cx="100" cy="100" r="50" style="fill:purple;"></circle>
<circle cx="100" cy="100" r="25" style="fill:red;"></circle>`
Insert cell
html`<svg width="110" height="110">
<polygon points="50,5 20,99 95,39 5,39 80,99" style="fill:blue;stroke:red;stroke-width:5;fill-rule:evenodd;" />
</circle>`
Insert cell
Insert cell
Insert cell
grilla_circ_conc = {
var coleccion = []; // Arreglo de datos a retornar
var cantidad_circulos = 3;
var incremento = 1;
var rad = 100;
var rad_dec = rad*0.25;
var color_ = ['green', 'purple', 'red'];
for(var r = 1; r < cantidad_circulos+incremento; r = r+incremento) {
rad = rad - rad_dec
var circle_elem = {
eje_x: 100,
eje_y: 100,
radio: rad,
color: color_[r-1],
};
coleccion.push(circle_elem);
}
return coleccion;
}
Insert cell
{
// 1. Creación de un área de dibujo (512x90 pixeles)
const svg = d3.create("svg")
.attr("width",400)
.attr("height",400);
// 2. Asociamos la colección de círculos a componentes gráficos "circle"
var circulos = svg.selectAll("circle") // Esta selección da vacio
.data(grilla_circ_conc) // Estos son los datos
.enter() // Para cada entrada
.append("circle"); // Agregá un círculo

// 3. Le decimos a d3 cómo utilizar la información disponible en el arreglo
// para setear las propiedades cx, cy, r y fill del componente HTML circle
circulos.attr("cx", function(d) {return d.eje_x;} )
.attr("cy", function(d) {return d.eje_y;} )
.attr("r" , function(d) {return d.radio;} )
.style("fill", function(d) {return d.color;} )

// 4. Retornamos el canvas
return svg.node();
}
Insert cell
Insert cell
function grilla_circ() {
var coleccion = [];

var filas = 17;
var columnas = 17;

for (var ix = 0; ix < filas; ix++) {
for (var iy = 0; iy < columnas; iy++) {
var red = Math.round((iy / (columnas - 1)) * 255);
var green = Math.round((ix / (columnas - 1)) * 255);
var color = `rgb(${red},${green},0)`;
var circle_elem = {
eje_x: (iy * 20) + 5,
eje_y: (ix * 20) + 15,
radio: 5,
color: color
};
coleccion.push(circle_elem);
}
}

return coleccion;
}
Insert cell
{
// 1. Creación de un área de dibujo (400x400 pixeles)
const svg = d3.create("svg")
.attr("width",400)
.attr("height",400);
// 2. Asociamos la colección de círculos a componentes gráficos "circle"
var circulos = svg.selectAll("circle") // Esta selección da vacio
.data(grilla_circ) // Estos son los datos
.enter() // Para cada entrada
.append("circle"); // Agregá un círculo

// 3. Le decimos a d3 cómo utilizar la información disponible en el arreglo
circulos.attr("cx", function(d) {return d.eje_x;} )
.attr("cy", function(d) {return d.eje_y;} )
.attr("r" , function(d) {return d.radio;} )
.style("fill", function(d) {return d.color;} )

// 4. Retornamos el canvas
return svg.node();
}

Insert cell
Insert cell
html`
<svg width="500" height="300">

<defs>
<g id="triangulos">
<polygon points="12.5 3.25, 25 25, 0 25" style="fill:yellow; stroke:blue; stroke-width:2" />
<polygon points="37.5 25, 50 3.25, 25 3.25" style="fill:white; stroke:red; stroke-width:2" />
<polygon points="62.5 3.25, 75 25, 50 25" style="fill:yellow; stroke:blue; stroke-width:2" />
<polygon points="87.5 25, 100 3.25, 75 3.25" style="fill:white; stroke:red; stroke-width:2" />
<polygon points="112.5 3.25, 125 25, 100 25" style="fill:yellow; stroke:blue; stroke-width:2" />
<polygon points="137.5 25, 150 3.25, 125 3.25" style="fill:white; stroke:red; stroke-width:2" />
<polygon points="162.5 3.25, 175 25, 150 25" style="fill:yellow; stroke:blue; stroke-width:2" />
<polygon points="187.5 25, 200 3.25, 175 3.25" style="fill:white; stroke:red; stroke-width:2" />
<polygon points="212.5 3.25, 225 25, 200 25" style="fill:yellow; stroke:blue; stroke-width:2" />
<polygon points="237.5 25, 250 3.25, 225 3.25" style="fill:white; stroke:red; stroke-width:2" />
<polygon points="262.5 3.25, 275 25, 250 25" style="fill:yellow; stroke:blue; stroke-width:2" />
<polygon points="287.5 25, 300 3.25, 275 3.25" style="fill:white; stroke:red; stroke-width:2" />
<polygon points="312.5 3.25, 325 25, 300 25" style="fill:yellow; stroke:blue; stroke-width:2" />
<polygon points="337.5 25, 350 3.25, 325 3.25" style="fill:white; stroke:red; stroke-width:2" />
<polygon points="362.5 3.25, 375 25, 350 25" style="fill:yellow; stroke:blue; stroke-width:2" />
<polygon points="387.5 25, 400 3.25, 375 3.25" style="fill:white; stroke:red; stroke-width:2" />
<polygon points="412.5 3.25, 425 25, 400 25" style="fill:yellow; stroke:blue; stroke-width:2" />
<polygon points="437.5 25, 450 3.25, 425 3.25" style="fill:white; stroke:red; stroke-width:2" />
<polygon points="462.5 3.25, 475 25, 450 25" style="fill:yellow; stroke:blue; stroke-width:2" />
<polygon points="487.5 25, 500 3.25, 475 3.25" style="fill:white; stroke:red; stroke-width:2" />
<polygon points="512.5 3.25, 525 25, 500 25" style="fill:yellow; stroke:blue; stroke-width:2" />
<polygon points="537.5 25, 550 3.25, 525 3.25" style="fill:white; stroke:red; stroke-width:2" />
<polygon points="562.5 3.25, 575 25, 550 25" style="fill:yellow; stroke:blue; stroke-width:2" />
<polygon points="587.5 25, 600 3.25, 575 3.25" style="fill:white; stroke:red; stroke-width:2" />
<polygon points="612.5 3.25, 625 25, 600 25" style="fill:yellow; stroke:blue; stroke-width:2" />
<polygon points="637.5 25, 650 3.25, 625 3.25" style="fill:white; stroke:red; stroke-width:2" />
<polygon points="662.5 3.25, 675 25, 650 25" style="fill:yellow; stroke:blue; stroke-width:2" />
<polygon points="687.5 25, 700 3.25, 675 3.25" style="fill:white; stroke:red; stroke-width:2" />
<polygon points="712.5 3.25, 725 25, 700 25" style="fill:yellow; stroke:blue; stroke-width:2" />
<polygon points="737.5 25, 750 3.25, 725 3.25" style="fill:white; stroke:red; stroke-width:2" />
</g>
</defs>

<g transform="scale(0.5)">
//Fila 1
<use xlink:href="#triangulos" />
//Fila 2
<use xlink:href="#triangulos" transform="translate(0, 30)" />
//Fila 3
<use xlink:href="#triangulos" transform="translate(0, 60)" />
//Fila 4
<use xlink:href="#triangulos" transform="translate(0, 90)" />
//Fila 5
<use xlink:href="#triangulos" transform="translate(0, 120)" />
//Fila 6
<use xlink:href="#triangulos" transform="translate(0, 150)" />
//Fila 7
<use xlink:href="#triangulos" transform="translate(0, 180)" />
//Fila 8
<use xlink:href="#triangulos" transform="translate(0, 210)" />
//Fila 9
<use xlink:href="#triangulos" transform="translate(0, 240)" />
//Fila 10
<use xlink:href="#triangulos" transform="translate(0, 270)" />
//Fila 11
<use xlink:href="#triangulos" transform="translate(0, 300)" />
//Fila 12
<use xlink:href="#triangulos" transform="translate(0, 330)" />
//Fila 13
<use xlink:href="#triangulos" transform="translate(0, 360)" />
//Fila 14
<use xlink:href="#triangulos" transform="translate(0, 390)" />
//Fila 15
<use xlink:href="#triangulos" transform="translate(0, 420)" />

</g>

</svg>
</html>`
Insert cell

{
// 1. Creación de un área de dibujo (512x90 pixeles)
const svg = d3.create("svg")
.attr("width",400)
.attr("height",400);
// 4. Retornamos el canvas
return svg.node();
}
Insert cell
Insert cell
{
// 1. Creación de un área de dibujo (256x256 pixeles).
// Si lo consideran necesario, pueden modificar el tamaño del canvas.
// También es posible que necesiten más de una celda para resolverlo.
const svg = d3.create("svg")
.attr("width",256)
.attr("height",256);
// n. Retornamos el canvas.
return svg.node();
}
Insert cell
// Función para generar hexágonos en x,y de radio r.
function hexagon(x, y, r) {
var x1 = x;
var y1 = y - r;
var x2 = x + Math.cos(Math.PI / 6) * r;
var y2 = y - Math.sin(Math.PI / 6) * r;
var x3 = x + Math.cos(Math.PI / 6) * r;
var y3 = y + Math.sin(Math.PI / 6) * r;
var x4 = x;
var y4 = y + r;
var x5 = x - Math.cos(Math.PI / 6) * r;
var y5 = y + Math.sin(Math.PI / 6) * r;
var x6 = x - Math.cos(Math.PI / 6) * r;
var y6 = y - Math.sin(Math.PI / 6) * r;

var path = x1 + ',' + y1 + " " + x2 + ',' + y2 + " " + x3 + ',' + y3 + " " + x4 + ',' + y4 + " " + x5 + ',' + y5 + " " + x6 + ',' + y6;
return path;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more