--- id: 587d7fac367417b2b2512bde title: Use a Pre-Defined Scale to Place Elements required: - src: 'https://cdnjs.cloudflare.com/ajax/libs/d3/4.3.0/d3.min.js' challengeType: 6 videoUrl: '' localeTitle: Use una escala predefinida para colocar elementos --- ## Description
Con las escalas configuradas, es hora de mapear el diagrama de dispersión nuevamente. Las escalas son como funciones de procesamiento que convierten los datos en bruto de x e y en valores que se ajustan y se representan correctamente en el lienzo de SVG. Mantienen los datos dentro del área de trazado de la pantalla. Establece los valores de los atributos de coordenadas para una forma SVG con la función de escalado. Esto incluye los atributos x e y para elementos rect o de text , o cx y cy para circles . Aquí hay un ejemplo:
forma
.attr ("x", (d) => xScale (d [0]))
Las escalas establecen atributos de coordenadas de forma para colocar los puntos de datos en el lienzo de SVG. No es necesario aplicar escalas cuando muestra el valor de datos real, por ejemplo, en el método text() para una información sobre herramientas o una etiqueta.
## Instructions
Utilice xScale y yScale para colocar las formas de circle y text en el lienzo de SVG. Para los circles , aplique las escalas para establecer los atributos cx y cy . Dales un radio de 5 unidades, también. Para los elementos de text , aplique las escalas para establecer los atributos x e y . Las etiquetas deben estar desplazadas a la derecha de los puntos. Para hacer esto, agregue 10 unidades al valor de datos x antes de pasarlo a xScale .
## Tests
```yml tests: - text: Tu código debe tener 10 elementos circle . testString: 'assert($("circle").length == 10, "Your code should have 10 circle elements.");' - text: El primer elemento del circle debe tener un valor de cx de aproximadamente 91 y un valor de cy de aproximadamente 368 después de aplicar las escalas. También debe tener un valor de r de 5. testString: 'assert(Math.round($("circle").eq(0).attr("cx")) == "91" && Math.round($("circle").eq(0).attr("cy")) == "368" && $("circle").eq(0).attr("r") == "5", "The first circle element should have a cx value of approximately 91 and a cy value of approximately 368 after applying the scales. It should also have an r value of 5.");' - text: El segundo elemento del circle debe tener un valor cx de aproximadamente 159 y un valor cy de aproximadamente 181 después de aplicar las escalas. También debe tener un valor de r de 5. testString: 'assert(Math.round($("circle").eq(1).attr("cx")) == "159" && Math.round($("circle").eq(1).attr("cy")) == "181" && $("circle").eq(1).attr("r") == "5", "The second circle element should have a cx value of approximately 159 and a cy value of approximately 181 after applying the scales. It should also have an r value of 5.");' - text: El tercer elemento del circle debe tener un valor cx de aproximadamente 340 y un valor cy de aproximadamente 329 después de aplicar las escalas. También debe tener un valor de r de 5. testString: 'assert(Math.round($("circle").eq(2).attr("cx")) == "340" && Math.round($("circle").eq(2).attr("cy")) == "329" && $("circle").eq(2).attr("r") == "5", "The third circle element should have a cx value of approximately 340 and a cy value of approximately 329 after applying the scales. It should also have an r value of 5.");' - text: El cuarto elemento del circle debe tener un valor cx de aproximadamente 131 y un valor cy de aproximadamente 60 después de aplicar las escalas. También debe tener un valor de r de 5. testString: 'assert(Math.round($("circle").eq(3).attr("cx")) == "131" && Math.round($("circle").eq(3).attr("cy")) == "60" && $("circle").eq(3).attr("r") == "5", "The fourth circle element should have a cx value of approximately 131 and a cy value of approximately 60 after applying the scales. It should also have an r value of 5.");' - text: El quinto elemento del circle debe tener un valor cx de aproximadamente 440 y un valor cy de aproximadamente 237 después de aplicar las escalas. También debe tener un valor de r de 5. testString: 'assert(Math.round($("circle").eq(4).attr("cx")) == "440" && Math.round($("circle").eq(4).attr("cy")) == "237" && $("circle").eq(4).attr("r") == "5", "The fifth circle element should have a cx value of approximately 440 and a cy value of approximately 237 after applying the scales. It should also have an r value of 5.");' - text: El elemento del sexto circle debe tener un valor cx de aproximadamente 271 y un valor cy de aproximadamente 306 después de aplicar las escalas. También debe tener un valor de r de 5. testString: 'assert(Math.round($("circle").eq(5).attr("cx")) == "271" && Math.round($("circle").eq(5).attr("cy")) == "306" && $("circle").eq(5).attr("r") == "5", "The sixth circle element should have a cx value of approximately 271 and a cy value of approximately 306 after applying the scales. It should also have an r value of 5.");' - text: El elemento del séptimo circle debe tener un valor cx de aproximadamente 361 y un valor cy de aproximadamente 351 después de aplicar las escalas. También debe tener un valor de r de 5. testString: 'assert(Math.round($("circle").eq(6).attr("cx")) == "361" && Math.round($("circle").eq(6).attr("cy")) == "351" && $("circle").eq(6).attr("r") == "5", "The seventh circle element should have a cx value of approximately 361 and a cy value of approximately 351 after applying the scales. It should also have an r value of 5.");' - text: El elemento del octavo circle debe tener un valor cx de aproximadamente 261 y un valor cy de aproximadamente 132 después de aplicar las escalas. También debe tener un valor de r de 5. testString: 'assert(Math.round($("circle").eq(7).attr("cx")) == "261" && Math.round($("circle").eq(7).attr("cy")) == "132" && $("circle").eq(7).attr("r") == "5", "The eighth circle element should have a cx value of approximately 261 and a cy value of approximately 132 after applying the scales. It should also have an r value of 5.");' - text: El elemento del noveno circle debe tener un valor cx de aproximadamente 131 y un valor cy de aproximadamente 144 después de aplicar las escalas. También debe tener un valor de r de 5. testString: 'assert(Math.round($("circle").eq(8).attr("cx")) == "131" && Math.round($("circle").eq(8).attr("cy")) == "144" && $("circle").eq(8).attr("r") == "5", "The ninth circle element should have a cx value of approximately 131 and a cy value of approximately 144 after applying the scales. It should also have an r value of 5.");' - text: El elemento del décimo circle debe tener un valor cx de aproximadamente 79 y un valor cy de aproximadamente 326 después de aplicar las escalas. También debe tener un valor de r de 5. testString: 'assert(Math.round($("circle").eq(9).attr("cx")) == "79" && Math.round($("circle").eq(9).attr("cy")) == "326" && $("circle").eq(9).attr("r") == "5", "The tenth circle element should have a cx value of approximately 79 and a cy value of approximately 326 after applying the scales. It should also have an r value of 5.");' - text: Su código debe tener 10 elementos de text . testString: 'assert($("text").length == 10, "Your code should have 10 text elements.");' - text: La primera etiqueta debe tener un valor de x de aproximadamente 100 y un valor de y de aproximadamente 368 después de aplicar las escalas. testString: 'assert(Math.round($("text").eq(0).attr("x")) == "100" && Math.round($("text").eq(0).attr("y")) == "368", "The first label should have an x value of approximately 100 and a y value of approximately 368 after applying the scales.");' - text: La segunda etiqueta debe tener un valor de x de aproximadamente 168 y un valor de y de aproximadamente 181 después de aplicar las escalas. testString: 'assert(Math.round($("text").eq(1).attr("x")) == "168" && Math.round($("text").eq(1).attr("y")) == "181", "The second label should have an x value of approximately 168 and a y value of approximately 181 after applying the scales.");' - text: La tercera etiqueta debe tener un valor de x de aproximadamente 350 y un valor de y de aproximadamente 329 después de aplicar las escalas. testString: 'assert(Math.round($("text").eq(2).attr("x")) == "350" && Math.round($("text").eq(2).attr("y")) == "329", "The third label should have an x value of approximately 350 and a y value of approximately 329 after applying the scales.");' - text: La cuarta etiqueta debe tener un valor de x de aproximadamente 141 y un valor de y de aproximadamente 60 después de aplicar las escalas. testString: 'assert(Math.round($("text").eq(3).attr("x")) == "141" && Math.round($("text").eq(3).attr("y")) == "60", "The fourth label should have an x value of approximately 141 and a y value of approximately 60 after applying the scales.");' - text: La quinta etiqueta debe tener un valor de x de aproximadamente 449 y un valor de y de aproximadamente 237 después de aplicar las escalas. testString: 'assert(Math.round($("text").eq(4).attr("x")) == "449" && Math.round($("text").eq(4).attr("y")) == "237", "The fifth label should have an x value of approximately 449 and a y value of approximately 237 after applying the scales.");' - text: La sexta etiqueta debe tener un valor de x de aproximadamente 280 y un valor de y de aproximadamente 306 después de aplicar las escalas. testString: 'assert(Math.round($("text").eq(5).attr("x")) == "280" && Math.round($("text").eq(5).attr("y")) == "306", "The sixth label should have an x value of approximately 280 and a y value of approximately 306 after applying the scales.");' - text: La séptima etiqueta debe tener un valor de x de aproximadamente 370 y un valor de y de aproximadamente 351 después de aplicar las escalas. testString: 'assert(Math.round($("text").eq(6).attr("x")) == "370" && Math.round($("text").eq(6).attr("y")) == "351", "The seventh label should have an x value of approximately 370 and a y value of approximately 351 after applying the scales.");' - text: La octava etiqueta debe tener un valor de x de aproximadamente 270 y un valor de y de aproximadamente 132 después de aplicar las escalas. testString: 'assert(Math.round($("text").eq(7).attr("x")) == "270" && Math.round($("text").eq(7).attr("y")) == "132", "The eighth label should have an x value of approximately 270 and a y value of approximately 132 after applying the scales.");' - text: La novena etiqueta debe tener un valor de x de aproximadamente 140 y un valor de y de aproximadamente 144 después de aplicar las escalas. testString: 'assert(Math.round($("text").eq(8).attr("x")) == "140" && Math.round($("text").eq(8).attr("y")) == "144", "The ninth label should have an x value of approximately 140 and a y value of approximately 144 after applying the scales.");' - text: La décima etiqueta debe tener un valor de x de aproximadamente 88 y un valor de y de aproximadamente 326 después de aplicar las escalas. testString: 'assert(Math.round($("text").eq(9).attr("x")) == "88" && Math.round($("text").eq(9).attr("y")) == "326", "The tenth label should have an x value of approximately 88 and a y value of approximately 326 after applying the scales.");' ```
## Challenge Seed
```html ```
## Solution
```js // solution required ```