org.jfree.chart.entity.PieSectionEntity Java Examples

The following examples show how to use org.jfree.chart.entity.PieSectionEntity. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StandardEntityCollectionTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Confirm that the equals method can distinguish all the required fields.
 */
public void testEquals() {
    StandardEntityCollection c1 = new StandardEntityCollection();
    StandardEntityCollection c2 = new StandardEntityCollection();
    assertTrue(c1.equals(c2));

    PieSectionEntity e1 = new PieSectionEntity(new Rectangle2D.Double(1.0,
            2.0, 3.0, 4.0), new DefaultPieDataset(), 0, 1, "Key",
            "ToolTip", "URL");
    c1.add(e1);
    assertFalse(c1.equals(c2));
    PieSectionEntity e2 = new PieSectionEntity(new Rectangle2D.Double(1.0,
            2.0, 3.0, 4.0), new DefaultPieDataset(), 0, 1, "Key",
            "ToolTip", "URL");
    c2.add(e2);
    assertTrue(c1.equals(c2));
}
 
Example #2
Source File: StandardEntityCollectionTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Confirm that the equals method can distinguish all the required fields.
 */
public void testEquals() {
    StandardEntityCollection c1 = new StandardEntityCollection();
    StandardEntityCollection c2 = new StandardEntityCollection();
    assertTrue(c1.equals(c2));
    
    PieSectionEntity e1 = new PieSectionEntity(new Rectangle2D.Double(1.0, 
            2.0, 3.0, 4.0), new DefaultPieDataset(), 0, 1, "Key", 
            "ToolTip", "URL");
    c1.add(e1);
    assertFalse(c1.equals(c2));
    PieSectionEntity e2 = new PieSectionEntity(new Rectangle2D.Double(1.0, 
            2.0, 3.0, 4.0), new DefaultPieDataset(), 0, 1, "Key", 
            "ToolTip", "URL");
    c2.add(e2);
    assertTrue(c1.equals(c2));        
}
 
Example #3
Source File: PieChartHyperlinkProvider.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public JRPrintHyperlink getEntityHyperlink(ChartEntity entity)
{
	JRPrintHyperlink printHyperlink = null;
	if (hasHyperlinks() && entity instanceof PieSectionEntity)
	{
		PieSectionEntity pieEntity = (PieSectionEntity) entity;
		printHyperlink = sectionHyperlinks.get(pieEntity.getSectionKey());
	}
	return printHyperlink;
}
 
Example #4
Source File: JFreeChartReportDrawable.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void draw( final Graphics2D graphics2D, final Rectangle2D bounds ) {
  this.bounds = (Rectangle2D) bounds.clone();
  if ( chartRenderingInfo != null ) {
    this.chartRenderingInfo.clear();
  }
  final Graphics2D g2 = (Graphics2D) graphics2D.create();
  this.chart.draw( g2, bounds, chartRenderingInfo );
  g2.dispose();

  if ( chartRenderingInfo == null || debugRendering == false ) {
    return;
  }

  graphics2D.setColor( Color.RED );
  final Rectangle2D dataArea = getDataAreaOffset();
  final EntityCollection entityCollection = chartRenderingInfo.getEntityCollection();
  for ( int i = 0; i < entityCollection.getEntityCount(); i++ ) {
    final ChartEntity chartEntity = entityCollection.getEntity( i );
    if ( chartEntity instanceof XYItemEntity ||
      chartEntity instanceof CategoryItemEntity ||
      chartEntity instanceof PieSectionEntity ) {
      final Area a = new Area( chartEntity.getArea() );
      if ( buggyDrawArea ) {
        a.transform( AffineTransform.getTranslateInstance( dataArea.getX(), dataArea.getY() ) );
      }
      a.intersect( new Area( dataArea ) );
      graphics2D.draw( a );
    } else {
      graphics2D.draw( chartEntity.getArea() );
    }
  }
}
 
Example #5
Source File: PieSectionEntityTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Confirm that the equals method can distinguish all the required fields.
 */
public void testEquals() {
    PieSectionEntity e1 = new PieSectionEntity(
        new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0), 
        new DefaultPieDataset(), 1, 2, "Key", "ToolTip", "URL"
    ); 
    PieSectionEntity e2 = new PieSectionEntity(
        new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0), 
        new DefaultPieDataset(), 1, 2, "Key", "ToolTip", "URL"
    ); 
    assertTrue(e1.equals(e2));  
    
    e1.setArea(new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0));
    assertFalse(e1.equals(e2));
    e2.setArea(new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0));
    assertTrue(e1.equals(e2));  

    e1.setToolTipText("New ToolTip");
    assertFalse(e1.equals(e2));
    e2.setToolTipText("New ToolTip");
    assertTrue(e1.equals(e2));  

    e1.setURLText("New URL");
    assertFalse(e1.equals(e2));
    e2.setURLText("New URL");
    assertTrue(e1.equals(e2));  
}
 
Example #6
Source File: PiePlot.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Draws a single data item.
 *
 * @param g2  the graphics device (<code>null</code> not permitted).
 * @param section  the section index.
 * @param selected  is the item selected?
 * @param dataArea  the data plot area.
 * @param state  state information for one chart.
 * @param currentPass  the current pass index.
 */
