jfreechart icon indicating copy to clipboard operation
jfreechart copied to clipboard

Crosshairs broken in v1.5.4

Open matoos32 opened this issue 2 years ago • 6 comments

Going from release v1.5.3 to v1.5.4 crosshair functionality stopped working. Clicking on charts no longer updates the crosshair.

To reproduce:

Setup

  1. Find demos with crosshairs: https://github.com/jfree/jfree-demos/search?q=crosshair Note: jfree-demos currently lists JfreeChart v1.5.3 in the README but doesn't have a v1.5.3 release tag. It's up to v1.5.2.
  2. git clone https://github.com/jfree/jfree-demos.git
  3. cd jfree-demos
  4. git checkout -b crosshair-test v2.0

Test v1.5.2

  1. mvn clean package
  2. java -cp target/org.jfree.demos-2.0-jar-with-dependencies.jar org.jfree.chart.demo2.TimeSeriesChartDemo1
  3. Observe clicking the chart updates the crosshair.
  4. Close the app.

Test v1.5.3

  1. Set the POM jfreechart dependency to v1.5.3
  2. Repeat build and launch steps.
  3. Observe clicking the chart updates the crosshair.
  4. Close the app.

Test v1.5.4

  1. Set the POM jfreechart dependency to v1.5.4
  2. Repeat build and launch steps.
  3. Observe the crosshair doesn't update. If you resize the window (trigger a re-draw) the crosshair updates to the last clicked location.

I suspect it's related to a v1.5.4 contribution.

matoos32 avatar Jan 14 '23 15:01 matoos32

For reference, I can reproduce the anomaly in TimeSeriesChartDemo1 and similar examples that make the crosshairs visible on the plot, but not in examples that use CrosshairOverlay, seen here and here.

trashgod avatar Jan 14 '23 19:01 trashgod

At first glance it seems to be caused by the removal of this line in ChartPanel.java between v1.5.3 and v1.5.4:

image

jfree avatar Jan 14 '23 20:01 jfree

Thanks for having taken a look!

matoos32 avatar Jan 15 '23 22:01 matoos32

Yes, thank you. After restoring the call to setNotify(), I can no longer reproduce the anomaly. Related discussion may be found here and here.

trashgod avatar Jan 16 '23 00:01 trashgod

At first glance it seems to be caused by the removal of this line in ChartPanel.java between v1.5.3 and v1.5.4:

image

I know exactly when this was introduced, see https://github.com/jfree/jfreechart/pull/233#discussion_r655296139. The problem now is that large charts are re-rendered every time when a user clicks with the mouse. This leads to very laggy behavior when selecting chart elements, though the selection itself is rendered using an ChartOverlay which is very fast.

Yuri-Blankenstein-TNO avatar Apr 04 '23 13:04 Yuri-Blankenstein-TNO

I've created an alternative solution that prevents charts without corsshairs to redraw on every mouse click, see #362.

For this I have reused - what seems - an older implementation JFreeChart#handleClick(...) that exactly seems to solve this issue. This public method isn't called anywhere else anymore within the library.

Yuri-Blankenstein-TNO avatar May 08 '23 08:05 Yuri-Blankenstein-TNO