Skip to content

Commit

Permalink
fix zero and negative value for grouped barcharts
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel-rubio committed Jan 25, 2024
1 parent bd9e0b6 commit 77f57e1
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/chart/barchart.ex
Original file line number Diff line number Diff line change
Expand Up @@ -504,12 +504,18 @@ defmodule Contex.BarChart do
end

defp prepare_bar_values(series_values, scale, :grouped) do
{scale_min, _} = Scale.get_range(scale)
scale_zero = Scale.domain_to_range(scale, 0.0)

results =
Enum.reduce(series_values, [], fn data_val, points ->
range_val = Scale.domain_to_range(scale, data_val)
[{scale_min, range_val} | points]
cond do
data_val != 0 ->
[{scale_zero, range_val} | points]

:else ->
[{scale_zero, scale_zero} | points]
end
end)

Enum.reverse(results)
Expand Down

0 comments on commit 77f57e1

Please sign in to comment.