JFreeSVG 1.8

A discussion forum for JFreeSVG (a fast, lightweight, SVG generator for the Java platform).

JFreeSVG 1.8

Postby david.gilbert » Fri Apr 11, 2014 9:14 am

A new version of JFreeSVG is now available to download. From the README file:

Code: Select all
Version 1.8 (11 April 2014)
- added additional KEY_BEGIN_GROUP options, plus special integration support for Orson Charts;
- added special handling for shape drawing when the Stroke is not an instance of BasicStroke;
- explicitly set encoding to UTF-8 for SVGUtils.writeToSVG() and SVGUtils.writeToHTML().

JFreeSVG is dual licensed under the GNU AGPL and a commercial licence.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Ask your company to buy the JFreeChart Developer Guide
:idea: Check out other products sold by my company Object Refinery Limited
david.gilbert
JFreeChart Project Leader
 
Posts: 11620
Joined: Fri Mar 14, 2003 10:29 am

Re: JFreeSVG 1.8

Postby Mala » Mon Apr 14, 2014 12:20 pm

Hi David,
Can you please give and example of integration of jFreeSVG with orson charts which is a feature of your new release jFreeSVG 1.8?
Mala
 
Posts: 8
Joined: Tue Jan 28, 2014 1:06 pm

Re: JFreeSVG 1.8

Postby david.gilbert » Tue Apr 15, 2014 8:12 am

Yes, sure. The SVGHints.KEY_BEGIN_GROUP rendering hint (since version 1.7) is a general purpose hint to start a new group in the SVG output, and these groups can be given an ID (when the hint value is a String). In JFreeSVG 1.8, the hint value can optionally be a Map with an "id" entry and a "ref" entry, in which case the SVG group element will take the specified ID plus a custom "ref" attribute ("jfreesvg:ref"). You can use this grouping feature for anything you want. Orson Charts uses the "ref" attribute to store a reference back to the data item that the elements in the SVG group is representing, so then it is possible to capture mouse events in JavaScript and know which data items the mouse events relate to.

The best example I have of this (at the moment) is in the Orson Charts download, if you look in the 'svg' folder there is a pre-generated SVGDemo1.html file containing a chart that has been created using these rendering hints in JFreeSVG. There are also some supporting JavaScript files to generate tooltips and to show popup messages when you click on chart elements (just for demo purposes). The Java code that generates this chart is also included in the demo source folder. Here is the resulting HTML page:

http://www.jfree.org/jfreesvg/demo1/SVGDemo1.html

What is the "special" Orson Charts integration? Orson Charts uses its own hint (Chart3DHints.KEY_BEGIN_ELEMENT, not SVGHints.KEY_BEGIN_GROUP) to avoid having a compile-time dependency on JFreeSVG. At start-up, JFreeSVG will check if Orson Charts is on the class path and add Chart3DHints.KEY_BEGIN_ELEMENT as a synonym for SVGHints.KEY_BEGIN_GROUP so it acts in exactly the same way. To have Orson Charts set these rendering hints during chart drawing, all you need to do is:

Code: Select all
chart.setElementHinting(true);


Most Graphics2D implementations will ignore the additional rendering hints, but the SVGGraphics2D implementation will pick them up and create the required SVG group elements and references. In the end, this special integration is designed to make the feature simple to use in Orson Charts without adding dependencies for people that don't need or want it.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Ask your company to buy the JFreeChart Developer Guide
:idea: Check out other products sold by my company Object Refinery Limited
david.gilbert
JFreeChart Project Leader
 
Posts: 11620
Joined: Fri Mar 14, 2003 10:29 am

Re: JFreeSVG 1.8

Postby remiohead » Tue Apr 15, 2014 8:50 pm

Thanks for the updates David.

Love the map option with KEY_BEGIN_GROUP. Support for custom key/values as part of that would be useful. This is the kind of thing I have in mind:

Code: Select all
            String groupId = null;
            String ref = null;
            List<Entry> keyValues = null;

            if (hintValue instanceof String) {
                groupId = (String) hintValue;
             } else if (hintValue instanceof Map) {
                Map hintValueMap = (Map) hintValue;
                groupId = (String) hintValueMap.get("id");
                ref = (String) hintValueMap.get("ref");
               
                for(final Object o:hintValueMap.entrySet()) {
                   final Entry e = (Entry)o;
                   final Object key = e.getKey();
                   if("id".equals(key)
                         || "ref".equals(key)) {
                      continue;
                   }
                   if(keyValues == null) {
                      keyValues = new ArrayList<Entry>();
                   }
                   keyValues.add(e);
                }
            }
           
            ...

            if(keyValues != null) {
               for(final Entry e:keyValues) {
                    this.sb.append(" ").append(e.getKey()).append("=\"");
                    this.sb.append(SVGUtils.escapeForXML(
                          String.valueOf(e.getValue()))).append("\"");
               }
            }


In my code I can then do something like this:

Code: Select all
g2.setRenderingHint(
   SVGHints.KEY_BEGIN_GROUP,
      ImmutableMap.of(
         "id", i.getMultiId(),
         "style", "display:none"));


Another hint suggestion would be KEY_ELEMENT_TITLE and handled like this:

Code: Select all
       } else if(SVGHints.KEY_ELEMENT_TITLE.equals(hintKey)) {
           if(hintValue != null) {
              this.sb.append("<title>");
              this.sb.append(SVGUtils.escapeForXML(
                    String.valueOf(hintValue)));
              this.sb.append("</title>");
           }
        }
remiohead
 
Posts: 201
Joined: Fri Oct 02, 2009 3:53 pm

Re: JFreeSVG 1.8

Postby david.gilbert » Thu Apr 24, 2014 1:49 pm

Great suggestions! These will be included in the upcoming 1.9 release.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Ask your company to buy the JFreeChart Developer Guide
:idea: Check out other products sold by my company Object Refinery Limited
david.gilbert
JFreeChart Project Leader
 
Posts: 11620
Joined: Fri Mar 14, 2003 10:29 am


Return to JFreeSVG

Who is online

Users browsing this forum: No registered users and 1 guest