just passing the full range.
This commit is contained in:
parent
079c471daf
commit
03ac305951
4 changed files with 10 additions and 7 deletions
|
@ -16,7 +16,7 @@ func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||||
Style: chart.Style{
|
Style: chart.Style{
|
||||||
Show: true,
|
Show: true,
|
||||||
StrokeWidth: chart.Disabled,
|
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,
|
DotColorProvider: chart.Viridis,
|
||||||
},
|
},
|
||||||
XValues: chart.Sequence.Random(128, 1024),
|
XValues: chart.Sequence.Random(128, 1024),
|
||||||
|
|
4
draw.go
4
draw.go
|
@ -66,11 +66,11 @@ func (d draw) LineSeries(r Renderer, canvasBox Box, xrange, yrange Range, style
|
||||||
|
|
||||||
dotWidth := defaultDotWidth
|
dotWidth := defaultDotWidth
|
||||||
if style.DotWidthProvider != nil {
|
if style.DotWidthProvider != nil {
|
||||||
dotWidth = style.DotWidthProvider(xrange.GetDelta(), yrange.GetDelta(), vx, vy)
|
dotWidth = style.DotWidthProvider(xrange, yrange, vx, vy)
|
||||||
}
|
}
|
||||||
|
|
||||||
if style.DotColorProvider != nil {
|
if style.DotColorProvider != nil {
|
||||||
dotColor := style.DotColorProvider(xrange.GetDelta(), yrange.GetDelta(), vx, vy)
|
dotColor := style.DotColorProvider(xrange, yrange, vx, vy)
|
||||||
|
|
||||||
r.SetFillColor(dotColor)
|
r.SetFillColor(dotColor)
|
||||||
r.SetStrokeColor(dotColor)
|
r.SetStrokeColor(dotColor)
|
||||||
|
|
|
@ -37,7 +37,7 @@ type FullBoundedValueProvider interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SizeProvider is a provider for integer size.
|
// 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.
|
// 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
|
||||||
|
|
|
@ -266,7 +266,10 @@ var viridisColors = [256]drawing.Color{
|
||||||
}
|
}
|
||||||
|
|
||||||
// Viridis creates a color map provider.
|
// Viridis creates a color map provider.
|
||||||
func Viridis(rx, ry, x, y float64) drawing.Color {
|
func Viridis(xr, yr Range, x, y float64) drawing.Color {
|
||||||
index := uint8((y / ry) * 256)
|
delta := yr.GetDelta()
|
||||||
|
normalized := y / delta
|
||||||
|
adjusted := normalized + yr.GetMin()
|
||||||
|
index := uint8(adjusted * 256)
|
||||||
return viridisColors[index]
|
return viridisColors[index]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue