La función threshold.copy() en d3.js se usa para crear y devolver la copia exacta de la escala de umbral. Cualquier cambio en la escala original no afectará la escala de la copia.
Sintaxis:
threshold.copy();
Parámetros: Esta función no acepta ningún parámetro.
Valor devuelto: esta función devuelve una copia exacta de la escala de umbral 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> <h2 style="color:green">GeekforGeeks</h2> <p>threshold.copy() Function </p> <script> var threshold = d3.scaleThreshold() // Domain .domain([1, 2, 3, 4]) // Range for the domain .range([10, 20, 30, 40, 50]); document.write("<h3>threshold(1): " + threshold(1) + "</h3>"); document.write("<h3>threshold(3): " + threshold(3) + "</h3>"); document.write( "<p> This is from copy scale.</p>"); var thresholdCopy = threshold.copy(); document.write("<h3>thresholdCopy(1): " + thresholdCopy(1) + "</h3>"); document.write("<h3>thresholdCopy(3): " + thresholdCopy(3) + "</h3>"); </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> <h2 style="color:green">GeekforGeeks</h2> <p>threshold.copy() Function </p> <script> var threshold = d3.scaleThreshold() // Domain .domain([1, 2, 3, 4]) // Range for the domain .range([10, 20, 30, 40, 50]); var thresholdCopy = threshold.copy(); document.write( "<div style=line-height:5px><h3>threshold(1): " + threshold(1) + "</h3>"); document.write("<h3>threshold(3): " + threshold(3) + "</h3>"); // Making changes on the original scale threshold.range([100, 200, 300, 400, 500]); document.write( "<p> After making changes in the original scale</p>"); document.write("<h3>threshold(3): " + threshold(3) + "</h3>"); document.write("<p> This is from copy scale.</p>"); document.write("<h3>thresholdCopy(1): " + thresholdCopy(1) + "</h3>"); document.write("<h3>thresholdCopy(3): " + thresholdCopy(3) + "</h3></div>"); </script> </body> </html>
Producción: