alireza59/gicentreutils

Can draw empty line chart with less than two points

Closed this issue · 1 comments

What steps will reproduce the problem?
1. Create a simple XYChart line chart (e.g. use same as from examples: 
http://www.gicentre.org/utils/chart/)
2. Pass empty point list with size<2 of, e.g. chart.setData(new Float[]{}, new 
Float[]{})
3. Draw the chart

What is the expected output? What do you see instead?
Expected that the chart would be empty or a single point would be drawn(if 
passed so).Instead - index out of bounds exceptions occurs:

Exception in thread "Animation Thread" 
java.lang.ArrayIndexOutOfBoundsException: -1
    at org.gicentre.utils.stat.XYChart.calcDataSpacing(XYChart.java:906)
    at org.gicentre.utils.stat.XYChart.draw(XYChart.java:129)
    at diagram.draw(diagram.java:154)
    at processing.core.PApplet.handleDraw(Unknown Source)
    at processing.core.PApplet.run(Unknown Source)
    at java.lang.Thread.run(Thread.java:722)

The XYChart assumes there's at least 2 points in data list. The expectation is 
wrong! Adding two or more points solves the problem, e.g:
  lineChart.setData(new float[] {0,1},
                    new float[] {0,1});


What version of the product are you using? On what operating system?
V3.2.0, Windows

Attached the code with the mentioned issue. 

Original issue reported on code.google.com by be.lietaus on 10 Feb 2013 at 8:43

Attachments:

Thanks for pointing this out. Fixed and updated source code so that providing 
an empty array or no data at all results in an empty chart with default 
scalings. Fix will be incorporated in release 3.3

Original comment by jwoLon...@gmail.com on 6 Apr 2013 at 6:36

  • Changed state: Fixed