Skip to content

Commit

Permalink
fixing market hours
Browse files Browse the repository at this point in the history
  • Loading branch information
wcharczuk committed Jul 31, 2016
1 parent 200116c commit 6d2a61b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
8 changes: 1 addition & 7 deletions market_hours_range.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -115,6 +108,7 @@ func (mhr *MarketHoursRange) GetTicks(vf ValueFormatter) []Tick {
Label: vf(endMarketClose),
})
}

return ticks
}

Expand Down
2 changes: 1 addition & 1 deletion market_hours_range_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
28 changes: 21 additions & 7 deletions xaxis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 6d2a61b

Please sign in to comment.