Skip to content

Commit

Permalink
Respond to comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ctessum committed Mar 8, 2018
1 parent 3ab221a commit 43e6beb
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 12 deletions.
7 changes: 6 additions & 1 deletion plotter/colorbar_test.go
Expand Up @@ -5,6 +5,7 @@
package plotter

import (
"image/color"
"log"
"testing"

Expand Down Expand Up @@ -41,7 +42,11 @@ func ExampleColorBar_horizontal_log() {
if err != nil {
log.Panic(err)
}
l := &ColorBar{ColorMap: moreland.ExtendedBlackBody()}
colorMap, err := moreland.NewLuminance([]color.Color{color.Black, color.White})
if err != nil {
log.Panic(err)
}
l := &ColorBar{ColorMap: colorMap}
l.ColorMap.SetMin(1)
l.ColorMap.SetMax(100)
p.Add(l)
Expand Down
23 changes: 13 additions & 10 deletions plotter/image.go
Expand Up @@ -56,7 +56,7 @@ func (img *Image) Plot(c draw.Canvas, p *plot.Plot) {
Min: vg.Point{X: xmin, Y: ymin},
Max: vg.Point{X: xmax, Y: ymax},
}
c.DrawImage(rect, img.transform(p))
c.DrawImage(rect, img.transformFor(p))
}

// DataRange implements the DataRange method
Expand All @@ -72,7 +72,7 @@ func (img *Image) GlyphBoxes(plt *plot.Plot) []plot.GlyphBox {
}

// transform warps the image to align with non-linear axes.
func (img *Image) transform(p *plot.Plot) image.Image {
func (img *Image) transformFor(p *plot.Plot) image.Image {
_, xLinear := p.X.Scale.(plot.LinearScale)
_, yLinear := p.Y.Scale.(plot.LinearScale)
if xLinear && yLinear {
Expand All @@ -81,21 +81,24 @@ func (img *Image) transform(p *plot.Plot) image.Image {
b := img.img.Bounds()
o := image.NewNRGBA64(b)
for c := 0; c < img.cols; c++ {
// Find the equivalent image column after applying axis transforms.
cTrans := int(p.X.Norm(img.x(c)) * float64(img.cols))
// Find the equivalent column of the previous image column after applying
// axis transforms.
cPrevTrans := int(p.X.Norm(img.x(maxInt(c-1, 0))) * float64(img.cols))
for r := 0; r < img.rows; r++ {
// Find the equivalent image row and column after applying
// the axis transforms.
cTrans := int(p.X.Norm(img.x(c)) * float64(img.cols))
// Find the equivalent image row after applying axis transforms.
rTrans := int(p.Y.Norm(img.y(r)) * float64(img.rows))
// Find the equivalent row and column of the previous image row
// and column after applying the axis transforms.
cPrevTrans := int(p.X.Norm(img.x(maxInt(c-1, 0))) * float64(img.cols))
// Find the equivalent row of the previous image row after applying
// axis transforms.
rPrevTrans := int(p.Y.Norm(img.y(maxInt(r-1, 0))) * float64(img.rows))
crColor := img.img.At(c, r)
crColor := img.img.At(c, img.rows-r-1)
// Set all the pixels in the new image between (cPrevTrans, rPrevTrans)
// and (cTrans, rTrans) to the color at (c,r) in the original image.
// TODO: Improve interpolation.
for cPrime := cPrevTrans; cPrime <= cTrans; cPrime++ {
for rPrime := rPrevTrans; rPrime <= rTrans; rPrime++ {
o.Set(cPrime, rPrime, crColor)
o.Set(cPrime, img.rows-rPrime-1, crColor)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion plotter/image_test.go
Expand Up @@ -63,7 +63,7 @@ func ExampleImage_log() {
p.Title.Text = "A Logo"

// load an image
f, err := os.Open("testdata/image_plot_input.png")
f, err := os.Open("../../gonum/gopher.png")
if err != nil {
log.Fatalf("error opening image file: %v\n", err)
}
Expand Down
Binary file modified plotter/testdata/colorBarHorizontalLog_golden.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified plotter/testdata/image_plot_log_golden.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 43e6beb

Please sign in to comment.