From 03ac3059512c83c673393b54de82db0403cda272 Mon Sep 17 00:00:00 2001 From: Will Charczuk Date: Sat, 15 Apr 2017 09:07:59 -0700 Subject: [PATCH] just passing the full range. --- _examples/scatter/main.go | 2 +- draw.go | 4 ++-- value_provider.go | 4 ++-- viridis.go | 7 +++++-- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/_examples/scatter/main.go b/_examples/scatter/main.go index 83650bb..71baaa2 100644 --- a/_examples/scatter/main.go +++ b/_examples/scatter/main.go @@ -16,7 +16,7 @@ func drawChart(res http.ResponseWriter, req *http.Request) { Style: chart.Style{ Show: true, StrokeWidth: chart.Disabled, - DotWidthProvider: func(rx, ry, x, y float64) float64 { return 10 * (y / ry) }, + DotWidthProvider: func(_, yr chart.Range, x, y float64) float64 { return 10 * (y / yr.GetDelta()) }, DotColorProvider: chart.Viridis, }, XValues: chart.Sequence.Random(128, 1024), diff --git a/draw.go b/draw.go index 6bfa90b..3f06cde 100644 --- a/draw.go +++ b/draw.go @@ -66,11 +66,11 @@ func (d draw) LineSeries(r Renderer, canvasBox Box, xrange, yrange Range, style dotWidth := defaultDotWidth if style.DotWidthProvider != nil { - dotWidth = style.DotWidthProvider(xrange.GetDelta(), yrange.GetDelta(), vx, vy) + dotWidth = style.DotWidthProvider(xrange, yrange, vx, vy) } if style.DotColorProvider != nil { - dotColor := style.DotColorProvider(xrange.GetDelta(), yrange.GetDelta(), vx, vy) + dotColor := style.DotColorProvider(xrange, yrange, vx, vy) r.SetFillColor(dotColor) r.SetStrokeColor(dotColor) diff --git a/value_provider.go b/value_provider.go index 143d63b..98ea965 100644 --- a/value_provider.go +++ b/value_provider.go @@ -37,7 +37,7 @@ type FullBoundedValueProvider interface { } // SizeProvider is a provider for integer size. -type SizeProvider func(rx, ry, x, y float64) float64 +type SizeProvider func(xrange, yrange Range, x, y float64) float64 // ColorProvider is a provider for dot size. -type ColorProvider func(rx, ry, x, y float64) drawing.Color +type ColorProvider func(xrange, yrange Range, x, y float64) drawing.Color diff --git a/viridis.go b/viridis.go index 1ec68a4..47f3bfb 100644 --- a/viridis.go +++ b/viridis.go @@ -266,7 +266,10 @@ var viridisColors = [256]drawing.Color{ } // Viridis creates a color map provider. -func Viridis(rx, ry, x, y float64) drawing.Color { - index := uint8((y / ry) * 256) +func Viridis(xr, yr Range, x, y float64) drawing.Color { + delta := yr.GetDelta() + normalized := y / delta + adjusted := normalized + yr.GetMin() + index := uint8(adjusted * 256) return viridisColors[index] }