The d3.interpolateCubehelixLong() function is used to return the cubehelix color space interpolator between the two given colors A and B. It uses the shortest path between the hues.
Syntax:
d3.interpolateCubehelixLong(a, b);
Parameters: It takes the two parameters as given above and described below.
- a: It is the name of color in string format.
- b: It is also the name of color in string format.
Return Value: It returns the function.
Example 1:
HTML
<!DOCTYPE html> < html lang = "en" > Â Â < head > Â Â Â Â < meta charset = "UTF-8" > Â Â Â Â < meta name = "viewport" content = Â Â Â Â Â Â Â Â "width=device-width,initial-scale=1.0" > Â Â Â Â Â Â Â Â <!--Fetching from CDN of D3.js --> Â Â Â Â < script type = "text/javascript" Â Â Â Â Â </ script > </ head > Â Â < body > Â Â Â Â Â Â < script > Â Â Â Â Â Â Â Â console.log("Type of the function is: ", Â Â Â Â Â Â Â Â Â Â Â Â typeof(d3.interpolateCubehelixLong("white", "red"))) Â Â Â Â Â Â Â Â Â Â console.log( Â Â Â Â Â Â Â Â Â Â Â Â d3.interpolateCubehelixLong("blue", "white")(0.9)) Â Â Â Â Â Â Â Â Â Â console.log( Â Â Â Â Â Â Â Â Â Â Â Â d3.interpolateCubehelixLong("white", "green")(0.1))Â Â Â Â Â </ script > </ body > Â Â </ html > |
Output:
Example 2:
HTML
<!DOCTYPE html> < html lang = "en" > Â Â < head > Â Â Â Â < meta charset = "UTF-8" > Â Â Â Â < meta name = "viewport" content = Â Â Â Â Â Â Â Â "width=device-width,initial-scale=1.0" > Â Â Â Â Â Â Â Â <!--Fetching from CDN of D3.js --> Â Â Â Â < script type = "text/javascript" Â Â Â Â Â </ script > Â Â Â Â Â Â Â Â < style > Â Â Â Â Â Â Â Â .bx1, Â Â Â Â Â Â Â Â .bx2 { Â Â Â Â Â Â Â Â Â Â Â Â width: 100px; Â Â Â Â Â Â Â Â Â Â Â Â height: 100px; Â Â Â Â Â Â Â Â } Â Â Â Â </ style > </ head > Â Â < body > Â Â Â Â Â Â < p >D3.interpolateCubehelixLong()</ p > Â Â Â Â Â Â < div class = "bx1" ></ div > Â Â Â Â < div class = "bx2" ></ div > Â Â Â Â Â Â Â Â Â Â < script > Â Â Â Â Â Â Â Â let color1 = Â Â Â Â Â Â Â Â Â Â Â Â d3.interpolateCubehelixLong("green", "white")(0.1) Â Â Â Â Â Â Â Â let color2 = Â Â Â Â Â Â Â Â Â Â Â Â d3.interpolateCubehelixLong("white", "green")(0.1) Â Â Â Â Â Â Â Â let bx1 = document.querySelector(".bx1"); Â Â Â Â Â Â Â Â bx1.style.backgroundColor = color1; Â Â Â Â Â Â Â Â let bx2 = document.querySelector(".bx2"); Â Â Â Â Â Â Â Â bx2.style.backgroundColor = color2;Â Â Â Â Â </ script > </ body > Â Â </ html > |
Output: Note the difference between giving green color as the first parameter and white color as the first parameter.