From 2dc8482db31a4f9ef63fe238484ab606aa16f9af Mon Sep 17 00:00:00 2001 From: Edwin Date: Mon, 16 Apr 2018 03:35:39 +0800 Subject: [PATCH 1/2] allow 'zero y-range delta' (#72) --- chart.go | 6 ------ chart_test.go | 16 ---------------- util/math.go | 6 ++++++ util/math_test.go | 2 ++ 4 files changed, 8 insertions(+), 22 deletions(-) diff --git a/chart.go b/chart.go index 83b70ec..1354bc0 100644 --- a/chart.go +++ b/chart.go @@ -317,9 +317,6 @@ func (c Chart) checkRanges(xr, yr, yra Range) error { if math.IsNaN(yDelta) { return errors.New("nan y-range delta") } - if yDelta == 0 { - return errors.New("zero y-range delta") - } if c.hasSecondarySeries() { yraDelta := yra.GetDelta() @@ -329,9 +326,6 @@ func (c Chart) checkRanges(xr, yr, yra Range) error { if math.IsNaN(yraDelta) { return errors.New("nan secondary y-range delta") } - if yraDelta == 0 { - return errors.New("zero secondary y-range delta") - } } return nil diff --git a/chart_test.go b/chart_test.go index 6adf62d..c7d089a 100644 --- a/chart_test.go +++ b/chart_test.go @@ -443,22 +443,6 @@ func TestChartCheckRanges(t *testing.T) { assert.Nil(c.checkRanges(xr, yr, yra)) } -func TestChartCheckRangesFailure(t *testing.T) { - assert := assert.New(t) - - c := Chart{ - Series: []Series{ - ContinuousSeries{ - XValues: []float64{1.0, 2.0}, - YValues: []float64{3.14, 3.14}, - }, - }, - } - - xr, yr, yra := c.getRanges() - assert.NotNil(c.checkRanges(xr, yr, yra)) -} - func TestChartCheckRangesWithRanges(t *testing.T) { assert := assert.New(t) diff --git a/util/math.go b/util/math.go index 73f4976..380a7f6 100644 --- a/util/math.go +++ b/util/math.go @@ -93,12 +93,18 @@ func (m mathUtil) GetRoundToForDelta(delta float64) float64 { // RoundUp rounds up to a given roundTo value. func (m mathUtil) RoundUp(value, roundTo float64) float64 { + if roundTo < 0.000000000000001 { + return value + } d1 := math.Ceil(value / roundTo) return d1 * roundTo } // RoundDown rounds down to a given roundTo value. func (m mathUtil) RoundDown(value, roundTo float64) float64 { + if roundTo < 0.000000000000001 { + return value + } d1 := math.Floor(value / roundTo) return d1 * roundTo } diff --git a/util/math_test.go b/util/math_test.go index 8306ae2..b143948 100644 --- a/util/math_test.go +++ b/util/math_test.go @@ -78,6 +78,7 @@ func TestRoundUp(t *testing.T) { assert.Equal(0.5, Math.RoundUp(0.49, 0.1)) assert.Equal(1.0, Math.RoundUp(0.51, 1.0)) assert.Equal(0.4999, Math.RoundUp(0.49988, 0.0001)) + assert.Equal(0.123, Math.RoundUp(0.123, 0)) } func TestRoundDown(t *testing.T) { @@ -85,6 +86,7 @@ func TestRoundDown(t *testing.T) { assert.Equal(0.5, Math.RoundDown(0.51, 0.1)) assert.Equal(1.0, Math.RoundDown(1.01, 1.0)) assert.Equal(0.5001, Math.RoundDown(0.50011, 0.0001)) + assert.Equal(0.123, Math.RoundDown(0.123, 0)) } func TestPercentDifference(t *testing.T) { From 62338336c37a94172eb910104db27a6d2d4af563 Mon Sep 17 00:00:00 2001 From: Nat Welch Date: Sun, 15 Apr 2018 15:36:03 -0400 Subject: [PATCH 2/2] Update .gitignore (#73) * Delete .DS_Store * Update .gitignore w/ common exclusions From https://github.com/github/gitignore/blob/master/Go.gitignore --- .DS_Store | Bin 8196 -> 0 bytes .gitignore | 17 +++++++++++++++++ 2 files changed, 17 insertions(+) delete mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 4680624dfd43e14eaa39036e6bf705ae350eddbd..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8196 zcmeHMO>7la6h7ahzziMefK@7X!oyPeNreK1LbUq&0}7P1p)D;x@|gE#prg~7@@8IJ zDAmTqm7;Nn5RFkcO57>vQr-BsFw%rT!bTUU3teEMB*u8|+<6W3Ct+a>hPlbT-@W&o zbAQf!_s*R6hzKo3YXeag5hg8O_kc3?1X(<)=lre(si3VtpT(T+14NucfIuZ{g z9!NZpcp&jW;(@!t1N_bwNtxxnFQrMDcp&k>J?Q~)KcqPe%)~e@F}gaqh(Z8H5duVs z>l_C}Ht85MF^)@&OnFQhJs>tk9AZG4vpg--88b1COO)mWX-^eb%)-H_%AUT8X=UARU4P_N@z{&0(5^sFEn zr_&7k*;Z9mMa}9}qobP}H`k>%H#UsbrAHeZ>+8}Do3@ONDaz8?4NW_b44gPQdTQ+X zH{|XR-w;$WWw&Q%-l`i6waTrgCQ4hqTH30*pj=yM?AqPFN9)MyONMwC9fP6cd%-@t z5HM!-ih%vFGw*wy1zX5_^S)ag@Pe$qIB&Z7qHBhBv+H&_CvEPl2=WErbvymQ5yR~7 z3+<6m$fk+<4g`K7Y>fuX>UuG-_u4#`Gi0~%h(VvjQwl>J>iI=Wm#1sZulg^8Ua8 zZ!w7bnp+Ixu$Z>p48o2<+v6pDDdy&_?cgQt7qVu{5(`plG6y6*YBHd}NJkwG(dVIO+Y2NOrp4+qa8zz9xa6sPbKUdCy>iq~)kZ{r=ji}&y$F5n_Q!Dsjm z-{TS{a1Gb-6Mn`oxPiY?b5jda@yC0r#QM(CHYBDh8D}`)%=-9%r_RmH`sy7|J-t)g zefP5d$|6bi`yW`Eu3fvnVcQcela!dkgIn1cQBZO$;$Dec(PO`j&=c}ZXv<6IW$NMR zVd~l=ia0^~e5w6#^-6_Vrz^6#s(OvW=R!|KO|7naoyzRj=Sb-WZIi-0*XK&<7HzA_ zCqXZh(#NzWg$b|ElTt%#R#ly3V^wvz`md4rYq~@~(64lZZqnbFhjLV51=e6awnfBk zMH_aY1D)85F7)6qvP|I|EDXTIAdWMQPhku%U>q+pjbDjq{5sC!9NxrROy~FU0nSg- z`BQw3ZNQ+nQ#$>PKwy{*Rb=Zx#Olf$ckH diff --git a/.gitignore b/.gitignore index 722d5e7..ab2dcb7 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,18 @@ +# Binaries for programs and plugins +*.exe +*.dll +*.so +*.dylib + +# Test binary, build with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736 +.glide/ + +# Other .vscode +.DS_Store