La función ordinal.copy() se usa para crear y devolver la copia exacta de la escala ordinal. Cualquier cambio en la escala original no afectará la escala de la copia y viceversa.
Sintaxis:
ordinal.copy();
Parámetros: Este método no toma ningún parámetro.
Valores devueltos: este método devuelve una copia de la escala original.
Ejemplo 1:
HTML
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" path1tent= "width=device-width, initial-scale = 1.0" /> <script src= "https://d3js.org/d3.v4.min.js"> </script> </head> <body> <script> // Creating the Ordinal scale. var ordinal = d3.scaleThreshold() // Setting domain for the scale .domain([1, 2, 3, 4]) .range([10, 20, 30, 40]); // Making copy of the scale. var ordinalCopy = ordinal.copy(); console.log("The value of ordinalCopy(1) is: ", ordinalCopy(1)); console.log("The value of ordinalCopy(2) is: ", ordinalCopy(2)); console.log("The value of ordinal(1) is: ", ordinal(1)); console.log("The value of ordinal(2) is: ", ordinal(2)); </script> </body> </html>
Producción:
Ejemplo 2:
HTML
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" path1tent= "width=device-width, initial-scale = 1.0" /> <script src= "https://d3js.org/d3.v4.min.js"> </script> </head> <body> <script> // Creating the Ordinal scale. var ordinal = d3.scaleThreshold() // Setting domain for the scale .domain([1, 2, 3, 4]) .range([10, 20, 30, 40, 50]); console.log("The value of ordinal(3) is: ", ordinal(3)); console.log("The value of ordinal(4) is: ", ordinal(4)); // Making copy of the scale. var ordinalCopy = ordinal.copy(); // making change in the original scale. ordinal.range(["The range of the " + "original scale is change"]); console.log("The value of ordinalCopy(3) is: ", ordinalCopy(3)); console.log("The value of ordinalCopy(4) is: ", ordinalCopy(4)); console.log("The value of ordinal(3) is: ", ordinal(3)); console.log("The value of ordinal(4) is: ", ordinal(4)); </script> </body> </html>
Producción: