Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

all: remove descent padding from horizontal axis #780

Merged
merged 3 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion axis.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ type horizontalAxis struct {
// size returns the height of the axis.
func (a horizontalAxis) size() (h vg.Length) {
if a.Label.Text != "" { // We assume that the label isn't rotated.
h += a.Label.TextStyle.FontExtents().Descent
h += a.Label.TextStyle.Height(a.Label.Text)
h += a.Label.Padding
}
Expand Down
2 changes: 2 additions & 0 deletions cmpimg/checkplot.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ func goldenPath(path string) string {
// For image.Image formats, a base64 encoded png representation is output to
// the testing log when a difference is identified.
func CheckPlot(ExampleFunc func(), t *testing.T, filenames ...string) {
t.Helper()

CheckPlotApprox(ExampleFunc, t, 0, filenames...)
}

Expand Down
18 changes: 9 additions & 9 deletions palette/moreland/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ type rgb struct {
// cieXYZ returns a CIE XYZ color representation of the receiver.
func (c rgb) cieXYZ() cieXYZ {
return cieXYZ{
X: 0.4124*c.R + 0.3576*c.G + 0.1805*c.B,
Y: 0.2126*c.R + 0.7152*c.G + 0.0722*c.B,
Z: 0.0193*c.R + 0.1192*c.G + 0.9505*c.B,
X: float64(0.4124*c.R) + float64(0.3576*c.G) + float64(0.1805*c.B),
Y: float64(0.2126*c.R) + float64(0.7152*c.G) + float64(0.0722*c.B),
Z: float64(0.0193*c.R) + float64(0.1192*c.G) + float64(0.9505*c.B),
}
}

Expand All @@ -29,7 +29,7 @@ func (c rgb) sRGBA(alpha float64) sRGBA {
// f converts from a linear RGB component to an sRGB component.
f := func(v float64) float64 {
if v > 0.0031308 {
return 1.055*math.Pow(v, 1/2.4) - 0.055
return float64(1.055*math.Pow(v, 1/2.4)) - 0.055
}
return 12.92 * v
}
Expand All @@ -51,9 +51,9 @@ type cieXYZ struct {
// rgb returns a linear RGB representation of the receiver.
func (c cieXYZ) rgb() rgb {
return rgb{
R: c.X*3.2406 + c.Y*-1.5372 + c.Z*-0.4986,
G: c.X*-0.9689 + c.Y*1.8758 + c.Z*0.0415,
B: c.X*0.0557 + c.Y*-0.204 + c.Z*1.057,
R: float64(c.X*3.2406) + float64(c.Y*-1.5372) + float64(c.Z*-0.4986),
G: float64(c.X*-0.9689) + float64(c.Y*1.8758) + float64(c.Z*0.0415),
B: float64(c.X*0.0557) + float64(c.Y*-0.204) + float64(c.Z*1.057),
}
}

Expand All @@ -64,14 +64,14 @@ func (c cieXYZ) cieLAB() cieLAB {
if v > 0.008856 {
return math.Pow(v, 1.0/3.0)
}
return 7.787*v + 16.0/116.0
return float64(7.787*v) + float64(16.0/116.0)
}

tempX := f(c.X / 0.9505)
tempY := f(c.Y)
tempZ := f(c.Z / 1.089)
return cieLAB{
L: (116.0 * tempY) - 16.0,
L: float64(116.0*tempY) - 16.0,
A: 500.0 * (tempX - tempY),
B: 200 * (tempY - tempZ),
}
Expand Down
8 changes: 4 additions & 4 deletions palette/moreland/luminance.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ func (l *luminance) At(v float64) (color.Color, error) {
c2 := l.colors[i]
frac := (scalar - l.scalars[i-1]) / (l.scalars[i] - l.scalars[i-1])
o := cieLAB{
L: frac*(c2.L-c1.L) + c1.L,
A: frac*(c2.A-c1.A) + c1.A,
B: frac*(c2.B-c1.B) + c1.B,
L: float64(frac*(c2.L-c1.L)) + float64(c1.L),
A: float64(frac*(c2.A-c1.A)) + float64(c1.A),
B: float64(frac*(c2.B-c1.B)) + float64(c1.B),
}.cieXYZ().rgb().sRGBA(l.alpha)
o.clamp()
return o, nil
Expand Down Expand Up @@ -179,7 +179,7 @@ func (l luminance) Palette(n int) palette.Palette {
var v float64
c := make([]color.Color, n)
for i := 0; i < n; i++ {
v = l.min + delta*float64(i)
v = l.min + float64(delta*float64(i))
var err error
c[i], err = l.At(v)
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions palette/moreland/smooth.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,20 +145,20 @@ func (p *smoothDiverging) interpolateMSHDiverging(scalar, convergePoint float64)
// interpolation factor
interp := scalar / convergePoint
return msh{
M: (p.convergeM-p.start.M)*interp + p.start.M,
M: float64((p.convergeM-p.start.M)*interp) + p.start.M,
S: p.start.S * (1 - interp),
H: p.start.H + startHTwist*interp,
H: p.start.H + float64(startHTwist*interp),
}
}
// interpolation factors
interp1 := (scalar - 1) / (convergePoint - 1)
interp2 := (scalar/convergePoint - 1)
var H float64
if scalar > convergePoint {
H = p.end.H + endHTwist*interp1
H = p.end.H + float64(endHTwist*interp1)
}
return msh{
M: (p.convergeM-p.end.M)*interp1 + p.end.M,
M: float64((p.convergeM-p.end.M)*interp1) + p.end.M,
S: p.end.S * interp2,
H: H,
}
Expand All @@ -173,7 +173,7 @@ func (p smoothDiverging) Palette(n int) palette.Palette {
delta := (p.max - p.min) / float64(n-1)
c := make([]color.Color, n)
for i := range c {
v := p.min + delta*float64(i)
v := p.min + float64(delta*float64(i))
var err error
c[i], err = p.At(v)
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions plot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"image/color"
"math"
"os"
"runtime"
"testing"
"time"

Expand Down Expand Up @@ -182,9 +183,9 @@ func TestDrawGlyphBoxes(t *testing.T) {
t.Fatalf("error: %+v", err)
}

err = os.WriteFile("testdata/glyphbox.png", buf.Bytes(), 0644)
err = os.WriteFile("testdata/glyphbox_"+runtime.GOARCH+".png", buf.Bytes(), 0644)
if err != nil {
t.Fatalf("could not save plot: %+v", err)
}
}, t, "glyphbox.png")
}, t, "glyphbox_"+runtime.GOARCH+".png")
}
3 changes: 2 additions & 1 deletion plotter/barchart_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package plotter_test
import (
"image/color"
"log"
"runtime"

"golang.org/x/exp/rand"

Expand Down Expand Up @@ -43,7 +44,7 @@ func ExampleBarChart() {
}
p2.Add(horizontalBarChart)
p2.NominalY(horizontalLabels...)
err = p2.Save(100, 100, "testdata/horizontalBarChart.png")
err = p2.Save(100, 100, "testdata/horizontalBarChart_"+runtime.GOARCH+".png")
if err != nil {
log.Panic(err)
}
Expand Down
3 changes: 2 additions & 1 deletion plotter/barchart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
package plotter_test

import (
"runtime"
"testing"

"gonum.org/v1/plot/cmpimg"
)

func TestBarChart(t *testing.T) {
cmpimg.CheckPlot(ExampleBarChart, t, "verticalBarChart.png",
"horizontalBarChart.png", "barChart2.png",
"horizontalBarChart_"+runtime.GOARCH+".png", "barChart2.png",
"stackedBarChart.png")
}

Expand Down
5 changes: 3 additions & 2 deletions plotter/contour_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package plotter_test
import (
"log"
"math"
"runtime"
"testing"

"golang.org/x/exp/rand"
Expand Down Expand Up @@ -51,7 +52,7 @@ func ExampleContour() {

p.Add(c)

err := p.Save(10*vg.Centimeter, 10*vg.Centimeter, "testdata/contour.png")
err := p.Save(10*vg.Centimeter, 10*vg.Centimeter, "testdata/contour_"+runtime.GOARCH+".png")
if err != nil {
log.Fatalf("could not save plot: %+v", err)
}
Expand All @@ -77,5 +78,5 @@ func (g unitGrid) Y(r int) float64 {
}

func TestContour(t *testing.T) {
cmpimg.CheckPlotApprox(ExampleContour, t, 0.01, "contour.png")
cmpimg.CheckPlotApprox(ExampleContour, t, 0.01, "contour_"+runtime.GOARCH+".png")
}
7 changes: 4 additions & 3 deletions plotter/labels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package plotter_test

import (
"image/color"
"runtime"
"testing"

"gonum.org/v1/plot"
Expand Down Expand Up @@ -145,11 +146,11 @@ func TestLabelsWithGlyphBoxes(t *testing.T) {
p.Add(plotter.NewGrid())
p.Add(plotter.NewGlyphBoxes())

err = p.Save(10*vg.Centimeter, 10*vg.Centimeter, "testdata/labels_glyphboxes.png")
err = p.Save(10*vg.Centimeter, 10*vg.Centimeter, "testdata/labels_glyphboxes_"+runtime.GOARCH+".png")
if err != nil {
t.Fatalf("could save plot: %+v", err)
t.Fatalf("could not save plot: %+v", err)
}
},
t, "labels_glyphboxes.png",
t, "labels_glyphboxes_"+runtime.GOARCH+".png",
)
}
3 changes: 2 additions & 1 deletion plotter/precision_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package plotter_test

import (
"log"
"runtime"
"testing"

"gonum.org/v1/plot"
Expand All @@ -14,7 +15,7 @@ import (
)

func TestFloatPrecision(t *testing.T) {
const fname = "precision.png"
const fname = "precision_" + runtime.GOARCH + ".png"

cmpimg.CheckPlot(func() {
p := plot.New()
Expand Down
3 changes: 2 additions & 1 deletion plotter/rotation_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"image/color"
"log"
"math"
"runtime"

"gonum.org/v1/plot"
"gonum.org/v1/plot/plotter"
Expand Down Expand Up @@ -92,7 +93,7 @@ func Example_rotation() {
p.Y.Tick.Label.XAlign = draw.XCenter
p.Y.Tick.Label.YAlign = draw.YBottom

err = p.Save(200, 150, "testdata/rotation.png")
err = p.Save(200, 150, "testdata/rotation_"+runtime.GOARCH+".png")
if err != nil {
log.Panic(err)
}
Expand Down
3 changes: 2 additions & 1 deletion plotter/rotation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
package plotter_test

import (
"runtime"
"testing"

"gonum.org/v1/plot/cmpimg"
)

func TestRotation(t *testing.T) {
cmpimg.CheckPlot(Example_rotation, t, "rotation.png")
cmpimg.CheckPlot(Example_rotation, t, "rotation_"+runtime.GOARCH+".png")
}
3 changes: 2 additions & 1 deletion plotter/sankey_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"image/color"
"log"
"os"
"runtime"

"gonum.org/v1/plot"
"gonum.org/v1/plot/plotter"
Expand Down Expand Up @@ -396,7 +397,7 @@ func ExampleSankey_grouped() {

p.Draw(dc)
pngimg := vgimg.PngCanvas{Canvas: c}
f, err := os.Create("testdata/sankeyGrouped.png")
f, err := os.Create("testdata/sankeyGrouped_" + runtime.GOARCH + ".png")
if err != nil {
log.Panic(err)
}
Expand Down
3 changes: 2 additions & 1 deletion plotter/sankey_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package plotter_test

import (
"runtime"
"testing"

"gonum.org/v1/plot"
Expand All @@ -20,7 +21,7 @@ func TestSankey_simple(t *testing.T) {
}

func TestSankey_grouped(t *testing.T) {
cmpimg.CheckPlot(ExampleSankey_grouped, t, "sankeyGrouped.png")
cmpimg.CheckPlot(ExampleSankey_grouped, t, "sankeyGrouped_"+runtime.GOARCH+".png")
}

// This test checks whether the Sankey plotter makes any changes to
Expand Down
Binary file modified plotter/testdata/bubbles_golden.png
Loading
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/clippedFilledLine_golden.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added plotter/testdata/contour_amd64_golden.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added plotter/testdata/contour_arm64_golden.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed plotter/testdata/contour_golden.png
Binary file not shown.
Binary file modified plotter/testdata/filledLine_golden.png
Loading
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/functions_golden.png
Loading
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/histogram_logy_golden.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
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/horizontalBoxPlot_golden.png
Loading
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/horizontalQuartPlot_golden.png
Loading
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/invertedlogscale_golden.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
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/logscale_autorescale_golden.png
Loading
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/logscale_golden.png
Loading
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/polygon_hexagons_golden.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading