Java Code Examples for org.jfree.chart.plot.XYPlot#getDataset()

The following examples show how to use org.jfree.chart.plot.XYPlot#getDataset() . 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: FunctionPanel.java    From opensim-gui with Apache License 2.0 6 votes vote down vote up
private FunctionNode findNodeAt(int x, int y) {
   XYPlot xyPlot = getChart().getXYPlot();
   XYDataset xyDataset = xyPlot.getDataset();
   RectangleEdge xAxisLocation = xyPlot.getDomainAxisEdge();
   RectangleEdge yAxisLocation = xyPlot.getRangeAxisEdge();
   Rectangle2D dataArea = getScreenDataArea();
   // Loop through the nodes from last to first, so if the circles
   // for two or more nodes overlap, you get the one drawn on top.
   for (int i=xyDataset.getSeriesCount()-1; i>=0; i--) {
      if (renderer.getSeriesShapesVisible(i)) {
         for (int j=xyDataset.getItemCount(i)-1; j>=0; j--) {
            double sx = xyPlot.getDomainAxis().valueToJava2D(xyDataset.getXValue(i, j), dataArea, xAxisLocation);
            double sy = xyPlot.getRangeAxis().valueToJava2D(xyDataset.getYValue(i, j), dataArea, yAxisLocation);
            double distance = Math.sqrt((sx-x)*(sx-x) + (sy-y)*(sy-y));
            if (distance < 6.0) {
               return new FunctionNode(i, j);
            }
         }
      }
   }
   return null;
}
 
Example 2
Source File: FunctionPanel.java    From opensim-gui with Apache License 2.0 6 votes vote down vote up
private ArrayList<FunctionNode> getBoxSelectNodes(Rectangle2D box) {
   ArrayList<FunctionNode> nodes = new ArrayList<FunctionNode>(0);
   XYPlot xyPlot = getChart().getXYPlot();
   XYDataset xyDataset = xyPlot.getDataset();
   // Compute dataBox (data coordinates, X right, Y up)
   // from box (screen coordinates, X right, Y down)
   RectangleEdge xAxisLocation = xyPlot.getDomainAxisEdge();
   RectangleEdge yAxisLocation = xyPlot.getRangeAxisEdge();
   Rectangle2D dataArea = getScreenDataArea();
   double dataXMin = xyPlot.getDomainAxis().java2DToValue(box.getMinX(), dataArea, xAxisLocation);
   double dataXMax = xyPlot.getDomainAxis().java2DToValue(box.getMaxX(), dataArea, xAxisLocation);
   double dataYMin = xyPlot.getRangeAxis().java2DToValue(box.getMaxY(), dataArea, yAxisLocation);
   double dataYMax = xyPlot.getRangeAxis().java2DToValue(box.getMinY(), dataArea, yAxisLocation);
   Rectangle2D dataBox = new Rectangle2D.Double(dataXMin, dataYMin, dataXMax - dataXMin, dataYMax - dataYMin);
   for (int i=0; i<xyDataset.getSeriesCount(); i++) {
      if (renderer.getSeriesShapesVisible(i)) {
         for (int j=0; j<xyDataset.getItemCount(i); j++) {
            double x = xyDataset.getXValue(i, j);
            double y = xyDataset.getYValue(i, j);
            if (dataBox.contains(x, y) == true)
               nodes.add(new FunctionNode(i, j));
         }
      }
   }
   return nodes;
}
 
Example 3
Source File: EyeCandySixtiesChartTheme.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected JFreeChart createXYBarChart() throws JRException
{
	JFreeChart jfreeChart = super.createXYBarChart();
	XYPlot xyPlot = (XYPlot)jfreeChart.getPlot();
	XYBarRenderer renderer = (XYBarRenderer)xyPlot.getRenderer();
	renderer.setMargin(0.1);
	renderer.setGradientPaintTransformer(
			new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL)
			);
	XYDataset xyDataset = xyPlot.getDataset();
	if (xyDataset != null)
	{
		for (int i = 0; i < xyDataset.getSeriesCount(); i++)
		{
			renderer.setSeriesPaint(i, ChartThemesConstants.EYE_CANDY_SIXTIES_GRADIENT_PAINTS.get(i));
		}
	}
	return jfreeChart;
}
 
