Image map and legend url

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
mskjeret
Posts: 27
Joined: Sun May 23, 2004 8:58 am

Image map and legend url

Post by mskjeret » Fri Oct 06, 2006 10:07 am

Hi

I have problems with creating a image map where I have a url on the legend items.

I have added a generator for the urls in the legend:

Code: Select all

 //Add drill-down urls to the legend
      ((LineAndShapeRenderer) plot.getRenderer()).setLegendItemURLGenerator(new LegendItemURLGenerator());
The url is correctly created as I can see in each of the LegendItems that it has the url assigned properly.

Still the image map contains only tooltips and urls for the plot area, but none for the legend.

Has anyone successfully added urls in the legend?
Any clues on what I might be doing wrong?

Magne

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 » Fri Oct 06, 2006 4:22 pm

I don't think you are doing anything wrong. I think this feature is currently broken, and probably has been for a while...I'll take a look and see if it will be hard to fix.
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:

Post by david.gilbert » Fri Oct 06, 2006 4:49 pm

It's not too hard to fix. I committed this patch, which will be in the 1.0.3 release:

Code: Select all

Index: source/org/jfree/chart/title/LegendItemBlockContainer.java
===================================================================
RCS file: /cvsroot/jfreechart/jfreechart/source/org/jfree/chart/title/Attic/LegendItemBlockContainer.java,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 LegendItemBlockContainer.java
--- source/org/jfree/chart/title/LegendItemBlockContainer.java	20 Jul 2006 16:21:59 -0000	1.1.2.1
+++ source/org/jfree/chart/title/LegendItemBlockContainer.java	6 Oct 2006 15:43:18 -0000
@@ -37,6 +37,7 @@
  * Changes
  * -------
  * 20-Jul-2006 : Version 1 (DG);
+ * 06-Oct-2006 : Added tooltip and URL text fields (DG);
  * 
  */
 
@@ -68,6 +69,12 @@
     /** The series index. */
     private int series;
     
+    /** The tool tip text (can be <code>null</code>). */
+    private String toolTipText;
+    
+    /** The URL text (can be <code>null</code>). */
+    private String urlText;
+    
     /**
      * Creates a new legend item block.
      * 
@@ -101,6 +108,50 @@
     }
     
     /**
+     * Returns the tool tip text.
+     * 
+     * @return The tool tip text (possibly <code>null</code>).
+     * 
+     * @since 1.0.3
+     */
+    public String getToolTipText() {
+        return this.toolTipText;
+    }
+    
+    /**
+     * Sets the tool tip text.
+     * 
+     * @param text  the text (<code>null</code> permitted).
+     * 
+     * @since 1.0.3
+     */
+    public void setToolTipText(String text) {
+        this.toolTipText = text;   
+    }
+    
+    /**
+     * Returns the URL text.
+     * 
+     * @return The URL text (possibly <code>null</code>).
+     * 
+     * @since 1.0.3
+     */
+    public String getURLText() {
+        return this.urlText;
+    }
+    
+    /**
+     * Sets the URL text.
+     * 
+     * @param text  the text (<code>null</code> permitted).
+     * 
+     * @since 1.0.3
+     */
+    public void setURLText(String text) {
+        this.urlText = text;   
+    }
+    
+    /**
      * Draws the block within the specified area.
      * 
      * @param g2  the graphics device.
@@ -122,6 +173,8 @@
                 LegendItemEntity entity = new LegendItemEntity(
                         (Shape) area.clone());
                 entity.setSeriesIndex(this.series);
+                entity.setToolTipText(getToolTipText());
+                entity.setURLText(getURLText());
                 ec.add(entity);
                 r.setEntityCollection(ec);
             }
Index: source/org/jfree/chart/title/LegendTitle.java
===================================================================
RCS file: /cvsroot/jfreechart/jfreechart/source/org/jfree/chart/title/LegendTitle.java,v
retrieving revision 1.20.2.6
diff -u -r1.20.2.6 LegendTitle.java
--- source/org/jfree/chart/title/LegendTitle.java	20 Jul 2006 16:21:59 -0000	1.20.2.6
+++ source/org/jfree/chart/title/LegendTitle.java	6 Oct 2006 15:43:18 -0000
@@ -51,6 +51,7 @@
  * ------------- JFREECHART 1.0.0 ---------------------------------------------
  * 20-Jul-2006 : Use new LegendItemBlockContainer to restore support for
  *               LegendItemEntities (DG);
+ * 06-Oct-2006 : Add tooltip and URL text to legend item (DG);
  * 
  */
 
@@ -432,8 +433,9 @@
         LabelBlock labelBlock = new LabelBlock(item.getLabel(), this.itemFont, 
                 this.itemPaint);
         labelBlock.setPadding(this.itemLabelPadding);
-        labelBlock.setToolTipText(item.getToolTipText());
         legendItem.add(labelBlock);
+        legendItem.setToolTipText(item.getToolTipText());
+        legendItem.setURLText(item.getURLText());
         
         result = new BlockContainer(new CenterArrangement());
         result.add(legendItem);
David Gilbert
JFreeChart Project Leader

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

mskjeret
Posts: 27
Joined: Sun May 23, 2004 8:58 am

Post by mskjeret » Fri Oct 06, 2006 6:20 pm

Thanks for the update.

Magne

Locked