Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BarChart 0 is not 0 #91

Open
Hermanverschooten opened this issue Jan 17, 2024 · 3 comments · May be fixed by #93
Open

BarChart 0 is not 0 #91

Hermanverschooten opened this issue Jan 17, 2024 · 3 comments · May be fixed by #93

Comments

@Hermanverschooten
Copy link

I just made my first grouped BarChart and I immediately noticed an oddity.
I have 2 series and I had 1 value in a serie that was below 0.
This causes all the bars that are 0 to display a bar from the bottom up to 0.
297056045-3633c82f-8993-4183-aab1-1843a5061e78

In a regular barchart, 0 would always be the baseline and the negative would be shown below it.

@mindok
Copy link
Owner

mindok commented Jan 19, 2024

Thanks @Hermanverschooten - I'll take a look. I think the way the x-axis is drawn may require a bit of code shuffling to solve this.

@manuel-rubio
Copy link

I experience the same problem, while I was expecting the graph to do this:
image
It was doing this:
image

@manuel-rubio
Copy link

As far as I can see... in addition to 0 being 0, the negative numbers are linked to a minimum as you can see in my previous message, I think it's starting here:

https://github.com/mindok/contex/blob/master/lib/chart/barchart.ex#L507-L513

It could be changed for this code:

    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)
        cond do
          data_val != 0 ->
            [{scale_zero, range_val} | points]

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

And it worked for me:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants