gillius / jfxutils

JavaFX Utilities - Zoom and Pan Charts and Pane Scaling
Apache License 2.0
68 stars 22 forks source link

Y-Axis is not ordered correctly and receiving the error delta must be positive #17

Closed Jeredriq closed 5 years ago

Jeredriq commented 6 years ago

Hi,

I've around 6 area objects which has around 30 points each and they're all connected. I'm using linechart and if someone chooses 3 areas starting from A1 to A3, chart should be responsible for 90 records.

Now the problem is, I've order for every object and they come to chart accordingly but for some reason 5 records of record A3 are shown at the bottom. So Y axis is like,

A1 A2 A3 A5 A6 A3

And when I try to restrict it to get a better view, lets say from A2 to A4, it gives the exception that delta must be positive

I believe problem maybe because of the number of records. If I try the same thing with lets say 10 records per area, it works pretty good. But when they're 30, I've this problem

gillius commented 6 years ago

Are you using auto ranging? The error happens when the lower bound is not less than the upper bound for the axis. Assuming lower is not larger than upper, then most likely they are the same value, perhaps because there are no data points? If you aren't using auto-range are you setting lower and upper bound explicitly and have lower >= upper? It's hard to tell without your points of data. If you can debug it, you can place a breakpoint in org.gillius.jfxutils.chart.StableTicksAxis#calculateTickSpacing method where exception is thrown to see how it got there (explicit range or autorange) and find out how the range is calculated.

Jeredriq commented 6 years ago

Thanks for replying so fast, I'm in a hard deadline :)

Well, I believe the source of the problem is with the sorting of the data. I checked the bounds for other examples and they work great. The problem is, as I explained above comes from A3, As you said I've placed there a debug point and delta is sometimes negative, as the exception says.

Sometimes delta exception is there (mostly if A3 has a record), sometimes it isnt but mostly my problem is with the Y-Axis. I get my records from the database and my test data were like A1, A2 so it may really ordered them alphabetically. So my question is, where can I check the order of the Y-Axis data? And re-order it?

gillius commented 6 years ago

The confusion I have about your mentioning of sorting issues is because my library and the StableTicksAxis doesn't look at the data; it gets the min and max value from the ValueAxis implementation in JFX. I'll be honest, shortly after working this project, before Java 9 came out, I stopped working with JFX so I don't remember enough about it to know whether or not sorted data is a requirement of the ValueAxis. However, if the sorting is a requirement, I think that comes from JFX itself and is not imposed by jfxutils. The documentation for autorange doesn't suggest it is value for minValue to be greater than maxValue.

Is it possible there is some code that explicitly sets the lower and upper bounds such that the upper bound is less than the lower? When you look in the debugger you should be able to see the stack trace if it came from auto-ranging or manual ranging method, and in either case you can observe the axis's lower and upper bounds and see if they are inverted.

Jeredriq commented 6 years ago

The problem seems to be exactly the case you told, sadly I may have to work on a different project for this week and will try your suggestion next week. I'll close the issue if it works, thanks!

Jeredriq commented 5 years ago

Yeap the thing you said solved the problem, thanks!

Btw, do you know any way to zoom in and out from code?