Image Map generation not flexible enough

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
giorgio42
Posts: 9
Joined: Tue Jul 15, 2003 5:44 pm
Location: Munich, Germany

Image Map generation not flexible enough

Post by giorgio42 » Fri Aug 08, 2003 8:24 am

JFreeChart needs a small framework, that allows developers to plug in custom image map generators, like that in jCharts.

Looking first through the developer guide, that I bought, and then through the source code, I detected, that, in order to use a tooltip library different from overlib, I actually have to patch the ChartEntity.getImageMapAreaTag() method.

This is, because, for instance, BarRenderer.drawHorizontalItem() simply does a "... new CategoryItemEntity(...)", when collecting the entity info.

Instead, there should be something like "...getEntityGenerator().getEntity(...)", such, that the renderers do not need to know the entity class.

Anyway, thanks for the great charting library.

richard_atkinson
Posts: 115
Joined: Fri Mar 14, 2003 3:13 pm
Location: London, England
Contact:

Image Map generation not flexible enough

Post by richard_atkinson » Tue Aug 12, 2003 2:48 pm

Giorgio,

I would agree the current image map generation is not flexible enough. I've made some changes to support pluggable generation of tooltip and URL area tag fragments. The changes do involve any API changes for those people who are currently using the ChartUtilties class to generate HTML image maps. I'll try and check the changes into CVS in the day or two.

In the meantime if anyone would like any other tooltip libraries supported in the core JFreeChart library (other than OverLib or the HTML title attribute), please let me know and I'll add them in.

Thanks and regards,
Richard...

New ChartUtilities method

Code: Select all

    import org.jfree.chart.imagemap.ToolTipTagFragmentGenerator;
    import org.jfree.chart.imagemap.URLTagFragmentGenerator;

    public static void writeImageMap(PrintWriter writer, String name, ChartRenderingInfo info,
                                     ToolTipTagFragmentGenerator toolTipTagFragmentGenerator,
                                     URLTagFragmentGenerator urlTagFragmentGenerator) throws IOException
New interfaces
org.jfree.chart.imagemap.ToolTipTagFragmentGenerator
org.jfree.chart.imagemap.URLTagFragmentGenerator

New classes
org.jfree.chart.imagemap.StandardURLTagFragmentGenerator
org.jfree.chart.imagemap.StandardToolTipTagFragmentGenerator
org.jfree.chart.imagemap.OverLIBToolTipTagFragmentGenerator

richard_atkinson
Posts: 115
Joined: Fri Mar 14, 2003 3:13 pm
Location: London, England
Contact:

Image Map generation not flexible enough

Post by richard_atkinson » Tue Aug 12, 2003 9:23 pm

Sorry just read my previous post and there is a rather critical typo.

The changes do not involve any API changes for those people who are currently using the ChartUtilities class to generate HTML image maps.

Anyway, the changes seem to be working well and are now checked into CVS. I've created an additional ToolTipTagFragmentGenerator to generate tooltips for the Dynamic Drive DHTML Tip Message library (http://www.dynamicdrive.com) which is rather cool. The library is similar to overLIB (actually it was originally based on overLIB) however it is lighter weight and provides some very funky transition effects.

Regards,
Richard...

giorgio42
Posts: 9
Joined: Tue Jul 15, 2003 5:44 pm
Location: Munich, Germany

Post by giorgio42 » Tue Aug 19, 2003 3:45 pm

Richard,

thanks for taking this up so quickly!
I am looking forward to the next release :-)

(By the way, the javascript library I am using to display tooltips is domTT, http://www.mojavelinux.com/forum/viewtopic.php?t=127).

Georg

mjacobsca
Posts: 16
Joined: Thu Aug 21, 2003 4:59 pm

onMouseOver and onMouseOut events

Post by mjacobsca » Fri Sep 19, 2003 6:51 pm

I like to set the window status when my users roll over the hotspots. I also need links from them. In order to accomplish this, I loop through the ChartEntities and change the tooltips by adding in:

onMouseOver="... and onMouseOut="...

Currently, it appears that the tooltips support the use of the ALT/TITLE tag for popups, and an HREF tag for URL's, but nothing more. It was very easy for me to add to the necessary tooltip generation code to accomplish what I wanted for my javascript functions, so I was hoping that you could consider adding expanded support for custom text to be added to the map generation inside the map tag.

Therefore, the map logic would be something like:

Code: Select all

<AREA SHAPE="POLY" COORDS="5,5,10,10" alt="ALTLABEL" href="HREFLABEL" CUSTOMTEXT>
Another advantage of this is that people could code their own DHTML popups that popup quicker, and have a different color than the default browser popups that take 3 seconds to appear.

Michael

richard_atkinson
Posts: 115
Joined: Fri Mar 14, 2003 3:13 pm
Location: London, England
Contact:

More flexible image map generation

Post by richard_atkinson » Sun Sep 21, 2003 7:44 pm

If you use JFreeChart 0.9.12, you can implement your own org.jfree.chart.imagemap.ToolTipTagFragmentGenerator to do whatever you require. See the ChartUtilities class for details on how it is called.

Regards,
Richard...

mjacobsca
Posts: 16
Joined: Thu Aug 21, 2003 4:59 pm

thanks

Post by mjacobsca » Tue Sep 23, 2003 10:56 pm

thanks Richard! I haven't had time to study the new changes in 0.9.12! I will check it out.

ewill3
Posts: 1
Joined: Wed Jan 18, 2006 12:15 am
Contact:

Increase in flexibility in tag generators

Post by ewill3 » Wed Jan 18, 2006 12:37 am

I'll admit I like JFreeChart in general (I'm toying with 1.0.0) but I do have a complaint similar to the original posting -- namely that the generators for tool tips and URLs still aren't quite flexible enough.