Example 4
Source File: FunctionPanel.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
protected int addNode(int series, int screenX, int screenY) {
   XYPlot xyPlot = getChart().getXYPlot();
   RectangleEdge xAxisLocation = xyPlot.getDomainAxisEdge();
   RectangleEdge yAxisLocation = xyPlot.getRangeAxisEdge();
   Rectangle2D dataArea = getScreenDataArea();
   double newNodeX = xyPlot.getDomainAxis().java2DToValue(screenX, dataArea, xAxisLocation);
   double newNodeY = xyPlot.getRangeAxis().java2DToValue(screenY, dataArea, yAxisLocation);

   // Notify all listeners about the change.
   Object[] listeners = this.functionPanelListeners.getListenerList();
   for (int i = listeners.length - 2; i >= 0; i -= 2) {
      if (listeners[i] == FunctionPanelListener.class) {
         ((FunctionPanelListener) listeners[i + 1]).addNode(series, newNodeX, newNodeY);
      }
   }

   // Now add the point to the series, first figuring out what its index will be.
   XYSeriesCollection seriesCollection = (XYSeriesCollection)xyPlot.getDataset();
   XYSeries dSeries = seriesCollection.getSeries(series);
   int index = dSeries.getItemCount();
   for (int i=0; i<dSeries.getItemCount(); i++) {
      if (dSeries.getDataItem(i).getX().doubleValue() > newNodeX) {
         index = i;
         break;
      }
   }
   dSeries.add(newNodeX, newNodeY);

   updateSelectedNodesAfterAddition(series, index);
   return index;
}
 
Example 5
Source File: ChartJFreeChartOutputScatter.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void createNewSerie(final IScope scope, final String serieid) {

	final ChartDataSeries dataserie = chartdataset.getDataSeries(scope, serieid);
	final XYIntervalSeries serie = new XYIntervalSeries(dataserie.getSerieLegend(scope), false, true);
	final XYPlot plot = (XYPlot) this.chart.getPlot();

	final XYIntervalSeriesCollection firstdataset = (XYIntervalSeriesCollection) plot.getDataset();

	if (!IdPosition.containsKey(serieid)) {

		if (firstdataset.getSeriesCount() == 0) {
			firstdataset.addSeries(serie);
			plot.setDataset(0, firstdataset);

		} else {

			final XYIntervalSeriesCollection newdataset = new XYIntervalSeriesCollection();
			newdataset.addSeries(serie);
			jfreedataset.add(newdataset);
			plot.setDataset(jfreedataset.size() - 1, newdataset);

		}
		plot.setRenderer(jfreedataset.size() - 1, (XYItemRenderer) getOrCreateRenderer(scope, serieid));
		IdPosition.put(serieid, jfreedataset.size() - 1);
		// DEBUG.LOG("new serie"+serieid+" at
		// "+IdPosition.get(serieid)+" fdsize "+plot.getSeriesCount()+" jfds
		// "+jfreedataset.size()+" datasc "+plot.getDatasetCount());
		// TODO Auto-generated method stub

	}
}
 
Example 6
Source File: EHistogramDialog.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * tries to find the next local maximum to jump to the prev peak
 */
private void jumpToNextPeak() {
  XYPlot plot = getXYPlot();
  if (plot == null)
    return;

  XYDataset data = plot.getDataset(0);
  // get center of zoom
  ValueAxis x = plot.getDomainAxis();
  // mid of range
  double mid = (x.getUpperBound() + x.getLowerBound()) / 2;

  boolean started = false;

  for (int i = 0; i < data.getItemCount(0) - 1; i++) {
    double mz = data.getXValue(0, i);
    if (mz > mid) {
      // wait for y to be 0 to start the search for a new peak
      if (!started) {
        if (data.getYValue(0, i) == 0)
          started = true;
      } else {
        // intensity drops?
        if (data.getYValue(0, i + 1) != 0 && data.getYValue(0, i) >= 100
            && data.getYValue(0, i + 1) < data.getYValue(0, i)) {
          // peak found with max at i
          setZoomAroundPeakAt(i);
          return;
        }
      }
    }
  }
}
 
Example 7
Source File: ChartJFreeChartOutputHeatmap.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void createNewSerie(final IScope scope, final String serieid) {

	final ChartDataSeries dataserie = chartdataset.getDataSeries(scope, serieid);
	final MatrixSeries serie = new MatrixSeries((String) dataserie.getSerieLegend(scope),
			Math.max(1, this.getChartdataset().getYSeriesValues().size()),
			Math.max(1, this.getChartdataset().getXSeriesValues().size()));
	final XYPlot plot = (XYPlot) this.chart.getPlot();

	final MatrixSeriesCollection firstdataset = (MatrixSeriesCollection) plot.getDataset();

	if (!IdPosition.containsKey(serieid)) {

		if (firstdataset.getSeriesCount() == 0) {
			firstdataset.addSeries(serie);
			plot.setDataset(0, firstdataset);

		} else {

			final MatrixSeriesCollection newdataset = new MatrixSeriesCollection();
			newdataset.addSeries(serie);
			jfreedataset.add(newdataset);
			plot.setDataset(jfreedataset.size() - 1, newdataset);

		}
		plot.setRenderer(jfreedataset.size() - 1, (XYItemRenderer) getOrCreateRenderer(scope, serieid));
		IdPosition.put(serieid, jfreedataset.size() - 1);
		// DEBUG.LOG("new serie"+serieid+" at
		// "+IdPosition.get(serieid)+" fdsize "+plot.getSeriesCount()+" jfds
		// "+jfreedataset.size()+" datasc "+plot.getDatasetCount());
		// TODO Auto-generated method stub

	}
}
 
Example 8
Source File: GraphPanel.java    From swift-k with Apache License 2.0 5 votes vote down vote up
private int getNextDatasetIndex(XYPlot plot) {
    for (int i = 0; i < plot.getDatasetCount(); i++) {
        if (plot.getDataset(i) == null) {
            return i;
        }
    }
    return plot.getDatasetCount();
}
 
Example 9
Source File: EyeCandySixtiesChartTheme.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected JFreeChart createScatterChart() throws JRException
{
	JFreeChart jfreeChart = super.createScatterChart();
	XYPlot xyPlot = (XYPlot) jfreeChart.getPlot();
	
	xyPlot.setRangeGridlinePaint(SCATTER_GRIDLINE_COLOR);
	xyPlot.setRangeGridlineStroke(new BasicStroke(0.75f));
	xyPlot.setDomainGridlinesVisible(true);
	xyPlot.setDomainGridlinePaint(SCATTER_GRIDLINE_COLOR);
	xyPlot.setDomainGridlineStroke(new BasicStroke(0.75f));
	xyPlot.setRangeZeroBaselinePaint(ChartThemesConstants.GRAY_PAINT_134);

	XYLineAndShapeRenderer lineRenderer = (XYLineAndShapeRenderer)xyPlot.getRenderer();
	lineRenderer.setUseFillPaint(true);
	JRScatterPlot scatterPlot = (JRScatterPlot) getPlot();
	boolean isShowLines = scatterPlot.getShowLines() == null ? false : scatterPlot.getShowLines();
	lineRenderer.setBaseLinesVisible(isShowLines);
	XYDataset xyDataset = xyPlot.getDataset();
	if (xyDataset != null)
	{
		for (int i = 0; i < xyDataset.getSeriesCount(); i++)
		{
			lineRenderer.setSeriesOutlinePaint(i, ChartThemesConstants.TRANSPARENT_PAINT);
			lineRenderer.setSeriesFillPaint(i, ChartThemesConstants.EYE_CANDY_SIXTIES_GRADIENT_PAINTS.get(i));
			lineRenderer.setSeriesPaint(i, ChartThemesConstants.EYE_CANDY_SIXTIES_COLORS.get(i));
			//lineRenderer.setSeriesShape(i, new Ellipse2D.Double(-3, -3, 6, 6));
		}
	}
	return jfreeChart;
}
 
Example 10
Source File: AbstractXYItemRenderer.java    From ECG-Viewer with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns a default legend item for the specified series.  Subclasses
 * should override this method to generate customised items.
 *
 * @param datasetIndex  the dataset index (zero-based).
 * @param series  the series index (zero-based).
 *
 * @return A legend item for the series.
 */
@Override
public LegendItem getLegendItem(int datasetIndex, int series) {
    XYPlot xyplot = getPlot();
    if (xyplot == null) {
        return null;
    }
    XYDataset dataset = xyplot.getDataset(datasetIndex);
    if (dataset == null) {
        return null;
    }
    String label = this.legendItemLabelGenerator.generateLabel(dataset,
            series);
    String description = label;
    String toolTipText = null;
    if (getLegendItemToolTipGenerator() != null) {
        toolTipText = getLegendItemToolTipGenerator().generateLabel(
                dataset, series);
    }
    String urlText = null;
    if (getLegendItemURLGenerator() != null) {
        urlText = getLegendItemURLGenerator().generateLabel(dataset,
                series);
    }
    Shape shape = lookupLegendShape(series);
    Paint paint = lookupSeriesPaint(series);
    LegendItem item = new LegendItem(label, paint);
    item.setToolTipText(toolTipText);
    item.setURLText(urlText);
    item.setLabelFont(lookupLegendTextFont(series));
    Paint labelPaint = lookupLegendTextPaint(series);
    if (labelPaint != null) {
        item.setLabelPaint(labelPaint);
    }
    item.setSeriesKey(dataset.getSeriesKey(series));
    item.setSeriesIndex(series);
    item.setDataset(dataset);
    item.setDatasetIndex(datasetIndex);

    if (getTreatLegendShapeAsLine()) {
        item.setLineVisible(true);
        item.setLine(shape);
        item.setLinePaint(paint);
        item.setShapeVisible(false);
    }
    else {
        Paint outlinePaint = lookupSeriesOutlinePaint(series);
        Stroke outlineStroke = lookupSeriesOutlineStroke(series);
        item.setOutlinePaint(outlinePaint);
        item.setOutlineStroke(outlineStroke);
    }
    return item;
}
 
Example 11
Source File: AbstractXYItemRenderer.java    From SIMVA-SoS with Apache License 2.0 4 votes vote down vote up
/**
 * Returns a default legend item for the specified series.  Subclasses
 * should override this method to generate customised items.
 *
 * @param datasetIndex  the dataset index (zero-based).
 * @param series  the series index (zero-based).
 *
 * @return A legend item for the series.
 */
@Override
public LegendItem getLegendItem(int datasetIndex, int series) {
    XYPlot xyplot = getPlot();
    if (xyplot == null) {
        return null;
    }
    XYDataset dataset = xyplot.getDataset(datasetIndex);
    if (dataset == null) {
        return null;
    }
    String label = this.legendItemLabelGenerator.generateLabel(dataset,
            series);
    String description = label;
    String toolTipText = null;
    if (getLegendItemToolTipGenerator() != null) {
        toolTipText = getLegendItemToolTipGenerator().generateLabel(
                dataset, series);
    }
    String urlText = null;
    if (getLegendItemURLGenerator() != null) {
        urlText = getLegendItemURLGenerator().generateLabel(dataset,
                series);
    }
    Shape shape = lookupLegendShape(series);
    Paint paint = lookupSeriesPaint(series);
    LegendItem item = new LegendItem(label, paint);
    item.setToolTipText(toolTipText);
    item.setURLText(urlText);
    item.setLabelFont(lookupLegendTextFont(series));
    Paint labelPaint = lookupLegendTextPaint(series);
    if (labelPaint != null) {
        item.setLabelPaint(labelPaint);
    }
    item.setSeriesKey(dataset.getSeriesKey(series));
    item.setSeriesIndex(series);
    item.setDataset(dataset);
    item.setDatasetIndex(datasetIndex);

    if (getTreatLegendShapeAsLine()) {
        item.setLineVisible(true);
        item.setLine(shape);
        item.setLinePaint(paint);
        item.setShapeVisible(false);
    }
    else {
        Paint outlinePaint = lookupSeriesOutlinePaint(series);
        Stroke outlineStroke = lookupSeriesOutlineStroke(series);
        item.setOutlinePaint(outlinePaint);
        item.setOutlineStroke(outlineStroke);
    }
    return item;
}
 
Example 12
Source File: XYLineAndShapeRenderer.java    From SIMVA-SoS with Apache License 2.0 4 votes vote down vote up
/**
 * Returns a legend item for the specified series.
 *
 * @param datasetIndex  the dataset index (zero-based).
 * @param series  the series index (zero-based).
 *
 * @return A legend item for the series (possibly {@code null}).
 */
@Override
public LegendItem getLegendItem(int datasetIndex, int series) {
    XYPlot plot = getPlot();
    if (plot == null) {
        return null;
    }

    XYDataset dataset = plot.getDataset(datasetIndex);
    if (dataset == null) {
        return null;
    }

    if (!getItemVisible(series, 0)) {
        return null;
    }
    String label = getLegendItemLabelGenerator().generateLabel(dataset,
            series);
    String description = label;
    String toolTipText = null;
    if (getLegendItemToolTipGenerator() != null) {
        toolTipText = getLegendItemToolTipGenerator().generateLabel(
                dataset, series);
    }
    String urlText = null;
    if (getLegendItemURLGenerator() != null) {
        urlText = getLegendItemURLGenerator().generateLabel(dataset,
                series);
    }
    boolean shapeIsVisible = getItemShapeVisible(series, 0);
    Shape shape = lookupLegendShape(series);
    boolean shapeIsFilled = getItemShapeFilled(series, 0);
    Paint fillPaint = (this.useFillPaint ? lookupSeriesFillPaint(series)
            : lookupSeriesPaint(series));
    boolean shapeOutlineVisible = this.drawOutlines;
    Paint outlinePaint = (this.useOutlinePaint ? lookupSeriesOutlinePaint(
            series) : lookupSeriesPaint(series));
    Stroke outlineStroke = lookupSeriesOutlineStroke(series);
    boolean lineVisible = getItemLineVisible(series, 0);
    Stroke lineStroke = lookupSeriesStroke(series);
    Paint linePaint = lookupSeriesPaint(series);
    LegendItem result = new LegendItem(label, description, toolTipText,
            urlText, shapeIsVisible, shape, shapeIsFilled, fillPaint,
            shapeOutlineVisible, outlinePaint, outlineStroke, lineVisible,
            this.legendLine, lineStroke, linePaint);
    result.setLabelFont(lookupLegendTextFont(series));
    Paint labelPaint = lookupLegendTextPaint(series);
    if (labelPaint != null) {
        result.setLabelPaint(labelPaint);
    }
    result.setSeriesKey(dataset.getSeriesKey(series));
    result.setSeriesIndex(series);
    result.setDataset(dataset);
    result.setDatasetIndex(datasetIndex);

    return result;
}
 
Example 13
Source File: AegeanChartTheme.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
protected void configurePlot(Plot plot, JRChartPlot jrPlot)
{

	super.configurePlot(plot, jrPlot);

	if(plot instanceof CategoryPlot)
	{
		CategoryPlot categoryPlot = (CategoryPlot)plot;
		CategoryItemRenderer categoryRenderer = categoryPlot.getRenderer();
		CategoryDataset categoryDataset = categoryPlot.getDataset();
		if(categoryDataset != null)
		{
			for(int i = 0; i < categoryDataset.getRowCount(); i++)
			{
				categoryRenderer.setSeriesOutlinePaint(i, ChartThemesConstants.TRANSPARENT_PAINT);
			}
		}
		categoryPlot.setRangeGridlinePaint(ChartThemesConstants.GRAY_PAINT_217);
		categoryPlot.setRangeGridlineStroke(new BasicStroke(0.5f));
		categoryPlot.setDomainGridlinesVisible(false);
		categoryPlot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45);
	}
	else if(plot instanceof XYPlot)
	{
		XYPlot xyPlot = (XYPlot)plot;
		XYItemRenderer xyItemRenderer = xyPlot.getRenderer();
		XYDataset xyDataset = xyPlot.getDataset();
		if(xyDataset != null)
		{
			for(int i = 0; i < xyDataset.getSeriesCount(); i++)
			{
				xyItemRenderer.setSeriesOutlinePaint(i, ChartThemesConstants.TRANSPARENT_PAINT);
			}
		}
		xyPlot.setRangeGridlinePaint(ChartThemesConstants.GRAY_PAINT_217);
		xyPlot.setRangeGridlineStroke(new BasicStroke(0.5f));
		xyPlot.setDomainGridlinesVisible(false);
		xyPlot.setRangeZeroBaselineVisible(true);
	}
}
 
Example 14
Source File: IntelligentItemLabelGenerator.java    From old-mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @see org.jfree.chart.labels.XYItemLabelGenerator#generateLabel(org.jfree.data.xy.XYDataset,
 *      int, int)
 */
public String generateLabel(XYDataset currentDataset, int currentSeries, int currentItem) {

  XYPlot plot = chartNode.getChart().getXYPlot();

  // X and Y values of the current data point
  final double currentXValue = currentDataset.getXValue(currentSeries, currentItem);
  final double currentYValue = currentDataset.getYValue(currentSeries, currentItem);

  // Calculate X axis span of 1 screen pixel
  final double xLength = plot.getDomainAxis().getRange().getLength();
  final double pixelX = xLength / chartNode.getWidth();

  // Calculate the distance from the current point where labels might
  // overlap
  final double dangerZoneX = (reservedPixels / 2) * pixelX;

  // Range on X axis that we're going to check for higher data points. If
  // a higher data point is found, we don't place a label on this one.
  final Range<Double> dangerZoneRange =
      Range.closed(currentXValue - dangerZoneX, currentXValue + dangerZoneX);

  // Iterate through data sets
  for (int datasetIndex = 0; datasetIndex < plot.getDatasetCount(); datasetIndex++) {

    XYDataset dataset = plot.getDataset(datasetIndex);

    // Some data sets could have been removed
    if (dataset == null)
      continue;

    final int seriesCount = dataset.getSeriesCount();

    // Iterate through series
    for (int seriesIndex = 0; seriesIndex < seriesCount; seriesIndex++) {

      final int itemCount = dataset.getItemCount(seriesIndex);

      // Find the index of a data point that is closest to
      // currentXValue
      int closestValueIndex;
      if (dataset == currentDataset && seriesIndex == currentSeries) {
        closestValueIndex = currentItem;
      } else {
        closestValueIndex =
            findClosestXIndex(dataset, seriesIndex, currentXValue, 0, itemCount - 1);
      }

      // Search to the left of the closest data point
      for (int i = closestValueIndex; (i >= 0)
          && (dangerZoneRange.contains(dataset.getX(seriesIndex, i).doubleValue())); i--) {
        if (dataset.getYValue(seriesIndex, i) > currentYValue)
          return null;

        // In the case there are equal values, only place the label
        // on the leftmost value
        if (dataset.getYValue(seriesIndex, i) == currentYValue
            && (dataset.getXValue(seriesIndex, i) < currentXValue))
          return null;

      }

      // Search to the right of the closest data point
      for (int i = closestValueIndex + 1; (i < itemCount)
          && (dangerZoneRange.contains(dataset.getX(seriesIndex, i).doubleValue())); i++) {
        if (dataset.getYValue(seriesIndex, i) > currentYValue)
          return null;
      }

    }

  }

  // If no higher data point was found, create the label
  String label = underlyingGenerator.generateLabel(currentDataset, currentSeries, currentItem);

  return label;

}
 
Example 15
Source File: AbstractXYItemRenderer.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Returns a default legend item for the specified series.  Subclasses
 * should override this method to generate customised items.
 *
 * @param datasetIndex  the dataset index (zero-based).
 * @param series  the series index (zero-based).
 *
 * @return A legend item for the series.
 */
@Override
public LegendItem getLegendItem(int datasetIndex, int series) {
    XYPlot xyplot = getPlot();
    if (xyplot == null) {
        return null;
    }
    XYDataset dataset = xyplot.getDataset(datasetIndex);
    if (dataset == null) {
        return null;
    }
    String label = this.legendItemLabelGenerator.generateLabel(dataset,
            series);
    String description = label;
    String toolTipText = null;
    if (getLegendItemToolTipGenerator() != null) {
        toolTipText = getLegendItemToolTipGenerator().generateLabel(
                dataset, series);
    }
    String urlText = null;
    if (getLegendItemURLGenerator() != null) {
        urlText = getLegendItemURLGenerator().generateLabel(dataset,
                series);
    }
    Shape shape = lookupLegendShape(series);
    Paint paint = lookupSeriesPaint(series);
    LegendItem item = new LegendItem(label, paint);
    item.setToolTipText(toolTipText);
    item.setURLText(urlText);
    item.setLabelFont(lookupLegendTextFont(series));
    Paint labelPaint = lookupLegendTextPaint(series);
    if (labelPaint != null) {
        item.setLabelPaint(labelPaint);
    }
    item.setSeriesKey(dataset.getSeriesKey(series));
    item.setSeriesIndex(series);
    item.setDataset(dataset);
    item.setDatasetIndex(datasetIndex);

    if (getTreatLegendShapeAsLine()) {
        item.setLineVisible(true);
        item.setLine(shape);
        item.setLinePaint(paint);
        item.setShapeVisible(false);
    }
    else {
        Paint outlinePaint = lookupSeriesOutlinePaint(series);
        Stroke outlineStroke = lookupSeriesOutlineStroke(series);
        item.setOutlinePaint(outlinePaint);
        item.setOutlineStroke(outlineStroke);
    }
    return item;
}
 
Example 16
Source File: AbstractXYItemRenderer.java    From ccu-historian with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Returns a default legend item for the specified series.  Subclasses
 * should override this method to generate customised items.
 *
 * @param datasetIndex  the dataset index (zero-based).
 * @param series  the series index (zero-based).
 *
 * @return A legend item for the series.
 */
@Override
public LegendItem getLegendItem(int datasetIndex, int series) {
    XYPlot xyplot = getPlot();
    if (xyplot == null) {
        return null;
    }
    XYDataset dataset = xyplot.getDataset(datasetIndex);
    if (dataset == null) {
        return null;
    }
    String label = this.legendItemLabelGenerator.generateLabel(dataset,
            series);
    String description = label;
    String toolTipText = null;
    if (getLegendItemToolTipGenerator() != null) {
        toolTipText = getLegendItemToolTipGenerator().generateLabel(
                dataset, series);
    }
    String urlText = null;
    if (getLegendItemURLGenerator() != null) {
        urlText = getLegendItemURLGenerator().generateLabel(dataset,
                series);
    }
    Shape shape = lookupLegendShape(series);
    Paint paint = lookupSeriesPaint(series);
    LegendItem item = new LegendItem(label, paint);
    item.setToolTipText(toolTipText);
    item.setURLText(urlText);
    item.setLabelFont(lookupLegendTextFont(series));
    Paint labelPaint = lookupLegendTextPaint(series);
    if (labelPaint != null) {
        item.setLabelPaint(labelPaint);
    }
    item.setSeriesKey(dataset.getSeriesKey(series));
    item.setSeriesIndex(series);
    item.setDataset(dataset);
    item.setDatasetIndex(datasetIndex);

    if (getTreatLegendShapeAsLine()) {
        item.setLineVisible(true);
        item.setLine(shape);
        item.setLinePaint(paint);
        item.setShapeVisible(false);
    }
    else {
        Paint outlinePaint = lookupSeriesOutlinePaint(series);
        Stroke outlineStroke = lookupSeriesOutlineStroke(series);
        item.setOutlinePaint(outlinePaint);
        item.setOutlineStroke(outlineStroke);
    }
    return item;
}
 
Example 17
Source File: XYLineAndShapeRenderer.java    From ccu-historian with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Returns a legend item for the specified series.
 *
 * @param datasetIndex  the dataset index (zero-based).
 * @param series  the series index (zero-based).
 *
 * @return A legend item for the series (possibly {@code null}).
 */
@Override
public LegendItem getLegendItem(int datasetIndex, int series) {
    XYPlot plot = getPlot();
    if (plot == null) {
        return null;
    }

    XYDataset dataset = plot.getDataset(datasetIndex);
    if (dataset == null) {
        return null;
    }

    if (!getItemVisible(series, 0)) {
        return null;
    }
    String label = getLegendItemLabelGenerator().generateLabel(dataset,
            series);
    String description = label;
    String toolTipText = null;
    if (getLegendItemToolTipGenerator() != null) {
        toolTipText = getLegendItemToolTipGenerator().generateLabel(
                dataset, series);
    }
    String urlText = null;
    if (getLegendItemURLGenerator() != null) {
        urlText = getLegendItemURLGenerator().generateLabel(dataset,
                series);
    }
    boolean shapeIsVisible = getItemShapeVisible(series, 0);
    Shape shape = lookupLegendShape(series);
    boolean shapeIsFilled = getItemShapeFilled(series, 0);
    Paint fillPaint = (this.useFillPaint ? lookupSeriesFillPaint(series)
            : lookupSeriesPaint(series));
    boolean shapeOutlineVisible = this.drawOutlines;
    Paint outlinePaint = (this.useOutlinePaint ? lookupSeriesOutlinePaint(
            series) : lookupSeriesPaint(series));
    Stroke outlineStroke = lookupSeriesOutlineStroke(series);
    boolean lineVisible = getItemLineVisible(series, 0);
    Stroke lineStroke = lookupSeriesStroke(series);
    Paint linePaint = lookupSeriesPaint(series);
    LegendItem result = new LegendItem(label, description, toolTipText,
            urlText, shapeIsVisible, shape, shapeIsFilled, fillPaint,
            shapeOutlineVisible, outlinePaint, outlineStroke, lineVisible,
            this.legendLine, lineStroke, linePaint);
    result.setLabelFont(lookupLegendTextFont(series));
    Paint labelPaint = lookupLegendTextPaint(series);
    if (labelPaint != null) {
        result.setLabelPaint(labelPaint);
    }
    result.setSeriesKey(dataset.getSeriesKey(series));
    result.setSeriesIndex(series);
    result.setDataset(dataset);
    result.setDatasetIndex(datasetIndex);

    return result;
}
 
Example 18
Source File: XYLineAndShapeRenderer.java    From buffer_bci with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Returns a legend item for the specified series.
 *
 * @param datasetIndex  the dataset index (zero-based).
 * @param series  the series index (zero-based).
 *
 * @return A legend item for the series (possibly {@code null}).
 */
@Override
public LegendItem getLegendItem(int datasetIndex, int series) {
    XYPlot plot = getPlot();
    if (plot == null) {
        return null;
    }

    XYDataset dataset = plot.getDataset(datasetIndex);
    if (dataset == null) {
        return null;
    }

    if (!getItemVisible(series, 0)) {
        return null;
    }
    String label = getLegendItemLabelGenerator().generateLabel(dataset,
            series);
    String description = label;
    String toolTipText = null;
    if (getLegendItemToolTipGenerator() != null) {
        toolTipText = getLegendItemToolTipGenerator().generateLabel(
                dataset, series);
    }
    String urlText = null;
    if (getLegendItemURLGenerator() != null) {
        urlText = getLegendItemURLGenerator().generateLabel(dataset,
                series);
    }
    boolean shapeIsVisible = getItemShapeVisible(series, 0);
    Shape shape = lookupLegendShape(series);
    boolean shapeIsFilled = getItemShapeFilled(series, 0);
    Paint fillPaint = (this.useFillPaint ? lookupSeriesFillPaint(series)
            : lookupSeriesPaint(series));
    boolean shapeOutlineVisible = this.drawOutlines;
    Paint outlinePaint = (this.useOutlinePaint ? lookupSeriesOutlinePaint(
            series) : lookupSeriesPaint(series));
    Stroke outlineStroke = lookupSeriesOutlineStroke(series);
    boolean lineVisible = getItemLineVisible(series, 0);
    Stroke lineStroke = lookupSeriesStroke(series);
    Paint linePaint = lookupSeriesPaint(series);
    LegendItem result = new LegendItem(label, description, toolTipText,
            urlText, shapeIsVisible, shape, shapeIsFilled, fillPaint,
            shapeOutlineVisible, outlinePaint, outlineStroke, lineVisible,
            this.legendLine, lineStroke, linePaint);
    result.setLabelFont(lookupLegendTextFont(series));
    Paint labelPaint = lookupLegendTextPaint(series);
    if (labelPaint != null) {
        result.setLabelPaint(labelPaint);
    }
    result.setSeriesKey(dataset.getSeriesKey(series));
    result.setSeriesIndex(series);
    result.setDataset(dataset);
    result.setDatasetIndex(datasetIndex);

    return result;
}
 
