Menu

#33 Plotting line series containing waveforms slow

v0.8.0
closed-fixed
nobody
swtchart (30)
5
2014-02-19
2012-11-25
No

Hi,

Plotting waveform line series (e.g. audio waveform) can become really slow. Such waveform line series oscillate between two values (usually -1 and 1) which results in a plot that basically consists of a series of vertical lines. An example plot is attached to this bug report.

I analyzed the the line coordinates in LineSeries.drawLineAndArea(GC, int, int, Axis, Axis) method and it seems that a lot of lines are unnecessarily drawn. I did a System.out.println() for each line that is drawn and got the following output (just a small extract).

...
x1: 401 y1: 108 x2: 401 y2: 107
x1: 401 y1: 107 x2: 401 y2: 106
x1: 401 y1: 106 x2: 401 y2: 105
x1: 401 y1: 105 x2: 401 y2: 106
x1: 401 y1: 106 x2: 401 y2: 105
x1: 401 y1: 105 x2: 401 y2: 104
x1: 401 y1: 104 x2: 401 y2: 105
x1: 401 y1: 105 x2: 401 y2: 103
x1: 401 y1: 103 x2: 401 y2: 104
x1: 401 y1: 104 x2: 401 y2: 103
x1: 401 y1: 103 x2: 401 y2: 103
x1: 401 y1: 103 x2: 401 y2: 104
x1: 401 y1: 104 x2: 401 y2: 103
x1: 401 y1: 103 x2: 401 y2: 104
x1: 401 y1: 104 x2: 401 y2: 105
x1: 401 y1: 105 x2: 401 y2: 104
x1: 401 y1: 104 x2: 401 y2: 105
x1: 401 y1: 105 x2: 401 y2: 106
...
This goes on and on.

As can be seen in that extract, it draws a vertical lines at x=401 and y between 103 and 107. It would be sufficient to draw line just ones (i.e. gc.drawLine(401, 103, 401, 107). This has big impact on performance. For example, the plot attached to this bug report takes 3s to draw.

I made some small changes to that method, so that it draws each vertical line only ones. I attached a patch to this bug report. The result is that I could reduce the time for the example plot from 3000ms to 30ms (factor of 100).

I hope I did not introduce any regressions. If you have any questions about the patch, please ask.

Thanks in advance,
Andreas

Discussion

  • Andreas Unger

    Andreas Unger - 2012-11-25

    Example waveform

     
  • Andreas Unger

    Andreas Unger - 2012-11-25

    LineSeries class patch

     
  • yoshitaka

    yoshitaka - 2013-11-28

    Hi Andreas,

    Thanks for your bug report and solution proposal.

    The fix has been done based on your solution.

    Best Regards,
    Yoshitaka

     
  • yoshitaka

    yoshitaka - 2013-11-28
    • status: open --> pending
    • Group: --> v0.8.0
     
  • yoshitaka

    yoshitaka - 2014-02-19
    • Status: pending --> closed-fixed