The diverging scales are very much similar to continuous scales. The only difference is that the output range of this scale is fixed by the interpolator thus the range is not configurable.
The diverging.interpolate() the function is used to configure the interpolator of the diverging scale. If the interpolator is not specified, it sets the interpolator of the scale to the specified function.
Syntax:
diverging.interpolator([interpolator]);
Parameters: This function accepts single parameter as mentioned above and described below:
- interpolator: This parameter accepts the interpolator function.
Return Values: This function does not return anything.
Below given are a few examples of the function given above.
Example 1:
<!DOCTYPE html> < html lang = "en" > < head > < meta charset = "UTF-8" /> < meta name = "viewport" path1tent=" width = device -width, initial-scale = 1 .0"/> < title >GeekforGeeks</ title > </ head > < style > </ style > < body > < h2 style = "color:green" > neveropen </ h2 > < h4 > D3.js | diverging.interpolator() Function </ h4 > < script > var diverging = d3.scaleDiverging() // Setting the interpolate function .interpolator(d3.interpolateRainbow); // Default domain is used i.e [0, 1] document.write( "< p >diverging(0.1): ", diverging(0.1) + "</ p >"); document.write( "< p >diverging(0.2): ", diverging(0.2) + "</ p >"); </ script > </ body > </ html > |
Output:
Example 2:
<!DOCTYPE html> < html lang = "en" > < head > < meta charset = "UTF-8" /> < meta name = "viewport" path1tent=" width = device -width, initial-scale = 1 .0"/> < title >GeekforGeeks</ title > </ head > < style > </ style > < body > < h2 style = "color:green" > neveropen </ h2 > < h4 > D3.js | diverging.interpolator() Function </ h4 > < script > var diverging = d3.scaleDiverging() // Setting the interpolate function .interpolator(d3.interpolateSpectral) // Setting up the domain .domain([1, 0.5, 10]); // Default domain is used i.e [0, 1] document.write( "< p >diverging(0.1): ", diverging(0.1) + "</ p >"); document.write( "< p >diverging(0.2): ", diverging(0.2) + "</ p >"); </ script > </ body > </ html > |
Output: