org.jfree.util.Rotation Java Examples

The following examples show how to use org.jfree.util.Rotation. 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: StatisticsController.java    From JDeSurvey with GNU Affero General Public License v3.0 5 votes vote down vote up
@Secured({"ROLE_ADMIN","ROLE_SURVEY_ADMIN"})
private JFreeChart createChart(PieDataset pieDataset, String title) {
try{
	JFreeChart chart = ChartFactory.createPieChart(title, pieDataset, false,true,false);

	chart.setBackgroundPaint(null);//this line necessary for transparency of background
       final ChartPanel chartPanel = new ChartPanel(chart);
       chartPanel.setOpaque(false); //this line necessary for transparency of background
       chartPanel.setBackground(new Color(0, 0, 0, 0)); //this line necessary for transparency of background
       
	PiePlot plot = (PiePlot) chart.getPlot();
	
	//Color[] colors = {new Color(170, 195, 217, 255),new Color(246, 140, 31, 255),new Color(204, 204, 204, 255),new Color(231, 238, 144, 255),new Color(51, 51, 51, 255),new Color(101, 125, 151, 255),new Color(0, 102, 255, 255)}; 
	//PieRenderer renderer = new PieRenderer(colors); 
	//renderer.setColor(plot, pieDataset);
	
	
	PieSectionLabelGenerator generator = new StandardPieSectionLabelGenerator("{0}:{1}%"); 
	plot.setLabelGenerator(generator);
	
	plot.setStartAngle(270);
	plot.setDirection(Rotation.CLOCKWISE);
	
	return chart;
} catch (Exception e) {
	log.error(e.getMessage(),e);
	throw (new RuntimeException(e));
}
}
 
Example #2
Source File: SpiderWebPlot.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new spider web plot with the given dataset.
 *
 * @param dataset  the dataset.
 * @param extract  controls how data is extracted ({@link TableOrder#BY_ROW}
 *                 or {@link TableOrder#BY_COLUMN}).
 */
public SpiderWebPlot(CategoryDataset dataset, TableOrder extract) {
    super();
    ParamChecks.nullNotPermitted(extract, "extract");
    this.dataset = dataset;
    if (dataset != null) {
        dataset.addChangeListener(this);
    }

    this.dataExtractOrder = extract;
    this.headPercent = DEFAULT_HEAD;
    this.axisLabelGap = DEFAULT_AXIS_LABEL_GAP;
    this.axisLinePaint = Color.black;
    this.axisLineStroke = new BasicStroke(1.0f);

    this.interiorGap = DEFAULT_INTERIOR_GAP;
    this.startAngle = DEFAULT_START_ANGLE;
    this.direction = Rotation.CLOCKWISE;
    this.maxValue = DEFAULT_MAX_VALUE;

    this.seriesPaint = null;
    this.seriesPaintList = new PaintList();
    this.baseSeriesPaint = null;

    this.seriesOutlinePaint = null;
    this.seriesOutlinePaintList = new PaintList();
    this.baseSeriesOutlinePaint = DEFAULT_OUTLINE_PAINT;

    this.seriesOutlineStroke = null;
    this.seriesOutlineStrokeList = new StrokeList();
    this.baseSeriesOutlineStroke = DEFAULT_OUTLINE_STROKE;

    this.labelFont = DEFAULT_LABEL_FONT;
    this.labelPaint = DEFAULT_LABEL_PAINT;
    this.labelGenerator = new StandardCategoryItemLabelGenerator();

    this.legendItemShape = DEFAULT_LEGEND_ITEM_CIRCLE;
}
 
Example #3
Source File: SpiderWebPlot.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new spider web plot with the given dataset.
 *
 * @param dataset  the dataset.
 * @param extract  controls how data is extracted ({@link TableOrder#BY_ROW}
 *                 or {@link TableOrder#BY_COLUMN}).
 */
public SpiderWebPlot(CategoryDataset dataset, TableOrder extract) {
    super();
    ParamChecks.nullNotPermitted(extract, "extract");
    this.dataset = dataset;
    if (dataset != null) {
        dataset.addChangeListener(this);
    }

    this.dataExtractOrder = extract;
    this.headPercent = DEFAULT_HEAD;
    this.axisLabelGap = DEFAULT_AXIS_LABEL_GAP;
    this.axisLinePaint = Color.black;
    this.axisLineStroke = new BasicStroke(1.0f);

    this.interiorGap = DEFAULT_INTERIOR_GAP;
    this.startAngle = DEFAULT_START_ANGLE;
    this.direction = Rotation.CLOCKWISE;
    this.maxValue = DEFAULT_MAX_VALUE;

    this.seriesPaint = null;
    this.seriesPaintList = new PaintList();
    this.baseSeriesPaint = null;

    this.seriesOutlinePaint = null;
    this.seriesOutlinePaintList = new PaintList();
    this.baseSeriesOutlinePaint = DEFAULT_OUTLINE_PAINT;

    this.seriesOutlineStroke = null;
    this.seriesOutlineStrokeList = new StrokeList();
    this.baseSeriesOutlineStroke = DEFAULT_OUTLINE_STROKE;

    this.labelFont = DEFAULT_LABEL_FONT;
    this.labelPaint = DEFAULT_LABEL_PAINT;
    this.labelGenerator = new StandardCategoryItemLabelGenerator();

    this.legendItemShape = DEFAULT_LEGEND_ITEM_CIRCLE;
}
 
Example #4
Source File: JFreeChartScriptlet.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void afterReportInit() throws JRScriptletException
{
	DefaultPieDataset dataset = new DefaultPieDataset();
	dataset.setValue("Java", 43.2d);
	dataset.setValue("Visual Basic", 10.0d);
	dataset.setValue("C/C++", 17.5d);
	dataset.setValue("PHP", 32.5d);
	dataset.setValue("Perl", 1.0d);

	JFreeChart chart = 
		ChartFactory.createPieChart3D(
			"Pie Chart 3D Demo 1",
			dataset,
			true,
			true,
			false
			);

	PiePlot3D plot = (PiePlot3D) chart.getPlot();
	plot.setStartAngle(290);
	plot.setDirection(Rotation.CLOCKWISE);
	plot.setForegroundAlpha(0.5f);
	plot.setNoDataMessage("No data to display");

	/*   */
	this.setVariableValue("Chart", new JCommonDrawableRendererImpl(chart));
}
 
Example #5
Source File: PiePlot.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the direction in which the pie sections are drawn and sends a 
 * {@link PlotChangeEvent} to all registered listeners.
 *
 * @param direction  the direction (<code>null</code> not permitted).
 * 
 * @see #getDirection()
 */
public void setDirection(Rotation direction) {
    if (direction == null) {
        throw new IllegalArgumentException("Null 'direction' argument.");
    }
    this.direction = direction;
    notifyListeners(new PlotChangeEvent(this));

}
 
Example #6
Source File: TransitionsPieChart.java    From osmo with GNU Lesser General Public License v2.1 5 votes vote down vote up
private JFreeChart createChart(String title) {
  JFreeChart chart = ChartFactory.createPieChart3D(title, data, true, true, false);
  PiePlot3D plot = (PiePlot3D) chart.getPlot();
  plot.setStartAngle(290);
  plot.setDirection(Rotation.CLOCKWISE);
  plot.setForegroundAlpha(0.5f);
  return chart;
}
 
Example #7
Source File: SpiderWebPlot.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new spider web plot with the given dataset.
 *
 * @param dataset  the dataset.
 * @param extract  controls how data is extracted ({@link TableOrder#BY_ROW}
 *                 or {@link TableOrder#BY_COLUMN}).
 */
public SpiderWebPlot(CategoryDataset dataset, TableOrder extract) {
    super();
    ParamChecks.nullNotPermitted(extract, "extract");
    this.dataset = dataset;
    if (dataset != null) {
        dataset.addChangeListener(this);
    }

    this.dataExtractOrder = extract;
    this.headPercent = DEFAULT_HEAD;
    this.axisLabelGap = DEFAULT_AXIS_LABEL_GAP;
    this.axisLinePaint = Color.black;
    this.axisLineStroke = new BasicStroke(1.0f);

    this.interiorGap = DEFAULT_INTERIOR_GAP;
    this.startAngle = DEFAULT_START_ANGLE;
    this.direction = Rotation.CLOCKWISE;
    this.maxValue = DEFAULT_MAX_VALUE;

    this.seriesPaint = null;
    this.seriesPaintList = new PaintList();
    this.baseSeriesPaint = null;

    this.seriesOutlinePaint = null;
    this.seriesOutlinePaintList = new PaintList();
    this.baseSeriesOutlinePaint = DEFAULT_OUTLINE_PAINT;

    this.seriesOutlineStroke = null;
    this.seriesOutlineStrokeList = new StrokeList();
    this.baseSeriesOutlineStroke = DEFAULT_OUTLINE_STROKE;

    this.labelFont = DEFAULT_LABEL_FONT;
    this.labelPaint = DEFAULT_LABEL_PAINT;
    this.labelGenerator = new StandardCategoryItemLabelGenerator();

    this.legendItemShape = DEFAULT_LEGEND_ITEM_CIRCLE;
}
 
Example #8
Source File: GraphStatsView.java    From eclipse-cs with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Crée le graphe JFreeChart.
 *
 * @param piedataset
 *          : la source de données à afficher
 * @return le diagramme
 */
private JFreeChart createChart(GraphPieDataset piedataset) {
  JFreeChart jfreechart = ChartFactory.createPieChart3D(null, piedataset, false, true, false);
  jfreechart.setAntiAlias(true);
  jfreechart.setTextAntiAlias(true);

  PiePlot pieplot3d = (PiePlot) jfreechart.getPlot();
  pieplot3d.setInsets(new RectangleInsets(0, 0, 0, 0));
  final double angle = 290D;
  pieplot3d.setStartAngle(angle);
  pieplot3d.setDirection(Rotation.CLOCKWISE);
  final float foreground = 0.5F;
  pieplot3d.setForegroundAlpha(foreground);
  pieplot3d.setNoDataMessage(Messages.GraphStatsView_noDataToDisplay);
  pieplot3d.setCircular(true);

  pieplot3d.setOutlinePaint(null);
  pieplot3d.setLabelFont(new Font("SansSerif", Font.PLAIN, 10));
  pieplot3d.setLabelGap(0.02);
  pieplot3d.setLabelOutlinePaint(null);
  pieplot3d.setLabelShadowPaint(null);
  pieplot3d.setLabelBackgroundPaint(Color.WHITE);
  pieplot3d.setBackgroundPaint(Color.WHITE);
  // avoid showing the percentage as an absolute number in the tooltip
  pieplot3d.setToolTipGenerator(new StandardPieToolTipGenerator("{0}: {2}"));
  pieplot3d.setInteriorGap(0.02);
  pieplot3d.setMaximumLabelWidth(0.20);

  return jfreechart;
}
 
Example #9
Source File: SpiderWebPlot.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new spider web plot with the given dataset.
 *
 * @param dataset  the dataset.
 * @param extract  controls how data is extracted ({@link TableOrder#BY_ROW}
 *                 or {@link TableOrder#BY_COLUMN}).
 */
public SpiderWebPlot(CategoryDataset dataset, TableOrder extract) {
    super();
    ParamChecks.nullNotPermitted(extract, "extract");
    this.dataset = dataset;
    if (dataset != null) {
        dataset.addChangeListener(this);
    }

    this.dataExtractOrder = extract;
    this.headPercent = DEFAULT_HEAD;
    this.axisLabelGap = DEFAULT_AXIS_LABEL_GAP;
    this.axisLinePaint = Color.black;
    this.axisLineStroke = new BasicStroke(1.0f);

    this.interiorGap = DEFAULT_INTERIOR_GAP;
    this.startAngle = DEFAULT_START_ANGLE;
    this.direction = Rotation.CLOCKWISE;
    this.maxValue = DEFAULT_MAX_VALUE;

    this.seriesPaint = null;
    this.seriesPaintList = new PaintList();
    this.baseSeriesPaint = null;

    this.seriesOutlinePaint = null;
    this.seriesOutlinePaintList = new PaintList();
    this.baseSeriesOutlinePaint = DEFAULT_OUTLINE_PAINT;

    this.seriesOutlineStroke = null;
    this.seriesOutlineStrokeList = new StrokeList();
    this.baseSeriesOutlineStroke = DEFAULT_OUTLINE_STROKE;

    this.labelFont = DEFAULT_LABEL_FONT;
    this.labelPaint = DEFAULT_LABEL_PAINT;
    this.labelGenerator = new StandardCategoryItemLabelGenerator();

    this.legendItemShape = DEFAULT_LEGEND_ITEM_CIRCLE;
}
 
Example #10
Source File: SpiderWebPlot.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new spider web plot with the given dataset.
 *
 * @param dataset  the dataset.
 * @param extract  controls how data is extracted ({@link TableOrder#BY_ROW}
 *                 or {@link TableOrder#BY_COLUMN}).
 */
public SpiderWebPlot(CategoryDataset dataset, TableOrder extract) {
    super();
    ParamChecks.nullNotPermitted(extract, "extract");
    this.dataset = dataset;
    if (dataset != null) {
        dataset.addChangeListener(this);
    }

    this.dataExtractOrder = extract;
    this.headPercent = DEFAULT_HEAD;
    this.axisLabelGap = DEFAULT_AXIS_LABEL_GAP;
    this.axisLinePaint = Color.black;
    this.axisLineStroke = new BasicStroke(1.0f);

    this.interiorGap = DEFAULT_INTERIOR_GAP;
    this.startAngle = DEFAULT_START_ANGLE;
    this.direction = Rotation.CLOCKWISE;
    this.maxValue = DEFAULT_MAX_VALUE;

    this.seriesPaint = null;
    this.seriesPaintList = new PaintList();
    this.baseSeriesPaint = null;

    this.seriesOutlinePaint = null;
    this.seriesOutlinePaintList = new PaintList();
    this.baseSeriesOutlinePaint = DEFAULT_OUTLINE_PAINT;

    this.seriesOutlineStroke = null;
    this.seriesOutlineStrokeList = new StrokeList();
    this.baseSeriesOutlineStroke = DEFAULT_OUTLINE_STROKE;

    this.labelFont = DEFAULT_LABEL_FONT;
    this.labelPaint = DEFAULT_LABEL_PAINT;
    this.labelGenerator = new StandardCategoryItemLabelGenerator();

    this.legendItemShape = DEFAULT_LEGEND_ITEM_CIRCLE;
}
 
Example #11
Source File: SpiderWebPlot.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new spider web plot with the given dataset.
 *
 * @param dataset  the dataset.
 * @param extract  controls how data is extracted ({@link TableOrder#BY_ROW}
 *                 or {@link TableOrder#BY_COLUMN}).
 */
public SpiderWebPlot(CategoryDataset dataset, TableOrder extract) {
    super();
    ParamChecks.nullNotPermitted(extract, "extract");
    this.dataset = dataset;
    if (dataset != null) {
        dataset.addChangeListener(this);
    }

    this.dataExtractOrder = extract;
    this.headPercent = DEFAULT_HEAD;
    this.axisLabelGap = DEFAULT_AXIS_LABEL_GAP;
    this.axisLinePaint = Color.black;
    this.axisLineStroke = new BasicStroke(1.0f);

    this.interiorGap = DEFAULT_INTERIOR_GAP;
    this.startAngle = DEFAULT_START_ANGLE;
    this.direction = Rotation.CLOCKWISE;
    this.maxValue = DEFAULT_MAX_VALUE;

    this.seriesPaint = null;
    this.seriesPaintList = new PaintList();
    this.baseSeriesPaint = null;

    this.seriesOutlinePaint = null;
    this.seriesOutlinePaintList = new PaintList();
    this.baseSeriesOutlinePaint = DEFAULT_OUTLINE_PAINT;

    this.seriesOutlineStroke = null;
    this.seriesOutlineStrokeList = new StrokeList();
    this.baseSeriesOutlineStroke = DEFAULT_OUTLINE_STROKE;

    this.labelFont = DEFAULT_LABEL_FONT;
    this.labelPaint = DEFAULT_LABEL_PAINT;
    this.labelGenerator = new StandardCategoryItemLabelGenerator();

    this.legendItemShape = DEFAULT_LEGEND_ITEM_CIRCLE;
}
 
Example #12
Source File: SpiderWebPlot.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new spider web plot with the given dataset.
 * 
 * @param dataset  the dataset.
 * @param extract  controls how data is extracted ({@link TableOrder#BY_ROW}
 *                 or {@link TableOrder#BY_COLUMN}).
 */
public SpiderWebPlot(CategoryDataset dataset, TableOrder extract) {
    super();
    if (extract == null) {
        throw new IllegalArgumentException("Null 'extract' argument.");
    }
    this.dataset = dataset;
    if (dataset != null) {
        dataset.addChangeListener(this);
    }

    this.dataExtractOrder = extract;
    this.headPercent = DEFAULT_HEAD;
    this.axisLabelGap = DEFAULT_AXIS_LABEL_GAP;
    this.axisLinePaint = Color.black;
    this.axisLineStroke = new BasicStroke(1.0f);
    
    this.interiorGap = DEFAULT_INTERIOR_GAP;
    this.startAngle = DEFAULT_START_ANGLE;
    this.direction = Rotation.CLOCKWISE;
    this.maxValue = DEFAULT_MAX_VALUE;

    this.seriesPaint = null;
    this.seriesPaintList = new PaintList();
    this.baseSeriesPaint = null;

    this.seriesOutlinePaint = null;
    this.seriesOutlinePaintList = new PaintList();
    this.baseSeriesOutlinePaint = DEFAULT_OUTLINE_PAINT;

    this.seriesOutlineStroke = null;
    this.seriesOutlineStrokeList = new StrokeList();
    this.baseSeriesOutlineStroke = DEFAULT_OUTLINE_STROKE;

    this.labelFont = DEFAULT_LABEL_FONT;
    this.labelPaint = DEFAULT_LABEL_PAINT;
    this.labelGenerator = new StandardCategoryItemLabelGenerator();
    
    this.legendItemShape = DEFAULT_LEGEND_ITEM_CIRCLE;
}
 
Example #13
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 #14
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 #15
Source File: PieChartTab.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
/**
   * Create a PieChart view that displays the data in a particular column.
   *
   * @param model Data source.
   * @param column Index of the column to collate.
   */
  public PieChartTab(MonitorModel model, int column) {
      super(model, false, ImageLoader.getNewIcon(MonitorWindow.PIE_ICON));

      String title = model.getName() + " - " + model.getColumnName(column);
      setName(title);

      pieModel = new TablePieDataset(model, column);

      chart = ChartFactory.createPieChart3D(null, pieModel, true, true, false);
      chart.setBackgroundPaint(getBackground());

      pieModel.calculate();

      // 2015-10-18 Changed to 3D pie
      final PiePlot3D plot = (PiePlot3D)chart.getPlot();

      //plot.setCircular(false);
      //plot.setRadius(0.60);
      //plot.setSectionLabelType(PiePlot.PERCENT_LABELS);

      plot.setStartAngle(270);
      plot.setDirection(Rotation.ANTICLOCKWISE);
      plot.setForegroundAlpha(0.6f);
      //plot.setInteriorGap(0.33);

      pieModel.addChangeListener(plot);

      chartpanel = new ChartPanel(chart, true);

      // 2015-10-18 Added setting below to keep the aspect ratio of 8:5
      // see http://www.jfree.org/forum/viewtopic.php?f=3&t=115763
      // Chart will always be drawn to an off-screen buffer that is the same size as the ChartPanel, so no scaling will happen when the offscreen image is copied to the panel.
      chartpanel.setPreferredSize(new Dimension (800, 300));
      chartpanel.setMinimumDrawWidth(0);
      chartpanel.setMaximumDrawWidth(Integer.MAX_VALUE);
      chartpanel.setMinimumDrawHeight(0);
      chartpanel.setMaximumDrawHeight(Integer.MAX_VALUE);

JPanel fixedSizePane = new JPanel(new FlowLayout());
fixedSizePane.add(chartpanel);
fixedSizePane.addComponentListener(new ComponentAdapter() {
          @Override
          public void componentResized(ComponentEvent e) {
          	int w = fixedSizePane.getWidth();
              int h = fixedSizePane.getHeight();
              int size =  Math.min(w, h);
              int newWidth = (int) (size *8D/3D);
              chartpanel.setPreferredSize(new Dimension(newWidth, size));
              fixedSizePane.revalidate();
          }
      });

      add(fixedSizePane, BorderLayout.CENTER);

      // 2015-10-18 Added rotator code
      final Rotator rotator = new Rotator(plot);
      rotator.start();
//System.out.println("PieChartTab : just done calling constructor");
  }
 
Example #16
Source File: PiePlot.java    From SIMVA-SoS with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the center for the specified section.
 * Checks to see if the section is exploded and recalculates the
 * new center if so.
 *
 * @param state  PiePlotState
 * @param key  section key.
 *
 * @return The center for the specified section.
 *
 * @since 1.0.14
 */
protected Point2D getArcCenter(PiePlotState state, Comparable key) {
    Point2D center = new Point2D.Double(state.getPieCenterX(), state
        .getPieCenterY());

    double ep = getExplodePercent(key);
    double mep = getMaximumExplodePercent();
    if (mep > 0.0) {
        ep = ep / mep;
    }
    if (ep != 0) {
        Rectangle2D pieArea = state.getPieArea();
        Rectangle2D expPieArea = state.getExplodedPieArea();
        double angle1, angle2;
        Number n = this.dataset.getValue(key);
        double value = n.doubleValue();

        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);

        Arc2D arc1 = new Arc2D.Double(pieArea, angle1, angle / 2,
                Arc2D.OPEN);
        Point2D point1 = arc1.getEndPoint();
        Arc2D.Double arc2 = new Arc2D.Double(expPieArea, angle1, angle / 2,
                Arc2D.OPEN);
        Point2D point2 = arc2.getEndPoint();
        double deltaX = (point1.getX() - point2.getX()) * ep;
        double deltaY = (point1.getY() - point2.getY()) * ep;

        center = new Point2D.Double(state.getPieCenterX() - deltaX,
                 state.getPieCenterY() - deltaY);

    }
    return center;
}
 
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 buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Returns the center for the specified section.
 * Checks to see if the section is exploded and recalculates the
 * new center if so.
 *
 * @param state  PiePlotState
 * @param key  section key.
 *
 * @return The center for the specified section.
 *
 * @since 1.0.14
 */
protected Point2D getArcCenter(PiePlotState state, Comparable key) {
    Point2D center = new Point2D.Double(state.getPieCenterX(), state
        .getPieCenterY());

    double ep = getExplodePercent(key);
    double mep = getMaximumExplodePercent();
    if (mep > 0.0) {
        ep = ep / mep;
    }
    if (ep != 0) {
        Rectangle2D pieArea = state.getPieArea();
        Rectangle2D expPieArea = state.getExplodedPieArea();
        double angle1, angle2;
        Number n = this.dataset.getValue(key);
        double value = n.doubleValue();

        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);

        Arc2D arc1 = new Arc2D.Double(pieArea, angle1, angle / 2,
                Arc2D.OPEN);
        Point2D point1 = arc1.getEndPoint();
        Arc2D.Double arc2 = new Arc2D.Double(expPieArea, angle1, angle / 2,
                Arc2D.OPEN);
        Point2D point2 = arc2.getEndPoint();
        double deltaX = (point1.getX() - point2.getX()) * ep;
        double deltaY = (point1.getY() - point2.getY()) * ep;

        center = new Point2D.Double(state.getPieCenterX() - deltaX,
                 state.getPieCenterY() - deltaY);

    }
    return center;
}
 
Example #19
Source File: PiePlot.java    From ECG-Viewer with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a plot that will draw a pie chart for the specified dataset.
 *
 * @param dataset  the dataset (<code>null</code> permitted).
 */
public PiePlot(PieDataset dataset) {
    super();
    this.dataset = dataset;
    if (dataset != null) {
        dataset.addChangeListener(this);
    }
    this.pieIndex = 0;

    this.interiorGap = DEFAULT_INTERIOR_GAP;
    this.circular = true;
    this.startAngle = DEFAULT_START_ANGLE;
    this.direction = Rotation.CLOCKWISE;
    this.minimumArcAngleToDraw = DEFAULT_MINIMUM_ARC_ANGLE_TO_DRAW;

    this.sectionPaint = null;
    this.sectionPaintMap = new PaintMap();
    this.baseSectionPaint = Color.gray;
    this.autoPopulateSectionPaint = true;

    this.sectionOutlinesVisible = true;
    this.sectionOutlinePaint = null;
    this.sectionOutlinePaintMap = new PaintMap();
    this.baseSectionOutlinePaint = DEFAULT_OUTLINE_PAINT;
    this.autoPopulateSectionOutlinePaint = false;

    this.sectionOutlineStroke = null;
    this.sectionOutlineStrokeMap = new StrokeMap();
    this.baseSectionOutlineStroke = DEFAULT_OUTLINE_STROKE;
    this.autoPopulateSectionOutlineStroke = false;

    this.explodePercentages = new TreeMap();

    this.labelGenerator = new StandardPieSectionLabelGenerator();
    this.labelFont = DEFAULT_LABEL_FONT;
    this.labelPaint = DEFAULT_LABEL_PAINT;
    this.labelBackgroundPaint = DEFAULT_LABEL_BACKGROUND_PAINT;
    this.labelOutlinePaint = DEFAULT_LABEL_OUTLINE_PAINT;
    this.labelOutlineStroke = DEFAULT_LABEL_OUTLINE_STROKE;
    this.labelShadowPaint = DEFAULT_LABEL_SHADOW_PAINT;
    this.labelLinksVisible = true;
    this.labelDistributor = new PieLabelDistributor(0);

    this.simpleLabels = false;
    this.simpleLabelOffset = new RectangleInsets(UnitType.RELATIVE, 0.18,
            0.18, 0.18, 0.18);
    this.labelPadding = new RectangleInsets(2, 2, 2, 2);

    this.toolTipGenerator = null;
    this.urlGenerator = null;
    this.legendLabelGenerator = new StandardPieSectionLabelGenerator();
    this.legendLabelToolTipGenerator = null;
    this.legendLabelURLGenerator = null;
    this.legendItemShape = Plot.DEFAULT_LEGEND_ITEM_CIRCLE;

    this.ignoreNullValues = false;
    this.ignoreZeroValues = false;

    this.shadowGenerator = null;
}
 
Example #20
Source File: PiePlot.java    From SIMVA-SoS with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a plot that will draw a pie chart for the specified dataset.
 *
 * @param dataset  the dataset (<code>null</code> permitted).
 */
public PiePlot(PieDataset dataset) {
    super();
    this.dataset = dataset;
    if (dataset != null) {
        dataset.addChangeListener(this);
    }
    this.pieIndex = 0;

    this.interiorGap = DEFAULT_INTERIOR_GAP;
    this.circular = true;
    this.startAngle = DEFAULT_START_ANGLE;
    this.direction = Rotation.CLOCKWISE;
    this.minimumArcAngleToDraw = DEFAULT_MINIMUM_ARC_ANGLE_TO_DRAW;

    this.sectionPaint = null;
    this.sectionPaintMap = new PaintMap();
    this.baseSectionPaint = Color.gray;
    this.autoPopulateSectionPaint = true;

    this.sectionOutlinesVisible = true;
    this.sectionOutlinePaint = null;
    this.sectionOutlinePaintMap = new PaintMap();
    this.baseSectionOutlinePaint = DEFAULT_OUTLINE_PAINT;
    this.autoPopulateSectionOutlinePaint = false;

    this.sectionOutlineStroke = null;
    this.sectionOutlineStrokeMap = new StrokeMap();
    this.baseSectionOutlineStroke = DEFAULT_OUTLINE_STROKE;
    this.autoPopulateSectionOutlineStroke = false;

    this.explodePercentages = new TreeMap();

    this.labelGenerator = new StandardPieSectionLabelGenerator();
    this.labelFont = DEFAULT_LABEL_FONT;
    this.labelPaint = DEFAULT_LABEL_PAINT;
    this.labelBackgroundPaint = DEFAULT_LABEL_BACKGROUND_PAINT;
    this.labelOutlinePaint = DEFAULT_LABEL_OUTLINE_PAINT;
    this.labelOutlineStroke = DEFAULT_LABEL_OUTLINE_STROKE;
    this.labelShadowPaint = DEFAULT_LABEL_SHADOW_PAINT;
    this.labelLinksVisible = true;
    this.labelDistributor = new PieLabelDistributor(0);

    this.simpleLabels = false;
    this.simpleLabelOffset = new RectangleInsets(UnitType.RELATIVE, 0.18,
            0.18, 0.18, 0.18);
    this.labelPadding = new RectangleInsets(2, 2, 2, 2);

    this.toolTipGenerator = null;
    this.urlGenerator = null;
    this.legendLabelGenerator = new StandardPieSectionLabelGenerator();
    this.legendLabelToolTipGenerator = null;
    this.legendLabelURLGenerator = null;
    this.legendItemShape = Plot.DEFAULT_LEGEND_ITEM_CIRCLE;

    this.ignoreNullValues = false;
    this.ignoreZeroValues = false;

    this.shadowGenerator = null;
}
 
Example #21
Source File: PiePlot.java    From ECG-Viewer with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the center for the specified section.
 * Checks to see if the section is exploded and recalculates the
 * new center if so.
 *
 * @param state  PiePlotState
 * @param key  section key.
 *
 * @return The center for the specified section.
 *
 * @since 1.0.14
 */
protected Point2D getArcCenter(PiePlotState state, Comparable key) {
    Point2D center = new Point2D.Double(state.getPieCenterX(), state
        .getPieCenterY());

    double ep = getExplodePercent(key);
    double mep = getMaximumExplodePercent();
    if (mep > 0.0) {
        ep = ep / mep;
    }
    if (ep != 0) {
        Rectangle2D pieArea = state.getPieArea();
        Rectangle2D expPieArea = state.getExplodedPieArea();
        double angle1, angle2;
        Number n = this.dataset.getValue(key);
        double value = n.doubleValue();

        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);

        Arc2D arc1 = new Arc2D.Double(pieArea, angle1, angle / 2,
                Arc2D.OPEN);
        Point2D point1 = arc1.getEndPoint();
        Arc2D.Double arc2 = new Arc2D.Double(expPieArea, angle1, angle / 2,
                Arc2D.OPEN);
        Point2D point2 = arc2.getEndPoint();
        double deltaX = (point1.getX() - point2.getX()) * ep;
        double deltaY = (point1.getY() - point2.getY()) * ep;

        center = new Point2D.Double(state.getPieCenterX() - deltaX,
                 state.getPieCenterY() - deltaY);

    }
    return center;
}
 
Example #22
Source File: PiePlot.java    From opensim-gui with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a plot that will draw a pie chart for the specified dataset.
 *
 * @param dataset  the dataset (<code>null</code> permitted).
 */
public PiePlot(PieDataset dataset) {
    super();
    this.dataset = dataset;
    if (dataset != null) {
        dataset.addChangeListener(this);
    }
    this.pieIndex = 0;
    
    this.interiorGap = DEFAULT_INTERIOR_GAP;
    this.circular = true;
    this.startAngle = DEFAULT_START_ANGLE;
    this.direction = Rotation.CLOCKWISE;
    this.minimumArcAngleToDraw = DEFAULT_MINIMUM_ARC_ANGLE_TO_DRAW;
    
    this.sectionPaint = null;
    this.sectionPaintMap = new PaintMap();
    this.baseSectionPaint = Color.gray;

    this.sectionOutlinesVisible = true;
    this.sectionOutlinePaint = null;
    this.sectionOutlinePaintMap = new PaintMap();
    this.baseSectionOutlinePaint = DEFAULT_OUTLINE_PAINT;

    this.sectionOutlineStroke = null;
    this.sectionOutlineStrokeMap = new StrokeMap();
    this.baseSectionOutlineStroke = DEFAULT_OUTLINE_STROKE;
    
    this.explodePercentages = new TreeMap();

    this.labelGenerator = new StandardPieSectionLabelGenerator();
    this.labelFont = DEFAULT_LABEL_FONT;
    this.labelPaint = DEFAULT_LABEL_PAINT;
    this.labelBackgroundPaint = DEFAULT_LABEL_BACKGROUND_PAINT;
    this.labelOutlinePaint = DEFAULT_LABEL_OUTLINE_PAINT;
    this.labelOutlineStroke = DEFAULT_LABEL_OUTLINE_STROKE;
    this.labelShadowPaint = DEFAULT_LABEL_SHADOW_PAINT;
    this.labelLinksVisible = true;
    
    this.toolTipGenerator = null;
    this.urlGenerator = null;
    this.legendLabelGenerator = new StandardPieSectionLabelGenerator();
    this.legendLabelToolTipGenerator = null;
    this.legendLabelURLGenerator = null;
    this.legendItemShape = Plot.DEFAULT_LEGEND_ITEM_CIRCLE;
    
    this.ignoreNullValues = false;
    this.ignoreZeroValues = false;
}
 
Example #23
Source File: PiePlot.java    From ccu-historian with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Returns the center for the specified section.
 * Checks to see if the section is exploded and recalculates the
 * new center if so.
 *
 * @param state  PiePlotState
 * @param key  section key.
 *
 * @return The center for the specified section.
 *
 * @since 1.0.14
 */
protected Point2D getArcCenter(PiePlotState state, Comparable key) {
    Point2D center = new Point2D.Double(state.getPieCenterX(), state
        .getPieCenterY());

    double ep = getExplodePercent(key);
    double mep = getMaximumExplodePercent();
    if (mep > 0.0) {
        ep = ep / mep;
    }
    if (ep != 0) {
        Rectangle2D pieArea = state.getPieArea();
        Rectangle2D expPieArea = state.getExplodedPieArea();
        double angle1, angle2;
        Number n = this.dataset.getValue(key);
        double value = n.doubleValue();

        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);

        Arc2D arc1 = new Arc2D.Double(pieArea, angle1, angle / 2,
                Arc2D.OPEN);
        Point2D point1 = arc1.getEndPoint();
        Arc2D.Double arc2 = new Arc2D.Double(expPieArea, angle1, angle / 2,
                Arc2D.OPEN);
        Point2D point2 = arc2.getEndPoint();
        double deltaX = (point1.getX() - point2.getX()) * ep;
        double deltaY = (point1.getY() - point2.getY()) * ep;

        center = new Point2D.Double(state.getPieCenterX() - deltaX,
                 state.getPieCenterY() - deltaY);

    }
    return center;
}
 
Example #24
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);
}
 
Example #25
Source File: PiePlot.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates a plot that will draw a pie chart for the specified dataset.
 *
 * @param dataset  the dataset (<code>null</code> permitted).
 */
public PiePlot(PieDataset dataset) {
    super();
    this.dataset = dataset;
    if (dataset != null) {
        dataset.addChangeListener(this);
    }
    this.pieIndex = 0;

    this.interiorGap = DEFAULT_INTERIOR_GAP;
    this.circular = true;
    this.startAngle = DEFAULT_START_ANGLE;
    this.direction = Rotation.CLOCKWISE;
    this.minimumArcAngleToDraw = DEFAULT_MINIMUM_ARC_ANGLE_TO_DRAW;

    this.sectionPaint = null;
    this.sectionPaintMap = new PaintMap();
    this.baseSectionPaint = Color.gray;
    this.autoPopulateSectionPaint = true;

    this.sectionOutlinesVisible = true;
    this.sectionOutlinePaint = null;
    this.sectionOutlinePaintMap = new PaintMap();
    this.baseSectionOutlinePaint = DEFAULT_OUTLINE_PAINT;
    this.autoPopulateSectionOutlinePaint = false;

    this.sectionOutlineStroke = null;
    this.sectionOutlineStrokeMap = new StrokeMap();
    this.baseSectionOutlineStroke = DEFAULT_OUTLINE_STROKE;
    this.autoPopulateSectionOutlineStroke = false;

    this.explodePercentages = new TreeMap();

    this.labelGenerator = new StandardPieSectionLabelGenerator();
    this.labelFont = DEFAULT_LABEL_FONT;
    this.labelPaint = DEFAULT_LABEL_PAINT;
    this.labelBackgroundPaint = DEFAULT_LABEL_BACKGROUND_PAINT;
    this.labelOutlinePaint = DEFAULT_LABEL_OUTLINE_PAINT;
    this.labelOutlineStroke = DEFAULT_LABEL_OUTLINE_STROKE;
    this.labelShadowPaint = DEFAULT_LABEL_SHADOW_PAINT;
    this.labelLinksVisible = true;
    this.labelDistributor = new PieLabelDistributor(0);

    this.simpleLabels = false;
    this.simpleLabelOffset = new RectangleInsets(UnitType.RELATIVE, 0.18,
            0.18, 0.18, 0.18);
    this.labelPadding = new RectangleInsets(2, 2, 2, 2);

    this.toolTipGenerator = null;
    this.urlGenerator = null;
    this.legendLabelGenerator = new StandardPieSectionLabelGenerator();
    this.legendLabelToolTipGenerator = null;
    this.legendLabelURLGenerator = null;
    this.legendItemShape = Plot.DEFAULT_LEGEND_ITEM_CIRCLE;

    this.ignoreNullValues = false;
    this.ignoreZeroValues = false;

    this.shadowGenerator = null;
}
 
Example #26
Source File: PiePlot.java    From ccu-historian with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates a plot that will draw a pie chart for the specified dataset.
 *
 * @param dataset  the dataset (<code>null</code> permitted).
 */
public PiePlot(PieDataset dataset) {
    super();
    this.dataset = dataset;
    if (dataset != null) {
        dataset.addChangeListener(this);
    }
    this.pieIndex = 0;

    this.interiorGap = DEFAULT_INTERIOR_GAP;
    this.circular = true;
    this.startAngle = DEFAULT_START_ANGLE;
    this.direction = Rotation.CLOCKWISE;
    this.minimumArcAngleToDraw = DEFAULT_MINIMUM_ARC_ANGLE_TO_DRAW;

    this.sectionPaint = null;
    this.sectionPaintMap = new PaintMap();
    this.baseSectionPaint = Color.gray;
    this.autoPopulateSectionPaint = true;

    this.sectionOutlinesVisible = true;
    this.sectionOutlinePaint = null;
    this.sectionOutlinePaintMap = new PaintMap();
    this.baseSectionOutlinePaint = DEFAULT_OUTLINE_PAINT;
    this.autoPopulateSectionOutlinePaint = false;

    this.sectionOutlineStroke = null;
    this.sectionOutlineStrokeMap = new StrokeMap();
    this.baseSectionOutlineStroke = DEFAULT_OUTLINE_STROKE;
    this.autoPopulateSectionOutlineStroke = false;

    this.explodePercentages = new TreeMap();

    this.labelGenerator = new StandardPieSectionLabelGenerator();
    this.labelFont = DEFAULT_LABEL_FONT;
    this.labelPaint = DEFAULT_LABEL_PAINT;
    this.labelBackgroundPaint = DEFAULT_LABEL_BACKGROUND_PAINT;
    this.labelOutlinePaint = DEFAULT_LABEL_OUTLINE_PAINT;
    this.labelOutlineStroke = DEFAULT_LABEL_OUTLINE_STROKE;
    this.labelShadowPaint = DEFAULT_LABEL_SHADOW_PAINT;
    this.labelLinksVisible = true;
    this.labelDistributor = new PieLabelDistributor(0);

    this.simpleLabels = false;
    this.simpleLabelOffset = new RectangleInsets(UnitType.RELATIVE, 0.18,
            0.18, 0.18, 0.18);
    this.labelPadding = new RectangleInsets(2, 2, 2, 2);

    this.toolTipGenerator = null;
    this.urlGenerator = null;
    this.legendLabelGenerator = new StandardPieSectionLabelGenerator();
    this.legendLabelToolTipGenerator = null;
    this.legendLabelURLGenerator = null;
    this.legendItemShape = Plot.DEFAULT_LEGEND_ITEM_CIRCLE;

    this.ignoreNullValues = false;
    this.ignoreZeroValues = false;

    this.shadowGenerator = null;
}
 
Example #27
Source File: PiePlot.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates a plot that will draw a pie chart for the specified dataset.
 *
 * @param dataset  the dataset (<code>null</code> permitted).
 */
public PiePlot(PieDataset dataset) {
    super();
    this.dataset = dataset;
    if (dataset != null) {
        dataset.addChangeListener(this);
    }
    this.pieIndex = 0;

    this.interiorGap = DEFAULT_INTERIOR_GAP;
    this.circular = true;
    this.startAngle = DEFAULT_START_ANGLE;
    this.direction = Rotation.CLOCKWISE;
    this.minimumArcAngleToDraw = DEFAULT_MINIMUM_ARC_ANGLE_TO_DRAW;

    this.sectionPaint = null;
    this.sectionPaintMap = new PaintMap();
    this.baseSectionPaint = Color.gray;
    this.autoPopulateSectionPaint = true;

    this.sectionOutlinesVisible = true;
    this.sectionOutlinePaint = null;
    this.sectionOutlinePaintMap = new PaintMap();
    this.baseSectionOutlinePaint = DEFAULT_OUTLINE_PAINT;
    this.autoPopulateSectionOutlinePaint = false;

    this.sectionOutlineStroke = null;
    this.sectionOutlineStrokeMap = new StrokeMap();
    this.baseSectionOutlineStroke = DEFAULT_OUTLINE_STROKE;
    this.autoPopulateSectionOutlineStroke = false;

    this.explodePercentages = new TreeMap();

    this.labelGenerator = new StandardPieSectionLabelGenerator();
    this.labelFont = DEFAULT_LABEL_FONT;
    this.labelPaint = DEFAULT_LABEL_PAINT;
    this.labelBackgroundPaint = DEFAULT_LABEL_BACKGROUND_PAINT;
    this.labelOutlinePaint = DEFAULT_LABEL_OUTLINE_PAINT;
    this.labelOutlineStroke = DEFAULT_LABEL_OUTLINE_STROKE;
    this.labelShadowPaint = DEFAULT_LABEL_SHADOW_PAINT;
    this.labelLinksVisible = true;
    this.labelDistributor = new PieLabelDistributor(0);

    this.simpleLabels = false;
    this.simpleLabelOffset = new RectangleInsets(UnitType.RELATIVE, 0.18,
            0.18, 0.18, 0.18);
    this.labelPadding = new RectangleInsets(2, 2, 2, 2);

    this.toolTipGenerator = null;
    this.urlGenerator = null;
    this.legendLabelGenerator = new StandardPieSectionLabelGenerator();
    this.legendLabelToolTipGenerator = null;
    this.legendLabelURLGenerator = null;
    this.legendItemShape = Plot.DEFAULT_LEGEND_ITEM_CIRCLE;

    this.ignoreNullValues = false;
    this.ignoreZeroValues = false;

    this.shadowGenerator = null;
}
 
Example #28
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 #29
Source File: PiePlot.java    From openstock with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Returns the center for the specified section.
 * Checks to see if the section is exploded and recalculates the
 * new center if so.
 *
 * @param state  PiePlotState
 * @param key  section key.
 *
 * @return The center for the specified section.
 *
 * @since 1.0.14
 */
protected Point2D getArcCenter(PiePlotState state, Comparable key) {
    Point2D center = new Point2D.Double(state.getPieCenterX(), state
        .getPieCenterY());

    double ep = getExplodePercent(key);
    double mep = getMaximumExplodePercent();
    if (mep > 0.0) {
        ep = ep / mep;
    }
    if (ep != 0) {
        Rectangle2D pieArea = state.getPieArea();
        Rectangle2D expPieArea = state.getExplodedPieArea();
        double angle1, angle2;
        Number n = this.dataset.getValue(key);
        double value = n.doubleValue();

        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);

        Arc2D arc1 = new Arc2D.Double(pieArea, angle1, angle / 2,
                Arc2D.OPEN);
        Point2D point1 = arc1.getEndPoint();
        Arc2D.Double arc2 = new Arc2D.Double(expPieArea, angle1, angle / 2,
                Arc2D.OPEN);
        Point2D point2 = arc2.getEndPoint();
        double deltaX = (point1.getX() - point2.getX()) * ep;
        double deltaY = (point1.getY() - point2.getY()) * ep;

        center = new Point2D.Double(state.getPieCenterX() - deltaX,
                 state.getPieCenterY() - deltaY);

    }
    return center;
}
 
Example #30
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);
}