Skip to content

Commit cf1295d

Browse files
authored
Fix bar_plot log with log parameter (#110)
Fixes the following error. ``` Failure: test_bar_plot_log[adapter: :array, backend: :plotly](PlotMethodsBarPlotTest::rendering): Exception raised: ArgumentError(<comparison of Array with Array failed>) /Users/mrkn/src/github.com/red-data-tools/charty/lib/charty/plotters/bar_plotter.rb:97:in `min' /Users/mrkn/src/github.com/red-data-tools/charty/lib/charty/plotters/bar_plotter.rb:97:in `annotate_axes' /Users/mrkn/src/github.com/red-data-tools/charty/lib/charty/plotters/bar_plotter.rb:53:in `render_plot' /Users/mrkn/src/github.com/red-data-tools/charty/lib/charty/plotters/abstract_plotter.rb:260:in `call_render_plot' /Users/mrkn/src/github.com/red-data-tools/charty/lib/charty/plotters/abstract_plotter.rb:254:in `render' /Users/mrkn/src/github.com/red-data-tools/charty/test/helper.rb:212:in `render_plot' /Users/mrkn/src/github.com/red-data-tools/charty/test/plot_methods/bar_plot_test.rb:236:in `block in test_bar_plot_log' ```
1 parent 6068c73 commit cf1295d

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

charty.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Gem::Specification.new do |spec|
3333
spec.add_dependency "matplotlib", ">= 1.2.0"
3434
spec.add_dependency "pandas", ">= 0.3.5"
3535
spec.add_dependency "playwright-ruby-client"
36+
spec.add_dependency "pycall", ">= 1.5.2"
3637

3738
spec.add_development_dependency "bundler", ">= 1.16"
3839
spec.add_development_dependency "rake"

lib/charty/plotters/bar_plotter.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,21 @@ def log=(val)
9191
super
9292

9393
if self.log
94-
min_value, max_value = @estimations.minmax
9594
if @plot_colors
95+
min_value = @estimations.map(&:min).min
96+
max_value = @estimations.map(&:max).max
9697
unless @conf_int.empty?
97-
min_value = [min_value, @conf_int[0]].min
98-
max_value = [max_value, @conf_int[1]].max
98+
ci_min = @conf_int.map {|cis| cis.map {|ci| ci[0] }.min }.min
99+
ci_max = @conf_int.map {|cis| cis.map {|ci| ci[1] }.max }.max
100+
min_value = [min_value, ci_min].min
101+
max_value = [max_value, ci_max].max
99102
end
100103
else
104+
min_value, max_value = @estimations.minmax
101105
ci_min = Util.filter_map(@conf_int) { |ci| ci[0] unless ci.empty? }
102106
ci_max = Util.filter_map(@conf_int) { |ci| ci[1] unless ci.empty? }
103-
min_value = [min_value, ci_min.min].min unless ci_min.empty?
104-
max_value = [max_value, ci_max.max].max unless ci_max.empty?
107+
min_value = [min_value, *ci_min].min
108+
max_value = [max_value, *ci_max].max
105109
end
106110
if min_value > 1
107111
min_value = 0

test/plot_methods/bar_plot_test.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,26 @@ def test_bar_plot_sd(data)
226226
render_plot(backend_name, plot)
227227
end
228228
end
229+
230+
def test_bar_plot_log(data)
231+
adapter_name, backend_name = data.values_at(:adapter, :backend)
232+
setup_data(adapter_name)
233+
setup_backend(backend_name)
234+
plot = Charty.bar_plot(data: @data, x: :x, y: :y, log: true)
235+
assert_nothing_raised do
236+
render_plot(backend_name, plot)
237+
end
238+
end
239+
240+
def test_bar_plot_log_with_color(data)
241+
adapter_name, backend_name = data.values_at(:adapter, :backend)
242+
setup_data(adapter_name)
243+
setup_backend(backend_name)
244+
plot = Charty.bar_plot(data: @data, x: :x, y: :y, color: :c, log: true)
245+
assert_nothing_raised do
246+
render_plot(backend_name, plot)
247+
end
248+
end
229249
end
230250

231251
sub_test_case("with nonzero origin index") do # [GH-93]

0 commit comments

Comments
 (0)