@@ -333,7 +333,7 @@ hcl =
333333-}
334334hclLong : Color -> Color -> Interpolator Color
335335hclLong =
336- hclImpl float
336+ hclImpl labChannel
337337
338338
339339{- | We do not want negative values in an rgb color
@@ -359,25 +359,51 @@ hclImpl hueInt from to =
359359 in
360360 map4 ( \ h c l alpha -> Lab . fromHcl { hue = h, chroma = c, luminance = l, alpha = alpha } )
361361 ( hueInt start. hue end. hue)
362- ( float start. chroma end. chroma)
363- ( float start. luminance end. luminance)
364- ( float start. alpha end. alpha)
362+ ( labChannel start. chroma end. chroma)
363+ ( labChannel start. luminance end. luminance)
364+ ( labChannel start. alpha end. alpha)
365365 >> forcePositive
366366
367367
368+ {- | Interpolates a single Lab/Hcl color channel. Mirrors d3-interpolate's
369+ color-channel interpolator (`nogamma`): if either endpoint is undefined (`NaN` —
370+ as happens for the hue of any grey, or the chroma of pure black/white), the
371+ channel holds the defined endpoint constant rather than letting the `NaN`
372+ propagate across the whole gradient. Without this, a single grey endpoint turns
373+ an entire HCL gradient grey (issue #151).
374+ -}
375+ labChannel : Float -> Float -> Interpolator Float
376+ labChannel from to =
377+ if isNaN from then
378+ always to
379+
380+ else if isNaN to then
381+ always from
382+
383+ else
384+ float from to
385+
386+
368387hue : Float -> Float -> Interpolator Float
369388hue from to =
370- let
371- d =
372- to - from
373- in
374- float from
375- ( if d > 0.5 || d < - 0.5 then
376- from + ( d - toFloat ( round d))
389+ if isNaN from then
390+ always to
377391
378- else
379- to
380- )
392+ else if isNaN to then
393+ always from
394+
395+ else
396+ let
397+ d =
398+ to - from
399+ in
400+ float from
401+ ( if d > 0.5 || d < - 0.5 then
402+ from + ( d - toFloat ( round d))
403+
404+ else
405+ to
406+ )
381407
382408
383409hue360 : Float -> Float -> Interpolator Float
0 commit comments