diff --git a/market_hours_range.go b/market_hours_range.go index ee24c72..7ad2e52 100644 --- a/market_hours_range.go +++ b/market_hours_range.go @@ -90,13 +90,6 @@ func (mhr *MarketHoursRange) GetTicks(vf ValueFormatter) []Tick { cursor := date.On(mhr.MarketClose, mhr.Min) maxClose := date.On(mhr.MarketClose, mhr.Max) - if mhr.Min.Before(cursor) { - ticks = append(ticks, Tick{ - Value: TimeToFloat64(cursor), - Label: vf(cursor), - }) - } - for date.BeforeDate(cursor, maxClose) { if date.IsWeekDay(cursor.Weekday()) && !mhr.GetHolidayProvider()(cursor) { ticks = append(ticks, Tick{ @@ -115,6 +108,7 @@ func (mhr *MarketHoursRange) GetTicks(vf ValueFormatter) []Tick { Label: vf(endMarketClose), }) } + return ticks } diff --git a/market_hours_range_test.go b/market_hours_range_test.go index c2eaa3d..8698b36 100644 --- a/market_hours_range_test.go +++ b/market_hours_range_test.go @@ -55,7 +55,7 @@ func TestMarketHoursRangeGetTicks(t *testing.T) { ticks := r.GetTicks(TimeValueFormatter) assert.NotEmpty(ticks) - assert.Len(ticks, 6) + assert.Len(ticks, 5) assert.NotEqual(TimeToFloat64(r.Min), ticks[0].Value) assert.NotEmpty(ticks[0].Label) } diff --git a/xaxis.go b/xaxis.go index 4db68c1..5855c12 100644 --- a/xaxis.go +++ b/xaxis.go @@ -67,21 +67,36 @@ func (xa XAxis) GetGridLines(ticks []Tick) []GridLine { // Measure returns the bounds of the axis. func (xa XAxis) Measure(r Renderer, canvasBox Box, ra Range, defaults Style, ticks []Tick) Box { - xa.Style.InheritFrom(defaults).WriteToRenderer(r) + tickStyle := xa.Style.InheritFrom(defaults) sort.Sort(Ticks(ticks)) + tp := xa.GetTickPosition() + var left, right, top, bottom = math.MaxInt32, 0, math.MaxInt32, 0 - for _, t := range ticks { + for index, t := range ticks { v := t.Value - lx := ra.Translate(v) + tickStyle.GetTextOptions().WriteToRenderer(r) tb := r.MeasureText(t.Label) - tx := canvasBox.Left + lx + var ltx, rtx int + tx := ra.Translate(v) ty := canvasBox.Bottom + DefaultXAxisMargin + tb.Height() + switch tp { + case TickPositionUnderTick, TickPositionUnset: + ltx = tx - tb.Width()>>1 + rtx = tx + tb.Width()>>1 + break + case TickPositionBetweenTicks: + if index > 0 { + ltx = ra.Translate(ticks[index-1].Value) + rtx = tx + } + break + } top = Math.MinInt(top, canvasBox.Bottom) - left = Math.MinInt(left, tx-(tb.Width()>>1)) - right = Math.MaxInt(right, tx+(tb.Width()>>1)) + left = Math.MinInt(left, ltx) + right = Math.MaxInt(right, rtx) bottom = Math.MaxInt(bottom, ty) } @@ -139,7 +154,6 @@ func (xa XAxis) Render(r Renderer, canvasBox Box, ra Range, defaults Style, tick } break } - } if xa.GridMajorStyle.Show || xa.GridMinorStyle.Show {