market hours range not quite working yet.

This commit is contained in:
Will Charczuk 2016-07-24 22:54:03 -07:00
parent 50a798f67f
commit 3bf31e45d3
2 changed files with 9 additions and 4 deletions

View file

@ -2,7 +2,7 @@ package chart
// GridLineProvider is a type that provides grid lines. // GridLineProvider is a type that provides grid lines.
type GridLineProvider interface { type GridLineProvider interface {
GetGridLines(ticks []Tick, isVertical bool) []GridLine GetGridLines(ticks []Tick, isVertical bool, majorStyle, minorStyle Style) []GridLine
} }
// GridLine is a line on a graph canvas. // GridLine is a line on a graph canvas.
@ -62,7 +62,12 @@ func (gl GridLine) Render(r Renderer, canvasBox Box, ra Range, defaults Style) {
func GenerateGridLines(ticks []Tick, majorStyle, minorStyle Style, isVertical bool) []GridLine { func GenerateGridLines(ticks []Tick, majorStyle, minorStyle Style, isVertical bool) []GridLine {
var gl []GridLine var gl []GridLine
isMinor := false isMinor := false
for _, t := range ticks {
if len(ticks) < 3 {
return gl
}
for _, t := range ticks[1 : len(ticks)-1] {
s := majorStyle s := majorStyle
if isMinor { if isMinor {
s = minorStyle s = minorStyle

View file

@ -108,9 +108,9 @@ func (mhr MarketHoursRange) String() string {
// Translate maps a given value into the ContinuousRange space. // Translate maps a given value into the ContinuousRange space.
func (mhr MarketHoursRange) Translate(value float64) int { func (mhr MarketHoursRange) Translate(value float64) int {
valueTime := Float64ToTime(value) valueTime := Float64ToTime(value)
valueTimeEastern := valueTime.In(date.Eastern())
deltaSeconds := date.CalculateMarketSecondsBetween(mhr.Min, mhr.Max, mhr.MarketOpen, mhr.MarketClose, mhr.HolidayProvider) deltaSeconds := date.CalculateMarketSecondsBetween(mhr.Min, mhr.Max, mhr.MarketOpen, mhr.MarketClose, mhr.HolidayProvider)
valueDelta := date.CalculateMarketSecondsBetween(mhr.Min, valueTime, mhr.MarketOpen, mhr.MarketClose, mhr.HolidayProvider) valueDelta := date.CalculateMarketSecondsBetween(mhr.Min, valueTimeEastern, mhr.MarketOpen, mhr.MarketClose, mhr.HolidayProvider)
translated := int((float64(valueDelta) / float64(deltaSeconds)) * float64(mhr.Domain)) translated := int((float64(valueDelta) / float64(deltaSeconds)) * float64(mhr.Domain))
return translated return translated
} }