Ideally, the ToolTipTagFragmentGenerator and URLGenerator (or their replacements/additions) would be able to get at the series number, point number, X value (if applicable), Y value, and maybe the category; I'm not entirely sure but a string passed in as a single String parameter doesn't quite cut it. :)

However, since they're interfaces and already defined, this poses a minor problem in how to properly extend this functionality.

I would hope that JFreeChart, at some point, can support the usage

Code: Select all

<AREA onmouseover='popup(series,point#)' onmouseout='popoff()' ...>
where popup() and popoff() are defined elsewhere somewhere in the Javascript. Apart from generating the strings 'popup(' and 'popoff(', there's no real need for the generators to do anything horribly strange here; it's just generating a bit of text.

The series I can hack in, if only because the format I'm getting to the ToolTipTagFragmentGenerator is of the form 'n: (x,y)', where n is a series number (0-whatever), and x and y are the point coordinates. (I'm primarily interested in flyovers for the scatter plot, although bar graph and line graph flyovers would also be useful). The odd thing is that the URL Fragment generator *does* get the point number, so it's obviously available ... somewhere.

I'm not sure I like the notion of a ToolTipTagExFragmentGenerator or a ToolTipBaseFragmentGenerator, but am wondering what plans, if any, are being contemplated to allow for more flexible tooltip generation in 1.1.0 (or 1.0.1?). Or should I just get a read-only CVS copy and dig? :)

I suppose in a pinch I could generate another implementation for ChartUtilities.getImageMap(), if I absolutely have to. That would make three, which as you no doubt already know gets unwieldly.

Thanks in advance.

angel
Posts: 899
Joined: Thu Jan 15, 2004 12:07 am
Location: Germany - Palatinate

Post by angel » Wed Jan 18, 2006 8:42 am

I never used it but I think you can extend the ToolTipFragmentGenerator and use it your own generator in writeImageMap() to create your own JScript calls.

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

Post by david.gilbert » Wed Jan 18, 2006 11:05 am

I don't know the best approach, but another place to look is the getImageMapAreaTag() method in the ChartEntity class - perhaps some flexibility can be injected there.
David Gilbert
JFreeChart Project Leader

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

d3ik
Posts: 2
Joined: Thu Jan 26, 2006 10:55 pm

Post by d3ik » Thu Jan 26, 2006 11:10 pm

I just got done looking at this in order to add a 'onclick' attribute to the imagemap tag. The easiest way I found was to create my own org.jfree.chart.imagemap.URLTagFragmentGenerator and org.jfree.chart.url.CategoryURLGenerator (in my test case I was using a CategoryPlot).

I had the generateURL() method from JavascriptCategoryURLGenerator return a JSON object (surrounded by parens), the prefix is used for the function name:

Code: Select all

    public String generateURL(CategoryDataset dataset, int series,
                              int category) {
        String url = this.prefix;
        Comparable seriesKey = dataset.getRowKey(series);
        Comparable categoryKey = dataset.getColumnKey(category);

        url += "( {" + this.seriesParameterName + ": "
            + "'" + seriesKey.toString() + "', ";

        url += this.categoryParameterName + ": "
            + "'" + categoryKey.toString() + "' } )";

        return url;
    }
Then the JavascriptURLTagFragmentGenerator was pretty simple:

Code: Select all

    public String generateURLFragment(String onclickText) {
        return " href=\"#\" onclick=\"" + onclickText + "; return false\"";
    }
Then when I'm building my image map:

Code: Select all

renderer.setItemURLGenerator(new JavascriptCategoryURLGenerator("drillDown", "series", "month") );

...

ChartUtilities.writeImageMap(
     pw,
     "chart",
     info,
     new StandardToolTipTagFragmentGenerator(),
     new JavascriptURLTagFragmentGenerator()
);
So when the mapped areas are clicked, they execute "functionName( { series: '15', month: 'Jan'} ); return false;".

Then just make sure you have the javascript code:

Code: Select all

	function drillDown( data ) {
		
		var series = data.series;
		var month = data.month;
		
		alert("Series: " + series + "\nMonth: " + month);
		
	}

pelski
Posts: 16
Joined: Thu Feb 23, 2006 2:02 am

Post by pelski » Tue Mar 21, 2006 6:34 am

Hi,

I am hitting similar walls with image map generation not being
flexible enough.

My problem is that I would like to overwrite the default image map
areas for a particular point. For example, I would like
a line chart to be clickable on the entire X-Axis, and not just at the point
on the line.

If there is already a way to do this, any hints would be greatly
appreciated.

Cheers,
Nick

Locked