just passing the full range.

This commit is contained in:
Will Charczuk 2017-04-15 09:07:59 -07:00
parent 079c471daf
commit 03ac305951
4 changed files with 10 additions and 7 deletions

View File

@ -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),

View File

@ -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)

View File

@ -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

View File

@ -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]
}