SVG element hinting in JFreeChart

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
essday
Posts: 5
Joined: Mon Dec 15, 2014 7:50 pm
antibot: No, of course not.

SVG element hinting in JFreeChart

Post by essday » Mon Dec 15, 2014 8:08 pm

Hi all,

I noticed some commits in the post-1.0.19 codebase suggesting that JFreeChart is including support for SVG element hinting, similar to the recently announced feature in Orson Charts.

I tried enabling this feature in JFreeChart, but I found that nothing was coming out on the SVG side. After further investigation, it appears that element hinting is currently only supported for certain chart types (not including the stacked XY I was trying to render).

Has anyone else already done the work to get this working across the rest of the library? I didn't see any commits, so I have started some work on it for my needs (and would be happy to submit a patch/pull request!)...but I would also be quite happy to avoid rework if it's already been done.

Thanks!
Scott

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

Re: SVG element hinting in JFreeChart

Post by david.gilbert » Tue Dec 16, 2014 12:07 am

Most of what I've done has been committed. I would like to eventually roll this out across all the renderers, so if you want to work on specific ones then please go ahead. If you have questions, I'll do my best to answer.
David Gilbert
JFreeChart Project Leader

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

essday
Posts: 5
Joined: Mon Dec 15, 2014 7:50 pm
antibot: No, of course not.

Re: SVG element hinting in JFreeChart

Post by essday » Tue Dec 23, 2014 4:53 pm

David,

Thanks for the response! I have since implemented this in my branch for the renderers I needed:
  • * AbstractCategoryItemRenderer
    * BarRenderer (needed to have state.elementHinting enabled)
    * DeviationRenderer
    * MultiPiePlot
    * PiePlot
    * StackedBarRenderer
    * StackedXYAreaRenderer
    * XYLineAndShapeRenderer
Question #1:

To make this work for the XYLineAndShapeRenderer, in the case where we are not drawing element shapes (which are otherwise added to the element group as the trigger area), I modified AbstractXYItemRenderer#addEntity to accept parameters for the Plot and Graphics2D, and to then draw a transparent shape using the calculated hotspot area.

Aside from the question of whether the transparent shape is the right approach, it also seems like this should be refactored to a common location so as not to entangle the imagemap and entity generation with the SVG drawing. However, I did not want to embark on this type of refactoring without some upstream guidance. Do you have any preferences on how this should be done?


Question #2:

In my use case, I wanted to have custom text serialized into the SVG rather than just the standard category/series IDs (or equivalent for the dataset type). To implement this, I subclassed all of the renderers in my own code and overrode the beginElementGroup() method with one of my own making. To get this to work, though, I also had to set up a "protected" beginElementGroup in the top-level renderer classes inside JFreeChart. Those protected methods accept the general data types used for the dataset and converts them to an ItemKey. I then modified the standard renderers within JFreeChart to use this method by calling it with the category/series, instead of constructing the ItemKey directly.

My code then overrides the beginElementGroup() method to convert the category/series into the real data we want to serialize.

For example, AbstractXYItemRenderer now contains:

Code: Select all

protected void beginElementGroup(Graphics2D g2, XYDataset dataset, int series, int itemIndex) {
        Comparable seriesKey = dataset.getSeriesKey(series);
        beginElementGroup(g2, new XYItemKey(seriesKey, itemIndex));
}
This works, but it isn't optimal since I need to subclass the entire set of renderers. It's also messy for the pie-type charts which don't use renderers at all, and it also necessitates the MultiPiePlot having a new constructor which contains an explicit PiePlot parameter (in order to accept our PiePlot subclass).

At least for my use case, the ideal option would be to have a SVGReferenceGenerator or equivalent, similar to what is already in place for imagemaps, but this is again something I would not embark upon without some guidance. Is this something that you would like to see?


Question #3:

I also have some miscellaneous patches to other parts of the code, such as:

- ChartFactory#createMultiplePieChart accepts a MultiplePiePlot parameter so that we can use a subclassed plot class.
- enabling custom row/column comparators for DefaultKeyedValues2D, DefaultCategoryDataset, TimeTableXYDataset.
- promoted some methods from private to protected in DateAxis so that I could implement my own QuarterlyDateAxis and WeeklyDateAxis

These are definitely useful to me. Are they of interest for inclusion in the main project?

Thanks again!

Scott

essday
Posts: 5
Joined: Mon Dec 15, 2014 7:50 pm
antibot: No, of course not.

Re: SVG element hinting in JFreeChart

Post by essday » Fri Jan 16, 2015 3:17 pm

Is there any upstream interest here in patches for the above?

Since I wrote the previous post, I now have additional patches to add support to ClusteredXYBarRenderer, as well as a bugfix to XYBarRenderer which prevented element hinting from occurring.

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

Re: SVG element hinting in JFreeChart

Post by david.gilbert » Mon Jan 19, 2015 11:04 pm

Yes, I'm very interested to get this working better for the next release of JFreeChart so if you have patches they are most welcome.
David Gilbert
JFreeChart Project Leader

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

essday
Posts: 5
Joined: Mon Dec 15, 2014 7:50 pm
antibot: No, of course not.

Re: SVG element hinting in JFreeChart

Post by essday » Tue Jan 20, 2015 10:43 pm

Hi David,

Great! I just posted the SVG element hinting patch here:

https://sourceforge.net/p/jfreechart/patches/314/

If you would prefer a different approach, particularly with regard to how beginElementGroup is invoked from the subclasses, or with using the EntityCollection-oriented method to draw the SVG hotspots, just let me know what you prefer and I can re-adjust and re-submit.

The other code I mentioned above is here in the following patch, which enables better subclassing of pie plots and DateAxis, as well as permits custom comparators to be supplied for various types of keys:

https://sourceforge.net/p/jfreechart/patches/315/

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

Re: SVG element hinting in JFreeChart

Post by david.gilbert » Fri Jan 23, 2015 7:05 am

Thanks. I've downloaded the patches to my laptop and will have a look at them as soon as possible.
David Gilbert
JFreeChart Project Leader

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

Locked