From 4ef085e27b48eec782c291dee7ac53a8fa6193a4 Mon Sep 17 00:00:00 2001 From: skinnyfit Date: Mon, 9 Oct 2017 22:20:28 +0100 Subject: [PATCH] Support negative axes --- lib/squid/axis.rb | 1 + spec/axis_spec.rb | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/lib/squid/axis.rb b/lib/squid/axis.rb index 5f63c74..58016aa 100644 --- a/lib/squid/axis.rb +++ b/lib/squid/axis.rb @@ -46,6 +46,7 @@ def min def max if @data.any? && values.last && values.last.any? + return 0 if min < 0 && values.last.max <= 0 closest_step_to values.last.max end end diff --git a/spec/axis_spec.rb b/spec/axis_spec.rb index 754b22f..7c60bab 100644 --- a/spec/axis_spec.rb +++ b/spec/axis_spec.rb @@ -99,4 +99,29 @@ it { expect(width).to eq 14 } end end + + describe '#minmax' do + subject(:axis) { Squid::Axis.new series, options } + let(:minmax) { axis.minmax } + + describe 'given all-zero series' do + let(:series) { [0, 0, 0] } + it { expect(minmax).to eq [0, steps] } + end + + describe 'given positive series' do + let(:series) { [0, 10, 12] } + it { expect(minmax).to eq [0, 12] } + end + + describe 'given negative series' do + let(:series) { [0, -10, -12] } + it { expect(minmax).to eq [-12, 0] } + end + + describe 'given mixed series' do + let(:series) { [0, -10, 12] } + it { expect(minmax).to eq [-10, 12] } + end + end end