protected void drawItem(Graphics2D g2, int section, boolean selected, 
        Rectangle2D dataArea, PiePlotState state, int currentPass) {

    Number n = this.dataset.getValue(section);
    if (n == null) {
        return;
    }
    double value = n.doubleValue();
    double angle1 = 0.0;
    double angle2 = 0.0;

    if (this.direction == Rotation.CLOCKWISE) {
        angle1 = state.getLatestAngle();
        angle2 = angle1 - value / state.getTotal() * 360.0;
    }
    else if (this.direction == Rotation.ANTICLOCKWISE) {
        angle1 = state.getLatestAngle();
        angle2 = angle1 + value / state.getTotal() * 360.0;
    }
    else {
        throw new IllegalStateException("Rotation type not recognised.");
    }

    double angle = (angle2 - angle1);
    if (Math.abs(angle) > getMinimumArcAngleToDraw()) {
        double ep = 0.0;
        double mep = getMaximumExplodePercent();
        if (mep > 0.0) {
            ep = getExplodePercent(getSectionKey(section)) / mep;
        }
        Rectangle2D arcBounds = getArcBounds(state.getPieArea(),
                state.getExplodedPieArea(), angle1, angle, ep);
        Arc2D.Double arc = new Arc2D.Double(arcBounds, angle1, angle,
                Arc2D.PIE);

        if (currentPass == 0) {
            if (this.shadowPaint != null) {
                Shape shadowArc = ShapeUtilities.createTranslatedShape(
                        arc, (float) this.shadowXOffset,
                        (float) this.shadowYOffset);
                g2.setPaint(this.shadowPaint);
                g2.fill(shadowArc);
            }
        }
        else if (currentPass == 1) {
            Comparable key = getSectionKey(section);
            Paint paint = lookupSectionPaint(key, selected);
            Shape savedClip = g2.getClip();
            g2.clip(arc);
            g2.setPaint(paint);
            g2.fill(arc);

            Paint outlinePaint = lookupSectionOutlinePaint(key, selected);
            Stroke outlineStroke = lookupSectionOutlineStroke(key,
                    selected);
            if (this.sectionOutlinesVisible) {
                g2.setPaint(outlinePaint);
                g2.setStroke(outlineStroke);
                g2.draw(arc);
            }
            g2.setClip(savedClip);

            // update the linking line target for later
            // add an entity for the pie section
            if (state.getInfo() != null) {
                EntityCollection entities = state.getEntityCollection();
                if (entities != null) {
                    String tip = null;
                    if (this.toolTipGenerator != null) {
                        tip = this.toolTipGenerator.generateToolTip(
                                this.dataset, key);
                    }
                    String url = null;
                    if (this.urlGenerator != null) {
                        url = this.urlGenerator.generateURL(this.dataset,
                                key, this.pieIndex);
                    }
                    PieSectionEntity entity = new PieSectionEntity(
                            arc, this.dataset, this.pieIndex, section, key,
                            tip, url);
                    entities.add(entity);
                }
            }
        }
    }
    state.setLatestAngle(angle2);
}
 
Example #7
Source File: PiePlot.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws a single data item.
 *
 * @param g2  the graphics device (<code>null</code> not permitted).
 * @param section  the section index.
 * @param dataArea  the data plot area.
 * @param state  state information for one chart.
 * @param currentPass  the current pass index.
 */
protected void drawItem(Graphics2D g2, int section, Rectangle2D dataArea,
                        PiePlotState state, int currentPass) {

    Number n = this.dataset.getValue(section);
    if (n == null) {
        return;
    }
    double value = n.doubleValue();
    double angle1 = 0.0;
    double angle2 = 0.0;

    if (this.direction == Rotation.CLOCKWISE) {
        angle1 = state.getLatestAngle();
        angle2 = angle1 - value / state.getTotal() * 360.0;
    }
    else if (this.direction == Rotation.ANTICLOCKWISE) {
        angle1 = state.getLatestAngle();
        angle2 = angle1 + value / state.getTotal() * 360.0;
    }
    else {
        throw new IllegalStateException("Rotation type not recognised.");
    }

    double angle = (angle2 - angle1);
    if (Math.abs(angle) > getMinimumArcAngleToDraw()) {
        double ep = 0.0;
        double mep = getMaximumExplodePercent();
        if (mep > 0.0) {
            ep = getExplodePercent(section) / mep;
        }
        Rectangle2D arcBounds = getArcBounds(state.getPieArea(),
                state.getExplodedPieArea(), angle1, angle, ep);
        Arc2D.Double arc = new Arc2D.Double(arcBounds, angle1, angle,
                Arc2D.PIE);

        if (currentPass == 0) {
            if (this.shadowPaint != null && this.shadowGenerator == null) {
                Shape shadowArc = ShapeUtilities.createTranslatedShape(
                        arc, (float) this.shadowXOffset,
                        (float) this.shadowYOffset);
                g2.setPaint(this.shadowPaint);
                g2.fill(shadowArc);
            }
        }
        else if (currentPass == 1) {
            Comparable key = getSectionKey(section);
            Paint paint = lookupSectionPaint(key, state);
            g2.setPaint(paint);
            g2.fill(arc);

            Paint outlinePaint = lookupSectionOutlinePaint(key);
            Stroke outlineStroke = lookupSectionOutlineStroke(key);
            if (this.sectionOutlinesVisible) {
                g2.setPaint(outlinePaint);
                g2.setStroke(outlineStroke);
                g2.draw(arc);
            }

            // update the linking line target for later
            // add an entity for the pie section
            if (state.getInfo() != null) {
                EntityCollection entities = state.getEntityCollection();
                if (entities != null) {
                    String tip = null;
                    if (this.toolTipGenerator != null) {
                        tip = this.toolTipGenerator.generateToolTip(
                                this.dataset, key);
                    }
                    String url = null;
                    if (this.urlGenerator != null) {
                        url = this.urlGenerator.generateURL(this.dataset,
                                key, this.pieIndex);
                    }
                    PieSectionEntity entity = new PieSectionEntity(
                            arc, this.dataset, this.pieIndex, section, key,
                            tip, url);
                    entities.add(entity);
                }
            }
        }
    }
    state.setLatestAngle(angle2);
}
 
Example #8
Source File: PiePlot.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws a single data item.
 *
 * @param g2  the graphics device (<code>null</code> not permitted).
 * @param section  the section index.
 * @param dataArea  the data plot area.
 * @param state  state information for one chart.
 * @param currentPass  the current pass index.
 */
protected void drawItem(Graphics2D g2, int section, Rectangle2D dataArea,
                        PiePlotState state, int currentPass) {

    Number n = this.dataset.getValue(section);
    if (n == null) {
        return;
    }
    double value = n.doubleValue();
    double angle1 = 0.0;
    double angle2 = 0.0;

    if (this.direction == Rotation.CLOCKWISE) {
        angle1 = state.getLatestAngle();
        angle2 = angle1 - value / state.getTotal() * 360.0;
    }
    else if (this.direction == Rotation.ANTICLOCKWISE) {
        angle1 = state.getLatestAngle();
        angle2 = angle1 + value / state.getTotal() * 360.0;
    }
    else {
        throw new IllegalStateException("Rotation type not recognised.");
    }

    double angle = (angle2 - angle1);
    if (Math.abs(angle) > getMinimumArcAngleToDraw()) {
        double ep = 0.0;
        double mep = getMaximumExplodePercent();
        if (mep > 0.0) {
            ep = getExplodePercent(section) / mep;
        }
        Rectangle2D arcBounds = getArcBounds(state.getPieArea(),
                state.getExplodedPieArea(), angle1, angle, ep);
        Arc2D.Double arc = new Arc2D.Double(arcBounds, angle1, angle,
                Arc2D.PIE);

        if (currentPass == 0) {
            if (this.shadowPaint != null && this.shadowGenerator == null) {
                Shape shadowArc = ShapeUtilities.createTranslatedShape(
                        arc, (float) this.shadowXOffset,
                        (float) this.shadowYOffset);
                g2.setPaint(this.shadowPaint);
                g2.fill(shadowArc);
            }
        }
        else if (currentPass == 1) {
            Comparable key = getSectionKey(section);
            Paint paint = lookupSectionPaint(key, state);
            g2.setPaint(paint);
            g2.fill(arc);

            Paint outlinePaint = lookupSectionOutlinePaint(key);
            Stroke outlineStroke = lookupSectionOutlineStroke(key);
            if (this.sectionOutlinesVisible) {
                g2.setPaint(outlinePaint);
                g2.setStroke(outlineStroke);
                g2.draw(arc);
            }

            // update the linking line target for later
            // add an entity for the pie section
            if (state.getInfo() != null) {
                EntityCollection entities = state.getEntityCollection();
                if (entities != null) {
                    String tip = null;
                    if (this.toolTipGenerator != null) {
                        tip = this.toolTipGenerator.generateToolTip(
                                this.dataset, key);
                    }
                    String url = null;
                    if (this.urlGenerator != null) {
                        url = this.urlGenerator.generateURL(this.dataset,
                                key, this.pieIndex);
                    }
                    PieSectionEntity entity = new PieSectionEntity(
                            arc, this.dataset, this.pieIndex, section, key,
                            tip, url);
                    entities.add(entity);
                }
            }
        }
    }
    state.setLatestAngle(angle2);
}
 
Example #9
Source File: JFreeChartReportDrawable.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Returns an optional image-map for the entry.
 *
 * @param bounds the bounds for which the image map is computed.
 * @return the computed image-map or null if there is no image-map available.
 */
public ImageMap getImageMap( final Rectangle2D bounds ) {
  if ( chartRenderingInfo == null ) {
    return null;
  }
  final Rectangle2D dataArea = getDataAreaOffset();
  final Rectangle2D otherArea = new Rectangle2D.Double();

  if ( ( ObjectUtilities.equal( bounds, this.bounds ) ) == false ) {
    final BufferedImage image = new BufferedImage( 1, 1, BufferedImage.TYPE_4BYTE_ABGR );
    final Graphics2D graphics = image.createGraphics();
    draw( graphics, bounds );
    graphics.dispose();
  }

  final ImageMap map = new ImageMap();
  final EntityCollection entityCollection = chartRenderingInfo.getEntityCollection();
  final int count = entityCollection.getEntityCount();
  for ( int i = 0; i < count; i++ ) {
    final ChartEntity chartEntity = entityCollection.getEntity( i );
    final Shape area = chartEntity.getArea();
    final String hrefValue = chartEntity.getURLText();
    final String tooltipValue = chartEntity.getToolTipText();
    if ( StringUtils.isEmpty( tooltipValue ) == false ||
      StringUtils.isEmpty( hrefValue ) == false ) {
      final AbstractImageMapEntry entry;
      if ( chartEntity instanceof XYItemEntity ||
        chartEntity instanceof CategoryItemEntity ||
        chartEntity instanceof PieSectionEntity ) {
        entry = createMapEntry( area, dataArea );
      } else {
        entry = createMapEntry( area, otherArea );
      }
      if ( entry == null ) {
        continue;
      }
      if ( StringUtils.isEmpty( hrefValue ) == false ) {
        entry.setAttribute( LibXmlInfo.XHTML_NAMESPACE, "href", hrefValue );
      } else {
        entry.setAttribute( LibXmlInfo.XHTML_NAMESPACE, "href", "#" );
      }
      if ( StringUtils.isEmpty( tooltipValue ) == false ) {
        entry.setAttribute( LibXmlInfo.XHTML_NAMESPACE, "title", tooltipValue );
      }
      map.addMapEntry( entry );
    }
  }

  return map;
}
 
Example #10
Source File: PiePlot.java    From opensim-gui with Apache License 2.0 4 votes vote down vote up
/**
 * Draws a single data item.
 *
 * @param g2  the graphics device (<code>null</code> not permitted).
 * @param section  the section index.
 * @param dataArea  the data plot area.
 * @param state  state information for one chart.
 * @param currentPass  the current pass index.
 */
protected void drawItem(Graphics2D g2, int section, Rectangle2D dataArea,
                        PiePlotState state, int currentPass) {

    Number n = this.dataset.getValue(section);
    if (n == null) {
        return;   
    }
    double value = n.doubleValue();
    double angle1 = 0.0;
    double angle2 = 0.0;
    
    if (this.direction == Rotation.CLOCKWISE) {
        angle1 = state.getLatestAngle();
        angle2 = angle1 - value / state.getTotal() * 360.0;
    }
    else if (this.direction == Rotation.ANTICLOCKWISE) {
        angle1 = state.getLatestAngle();
        angle2 = angle1 + value / state.getTotal() * 360.0;         
    }
    else {
        throw new IllegalStateException("Rotation type not recognised.");   
    }
    
    double angle = (angle2 - angle1);
    if (Math.abs(angle) > getMinimumArcAngleToDraw()) {
        double ep = 0.0;
        double mep = getMaximumExplodePercent();
        if (mep > 0.0) {
            ep = getExplodePercent(section) / mep;                
        }
        Rectangle2D arcBounds = getArcBounds(state.getPieArea(), 
                state.getExplodedPieArea(), angle1, angle, ep);
        Arc2D.Double arc = new Arc2D.Double(arcBounds, angle1, angle, 
                Arc2D.PIE);
        
        if (currentPass == 0) {
            if (this.shadowPaint != null) {
                Shape shadowArc = ShapeUtilities.createTranslatedShape(
                        arc, (float) this.shadowXOffset, 
                        (float) this.shadowYOffset);
                g2.setPaint(this.shadowPaint);
                g2.fill(shadowArc);
            }
        }
        else if (currentPass == 1) {
            Comparable key = getSectionKey(section);
            Paint paint = lookupSectionPaint(key, true);
            g2.setPaint(paint);
            g2.fill(arc);

            Paint outlinePaint = lookupSectionOutlinePaint(key);
            Stroke outlineStroke = lookupSectionOutlineStroke(key);
            if (this.sectionOutlinesVisible) {
                g2.setPaint(outlinePaint);
                g2.setStroke(outlineStroke);
                g2.draw(arc);
            }
            
            // update the linking line target for later
            // add an entity for the pie section
            if (state.getInfo() != null) {
                EntityCollection entities = state.getEntityCollection();
                if (entities != null) {
                    String tip = null;
                    if (this.toolTipGenerator != null) {
                        tip = this.toolTipGenerator.generateToolTip(
                                this.dataset, key);
                    }
                    String url = null;
                    if (this.urlGenerator != null) {
                        url = this.urlGenerator.generateURL(this.dataset, 
                                key, this.pieIndex);
                    }
                    PieSectionEntity entity = new PieSectionEntity(
                            arc, this.dataset, this.pieIndex, section, key,
                            tip, url);
                    entities.add(entity);
                }
            }
        }
    }    
    state.setLatestAngle(angle2);
}
 
Example #11
Source File: PiePlot.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Draws a single data item.
 *
 * @param g2  the graphics device (<code>null</code> not permitted).
 * @param section  the section index.
 * @param dataArea  the data plot area.
 * @param state  state information for one chart.
 * @param currentPass  the current pass index.
 */
protected void drawItem(Graphics2D g2, int section, Rectangle2D dataArea,
                        PiePlotState state, int currentPass) {

    Number n = this.dataset.getValue(section);
    if (n == null) {
        return;   
    }
    double value = n.doubleValue();
    double angle1 = 0.0;
    double angle2 = 0.0;
    
    if (this.direction == Rotation.CLOCKWISE) {
        angle1 = state.getLatestAngle();
        angle2 = angle1 - value / state.getTotal() * 360.0;
    }
    else if (this.direction == Rotation.ANTICLOCKWISE) {
        angle1 = state.getLatestAngle();
        angle2 = angle1 + value / state.getTotal() * 360.0;         
    }
    else {
        throw new IllegalStateException("Rotation type not recognised.");   
    }
    
    double angle = (angle2 - angle1);
    if (Math.abs(angle) > getMinimumArcAngleToDraw()) {
        double ep = 0.0;
        double mep = getMaximumExplodePercent();
        if (mep > 0.0) {
            ep = getExplodePercent(getSectionKey(section)) / mep;                
        }
        Rectangle2D arcBounds = getArcBounds(state.getPieArea(), 
                state.getExplodedPieArea(), angle1, angle, ep);
        Arc2D.Double arc = new Arc2D.Double(arcBounds, angle1, angle, 
                Arc2D.PIE);
        
        if (currentPass == 0) {
            if (this.shadowPaint != null) {
                Shape shadowArc = ShapeUtilities.createTranslatedShape(
                        arc, (float) this.shadowXOffset, 
                        (float) this.shadowYOffset);
                g2.setPaint(this.shadowPaint);
                g2.fill(shadowArc);
            }
        }
        else if (currentPass == 1) {
            Comparable key = getSectionKey(section);
            Paint paint = lookupSectionPaint(key, true);
            g2.setPaint(paint);
            g2.fill(arc);

            Paint outlinePaint = lookupSectionOutlinePaint(key);
            Stroke outlineStroke = lookupSectionOutlineStroke(key);
            if (this.sectionOutlinesVisible) {
                g2.setPaint(outlinePaint);
                g2.setStroke(outlineStroke);
                g2.draw(arc);
            }
            
            // update the linking line target for later
            // add an entity for the pie section
            if (state.getInfo() != null) {
                EntityCollection entities = state.getEntityCollection();
                if (entities != null) {
                    String tip = null;
                    if (this.toolTipGenerator != null) {
                        tip = this.toolTipGenerator.generateToolTip(
                                this.dataset, key);
                    }
                    String url = null;
                    if (this.urlGenerator != null) {
                        url = this.urlGenerator.generateURL(this.dataset, 
                                key, this.pieIndex);
                    }
                    PieSectionEntity entity = new PieSectionEntity(
                            arc, this.dataset, this.pieIndex, section, key,
                            tip, url);
                    entities.add(entity);
                }
            }
        }
    }    
    state.setLatestAngle(angle2);
}
 
Example #12
Source File: PiePlot.java    From openstock with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws a single data item.
 *
 * @param g2  the graphics device (<code>null</code> not permitted).
 * @param section  the section index.
 * @param dataArea  the data plot area.
 * @param state  state information for one chart.
 * @param currentPass  the current pass index.
 */
protected void drawItem(Graphics2D g2, int section, Rectangle2D dataArea,
                        PiePlotState state, int currentPass) {

    Number n = this.dataset.getValue(section);
    if (n == null) {
        return;
    }
    double value = n.doubleValue();
    double angle1 = 0.0;
    double angle2 = 0.0;

    if (this.direction == Rotation.CLOCKWISE) {
        angle1 = state.getLatestAngle();
        angle2 = angle1 - value / state.getTotal() * 360.0;
    }
    else if (this.direction == Rotation.ANTICLOCKWISE) {
        angle1 = state.getLatestAngle();
        angle2 = angle1 + value / state.getTotal() * 360.0;
    }
    else {
        throw new IllegalStateException("Rotation type not recognised.");
    }

    double angle = (angle2 - angle1);
    if (Math.abs(angle) > getMinimumArcAngleToDraw()) {
        double ep = 0.0;
        double mep = getMaximumExplodePercent();
        if (mep > 0.0) {
            ep = getExplodePercent(section) / mep;
        }
        Rectangle2D arcBounds = getArcBounds(state.getPieArea(),
                state.getExplodedPieArea(), angle1, angle, ep);
        Arc2D.Double arc = new Arc2D.Double(arcBounds, angle1, angle,
                Arc2D.PIE);

        if (currentPass == 0) {
            if (this.shadowPaint != null && this.shadowGenerator == null) {
                Shape shadowArc = ShapeUtilities.createTranslatedShape(
                        arc, (float) this.shadowXOffset,
                        (float) this.shadowYOffset);
                g2.setPaint(this.shadowPaint);
                g2.fill(shadowArc);
            }
        }
        else if (currentPass == 1) {
            Comparable key = getSectionKey(section);
            Paint paint = lookupSectionPaint(key, state);
            g2.setPaint(paint);
            g2.fill(arc);

            Paint outlinePaint = lookupSectionOutlinePaint(key);
            Stroke outlineStroke = lookupSectionOutlineStroke(key);
            if (this.sectionOutlinesVisible) {
                g2.setPaint(outlinePaint);
                g2.setStroke(outlineStroke);
                g2.draw(arc);
            }

            // update the linking line target for later
            // add an entity for the pie section
            if (state.getInfo() != null) {
                EntityCollection entities = state.getEntityCollection();
                if (entities != null) {
                    String tip = null;
                    if (this.toolTipGenerator != null) {
                        tip = this.toolTipGenerator.generateToolTip(
                                this.dataset, key);
                    }
                    String url = null;
                    if (this.urlGenerator != null) {
                        url = this.urlGenerator.generateURL(this.dataset,
                                key, this.pieIndex);
                    }
                    PieSectionEntity entity = new PieSectionEntity(
                            arc, this.dataset, this.pieIndex, section, key,
                            tip, url);
                    entities.add(entity);
                }
            }
        }
    }
    state.setLatestAngle(angle2);
}
 
Example #13
Source File: PieSectionEntityTests.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Confirm that the equals method can distinguish all the required fields.
 */
public void testEquals() {
    PieSectionEntity e1 = new PieSectionEntity(new Rectangle2D.Double(
            1.0, 2.0, 3.0, 4.0), new DefaultPieDataset(), 1, 2, "Key",
            "ToolTip", "URL");
    PieSectionEntity e2 = new PieSectionEntity(new Rectangle2D.Double(1.0,
            2.0, 3.0, 4.0), new DefaultPieDataset(), 1, 2, "Key",
            "ToolTip", "URL");
    assertTrue(e1.equals(e2));

    e1.setArea(new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0));
    assertFalse(e1.equals(e2));
    e2.setArea(new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0));
    assertTrue(e1.equals(e2));

    e1.setToolTipText("New ToolTip");
    assertFalse(e1.equals(e2));
    e2.setToolTipText("New ToolTip");
    assertTrue(e1.equals(e2));

    e1.setURLText("New URL");
    assertFalse(e1.equals(e2));
    e2.setURLText("New URL");
    assertTrue(e1.equals(e2));

    e1.setDataset(null);
    assertFalse(e1.equals(e2));
    e2.setDataset(null);
    assertTrue(e1.equals(e2));

    e1.setPieIndex(99);
    assertFalse(e1.equals(e2));
    e2.setPieIndex(99);
    assertTrue(e1.equals(e2));

    e1.setSectionIndex(66);
    assertFalse(e1.equals(e2));
    e2.setSectionIndex(66);
    assertTrue(e1.equals(e2));

    e1.setSectionKey("ABC");
    assertFalse(e1.equals(e2));
    e2.setSectionKey("ABC");
    assertTrue(e1.equals(e2));
}
 
Example #14
Source File: PiePlot.java    From ECG-Viewer with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Draws a single data item.
 *
 * @param g2  the graphics device (<code>null</code> not permitted).
 * @param section  the section index.
 * @param dataArea  the data plot area.
 * @param state  state information for one chart.
 * @param currentPass  the current pass index.
 */
protected void drawItem(Graphics2D g2, int section, Rectangle2D dataArea,
                        PiePlotState state, int currentPass) {

    Number n = this.dataset.getValue(section);
    if (n == null) {
        return;
    }
    double value = n.doubleValue();
    double angle1 = 0.0;
    double angle2 = 0.0;

    if (this.direction == Rotation.CLOCKWISE) {
        angle1 = state.getLatestAngle();
        angle2 = angle1 - value / state.getTotal() * 360.0;
    }
    else if (this.direction == Rotation.ANTICLOCKWISE) {
        angle1 = state.getLatestAngle();
        angle2 = angle1 + value / state.getTotal() * 360.0;
    }
    else {
        throw new IllegalStateException("Rotation type not recognised.");
    }

    double angle = (angle2 - angle1);
    if (Math.abs(angle) > getMinimumArcAngleToDraw()) {
        double ep = 0.0;
        double mep = getMaximumExplodePercent();
        if (mep > 0.0) {
            ep = getExplodePercent(section) / mep;
        }
        Rectangle2D arcBounds = getArcBounds(state.getPieArea(),
                state.getExplodedPieArea(), angle1, angle, ep);
        Arc2D.Double arc = new Arc2D.Double(arcBounds, angle1, angle,
                Arc2D.PIE);

        if (currentPass == 0) {
            if (this.shadowPaint != null && this.shadowGenerator == null) {
                Shape shadowArc = ShapeUtilities.createTranslatedShape(
                        arc, (float) this.shadowXOffset,
                        (float) this.shadowYOffset);
                g2.setPaint(this.shadowPaint);
                g2.fill(shadowArc);
            }
        }
        else if (currentPass == 1) {
            Comparable key = getSectionKey(section);
            Paint paint = lookupSectionPaint(key, state);
            g2.setPaint(paint);
            g2.fill(arc);

            Paint outlinePaint = lookupSectionOutlinePaint(key);
            Stroke outlineStroke = lookupSectionOutlineStroke(key);
            if (this.sectionOutlinesVisible) {
                g2.setPaint(outlinePaint);
                g2.setStroke(outlineStroke);
                g2.draw(arc);
            }

            // update the linking line target for later
            // add an entity for the pie section
            if (state.getInfo() != null) {
                EntityCollection entities = state.getEntityCollection();
                if (entities != null) {
                    String tip = null;
                    if (this.toolTipGenerator != null) {
                        tip = this.toolTipGenerator.generateToolTip(
                                this.dataset, key);
                    }
                    String url = null;
                    if (this.urlGenerator != null) {
                        url = this.urlGenerator.generateURL(this.dataset,
                                key, this.pieIndex);
                    }
                    PieSectionEntity entity = new PieSectionEntity(
                            arc, this.dataset, this.pieIndex, section, key,
                            tip, url);
                    entities.add(entity);
                }
            }
        }
    }
    state.setLatestAngle(angle2);
}
 
Example #15
Source File: Chart_15_PiePlot_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Draws a single data item.
 *
 * @param g2  the graphics device (<code>null</code> not permitted).
 * @param section  the section index.
 * @param dataArea  the data plot area.
 * @param state  state information for one chart.
 * @param currentPass  the current pass index.
 */
protected void drawItem(Graphics2D g2, int section, Rectangle2D dataArea,
                        PiePlotState state, int currentPass) {

    Number n = this.dataset.getValue(section);
    if (n == null) {
        return;   
    }
    double value = n.doubleValue();
    double angle1 = 0.0;
    double angle2 = 0.0;
    
    if (this.direction == Rotation.CLOCKWISE) {
        angle1 = state.getLatestAngle();
        angle2 = angle1 - value / state.getTotal() * 360.0;
    }
    else if (this.direction == Rotation.ANTICLOCKWISE) {
        angle1 = state.getLatestAngle();
        angle2 = angle1 + value / state.getTotal() * 360.0;         
    }
    else {
        throw new IllegalStateException("Rotation type not recognised.");   
    }
    
    double angle = (angle2 - angle1);
    if (Math.abs(angle) > getMinimumArcAngleToDraw()) {
        double ep = 0.0;
        double mep = getMaximumExplodePercent();
        if (mep > 0.0) {
            ep = getExplodePercent(getSectionKey(section)) / mep;                
        }
        Rectangle2D arcBounds = getArcBounds(state.getPieArea(), 
                state.getExplodedPieArea(), angle1, angle, ep);
        Arc2D.Double arc = new Arc2D.Double(arcBounds, angle1, angle, 
                Arc2D.PIE);
        
        if (currentPass == 0) {
            if (this.shadowPaint != null) {
                Shape shadowArc = ShapeUtilities.createTranslatedShape(
                        arc, (float) this.shadowXOffset, 
                        (float) this.shadowYOffset);
                g2.setPaint(this.shadowPaint);
                g2.fill(shadowArc);
            }
        }
        else if (currentPass == 1) {
            Comparable key = getSectionKey(section);
            Paint paint = lookupSectionPaint(key, true);
            g2.setPaint(paint);
            g2.fill(arc);

            Paint outlinePaint = lookupSectionOutlinePaint(key);
            Stroke outlineStroke = lookupSectionOutlineStroke(key);
            if (this.sectionOutlinesVisible) {
                g2.setPaint(outlinePaint);
                g2.setStroke(outlineStroke);
                g2.draw(arc);
            }
            
            // update the linking line target for later
            // add an entity for the pie section
            if (state.getInfo() != null) {
                EntityCollection entities = state.getEntityCollection();
                if (entities != null) {
                    String tip = null;
                    if (this.toolTipGenerator != null) {
                        tip = this.toolTipGenerator.generateToolTip(
                                this.dataset, key);
                    }
                    String url = null;
                    if (this.urlGenerator != null) {
                        url = this.urlGenerator.generateURL(this.dataset, 
                                key, this.pieIndex);
                    }
                    PieSectionEntity entity = new PieSectionEntity(
                            arc, this.dataset, this.pieIndex, section, key,
                            tip, url);
                    entities.add(entity);
                }
            }
        }
    }    
    state.setLatestAngle(angle2);
}
 
