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

inconsistency in the scaling of the y-axes #3691

Open
michkami opened this issue Mar 12, 2024 · 4 comments
Open

inconsistency in the scaling of the y-axes #3691

michkami opened this issue Mar 12, 2024 · 4 comments
Labels

Comments

@michkami
Copy link
Collaborator

michkami commented Mar 12, 2024

Description

In the example below we have 3 data rows.
Data1 and Data2 are grouped and assigned to the y-Axis.
Data3 is assigned to the y2-Axis.
When setting bar.zerobased: false it results in following chart:
grafik

I would expect the y2-Axis to be also scaled like the y-Axis, as all values on this axis are positive too.
I see no reason here to treat the y2-axis differently from the y-axis in this case.

The same happens when the data is not grouped at all:
grafik
In this case data3 on y2-axis is not scaled.

Using bar.zerobased: true leads to following and correct result:
grafik

Removing data2 from the chart and setting bar.zerobased: false results in this chart:
grafik
Here I would also expect for both axes to be scaled like the Y-Axis in Screenshot 1 (the stacked bars)

bar.zerobased: true scales as expected:
grafik

Having 2 grouped data rows on each axis results in both being scaled correctly:
grafik

Same with all 4 data rows being not grouped:
grafik

Overall, it seems like there is an inconsistency how the grouped data affects the scaling of the y-axes. It seems like you need at least 2 data rows per group for the scaling to work as expected.

Is the "wrong" behavior I described above the expected behavior, or can we classify this as a bug?

Steps to check or reproduce

https://jsfiddle.net/michkami/a9uzyrs8/

@netil
Copy link
Member

netil commented Mar 18, 2024

@michkami
When there're 2 or more values aligned to single axis(y or y2), the domain range will set according it.

Let's say, given values are 300 and 500, in this case, min=300 and max=500.
But when single value (ex. 500) is given, can't determine min/max, because there's no data to determine or compare.

So, in this case min will be set as 0 and max 500.
https://github.com/naver/billboard.js/blob/master/src/ChartInternal/internals/domain.ts#L136

@michkami
Copy link
Collaborator Author

michkami commented Mar 19, 2024

@michkami When there're 2 or more values aligned to single axis(y or y2), the domain range will set according it.

Let's say, given values are 300 and 500, in this case, min=300 and max=500. But when single value (ex. 500) is given, can't determine min/max, because there's no data to determine or compare.

So, in this case min will be set as 0 and max 500. https://github.com/naver/billboard.js/blob/master/src/ChartInternal/internals/domain.ts#L136

I see, this makes sense.

Maybe not completely connected to the question above, but I found this line here

// Cancel zerobased if axis_*_min / axis_*_max specified
which cancels the zerobased setting when y min or max is set. But in case of y.min: 0 or y.max: 0 I would still expect the zerobased option put the zero on the x axis level.

Do you see any reason to not add an exception for the 0 values here?

In this case I would expect the zerobased option to still be working:
https://jsfiddle.net/michkami/6vr1z20f/

@netil
Copy link
Member

netil commented Mar 20, 2024

Do you see any reason to not add an exception for the 0 values here?

The conditional stayed from the start of the project and maintained as, mainly to not break any possible issue.
https://github.com/naver/billboard.js/blob/1.0.0/src/internals/domain.js#L156

@michkami
Copy link
Collaborator Author

The conditional stayed from the start of the project and maintained as, mainly to not break any possible issue. https://github.com/naver/billboard.js/blob/1.0.0/src/internals/domain.js#L156

Yes, I saw this. My question was if there it would be possible to add 0 as an exception here in case zerobased is true, so that the y axis will start on the x axis level when min is set to 0.

The current behaviour is what i would only expect if I set zerobased: false and then set the min value to 0.
If zerobased: true and I set the y axis min to 0, I would expect for it to start at the same level as the x axis.
I played around and saw, that if i pass null to y axis min, it would in this case work as expected, but the types only accept number | undefined.

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

No branches or pull requests

2 participants