Example 19
Source File: HistogramDialog.java    From mzmine3 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Set zoom factor around peak at data point i
 *
 * @param i
 */
private void setZoomAroundPeakAt(int i) {
  XYPlot plot = getXYPlot();
  if (plot == null) {
    return;
  }

  XYDataset data = plot.getDataset(0);

  // keep same domain axis range length
  boolean keepRange = cbKeepSameXaxis.isSelected();

  // find lower bound (where y=0)
  double lower = data.getXValue(0, i);
  for (int x = i; x >= 0; x--) {
    if (data.getYValue(0, x) == 0) {
      lower = data.getXValue(0, x);
      break;
    }
  }
  // find upper bound /where y=0)
  double upper = data.getXValue(0, i);
  for (int x = i; x < data.getItemCount(0); x++) {
    if (data.getYValue(0, x) == 0) {
      upper = data.getXValue(0, x);
      break;
    }
  }

  if (keepRange) {
    // set constant range zoom
    double length = plot.getDomainAxis().getRange().getLength();
    plot.getDomainAxis().setRangeAboutValue(data.getXValue(0, i), length);
  } else {
    // set range directly around peak
    plot.getDomainAxis().setRange(lower, upper);
  }

  // auto gaussian fit
  if (getHistoPanel().isGaussianFitEnabled()) {
    // find
    getHistoPanel().setGaussianFitRange(lower, upper);
  }

  // auto range y
  ChartLogicsFX.autoRangeAxis(getChartPanel());
}
 
Example 20
Source File: XYLineAndShapeRenderer.java    From openstock with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Returns a legend item for the specified series.
 *
 * @param datasetIndex  the dataset index (zero-based).
 * @param series  the series index (zero-based).
 *
 * @return A legend item for the series (possibly {@code null}).
 */
@Override
public LegendItem getLegendItem(int datasetIndex, int series) {
    XYPlot plot = getPlot();
    if (plot == null) {
        return null;
    }

    XYDataset dataset = plot.getDataset(datasetIndex);
    if (dataset == null) {
        return null;
    }

    if (!getItemVisible(series, 0)) {
        return null;
    }
    String label = getLegendItemLabelGenerator().generateLabel(dataset,
            series);
    String description = label;
    String toolTipText = null;
    if (getLegendItemToolTipGenerator() != null) {
        toolTipText = getLegendItemToolTipGenerator().generateLabel(
                dataset, series);
    }
    String urlText = null;
    if (getLegendItemURLGenerator() != null) {
        urlText = getLegendItemURLGenerator().generateLabel(dataset,
                series);
    }
    boolean shapeIsVisible = getItemShapeVisible(series, 0);
    Shape shape = lookupLegendShape(series);
    boolean shapeIsFilled = getItemShapeFilled(series, 0);
    Paint fillPaint = (this.useFillPaint ? lookupSeriesFillPaint(series)
            : lookupSeriesPaint(series));
    boolean shapeOutlineVisible = this.drawOutlines;
    Paint outlinePaint = (this.useOutlinePaint ? lookupSeriesOutlinePaint(
            series) : lookupSeriesPaint(series));
    Stroke outlineStroke = lookupSeriesOutlineStroke(series);
    boolean lineVisible = getItemLineVisible(series, 0);
    Stroke lineStroke = lookupSeriesStroke(series);
    Paint linePaint = lookupSeriesPaint(series);
    LegendItem result = new LegendItem(label, description, toolTipText,
            urlText, shapeIsVisible, shape, shapeIsFilled, fillPaint,
            shapeOutlineVisible, outlinePaint, outlineStroke, lineVisible,
            this.legendLine, lineStroke, linePaint);
    result.setLabelFont(lookupLegendTextFont(series));
    Paint labelPaint = lookupLegendTextPaint(series);
    if (labelPaint != null) {
        result.setLabelPaint(labelPaint);
    }
    result.setSeriesKey(dataset.getSeriesKey(series));
    result.setSeriesIndex(series);
    result.setDataset(dataset);
    result.setDatasetIndex(datasetIndex);

    return result;
}