Example #16
Source File: Chart_15_PiePlot_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Draws a single data item.
 *
 * @param g2  the graphics device (<code>null</code> not permitted).
 * @param section  the section index.
 * @param dataArea  the data plot area.
 * @param state  state information for one chart.
 * @param currentPass  the current pass index.
 */
protected void drawItem(Graphics2D g2, int section, Rectangle2D dataArea,
                        PiePlotState state, int currentPass) {

    Number n = this.dataset.getValue(section);
    if (n == null) {
        return;   
    }
    double value = n.doubleValue();
    double angle1 = 0.0;
    double angle2 = 0.0;
    
    if (this.direction == Rotation.CLOCKWISE) {
        angle1 = state.getLatestAngle();
        angle2 = angle1 - value / state.getTotal() * 360.0;
    }
    else if (this.direction == Rotation.ANTICLOCKWISE) {
        angle1 = state.getLatestAngle();
        angle2 = angle1 + value / state.getTotal() * 360.0;         
    }
    else {
        throw new IllegalStateException("Rotation type not recognised.");   
    }
    
    double angle = (angle2 - angle1);
    if (Math.abs(angle) > getMinimumArcAngleToDraw()) {
        double ep = 0.0;
        double mep = getMaximumExplodePercent();
        if (mep > 0.0) {
            ep = getExplodePercent(getSectionKey(section)) / mep;                
        }
        Rectangle2D arcBounds = getArcBounds(state.getPieArea(), 
                state.getExplodedPieArea(), angle1, angle, ep);
        Arc2D.Double arc = new Arc2D.Double(arcBounds, angle1, angle, 
                Arc2D.PIE);
        
        if (currentPass == 0) {
            if (this.shadowPaint != null) {
                Shape shadowArc = ShapeUtilities.createTranslatedShape(
                        arc, (float) this.shadowXOffset, 
                        (float) this.shadowYOffset);
                g2.setPaint(this.shadowPaint);
                g2.fill(shadowArc);
            }
        }
        else if (currentPass == 1) {
            Comparable key = getSectionKey(section);
            Paint paint = lookupSectionPaint(key, true);
            g2.setPaint(paint);
            g2.fill(arc);

            Paint outlinePaint = lookupSectionOutlinePaint(key);
            Stroke outlineStroke = lookupSectionOutlineStroke(key);
            if (this.sectionOutlinesVisible) {
                g2.setPaint(outlinePaint);
                g2.setStroke(outlineStroke);
                g2.draw(arc);
            }
            
            // update the linking line target for later
            // add an entity for the pie section
            if (state.getInfo() != null) {
                EntityCollection entities = state.getEntityCollection();
                if (entities != null) {
                    String tip = null;
                    if (this.toolTipGenerator != null) {
                        tip = this.toolTipGenerator.generateToolTip(
                                this.dataset, key);
                    }
                    String url = null;
                    if (this.urlGenerator != null) {
                        url = this.urlGenerator.generateURL(this.dataset, 
                                key, this.pieIndex);
                    }
                    PieSectionEntity entity = new PieSectionEntity(
                            arc, this.dataset, this.pieIndex, section, key,
                            tip, url);
                    entities.add(entity);
                }
            }
        }
    }    
    state.setLatestAngle(angle2);
}
 
Example #17
Source File: PiePlot.java    From SIMVA-SoS with Apache License 2.0 4 votes vote down vote up
/**
 * Draws a single data item.
 *
 * @param g2  the graphics device (<code>null</code> not permitted).
 * @param section  the section index.
 * @param dataArea  the data plot area.
 * @param state  state information for one chart.
 * @param currentPass  the current pass index.
 */
