bug fixes and refinements.
This commit is contained in:
parent
52e80c183d
commit
debd56f494
|
@ -55,9 +55,9 @@ func TestAnnotationSeriesMeasure(t *testing.T) {
|
||||||
|
|
||||||
box := as.Measure(r, cb, xrange, yrange, sd)
|
box := as.Measure(r, cb, xrange, yrange, sd)
|
||||||
assert.False(box.IsZero())
|
assert.False(box.IsZero())
|
||||||
assert.Equal(-5.0, box.Top)
|
assert.Equal(-3.0, box.Top)
|
||||||
assert.Equal(5.0, box.Left)
|
assert.Equal(5.0, box.Left)
|
||||||
assert.Equal(146.0, box.Right) //the top,left annotation sticks up 5px and out ~44px.
|
assert.Equal(147.0, box.Right) //the top,left annotation sticks up 5px and out ~44px.
|
||||||
assert.Equal(115.0, box.Bottom)
|
assert.Equal(115.0, box.Bottom)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,10 +114,10 @@ func TestAnnotationSeriesRender(t *testing.T) {
|
||||||
assert.True(isRaster)
|
assert.True(isRaster)
|
||||||
assert.NotNil(rr)
|
assert.NotNil(rr)
|
||||||
|
|
||||||
c := rr.i.At(39, 70)
|
c := rr.i.At(38, 70)
|
||||||
converted, isRGBA := color.RGBAModel.Convert(c).(color.RGBA)
|
converted, isRGBA := color.RGBAModel.Convert(c).(color.RGBA)
|
||||||
assert.True(isRGBA)
|
assert.True(isRGBA)
|
||||||
assert.Equal(3, converted.R)
|
assert.Equal(0, converted.R)
|
||||||
assert.Equal(3, converted.G)
|
assert.Equal(0, converted.G)
|
||||||
assert.Equal(3, converted.B)
|
assert.Equal(0, converted.B)
|
||||||
}
|
}
|
||||||
|
|
15
chart.go
15
chart.go
|
@ -144,7 +144,7 @@ func (c Chart) getRanges() (xrange, yrange, yrangeAlt Range) {
|
||||||
} else {
|
} else {
|
||||||
xrange.Min = globalMinX
|
xrange.Min = globalMinX
|
||||||
xrange.Max = globalMaxX
|
xrange.Max = globalMaxX
|
||||||
xrange.Min, xrange.Max = xrange.GetRoundedRangeBounds()
|
//xrange.Min, xrange.Max = xrange.GetRoundedRangeBounds()
|
||||||
}
|
}
|
||||||
|
|
||||||
if !c.YAxis.Range.IsZero() {
|
if !c.YAxis.Range.IsZero() {
|
||||||
|
@ -285,11 +285,14 @@ func (c Chart) getAxisAdjustedCanvasBox(r Renderer, canvasBox Box, xr, yr, yra R
|
||||||
return newBox
|
return newBox
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Chart) setRangeDomains(canvasBox Box, xrange, yrange, yrangeAlt Range) (Range, Range, Range) {
|
func (c Chart) setRangeDomains(canvasBox Box, xr, yr, yra Range) (xr2, yr2, yra2 Range) {
|
||||||
xrange.Domain = canvasBox.Width
|
xr2.Min, xr2.Max = xr.Min, xr.Max
|
||||||
yrange.Domain = canvasBox.Height
|
xr2.Domain = canvasBox.Width
|
||||||
yrangeAlt.Domain = canvasBox.Height
|
yr2.Min, yr2.Max = yr.Min, yr.Max
|
||||||
return xrange, yrange, yrangeAlt
|
yr2.Domain = canvasBox.Height
|
||||||
|
yra2.Min, yra2.Max = yra.Min, yra.Max
|
||||||
|
yra2.Domain = canvasBox.Height
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Chart) hasAnnotationSeries() bool {
|
func (c Chart) hasAnnotationSeries() bool {
|
||||||
|
|
|
@ -8,8 +8,15 @@ import (
|
||||||
|
|
||||||
func TestRangeTranslate(t *testing.T) {
|
func TestRangeTranslate(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
values := []float64{1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0}
|
values := []float64{1.0, 2.0, 2.5, 2.7, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0}
|
||||||
r := Range{Domain: 1000}
|
r := Range{Domain: 1000}
|
||||||
r.Min, r.Max = MinAndMax(values...)
|
r.Min, r.Max = MinAndMax(values...)
|
||||||
assert.Equal(428, r.Translate(5.0))
|
|
||||||
|
// delta = ~7.0
|
||||||
|
// value = ~5.0
|
||||||
|
// domain = ~1000
|
||||||
|
// 5/8 * 1000 ~=
|
||||||
|
assert.Equal(0, r.Translate(1.0))
|
||||||
|
assert.Equal(1000, r.Translate(8.0))
|
||||||
|
assert.Equal(572, r.Translate(5.0))
|
||||||
}
|
}
|
||||||
|
|
2
tick.go
2
tick.go
|
@ -3,7 +3,7 @@ package chart
|
||||||
// GenerateTicksWithStep generates a set of ticks.
|
// GenerateTicksWithStep generates a set of ticks.
|
||||||
func GenerateTicksWithStep(ra Range, step float64, vf ValueFormatter) []Tick {
|
func GenerateTicksWithStep(ra Range, step float64, vf ValueFormatter) []Tick {
|
||||||
var ticks []Tick
|
var ticks []Tick
|
||||||
min, max := ra.GetRoundedRangeBounds()
|
min, max := ra.Min, ra.Max
|
||||||
for cursor := min; cursor <= max; cursor += step {
|
for cursor := min; cursor <= max; cursor += step {
|
||||||
ticks = append(ticks, Tick{
|
ticks = append(ticks, Tick{
|
||||||
Value: cursor,
|
Value: cursor,
|
||||||
|
|
|
@ -10,5 +10,5 @@ func TestGenerateTicksWithStep(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
ticks := GenerateTicksWithStep(Range{Min: 1.0, Max: 10.0, Domain: 100}, 1.0, FloatValueFormatter)
|
ticks := GenerateTicksWithStep(Range{Min: 1.0, Max: 10.0, Domain: 100}, 1.0, FloatValueFormatter)
|
||||||
assert.Len(ticks, 9)
|
assert.Len(ticks, 10)
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ func TestVectorRendererMeasureText(t *testing.T) {
|
||||||
vr.SetFont(f)
|
vr.SetFont(f)
|
||||||
vr.SetFontSize(12.0)
|
vr.SetFontSize(12.0)
|
||||||
|
|
||||||
w, h := vr.MeasureText("Ljp")
|
tb := vr.MeasureText("Ljp")
|
||||||
assert.Equal(21, w)
|
assert.Equal(21, tb.Width)
|
||||||
assert.Equal(15, h)
|
assert.Equal(15, tb.Height)
|
||||||
}
|
}
|
||||||
|
|
4
yaxis.go
4
yaxis.go
|
@ -122,10 +122,10 @@ func (ya YAxis) Render(r Renderer, canvasBox Box, ra Range, ticks []Tick) {
|
||||||
var tx int
|
var tx int
|
||||||
if ya.AxisType == YAxisPrimary {
|
if ya.AxisType == YAxisPrimary {
|
||||||
lx = canvasBox.Right
|
lx = canvasBox.Right
|
||||||
tx = canvasBox.Right + DefaultYAxisMargin
|
tx = lx + DefaultYAxisMargin
|
||||||
} else if ya.AxisType == YAxisSecondary {
|
} else if ya.AxisType == YAxisSecondary {
|
||||||
lx = canvasBox.Left
|
lx = canvasBox.Left
|
||||||
tx = canvasBox.Left - DefaultYAxisMargin
|
tx = lx - DefaultYAxisMargin
|
||||||
}
|
}
|
||||||
|
|
||||||
r.MoveTo(lx, canvasBox.Bottom)
|
r.MoveTo(lx, canvasBox.Bottom)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user