Skip to content

Instantly share code, notes, and snippets.

@fgassert
Forked from mbostock/.block
Last active August 29, 2015 14:00

Revisions

  1. fgassert revised this gist Apr 25, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion index.html
    Original file line number Diff line number Diff line change
    @@ -25,7 +25,7 @@
    .domain(d3.keys(interpolators))
    .rangeRoundBands([0, height], .1);

    var values = d3.range(960 - 28);
    var values = d3.range(5);

    var x = d3.scale.ordinal()
    .domain(values)
  2. fgassert revised this gist Apr 25, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion index.html
    Original file line number Diff line number Diff line change
    @@ -33,7 +33,7 @@

    var color = d3.scale.linear()
    .domain([0, values.length - 1])
    .range(["hsl(62,100%,90%)", "hsl(228,30%,20%)"]);
    .range(["#ff1900", "#dddddd"]);

    var svg = d3.select("body").append("svg")
    .attr("width", width)
  3. @mbostock mbostock revised this gist Aug 23, 2013. 2 changed files with 2 additions and 2 deletions.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    D3 2.10 adds support for CIE [L\*a\*b\*](http://en.wikipedia.org/wiki/Lab_color_space) and [HCL](http://en.wikipedia.org/wiki/CIELUV). These perceptually-motivated color spaces are designed with humans (rather than computers) in mind. RGB and HSL interpolation can cause unintentional grouping due to parts of the color space appearing more visually similar; L\*a\*b\* and HCL, in contrast, are perceptually uniform. For more information, see Gregor Aisch’s post [How To Avoid Equidistant HSV Colors](http://vis4.net/blog/posts/avoid-equidistant-hsv-colors/) and Drew Skau’s post [Dear NASA: No More Rainbow Color Scales, Please](http://blog.visual.ly/rainbow-color-scales/).
    D3 support for CIE [L\*a\*b\*](http://en.wikipedia.org/wiki/Lab_color_space) and [HCL](http://en.wikipedia.org/wiki/CIELUV). These perceptually-motivated color spaces are designed with humans (rather than computers) in mind. RGB and HSL interpolation can cause unintentional grouping due to parts of the color space appearing more visually similar; L\*a\*b\* and HCL, in contrast, are perceptually uniform. For more information, see Gregor Aisch’s post [How To Avoid Equidistant HSV Colors](http://vis4.net/blog/posts/avoid-equidistant-hsv-colors/) and Drew Skau’s post [Dear NASA: No More Rainbow Color Scales, Please](http://blog.visual.ly/rainbow-color-scales/).

    You can create L\*a\*b\* or HCL colors directly using d3.lab or d3.hcl. For example:

    2 changes: 1 addition & 1 deletion index.html
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@

    </style>
    <body>
    <script src="http://d3js.org/d3.v2.min.js?2.10.0"></script>
    <script src="http://d3js.org/d3.v3.min.js"></script>
    <script>

    var interpolators = {
  4. @mbostock mbostock revised this gist Oct 12, 2012. 1 changed file with 0 additions and 0 deletions.
    Binary file added thumbnail.png
    Loading
    Sorry, something went wrong. Reload?
    Sorry, we cannot display this file.
    Sorry, this file is invalid so it cannot be displayed.
  5. @mbostock mbostock revised this gist Aug 10, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@ var steelblue = d3.lab(52, -4, -32);
    var steelblue = d3.hcl(-97, 32, 52);
    ```

    You can also convert from RGB or HSL. This is useful for creating brighter or darker colors, again with uniform changes in perception:
    You can also convert from RGB or HSL. This is useful for creating brighter or darker colors with uniform changes in perception:

    ```javascript
    var lightsteelblue = d3.lab("#4682b4").brighter();
  6. @mbostock mbostock revised this gist Aug 10, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    D3 2.10.0 adds support for CIE [L\*a\*b\*](http://en.wikipedia.org/wiki/Lab_color_space) and [HCL](http://en.wikipedia.org/wiki/CIELUV). These perceptually-motivated color spaces are designed with humans (rather than computers) in mind. RGB and HSL interpolation can cause unintentional grouping due to parts of the color space appearing more visually similar; L\*a\*b\* and HCL, in contrast, are perceptually uniform. For more information, see Gregor Aisch’s post [How To Avoid Equidistant HSV Colors](http://vis4.net/blog/posts/avoid-equidistant-hsv-colors/) and Drew Skau’s post [Dear NASA: No More Rainbow Color Scales, Please](http://blog.visual.ly/rainbow-color-scales/).
    D3 2.10 adds support for CIE [L\*a\*b\*](http://en.wikipedia.org/wiki/Lab_color_space) and [HCL](http://en.wikipedia.org/wiki/CIELUV). These perceptually-motivated color spaces are designed with humans (rather than computers) in mind. RGB and HSL interpolation can cause unintentional grouping due to parts of the color space appearing more visually similar; L\*a\*b\* and HCL, in contrast, are perceptually uniform. For more information, see Gregor Aisch’s post [How To Avoid Equidistant HSV Colors](http://vis4.net/blog/posts/avoid-equidistant-hsv-colors/) and Drew Skau’s post [Dear NASA: No More Rainbow Color Scales, Please](http://blog.visual.ly/rainbow-color-scales/).

    You can create L\*a\*b\* or HCL colors directly using d3.lab or d3.hcl. For example:

  7. @mbostock mbostock revised this gist Aug 10, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    D3 2.10.0 adds support for CIE [L\*a\*b\*](http://en.wikipedia.org/wiki/Lab_color_space) and [HCL](http://en.wikipedia.org/wiki/CIELUV). These perceptually-motiviated color spaces are designed with humans (rather than computers) in mind. RGB and HSL interpolation can cause unintentional grouping due to parts of the color space appearing more visually similar; L\*a\*b\* and HCL, in contrast, are perceptually uniform. For more information, see Gregor Aisch’s post [How To Avoid Equidistant HSV Colors](http://vis4.net/blog/posts/avoid-equidistant-hsv-colors/) and Drew Skau’s post [Dear NASA: No More Rainbow Color Scales, Please](http://blog.visual.ly/rainbow-color-scales/).
    D3 2.10.0 adds support for CIE [L\*a\*b\*](http://en.wikipedia.org/wiki/Lab_color_space) and [HCL](http://en.wikipedia.org/wiki/CIELUV). These perceptually-motivated color spaces are designed with humans (rather than computers) in mind. RGB and HSL interpolation can cause unintentional grouping due to parts of the color space appearing more visually similar; L\*a\*b\* and HCL, in contrast, are perceptually uniform. For more information, see Gregor Aisch’s post [How To Avoid Equidistant HSV Colors](http://vis4.net/blog/posts/avoid-equidistant-hsv-colors/) and Drew Skau’s post [Dear NASA: No More Rainbow Color Scales, Please](http://blog.visual.ly/rainbow-color-scales/).

    You can create L\*a\*b\* or HCL colors directly using d3.lab or d3.hcl. For example:

  8. @mbostock mbostock revised this gist Aug 10, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    D3 2.10.0 adds support for CIE [L\*a\*b\*](http://en.wikipedia.org/wiki/Lab_color_space) and [HCL](http://en.wikipedia.org/wiki/CIELUV). These perceptually-motiviated colors spaces are designed with humans (rather than computers) in mind. RGB and HSL interpolation can cause unintentional grouping due to parts of the color space appearing more visually similar; L\*a\*b\* and HCL, in contrast, are perceptually uniform. For more information, see Gregor Aisch’s post [How To Avoid Equidistant HSV Colors](http://vis4.net/blog/posts/avoid-equidistant-hsv-colors/) and Drew Skau’s post [Dear NASA: No More Rainbow Color Scales, Please](http://blog.visual.ly/rainbow-color-scales/).
    D3 2.10.0 adds support for CIE [L\*a\*b\*](http://en.wikipedia.org/wiki/Lab_color_space) and [HCL](http://en.wikipedia.org/wiki/CIELUV). These perceptually-motiviated color spaces are designed with humans (rather than computers) in mind. RGB and HSL interpolation can cause unintentional grouping due to parts of the color space appearing more visually similar; L\*a\*b\* and HCL, in contrast, are perceptually uniform. For more information, see Gregor Aisch’s post [How To Avoid Equidistant HSV Colors](http://vis4.net/blog/posts/avoid-equidistant-hsv-colors/) and Drew Skau’s post [Dear NASA: No More Rainbow Color Scales, Please](http://blog.visual.ly/rainbow-color-scales/).

    You can create L\*a\*b\* or HCL colors directly using d3.lab or d3.hcl. For example:

  9. @mbostock mbostock revised this gist Aug 10, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    D3 2.10.0 adds support for CIE [L\*a\*b\*](http://en.wikipedia.org/wiki/Lab_color_space) and [HCL](http://en.wikipedia.org/wiki/CIELUV). These colors spaces are designed with perception in mind. RGB and HSL interpolation can cause unintentional grouping due to parts of the color space appearing more visually similar; L\*a\*b\* and HCL, in contrast, are perceptually uniform. For more information, see Gregor Aisch’s post [How To Avoid Equidistant HSV Colors](http://vis4.net/blog/posts/avoid-equidistant-hsv-colors/) and Drew Skau’s post [Dear NASA: No More Rainbow Color Scales, Please](http://blog.visual.ly/rainbow-color-scales/).
    D3 2.10.0 adds support for CIE [L\*a\*b\*](http://en.wikipedia.org/wiki/Lab_color_space) and [HCL](http://en.wikipedia.org/wiki/CIELUV). These perceptually-motiviated colors spaces are designed with humans (rather than computers) in mind. RGB and HSL interpolation can cause unintentional grouping due to parts of the color space appearing more visually similar; L\*a\*b\* and HCL, in contrast, are perceptually uniform. For more information, see Gregor Aisch’s post [How To Avoid Equidistant HSV Colors](http://vis4.net/blog/posts/avoid-equidistant-hsv-colors/) and Drew Skau’s post [Dear NASA: No More Rainbow Color Scales, Please](http://blog.visual.ly/rainbow-color-scales/).

    You can create L\*a\*b\* or HCL colors directly using d3.lab or d3.hcl. For example:

  10. @mbostock mbostock revised this gist Aug 10, 2012. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions index.html
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@

    </style>
    <body>
    <script src="https://raw.github.com/mbostock/d3/2.10.0/d3.v2.min.js"></script>
    <script src="http://d3js.org/d3.v2.min.js?2.10.0"></script>
    <script>

    var interpolators = {
    @@ -62,4 +62,4 @@
    .attr("dy", ".35em")
    .text(function(d) { return d.key; });

    </script>
    </script>
  11. @mbostock mbostock revised this gist Aug 10, 2012. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,17 +1,17 @@
    D3 2.10.0 adds support for CIE [L\*a\*b\*](http://en.wikipedia.org/wiki/Lab_color_space) and [HCL](http://en.wikipedia.org/wiki/CIELUV). These colors spaces are designed with perception in mind. RGB and HSL interpolation can cause unintentional grouping due to parts of the color space appearing more visually similar; L\*a\*b\* and HCL, in contrast, are perceptually uniform. For more information, see Gregor Aisch’s post [How To Avoid Equidistant HSV Colors](http://vis4.net/blog/posts/avoid-equidistant-hsv-colors/) and Drew Skau’s post [Dear NASA: No More Rainbow Color Scales, Please](http://blog.visual.ly/rainbow-color-scales/).

    You can create L\*a\*b\* or HCL colors using d3.lab or d3.hcl. For example:
    You can create L\*a\*b\* or HCL colors directly using d3.lab or d3.hcl. For example:

    ```javascript
    var steelblue = d3.lab(52, -4, -32);
    var steelblue = d3.hcl(-97, 32, 52);
    ```

    You can also convert from RGB or HSL:
    You can also convert from RGB or HSL. This is useful for creating brighter or darker colors, again with uniform changes in perception:

    ```javascript
    var steelblue = d3.lab("#4682b4");
    var steelblue = d3.hcl("hsl(207, 44%, 49%)");
    var lightsteelblue = d3.lab("#4682b4").brighter();
    var darksteelblue = d3.hcl("hsl(207, 44%, 49%)").darker();
    ```

    Best of all, you can use d3.interpolateLab or d3.interpolateHcl in conjunction with [quantitative scales](https://github.com/mbostock/d3/wiki/Quantitative-Scales) and [transitions](https://github.com/mbostock/d3/wiki/Transitions):
  12. @mbostock mbostock revised this gist Aug 10, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    D3 2.10.0 adds support for CIE [L\*a\*b\*](http://en.wikipedia.org/wiki/Lab_color_space) and [HCL](http://en.wikipedia.org/wiki/CIELUV). These colors spaces are designed with perception in mind. RGB and HSL interpolation can cause unintentional grouping due to parts of the color space appearing more visually similar; L\*a\*b\* and HCL, in contrast, are perceptually-uniform. For more information, see Gregor Aisch’s post [How To Avoid Equidistant HSV Colors](http://vis4.net/blog/posts/avoid-equidistant-hsv-colors/) and Drew Skau’s post [Dear NASA: No More Rainbow Color Scales, Please](http://blog.visual.ly/rainbow-color-scales/).
    D3 2.10.0 adds support for CIE [L\*a\*b\*](http://en.wikipedia.org/wiki/Lab_color_space) and [HCL](http://en.wikipedia.org/wiki/CIELUV). These colors spaces are designed with perception in mind. RGB and HSL interpolation can cause unintentional grouping due to parts of the color space appearing more visually similar; L\*a\*b\* and HCL, in contrast, are perceptually uniform. For more information, see Gregor Aisch’s post [How To Avoid Equidistant HSV Colors](http://vis4.net/blog/posts/avoid-equidistant-hsv-colors/) and Drew Skau’s post [Dear NASA: No More Rainbow Color Scales, Please](http://blog.visual.ly/rainbow-color-scales/).

    You can create L\*a\*b\* or HCL colors using d3.lab or d3.hcl. For example:

  13. @mbostock mbostock revised this gist Aug 9, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -14,7 +14,7 @@ var steelblue = d3.lab("#4682b4");
    var steelblue = d3.hcl("hsl(207, 44%, 49%)");
    ```

    Best of all, you can use d3.interpolateLab or d3.interpolateHcl in conjunction with [quantitative scales](https://github.com/mbostock/d3/wiki/Quantitative-Scales) or with [transitions](https://github.com/mbostock/d3/wiki/Transitions):
    Best of all, you can use d3.interpolateLab or d3.interpolateHcl in conjunction with [quantitative scales](https://github.com/mbostock/d3/wiki/Quantitative-Scales) and [transitions](https://github.com/mbostock/d3/wiki/Transitions):

    ```javascript
    var color = d3.scale.linear()
  14. @mbostock mbostock revised this gist Aug 9, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -14,7 +14,7 @@ var steelblue = d3.lab("#4682b4");
    var steelblue = d3.hcl("hsl(207, 44%, 49%)");
    ```

    Best of all, you can use d3.interpolateLab or d3.interpolateHcl in conjunction with [quantitative scales](https://github.com/mbostock/d3/wiki/Quantitative-Scales):
    Best of all, you can use d3.interpolateLab or d3.interpolateHcl in conjunction with [quantitative scales](https://github.com/mbostock/d3/wiki/Quantitative-Scales) or with [transitions](https://github.com/mbostock/d3/wiki/Transitions):

    ```javascript
    var color = d3.scale.linear()
  15. @mbostock mbostock revised this gist Aug 9, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    D3 2.10.0 adds support for CIE [L\*a\*b\*](http://en.wikipedia.org/wiki/Lab_color_space) and [HCL](http://en.wikipedia.org/wiki/CIELUV). These colors spaces are designed with perception in mind. RGB and HSL interpolation can cause unintentional grouping due to parts of the color space appearing more visually similar. L\*a\*b\* and HCL, in contrast, are perceptually-uniform color spaces. For more information, see Gregor Aisch’s post [How To Avoid Equidistant HSV Colors](http://vis4.net/blog/posts/avoid-equidistant-hsv-colors/) and Drew Skau’s post [Dear NASA: No More Rainbow Color Scales, Please](http://blog.visual.ly/rainbow-color-scales/).
    D3 2.10.0 adds support for CIE [L\*a\*b\*](http://en.wikipedia.org/wiki/Lab_color_space) and [HCL](http://en.wikipedia.org/wiki/CIELUV). These colors spaces are designed with perception in mind. RGB and HSL interpolation can cause unintentional grouping due to parts of the color space appearing more visually similar; L\*a\*b\* and HCL, in contrast, are perceptually-uniform. For more information, see Gregor Aisch’s post [How To Avoid Equidistant HSV Colors](http://vis4.net/blog/posts/avoid-equidistant-hsv-colors/) and Drew Skau’s post [Dear NASA: No More Rainbow Color Scales, Please](http://blog.visual.ly/rainbow-color-scales/).

    You can create L\*a\*b\* or HCL colors using d3.lab or d3.hcl. For example:

  16. @mbostock mbostock revised this gist Aug 9, 2012. 1 changed file with 24 additions and 2 deletions.
    26 changes: 24 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,25 @@
    D3 2.10.0 adds support for CIE [L\*a\*b\*](http://en.wikipedia.org/wiki/Lab_color_space) and [HCL](http://en.wikipedia.org/wiki/CIELUV). These colors spaces are designed with perception in mind: unlike RGB and HSL interpolation which can cause banding, interpolating in L\*a\*b\* or HCL results in perceptually-uniform changes. For more on color spaces, see Gregor Aisch’s post [How To Avoid Equidistant HSV Colors](http://vis4.net/blog/posts/avoid-equidistant-hsv-colors/) and Drew Skau’s post [Dear NASA: No More Rainbow Color Scales, Please](http://blog.visual.ly/rainbow-color-scales/).
    D3 2.10.0 adds support for CIE [L\*a\*b\*](http://en.wikipedia.org/wiki/Lab_color_space) and [HCL](http://en.wikipedia.org/wiki/CIELUV). These colors spaces are designed with perception in mind. RGB and HSL interpolation can cause unintentional grouping due to parts of the color space appearing more visually similar. L\*a\*b\* and HCL, in contrast, are perceptually-uniform color spaces. For more information, see Gregor Aisch’s post [How To Avoid Equidistant HSV Colors](http://vis4.net/blog/posts/avoid-equidistant-hsv-colors/) and Drew Skau’s post [Dear NASA: No More Rainbow Color Scales, Please](http://blog.visual.ly/rainbow-color-scales/).

    Create L\*a\*b\* or HCL colors using d3.lab or d3.hcl.
    You can create L\*a\*b\* or HCL colors using d3.lab or d3.hcl. For example:

    ```javascript
    var steelblue = d3.lab(52, -4, -32);
    var steelblue = d3.hcl(-97, 32, 52);
    ```

    You can also convert from RGB or HSL:

    ```javascript
    var steelblue = d3.lab("#4682b4");
    var steelblue = d3.hcl("hsl(207, 44%, 49%)");
    ```

    Best of all, you can use d3.interpolateLab or d3.interpolateHcl in conjunction with [quantitative scales](https://github.com/mbostock/d3/wiki/Quantitative-Scales):

    ```javascript
    var color = d3.scale.linear()
    .range(["steelblue", "brown"])
    .interpolate(d3.interpolateHcl);
    ```

    L\*a\*b\* and HCL interpolation is a convenient way to implement color scales that are comparable in quality to [Colorbrewer](http://colorbrewer2.org/).
  17. @mbostock mbostock revised this gist Aug 9, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,3 @@
    D3 2.10.0 adds support for CIE [L\*a\*b\*](http://en.wikipedia.org/wiki/Lab_color_space) and [HCL](http://en.wikipedia.org/wiki/CIELUV). These colors spaces are designed with perception in mind: unlike RGB and HSL, interpolating in L\*a\*b\* or HCL results in perceptually-uniform changes in color. For more on color spaces, see Gregor Aisch’s post [How To Avoid Equidistant HSV Colors](http://vis4.net/blog/posts/avoid-equidistant-hsv-colors/) and Drew Skau’s post [Dear NASA: No More Rainbow Color Scales, Please](http://blog.visual.ly/rainbow-color-scales/).
    D3 2.10.0 adds support for CIE [L\*a\*b\*](http://en.wikipedia.org/wiki/Lab_color_space) and [HCL](http://en.wikipedia.org/wiki/CIELUV). These colors spaces are designed with perception in mind: unlike RGB and HSL interpolation which can cause banding, interpolating in L\*a\*b\* or HCL results in perceptually-uniform changes. For more on color spaces, see Gregor Aisch’s post [How To Avoid Equidistant HSV Colors](http://vis4.net/blog/posts/avoid-equidistant-hsv-colors/) and Drew Skau’s post [Dear NASA: No More Rainbow Color Scales, Please](http://blog.visual.ly/rainbow-color-scales/).

    Create L\*a\*b\* or HCL colors using d3.lab or d3.hcl.
  18. @mbostock mbostock revised this gist Aug 9, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,3 @@
    D3 2.10.0 adds support for CIE [L\*a\*b\*](http://en.wikipedia.org/wiki/Lab_color_space) and [HCL](http://en.wikipedia.org/wiki/CIELUV). These colors spaces are designed with perception in mind: unlike RGB and HSL, interpolating in L\*a\*\b\* or HCL results in perceptually-uniform changes in color. For more on color spaces, see Gregor Aisch’s post [How To Avoid Equidistant HSV Colors](http://vis4.net/blog/posts/avoid-equidistant-hsv-colors/) and Drew Skau’s post [Dear NASA: No More Rainbow Color Scales, Please](http://blog.visual.ly/rainbow-color-scales/).
    D3 2.10.0 adds support for CIE [L\*a\*b\*](http://en.wikipedia.org/wiki/Lab_color_space) and [HCL](http://en.wikipedia.org/wiki/CIELUV). These colors spaces are designed with perception in mind: unlike RGB and HSL, interpolating in L\*a\*b\* or HCL results in perceptually-uniform changes in color. For more on color spaces, see Gregor Aisch’s post [How To Avoid Equidistant HSV Colors](http://vis4.net/blog/posts/avoid-equidistant-hsv-colors/) and Drew Skau’s post [Dear NASA: No More Rainbow Color Scales, Please](http://blog.visual.ly/rainbow-color-scales/).

    Create L\*a\*b\* or HCL colors using d3.lab or d3.hcl.
  19. @mbostock mbostock revised this gist Aug 9, 2012. No changes.
  20. @mbostock mbostock revised this gist Aug 9, 2012. 3 changed files with 5 additions and 161 deletions.
    4 changes: 2 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,3 @@
    The above gradients compare interpolation in RGB, HSL, [CIE Lab](http://en.wikipedia.org/wiki/Lab_color_space) and [CIE LCh](http://en.wikipedia.org/wiki/CIELUV) color spaces. For more on color spaces, see Gregor Aisch’s post, [How To Avoid Equidistant HSV Colors](http://vis4.net/blog/posts/avoid-equidistant-hsv-colors/).
    D3 2.10.0 adds support for CIE [L\*a\*b\*](http://en.wikipedia.org/wiki/Lab_color_space) and [HCL](http://en.wikipedia.org/wiki/CIELUV). These colors spaces are designed with perception in mind: unlike RGB and HSL, interpolating in L\*a\*\b\* or HCL results in perceptually-uniform changes in color. For more on color spaces, see Gregor Aisch’s post [How To Avoid Equidistant HSV Colors](http://vis4.net/blog/posts/avoid-equidistant-hsv-colors/) and Drew Skau’s post [Dear NASA: No More Rainbow Color Scales, Please](http://blog.visual.ly/rainbow-color-scales/).

    This example is built with [D3](http://d3js.org). Code and documentation are available as the [d3.cie plugin](https://github.com/d3/d3-plugins/tree/master/cie).
    Create L\*a\*b\* or HCL colors using d3.lab or d3.hcl.
    155 changes: 0 additions & 155 deletions cie.js
    Original file line number Diff line number Diff line change
    @@ -1,155 +0,0 @@
    (function(d3) {
    var cie = d3.cie = {};

    cie.lab = function(l, a, b) {
    return arguments.length === 1
    ? (l instanceof Lab ? lab(l.l, l.a, l.b)
    : (l instanceof Lch ? lch_lab(l.l, l.c, l.h)
    : rgb_lab((l = d3.rgb(l)).r, l.g, l.b)))
    : lab(+l, +a, +b);
    };

    cie.lch = function(l, c, h) {
    return arguments.length === 1
    ? (l instanceof Lch ? lch(l.l, l.c, l.h)
    : (l instanceof Lab ? lab_lch(l.l, l.a, l.b)
    : lab_lch((l = rgb_lab((l = d3.rgb(l)).r, l.g, l.b)).l, l.a, l.b)))
    : lch(+l, +c, +h);
    };

    cie.interpolateLab = function(a, b) {
    a = cie.lab(a);
    b = cie.lab(b);
    var al = a.l,
    aa = a.a,
    ab = a.b,
    bl = b.l - al,
    ba = b.a - aa,
    bb = b.b - ab;
    return function(t) {
    return lab_rgb(al + bl * t, aa + ba * t, ab + bb * t) + "";
    };
    };

    cie.interpolateLch = function(a, b) {
    a = cie.lch(a);
    b = cie.lch(b);
    var al = a.l,
    ac = a.c,
    ah = a.h,
    bl = b.l - al,
    bc = b.c - ac,
    bh = b.h - ah;
    if (bh > 180) bh -= 360; else if (bh < -180) bh += 360; // shortest path
    return function(t) {
    return lch_lab(al + bl * t, ac + bc * t, ah + bh * t) + "";
    };
    };

    function lab(l, a, b) {
    return new Lab(l, a, b);
    }

    function Lab(l, a, b) {
    this.l = l;
    this.a = a;
    this.b = b;
    }

    Lab.prototype.brighter = function(k) {
    return lab(Math.min(100, this.l + K * (arguments.length ? k : 1)), this.a, this.b);
    };

    Lab.prototype.darker = function(k) {
    return lab(Math.max(0, this.l - K * (arguments.length ? k : 1)), this.a, this.b);
    };

    Lab.prototype.rgb = function() {
    return lab_rgb(this.l, this.a, this.b);
    };

    Lab.prototype.toString = function() {
    return this.rgb() + "";
    };

    function lch(l, c, h) {
    return new Lch(l, c, h);
    }

    function Lch(l, c, h) {
    this.l = l;
    this.c = c;
    this.h = h;
    }

    Lch.prototype.brighter = function(k) {
    return lch(Math.min(100, this.l + K * (arguments.length ? k : 1)), this.c, this.h);
    };

    Lch.prototype.darker = function(k) {
    return lch(Math.max(0, this.l - K * (arguments.length ? k : 1)), this.c, this.h);
    };

    Lch.prototype.rgb = function() {
    return lch_lab(this.l, this.c, this.h).rgb();
    };

    Lch.prototype.toString = function() {
    return this.rgb() + "";
    };

    // Corresponds roughly to RGB brighter/darker
    var K = 18;

    // D65 standard referent
    var X = 0.950470, Y = 1, Z = 1.088830;

    function lab_rgb(l, a, b) {
    var y = (l + 16) / 116, x = y + a / 500, z = y - b / 200;
    x = lab_xyz(x) * X;
    y = lab_xyz(y) * Y;
    z = lab_xyz(z) * Z;
    return d3.rgb(
    xyz_rgb( 3.2404542 * x - 1.5371385 * y - 0.4985314 * z),
    xyz_rgb(-0.9692660 * x + 1.8760108 * y + 0.0415560 * z),
    xyz_rgb( 0.0556434 * x - 0.2040259 * y + 1.0572252 * z)
    );
    }

    function rgb_lab(r, g, b) {
    r = rgb_xyz(r);
    g = rgb_xyz(g);
    b = rgb_xyz(b);
    var x = xyz_lab((0.4124564 * r + 0.3575761 * g + 0.1804375 * b) / X),
    y = xyz_lab((0.2126729 * r + 0.7151522 * g + 0.0721750 * b) / Y),
    z = xyz_lab((0.0193339 * r + 0.1191920 * g + 0.9503041 * b) / Z);
    return lab(116 * y - 16, 500 * (x - y), 200 * (y - z));
    }

    function lab_lch(l, a, b) {
    var c = Math.sqrt(a * a + b * b),
    h = Math.atan2(b, a) / Math.PI * 180;
    return lch(l, c, h);
    }

    function lch_lab(l, c, h) {
    h = h * Math.PI / 180;
    return lab(l, Math.cos(h) * c, Math.sin(h) * c);
    }

    function lab_xyz(x) {
    return x > 0.206893034 ? x * x * x : (x - 4 / 29) / 7.787037;
    }

    function xyz_lab(x) {
    return x > 0.008856 ? Math.pow(x, 1 / 3) : 7.787037 * x + 4 / 29;
    }

    function xyz_rgb(r) {
    return Math.round(255 * (r <= 0.00304 ? 12.92 * r : 1.055 * Math.pow(r, 1 / 2.4) - 0.055));
    }

    function rgb_xyz(r) {
    return (r /= 255) <= 0.04045 ? r / 12.92 : Math.pow((r + 0.055) / 1.055, 2.4);
    }
    })(d3);
    7 changes: 3 additions & 4 deletions index.html
    Original file line number Diff line number Diff line change
    @@ -8,14 +8,13 @@

    </style>
    <body>
    <script src="http://d3js.org/d3.v2.min.js?2.9.5"></script>
    <script src="cie.js"></script>
    <script src="https://raw.github.com/mbostock/d3/2.10.0/d3.v2.min.js"></script>
    <script>

    var interpolators = {
    "HSL": d3.interpolateHsl,
    "LCh": d3.cie.interpolateLch,
    "Lab": d3.cie.interpolateLab,
    "HCL": d3.interpolateHcl,
    "Lab": d3.interpolateLab,
    "RGB": d3.interpolateRgb
    };

  21. @mbostock mbostock revised this gist Jul 4, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion index.html
    Original file line number Diff line number Diff line change
    @@ -14,7 +14,7 @@

    var interpolators = {
    "HSL": d3.interpolateHsl,
    "LCH": d3.cie.interpolateLch,
    "LCh": d3.cie.interpolateLch,
    "Lab": d3.cie.interpolateLab,
    "RGB": d3.interpolateRgb
    };
  22. @mbostock mbostock revised this gist Jun 29, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,3 @@
    The above gradients compare interpolation in RGB, HSL, [CIE Lab](http://en.wikipedia.org/wiki/CIELUV) and [CIE LCh](http://en.wikipedia.org/wiki/CIELUV) color spaces. For more on color spaces, see Gregor Aisch’s post, [How To Avoid Equidistant HSV Colors](http://vis4.net/blog/posts/avoid-equidistant-hsv-colors/).
    The above gradients compare interpolation in RGB, HSL, [CIE Lab](http://en.wikipedia.org/wiki/Lab_color_space) and [CIE LCh](http://en.wikipedia.org/wiki/CIELUV) color spaces. For more on color spaces, see Gregor Aisch’s post, [How To Avoid Equidistant HSV Colors](http://vis4.net/blog/posts/avoid-equidistant-hsv-colors/).

    This example is built with [D3](http://d3js.org). Code and documentation are available as the [d3.cie plugin](https://github.com/d3/d3-plugins/tree/master/cie).
  23. @mbostock mbostock revised this gist Jun 29, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,3 @@
    The above gradients compare interpolation in RGB, HSL, CIE Lab and CIE LCh color spaces. For more on color spaces, see Gregor Aisch’s post, [How To Avoid Equidistant HSV Colors](http://vis4.net/blog/posts/avoid-equidistant-hsv-colors/).
    The above gradients compare interpolation in RGB, HSL, [CIE Lab](http://en.wikipedia.org/wiki/CIELUV) and [CIE LCh](http://en.wikipedia.org/wiki/CIELUV) color spaces. For more on color spaces, see Gregor Aisch’s post, [How To Avoid Equidistant HSV Colors](http://vis4.net/blog/posts/avoid-equidistant-hsv-colors/).

    This example is built with [D3](http://d3js.org). Code and documentation are available as the [d3.cie plugin](https://github.com/d3/d3-plugins/tree/master/cie).
  24. @mbostock mbostock revised this gist Jun 29, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,3 @@
    The above gradients compare interpolation in RGB, HSL, CIE Lab and CIE LCH color spaces. For more on color spaces, see Gregor Aisch’s post, [How To Avoid Equidistant HSV Colors](http://vis4.net/blog/posts/avoid-equidistant-hsv-colors/).
    The above gradients compare interpolation in RGB, HSL, CIE Lab and CIE LCh color spaces. For more on color spaces, see Gregor Aisch’s post, [How To Avoid Equidistant HSV Colors](http://vis4.net/blog/posts/avoid-equidistant-hsv-colors/).

    This example is built with [D3](http://d3js.org). Code and documentation are available as the [d3.cie plugin](https://github.com/d3/d3-plugins/tree/master/cie).
  25. @mbostock mbostock revised this gist Jun 29, 2012. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions index.html
    Original file line number Diff line number Diff line change
    @@ -12,8 +12,6 @@
    <script src="cie.js"></script>
    <script>

    var values = d3.range(960);

    var interpolators = {
    "HSL": d3.interpolateHsl,
    "LCH": d3.cie.interpolateLch,
    @@ -28,9 +26,11 @@
    .domain(d3.keys(interpolators))
    .rangeRoundBands([0, height], .1);

    var values = d3.range(960 - 28);

    var x = d3.scale.ordinal()
    .domain(values)
    .rangeRoundBands([0, width]);
    .rangeRoundBands([14, width - 14]);

    var color = d3.scale.linear()
    .domain([0, values.length - 1])
    @@ -58,7 +58,7 @@
    });

    g.append("text")
    .attr("x", 16)
    .attr("x", 28)
    .attr("y", y.rangeBand() / 2)
    .attr("dy", ".35em")
    .text(function(d) { return d.key; });
  26. @mbostock mbostock revised this gist Jun 29, 2012. 2 changed files with 4 additions and 3 deletions.
    1 change: 1 addition & 0 deletions cie.js
    Original file line number Diff line number Diff line change
    @@ -40,6 +40,7 @@
    bl = b.l - al,
    bc = b.c - ac,
    bh = b.h - ah;
    if (bh > 180) bh -= 360; else if (bh < -180) bh += 360; // shortest path
    return function(t) {
    return lch_lab(al + bl * t, ac + bc * t, ah + bh * t) + "";
    };
    6 changes: 3 additions & 3 deletions index.html
    Original file line number Diff line number Diff line change
    @@ -16,9 +16,9 @@

    var interpolators = {
    "HSL": d3.interpolateHsl,
    "RGB": d3.interpolateRgb,
    "LCH": d3.cie.interpolateLch,
    "Lab": d3.cie.interpolateLab,
    "LCH": d3.cie.interpolateLch
    "RGB": d3.interpolateRgb
    };

    var width = 960,
    @@ -34,7 +34,7 @@

    var color = d3.scale.linear()
    .domain([0, values.length - 1])
    .range(["#ffc", "#232842"]);
    .range(["hsl(62,100%,90%)", "hsl(228,30%,20%)"]);

    var svg = d3.select("body").append("svg")
    .attr("width", width)
  27. @mbostock mbostock revised this gist Jun 28, 2012. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,3 @@
    The above gradients compare interpolation in RGB, HSL, CIE Lab and CIE LCH color spaces.
    The above gradients compare interpolation in RGB, HSL, CIE Lab and CIE LCH color spaces. For more on color spaces, see Gregor Aisch’s post, [How To Avoid Equidistant HSV Colors](http://vis4.net/blog/posts/avoid-equidistant-hsv-colors/).

    Code and documentation are available as the [d3.cie plugin](https://github.com/d3/d3-plugins/tree/master/cie).
    This example is built with [D3](http://d3js.org). Code and documentation are available as the [d3.cie plugin](https://github.com/d3/d3-plugins/tree/master/cie).
  28. @mbostock mbostock revised this gist Jun 28, 2012. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions index.html
    Original file line number Diff line number Diff line change
    @@ -15,10 +15,10 @@
    var values = d3.range(960);

    var interpolators = {
    "hsl": d3.interpolateHsl,
    "rgb": d3.interpolateRgb,
    "lab": d3.cie.interpolateLab,
    "lch": d3.cie.interpolateLch
    "HSL": d3.interpolateHsl,
    "RGB": d3.interpolateRgb,
    "Lab": d3.cie.interpolateLab,
    "LCH": d3.cie.interpolateLch
    };

    var width = 960,
  29. @mbostock mbostock revised this gist Jun 28, 2012. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,3 @@
    This demonstration compares interpolation in RGB, HSL, CIE Lab and CIE LCH color spaces.
    The above gradients compare interpolation in RGB, HSL, CIE Lab and CIE LCH color spaces.

    The code is available as the [d3.cie plugin](https://github.com/d3/d3-plugins/tree/master/cie).
    Code and documentation are available as the [d3.cie plugin](https://github.com/d3/d3-plugins/tree/master/cie).
  30. @mbostock mbostock revised this gist Jun 28, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion index.html
    Original file line number Diff line number Diff line change
    @@ -26,7 +26,7 @@

    var y = d3.scale.ordinal()
    .domain(d3.keys(interpolators))
    .rangeRoundBands([0, height]);
    .rangeRoundBands([0, height], .1);

    var x = d3.scale.ordinal()
    .domain(values)