fixing market hours

This commit is contained in:
Will Charczuk 2016-07-30 21:34:41 -07:00
parent 200116c193
commit 6d2a61b790
3 changed files with 23 additions and 15 deletions

View file

@ -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
}

View file

@ -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)
}

View file

@ -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 {