@@ -328,7 +328,7 @@ hcl =
328328-}
329329hclLong : Color -> Color -> Interpolator Color
330330hclLong =
331- hclImpl float
331+ hclImpl labChannel
332332
333333
334334{- | We do not want negative values in an rgb color
@@ -354,25 +354,51 @@ hclImpl hueInt from to =
354354 in
355355 map4 ( \ h c l alpha -> Lab . fromHcl { hue = h, chroma = c, luminance = l, alpha = alpha } )
356356 ( hueInt start. hue end. hue)
357- ( float start. chroma end. chroma)
358- ( float start. luminance end. luminance)
359- ( float start. alpha end. alpha)
357+ ( labChannel start. chroma end. chroma)
358+ ( labChannel start. luminance end. luminance)
359+ ( labChannel start. alpha end. alpha)
360360 >> forcePositive
361361
362362
363+ {- | Interpolates a single Lab/Hcl color channel. Mirrors d3-interpolate's
364+ color-channel interpolator (`nogamma`): if either endpoint is undefined (`NaN` —
365+ as happens for the hue of any grey, or the chroma of pure black/white), the
366+ channel holds the defined endpoint constant rather than letting the `NaN`
367+ propagate across the whole gradient. Without this, a single grey endpoint turns
368+ an entire HCL gradient grey (issue #151).
369+ -}
370+ labChannel : Float -> Float -> Interpolator Float
371+ labChannel from to =
372+ if isNaN from then
373+ always to
374+
375+ else if isNaN to then
376+ always from
377+
378+ else
379+ float from to
380+
381+
363382hue : Float -> Float -> Interpolator Float
364383hue from to =
365- let
366- d =
367- to - from
368- in
369- float from
370- ( if d > 0.5 || d < - 0.5 then
371- from + ( d - toFloat ( round d))
384+ if isNaN from then
385+ always to
386+
387+ else if isNaN to then
388+ always from
389+
390+ else
391+ let
392+ d =
393+ to - from
394+ in
395+ float from
396+ ( if d > 0.5 || d < - 0.5 then
397+ from + ( d - toFloat ( round d))
372398
373- else
374- to
375- )
399+ else
400+ to
401+ )
376402
377403
378404hue360 : Float -> Float -> Interpolator Float
0 commit comments