diff --git a/_examples/basic/main.go b/_examples/basic/main.go index 215c4e4..1fd9d38 100644 --- a/_examples/basic/main.go +++ b/_examples/basic/main.go @@ -26,8 +26,8 @@ func drawChartWide(res http.ResponseWriter, req *http.Request) { Width: 1920, //this overrides the default. Series: []chart.Series{ chart.ContinuousSeries{ - XValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0}, - YValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0}, + XValues: []float64{1.0, 2.0, 3.0, 4.0}, + YValues: []float64{1.0, 2.0, 3.0, 4.0}, }, }, } diff --git a/_examples/scatter/main.go b/_examples/scatter/main.go index 06b89e0..de8ef3a 100644 --- a/_examples/scatter/main.go +++ b/_examples/scatter/main.go @@ -7,9 +7,15 @@ import ( _ "net/http/pprof" "github.com/wcharczuk/go-chart" + "github.com/wcharczuk/go-chart/drawing" ) func drawChart(res http.ResponseWriter, req *http.Request) { + + viridisByY := func(xr, yr chart.Range, x, y float64) drawing.Color { + return chart.Viridis(y, yr.GetMin(), yr.GetMax()) + } + graph := chart.Chart{ Series: []chart.Series{ chart.ContinuousSeries{ @@ -17,7 +23,7 @@ func drawChart(res http.ResponseWriter, req *http.Request) { Show: true, StrokeWidth: chart.Disabled, DotWidth: 5, - DotColorProvider: chart.Jet, + DotColorProvider: viridisByY, }, XValues: chart.Sequence.Random(128, 1024), YValues: chart.Sequence.Random(128, 1024), diff --git a/_examples/scatter/output.png b/_examples/scatter/output.png index 535e479..1f16d44 100644 Binary files a/_examples/scatter/output.png and b/_examples/scatter/output.png differ diff --git a/jet.go b/jet.go index 68d6f72..a948525 100644 --- a/jet.go +++ b/jet.go @@ -3,11 +3,7 @@ package chart import "github.com/wcharczuk/go-chart/drawing" // Jet is a color map provider based on matlab's jet color map. -func Jet(xr, yr Range, x, y float64) drawing.Color { - return getJetColour(y, yr.GetMin(), yr.GetMax()) -} - -func getJetColour(v, vmin, vmax float64) drawing.Color { +func Jet(v, vmin, vmax float64) drawing.Color { c := drawing.Color{R: 0xff, G: 0xff, B: 0xff, A: 0xff} // white var dv float64 diff --git a/style.go b/style.go index c51e1d2..72f2577 100644 --- a/style.go +++ b/style.go @@ -46,7 +46,7 @@ type Style struct { DotWidth float64 DotWidthProvider SizeProvider - DotColorProvider ColorProvider + DotColorProvider DotColorProvider FillColor drawing.Color diff --git a/value_provider.go b/value_provider.go index 98ea965..030e802 100644 --- a/value_provider.go +++ b/value_provider.go @@ -39,5 +39,8 @@ type FullBoundedValueProvider interface { // SizeProvider is a provider for integer size. type SizeProvider func(xrange, yrange Range, x, y float64) float64 -// ColorProvider is a provider for dot size. -type ColorProvider func(xrange, yrange Range, x, y float64) drawing.Color +// ColorProvider is a general provider for color ranges based on values. +type ColorProvider func(v, vmin, vmax float64) drawing.Color + +// DotColorProvider is a provider for dot color. +type DotColorProvider func(xrange, yrange Range, x, y float64) drawing.Color diff --git a/viridis.go b/viridis.go index 7db2bfb..e801537 100644 --- a/viridis.go +++ b/viridis.go @@ -262,8 +262,8 @@ var viridisColors = [256]drawing.Color{ } // Viridis creates a color map provider. -func Viridis(xr, yr Range, x, y float64) drawing.Color { - normalized := (y - yr.GetMin()) / yr.GetDelta() +func Viridis(v, vmin, vmax float64) drawing.Color { + normalized := (v - vmin) / (vmax - vmin) index := uint8(normalized * 255) return viridisColors[index] }