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

Let the user decide the beginning of the interval #893

Closed
joeldomke opened this issue Feb 4, 2022 · 13 comments
Closed

Let the user decide the beginning of the interval #893

joeldomke opened this issue Feb 4, 2022 · 13 comments
Labels
enhancement New feature or request Line Chart

Comments

@joeldomke
Copy link
Contributor

When I choose an intervall of 50, I always want my titles to be at 0, 50, 100, ... This is what happens, if I set my minY to a multiple of 50, or if 0 is between minY and maxY.

But if I select something like minY = 35 and maxY = 130, I will get titles at 35 and 85.

The user should have more control over the beginning of the interval. I would like to implement this feature, and there are two solutions that come to my mind:

  1. Give an option to have the interval zero aligned.
  2. Let the user choose a value at which the interval should be aligned. E.g. the user choses 10 for the alignment, 50 as the interval, 30 as minY and 150 as maxY, then they would get titles at 60 and 110.

This could be either set for horizontal and vertical, or for left, top, right and bottom.

@joeldomke joeldomke changed the title Let the user decide the beginning of the intervall Let the user decide the beginning of the interval Feb 4, 2022
@joeldomke
Copy link
Contributor Author

I just noticed that the interval is also used for the grid lines. So this change should probably also apply to the grid lines, since they are currently placed on the same interval as the titles.

@imaNNeo imaNNeo added Line Chart enhancement New feature or request labels Feb 4, 2022
@imaNNeo
Copy link
Owner

imaNNeo commented Feb 4, 2022

Yes, you're right!

@imaNNeo
Copy link
Owner

imaNNeo commented Feb 4, 2022

At the moment we have a function called Utils.getBestInitialIntervalValue(min, max, interval)
with this definition:

/// Finds the best initial interval value
///
/// If there is a zero point in the axis, we a value that passes through it.
/// For example if we have -3 to +3, with interval 2. if we start from -3, we get something like this: -3, -1, +1, +3
/// But the most important point is zero in most cases. with this logic we get this: -2, 0, 2
double getBestInitialIntervalValue(double min, double max, double interval) {
  if (min > 0 || max < 0) {
    return min;
  }
  if (max - min <= interval) {
    return min;
  }
  return interval * (min ~/ interval).toDouble();
}

It tries to find a value as an initial value based on the interval, we wanted to make sure that this value goes through the zero when zero is between in min and max. But it didn't cover your sample (35 to 130) because there is no zero in between :))

Maybe you can work on this function to fix this issue without adding any parameters.

BTW your second solution makes sense to me.

@joeldomke
Copy link
Contributor Author

Without changing the parameters there isn't much flexibility. Option 1 would be possible with the limitation that we can't make it optional (if I am not mistaken). Meaning it would change the behavior of existing charts, which would have to be mentioned as a breaking change.

In this case we could remove the if conditions and only use

 return interval * (min ~/ interval).toDouble();

to always have the interval zero aligned.

@imaNNeo
Copy link
Owner

imaNNeo commented Feb 4, 2022

@joeldomke You're right we need to add that option.
That function is implemented with a predefined value for interval for zero (there is no parameter, it was just on my head).
Now if we can fix the problem for zero, we can then make it an optional value.

I'm working on it right now.

@imaNNeo
Copy link
Owner

imaNNeo commented Feb 4, 2022

What is your suggestion for name of that optional value? baselineAlignment?
(which the default value is zero)

@imaNNeo
Copy link
Owner

imaNNeo commented Feb 4, 2022

Actually, I'm thinking of adding a baseline property in our axis-based charts (LineChart, BarChart, ...)

The default value of the baseline is zero in both axes.
Then we can show the base lines attractive in the grid lines or even the titles by default.
Something like the below image:

Then we can use the baseline value to align the interval that we are talking about.

What do you think?

@joeldomke
Copy link
Contributor Author

I think that's a great idea!

@imaNNeo
Copy link
Owner

imaNNeo commented Feb 4, 2022

Let the user choose a value at which the interval should be aligned. E.g. the user choses 10 for the alignment, 50 as the interval, 30 as minY and 150 as maxY, then they would get titles at 60 and 110.

This way, it should cover your example. (with baseline 10).

Correct?

@joeldomke
Copy link
Contributor Author

This way, it should cover your example. (with baseline 10).

Yes, this would fix it

@imaNNeo
Copy link
Owner

imaNNeo commented Feb 4, 2022

Yaay!

simplescreenrecorder-2022-02-04_18.53.47.mp4

imaNNeo added a commit that referenced this issue Feb 4, 2022
…rts (Line, Bar, Scatter). default is zero, #893.
imaNNeo added a commit that referenced this issue Feb 11, 2022
…rts (Line, Bar, Scatter). default is zero, #893.
imaNNeo added a commit that referenced this issue Feb 11, 2022
…zero (#894)

* Fix getBestInitialIntervalValue() problem with values above or below zero, #893.

* Add `baselineX` and `baselineY` property to all of our axis-based charts (Line, Bar, Scatter). default is zero, #893.

* Remove all linux/flutter/ephemeral files from example directory

* Update CHANGELOG.md, bar_chart.md, and line_chart.md

* Update line_chart.md

* Update CHANGELOG.md
imaNNeo added a commit that referenced this issue Feb 12, 2022
…zero (#894)

* Fix getBestInitialIntervalValue() problem with values above or below zero, #893.

* Add `baselineX` and `baselineY` property to all of our axis-based charts (Line, Bar, Scatter). default is zero, #893.

* Remove all linux/flutter/ephemeral files from example directory

* Update CHANGELOG.md, bar_chart.md, and line_chart.md

* Update line_chart.md

* Update CHANGELOG.md
@imaNNeo
Copy link
Owner

imaNNeo commented Feb 12, 2022

Hi.
We have just fixed it in 0.45.0.
Please check it out!

@imaNNeo imaNNeo closed this as completed Feb 12, 2022
@joeldomke
Copy link
Contributor Author

Looks good, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Line Chart
Projects
None yet
Development

No branches or pull requests

2 participants