From 3bf31e45d37356d42d2fd3a95c4f94ad2b6bc831 Mon Sep 17 00:00:00 2001 From: Will Charczuk Date: Sun, 24 Jul 2016 22:54:03 -0700 Subject: [PATCH] market hours range not quite working yet. --- grid_line.go | 9 +++++++-- market_hours_range.go | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/grid_line.go b/grid_line.go index d7d7781..63fafb6 100644 --- a/grid_line.go +++ b/grid_line.go @@ -2,7 +2,7 @@ package chart // GridLineProvider is a type that provides grid lines. 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. @@ -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 { var gl []GridLine isMinor := false - for _, t := range ticks { + + if len(ticks) < 3 { + return gl + } + + for _, t := range ticks[1 : len(ticks)-1] { s := majorStyle if isMinor { s = minorStyle diff --git a/market_hours_range.go b/market_hours_range.go index 7fbc098..e063435 100644 --- a/market_hours_range.go +++ b/market_hours_range.go @@ -108,9 +108,9 @@ func (mhr MarketHoursRange) String() string { // Translate maps a given value into the ContinuousRange space. func (mhr MarketHoursRange) Translate(value float64) int { valueTime := Float64ToTime(value) + valueTimeEastern := valueTime.In(date.Eastern()) 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)) return translated }