Getting a reference to ChartCanvas (JavaFX)

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
plusik
Posts: 28
Joined: Tue May 16, 2006 3:36 am
Location: Boston, MA, USA

Getting a reference to ChartCanvas (JavaFX)

Post by plusik » Sun Feb 14, 2016 4:21 am

Hi,

It seems there is no way to get a reference to ChartCanvas from the corresponding ChartViewer node. I need the reference to manipulate the mouse listeners, which are properties of the canvas, not of the ChartViewer.

Perhaps this is an easy thing to add to version 1.0.20?

Tomas

plusik
Posts: 28
Joined: Tue May 16, 2006 3:36 am
Location: Boston, MA, USA

Re: Getting a reference to ChartCanvas (JavaFX)

Post by plusik » Sun Feb 14, 2016 4:26 am

In a related comment, it seems there used to be an option to enable/disable domain/range axis mouse-wheel zooming, but that option is not present in the JavaFX ChartViewer.

See this line: https://github.com/jfree/jfreechart/blo ... .java#L133

It would be nice to have that option, though.

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: Getting a reference to ChartCanvas (JavaFX)

Post by david.gilbert » Mon Feb 15, 2016 9:51 pm

plusik wrote:It seems there is no way to get a reference to ChartCanvas from the corresponding ChartViewer node. I need the reference to manipulate the mouse listeners, which are properties of the canvas, not of the ChartViewer.

Perhaps this is an easy thing to add to version 1.0.20?
Thanks for the feedback. I agree this is necessary, I will add it for the 1.0.20 release.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: Getting a reference to ChartCanvas (JavaFX)

Post by david.gilbert » Mon Feb 15, 2016 9:57 pm

plusik wrote:In a related comment, it seems there used to be an option to enable/disable domain/range axis mouse-wheel zooming, but that option is not present in the JavaFX ChartViewer.

See this line: https://github.com/jfree/jfreechart/blo ... .java#L133

It would be nice to have that option, though.
I will add this too.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: Getting a reference to ChartCanvas (JavaFX)

Post by david.gilbert » Mon Feb 15, 2016 10:18 pm

Here is the change to add the reference to the ChartCanvas:

https://github.com/jfree/jfreechart/com ... 3b2c41e78d
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: Getting a reference to ChartCanvas (JavaFX)

Post by david.gilbert » Tue Feb 16, 2016 12:42 pm

Actually I'm considering doing away with the ChartViewer control and just building everything into the ChartCanvas class, I don't see much real need for the separation anymore.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

plusik
Posts: 28
Joined: Tue May 16, 2006 3:36 am
Location: Boston, MA, USA

Re: Getting a reference to ChartCanvas (JavaFX)

Post by plusik » Tue Feb 16, 2016 1:37 pm

Why not remove ChartCanvas and put everything into ChartViewer, for the sake of backwards compatibility?

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: Getting a reference to ChartCanvas (JavaFX)

Post by david.gilbert » Tue Feb 16, 2016 9:37 pm

Maybe. Whatever the name of the class, it will have to extend the JavaFX Canvas (as ChartCanvas does now). I think it won't be possible to keep backward compatibility completely, but I'm not so worried about that for the JavaFX code (it's mentioned in the API docs that the API is subject to change, since I knew it would probably have to).
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

plusik
Posts: 28
Joined: Tue May 16, 2006 3:36 am
Location: Boston, MA, USA

Re: Getting a reference to ChartCanvas (JavaFX)

Post by plusik » Tue Feb 16, 2016 9:51 pm

I guess ChartViewer extending Control makes some sense, because Control is for components that the user interacts with, while Canvas is for plain drawing.
JFreeChart seems more like Control to me, because it has zooming, context menus, tooltips, etc.

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: Getting a reference to ChartCanvas (JavaFX)

Post by david.gilbert » Wed Feb 17, 2016 12:45 pm

Yes, I agree with that. But what I'm finding is that extending Control isn't bringing a lot of benefits and it's making the implementation more complex. So why not just merge ChartViewer and ChartCanvas into a single class extending Canvas? I think for the typical use case, it will be easier to work with.

I also notice that the JavaFX chart classes don't extend Control, although I don't know why they chose to do that.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

plusik
Posts: 28
Joined: Tue May 16, 2006 3:36 am
Location: Boston, MA, USA

Re: Getting a reference to ChartCanvas (JavaFX)

Post by plusik » Sun Feb 21, 2016 7:02 pm

If it becomes a Canvas extension, please keep the contextMenu property (as a JavaFX property), so the context menu can be defined it FXML.

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: Getting a reference to ChartCanvas (JavaFX)

Post by david.gilbert » Tue Feb 23, 2016 5:10 am

In the end I decided to keep the ChartViewer class as a Control subclass, partly for the contextMenu that you mention.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

Locked