The d3.hcl() function in D3.js is used to construct a new HCL color and returns HCL properties of the specified color taken as the parameter of the function.
Syntax:
d3.hcl(color);
Parameters: This function accepts single parameter color which is used to specify the CSS color.
Return Value: This function returns HCL properties of the specified CSS color taken as the parameter of the function.
Below programs illustrate the d3.hcl() function in D3.js:
Example 1:
<!DOCTYPE html> <html> <head> <title>d3.hcl() function </title> </head> <body> <script> // Calling the d3.hcl() function // with some parameters var color1 = d3.hcl( "red" ); var color2 = d3.hcl( "green" ); var color3 = d3.hcl( "blue" ); // Getting the HCL properties console.log(color1); console.log(color2); console.log(color3); </script> </body> </html> |
Output:
{"h":39.99901061253295,"c":104.55176567686985,"l":53.24079414130722,"opacity":1} {"h":136.01595303206318,"c":71.8500499715016,"l":46.22743146876261,"opacity":1} {"h":306.2849380699878,"c":133.80761485376166,"l":32.297010932850725,"opacity":1}
Example 2:
<!DOCTYPE html> <html> <head> <title>d3.hcl() function </title> </head> <body> <script> // Calling the d3.hcl() function // without any parameters var color = d3.hcl(); // Getting the HCL values console.log(color); </script> </body> </html> |
Output:
{"h":null,"c":null,"l":null,"opacity":1}
Reference: https://devdocs.io/d3~5/d3-color#hcl