protected void drawItem(Graphics2D g2, int section, Rectangle2D dataArea,
                        PiePlotState state, int currentPass) {

    Number n = this.dataset.getValue(section);
    if (n == null) {
        return;
    }
    double value = n.doubleValue();
    double angle1 = 0.0;
    double angle2 = 0.0;

    if (this.direction == Rotation.CLOCKWISE) {
        angle1 = state.getLatestAngle();
        angle2 = angle1 - value / state.getTotal() * 360.0;
    }
    else if (this.direction == Rotation.ANTICLOCKWISE) {
        angle1 = state.getLatestAngle();
        angle2 = angle1 + value / state.getTotal() * 360.0;
    }
    else {
        throw new IllegalStateException("Rotation type not recognised.");
    }

    double angle = (angle2 - angle1);
    if (Math.abs(angle) > getMinimumArcAngleToDraw()) {
        double ep = 0.0;
        double mep = getMaximumExplodePercent();
        if (mep > 0.0) {
            ep = getExplodePercent(section) / mep;
        }
        Rectangle2D arcBounds = getArcBounds(state.getPieArea(),
                state.getExplodedPieArea(), angle1, angle, ep);
        Arc2D.Double arc = new Arc2D.Double(arcBounds, angle1, angle,
                Arc2D.PIE);

        if (currentPass == 0) {
            if (this.shadowPaint != null && this.shadowGenerator == null) {
                Shape shadowArc = ShapeUtilities.createTranslatedShape(
                        arc, (float) this.shadowXOffset,
                        (float) this.shadowYOffset);
                g2.setPaint(this.shadowPaint);
                g2.fill(shadowArc);
            }
        }
        else if (currentPass == 1) {
            Comparable key = getSectionKey(section);
            Paint paint = lookupSectionPaint(key, state);
            g2.setPaint(paint);
            g2.fill(arc);

            Paint outlinePaint = lookupSectionOutlinePaint(key);
            Stroke outlineStroke = lookupSectionOutlineStroke(key);
            if (this.sectionOutlinesVisible) {
                g2.setPaint(outlinePaint);
                g2.setStroke(outlineStroke);
                g2.draw(arc);
            }

            // update the linking line target for later
            // add an entity for the pie section
            if (state.getInfo() != null) {
                EntityCollection entities = state.getEntityCollection();
                if (entities != null) {
                    String tip = null;
                    if (this.toolTipGenerator != null) {
                        tip = this.toolTipGenerator.generateToolTip(
                                this.dataset, key);
                    }
                    String url = null;
                    if (this.urlGenerator != null) {
                        url = this.urlGenerator.generateURL(this.dataset,
                                key, this.pieIndex);
                    }
                    PieSectionEntity entity = new PieSectionEntity(
                            arc, this.dataset, this.pieIndex, section, key,
                            tip, url);
                    entities.add(entity);
                }
            }
        }
    }
    state.setLatestAngle(angle2);
}
 
Example #18
Source File: PiePlot.java    From ccu-historian with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws a single data item.
 *
 * @param g2  the graphics device (<code>null</code> not permitted).
 * @param section  the section index.
 * @param dataArea  the data plot area.
 * @param state  state information for one chart.
 * @param currentPass  the current pass index.
 */
protected void drawItem(Graphics2D g2, int section, Rectangle2D dataArea,
                        PiePlotState state, int currentPass) {

    Number n = this.dataset.getValue(section);
    if (n == null) {
        return;
    }
    double value = n.doubleValue();
    double angle1 = 0.0;
    double angle2 = 0.0;

    if (this.direction == Rotation.CLOCKWISE) {
        angle1 = state.getLatestAngle();
        angle2 = angle1 - value / state.getTotal() * 360.0;
    }
    else if (this.direction == Rotation.ANTICLOCKWISE) {
        angle1 = state.getLatestAngle();
        angle2 = angle1 + value / state.getTotal() * 360.0;
    }
    else {
        throw new IllegalStateException("Rotation type not recognised.");
    }

    double angle = (angle2 - angle1);
    if (Math.abs(angle) > getMinimumArcAngleToDraw()) {
        double ep = 0.0;
        double mep = getMaximumExplodePercent();
        if (mep > 0.0) {
            ep = getExplodePercent(section) / mep;
        }
        Rectangle2D arcBounds = getArcBounds(state.getPieArea(),
                state.getExplodedPieArea(), angle1, angle, ep);
        Arc2D.Double arc = new Arc2D.Double(arcBounds, angle1, angle,
                Arc2D.PIE);

        if (currentPass == 0) {
            if (this.shadowPaint != null && this.shadowGenerator == null) {
                Shape shadowArc = ShapeUtilities.createTranslatedShape(
                        arc, (float) this.shadowXOffset,
                        (float) this.shadowYOffset);
                g2.setPaint(this.shadowPaint);
                g2.fill(shadowArc);
            }
        }
        else if (currentPass == 1) {
            Comparable key = getSectionKey(section);
            Paint paint = lookupSectionPaint(key, state);
            g2.setPaint(paint);
            g2.fill(arc);

            Paint outlinePaint = lookupSectionOutlinePaint(key);
            Stroke outlineStroke = lookupSectionOutlineStroke(key);
            if (this.sectionOutlinesVisible) {
                g2.setPaint(outlinePaint);
                g2.setStroke(outlineStroke);
                g2.draw(arc);
            }

            // update the linking line target for later
            // add an entity for the pie section
            if (state.getInfo() != null) {
                EntityCollection entities = state.getEntityCollection();
                if (entities != null) {
                    String tip = null;
                    if (this.toolTipGenerator != null) {
                        tip = this.toolTipGenerator.generateToolTip(
                                this.dataset, key);
                    }
                    String url = null;
                    if (this.urlGenerator != null) {
                        url = this.urlGenerator.generateURL(this.dataset,
                                key, this.pieIndex);
                    }
                    PieSectionEntity entity = new PieSectionEntity(
                            arc, this.dataset, this.pieIndex, section, key,
                            tip, url);
                    entities.add(entity);
                }
            }
        }
    }
    state.setLatestAngle(angle2);
}