Search in sources :

Example 86 with CategoryPlot

use of org.jfree.chart.plot.CategoryPlot in project SIMVA-SoS by SESoS.

the class BarRenderer method getLegendItem.

/**
 * Returns a legend item for a series.
 *
 * @param datasetIndex  the dataset index (zero-based).
 * @param series  the series index (zero-based).
 *
 * @return The legend item (possibly <code>null</code>).
 */
@Override
public LegendItem getLegendItem(int datasetIndex, int series) {
    CategoryPlot cp = getPlot();
    if (cp == null) {
        return null;
    }
    // check that a legend item needs to be displayed...
    if (!isSeriesVisible(series) || !isSeriesVisibleInLegend(series)) {
        return null;
    }
    CategoryDataset dataset = cp.getDataset(datasetIndex);
    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);
    }
    Shape shape = lookupLegendShape(series);
    Paint paint = lookupSeriesPaint(series);
    Paint outlinePaint = lookupSeriesOutlinePaint(series);
    Stroke outlineStroke = lookupSeriesOutlineStroke(series);
    LegendItem result = new LegendItem(label, description, toolTipText, urlText, true, shape, true, paint, isDrawBarOutline(), outlinePaint, outlineStroke, false, new Line2D.Float(), new BasicStroke(1.0f), Color.black);
    result.setLabelFont(lookupLegendTextFont(series));
    Paint labelPaint = lookupLegendTextPaint(series);
    if (labelPaint != null) {
        result.setLabelPaint(labelPaint);
    }
    result.setDataset(dataset);
    result.setDatasetIndex(datasetIndex);
    result.setSeriesKey(dataset.getRowKey(series));
    result.setSeriesIndex(series);
    if (this.gradientPaintTransformer != null) {
        result.setFillPaintTransformer(this.gradientPaintTransformer);
    }
    return result;
}
Also used : BasicStroke(java.awt.BasicStroke) Stroke(java.awt.Stroke) BasicStroke(java.awt.BasicStroke) Shape(java.awt.Shape) LegendItem(org.jfree.chart.LegendItem) CategoryDataset(org.jfree.data.category.CategoryDataset) Paint(java.awt.Paint) Line2D(java.awt.geom.Line2D) CategoryPlot(org.jfree.chart.plot.CategoryPlot)

Example 87 with CategoryPlot

use of org.jfree.chart.plot.CategoryPlot in project SIMVA-SoS by SESoS.

the class AreaRenderer method getLegendItem.

/**
 * Returns a legend item for a series.
 *
 * @param datasetIndex  the dataset index (zero-based).
 * @param series  the series index (zero-based).
 *
 * @return The legend item.
 */
@Override
public LegendItem getLegendItem(int datasetIndex, int series) {
    // if there is no plot, there is no dataset to access...
    CategoryPlot cp = getPlot();
    if (cp == null) {
        return null;
    }
    // check that a legend item needs to be displayed...
    if (!isSeriesVisible(series) || !isSeriesVisibleInLegend(series)) {
        return null;
    }
    CategoryDataset dataset = cp.getDataset(datasetIndex);
    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);
    }
    Shape shape = lookupLegendShape(series);
    Paint paint = lookupSeriesPaint(series);
    Paint outlinePaint = lookupSeriesOutlinePaint(series);
    Stroke outlineStroke = lookupSeriesOutlineStroke(series);
    LegendItem result = new LegendItem(label, description, toolTipText, urlText, shape, paint, outlineStroke, outlinePaint);
    result.setLabelFont(lookupLegendTextFont(series));
    Paint labelPaint = lookupLegendTextPaint(series);
    if (labelPaint != null) {
        result.setLabelPaint(labelPaint);
    }
    result.setDataset(dataset);
    result.setDatasetIndex(datasetIndex);
    result.setSeriesKey(dataset.getRowKey(series));
    result.setSeriesIndex(series);
    return result;
}
Also used : Stroke(java.awt.Stroke) Shape(java.awt.Shape) LegendItem(org.jfree.chart.LegendItem) CategoryDataset(org.jfree.data.category.CategoryDataset) Paint(java.awt.Paint) CategoryPlot(org.jfree.chart.plot.CategoryPlot)

Example 88 with CategoryPlot

use of org.jfree.chart.plot.CategoryPlot in project pentaho-kettle by pentaho.

the class StepPerformanceSnapShotDialog method updateCanvas.

private void updateCanvas() {
    Rectangle bounds = canvas.getBounds();
    if (bounds.width <= 0 || bounds.height <= 0) {
        return;
    }
    // The list of snapshots : convert to JFreeChart dataset
    // 
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    String[] selectedSteps = stepsList.getSelection();
    if (selectedSteps == null || selectedSteps.length == 0) {
        // first step
        selectedSteps = new String[] { steps[0] };
        stepsList.select(0);
    }
    int[] dataIndices = dataList.getSelectionIndices();
    if (dataIndices == null || dataIndices.length == 0) {
        dataIndices = new int[] { DATA_CHOICE_WRITTEN };
        dataList.select(0);
    }
    boolean multiStep = stepsList.getSelectionCount() > 1;
    boolean multiData = dataList.getSelectionCount() > 1;
    // A single metric shown for a single step
    boolean calcMoving = !multiStep && !multiData;
    List<Double> movingList = new ArrayList<Double>();
    int movingSize = 10;
    double movingTotal = 0;
    int totalTimeInSeconds = 0;
    for (int t = 0; t < selectedSteps.length; t++) {
        String stepNameCopy = selectedSteps[t];
        List<StepPerformanceSnapShot> snapShotList = stepPerformanceSnapShots.get(stepNameCopy);
        if (snapShotList != null && snapShotList.size() > 1) {
            totalTimeInSeconds = (int) Math.round(((double) (snapShotList.get(snapShotList.size() - 1).getDate().getTime() - snapShotList.get(0).getDate().getTime())) / 1000);
            for (int i = 0; i < snapShotList.size(); i++) {
                StepPerformanceSnapShot snapShot = snapShotList.get(i);
                if (snapShot.getTimeDifference() != 0) {
                    double factor = (double) 1000 / (double) snapShot.getTimeDifference();
                    for (int d = 0; d < dataIndices.length; d++) {
                        String dataType;
                        if (multiStep) {
                            dataType = stepNameCopy;
                        } else {
                            dataType = dataChoices[dataIndices[d]];
                        }
                        String xLabel = Integer.toString(Math.round(i * timeDifference / 1000));
                        Double metric = null;
                        switch(dataIndices[d]) {
                            case DATA_CHOICE_INPUT:
                                metric = snapShot.getLinesInput() * factor;
                                break;
                            case DATA_CHOICE_OUTPUT:
                                metric = snapShot.getLinesOutput() * factor;
                                break;
                            case DATA_CHOICE_READ:
                                metric = snapShot.getLinesRead() * factor;
                                break;
                            case DATA_CHOICE_WRITTEN:
                                metric = snapShot.getLinesWritten() * factor;
                                break;
                            case DATA_CHOICE_UPDATED:
                                metric = snapShot.getLinesUpdated() * factor;
                                break;
                            case DATA_CHOICE_REJECTED:
                                metric = snapShot.getLinesRejected() * factor;
                                break;
                            case DATA_CHOICE_INPUT_BUFFER_SIZE:
                                metric = (double) snapShot.getInputBufferSize();
                                break;
                            case DATA_CHOICE_OUTPUT_BUFFER_SIZE:
                                metric = (double) snapShot.getOutputBufferSize();
                                break;
                            default:
                                break;
                        }
                        if (metric != null) {
                            dataset.addValue(metric, dataType, xLabel);
                            if (calcMoving) {
                                movingTotal += metric;
                                movingList.add(metric);
                                if (movingList.size() > movingSize) {
                                    movingTotal -= movingList.get(0);
                                    movingList.remove(0);
                                }
                                double movingAverage = movingTotal / movingList.size();
                                dataset.addValue(movingAverage, dataType + "(Avg)", xLabel);
                            // System.out.println("moving average = "+movingAverage+", movingTotal="+movingTotal+", m");
                            }
                        }
                    }
                }
            }
        }
    }
    String chartTitle = title;
    if (multiStep) {
        chartTitle += " (" + dataChoices[dataIndices[0]] + ")";
    } else {
        chartTitle += " (" + selectedSteps[0] + ")";
    }
    final JFreeChart chart = // chart title
    ChartFactory.createLineChart(// chart title
    chartTitle, BaseMessages.getString(PKG, "StepPerformanceSnapShotDialog.TimeInSeconds.Label", Integer.toString(totalTimeInSeconds), // domain axis label
    Long.toString(timeDifference)), // range axis label
    BaseMessages.getString(PKG, "StepPerformanceSnapShotDialog.RowsPerSecond.Label"), // data
    dataset, // orientation
    PlotOrientation.VERTICAL, // include legend
    true, // tooltips
    true, // urls
    false);
    chart.setBackgroundPaint(Color.white);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setForegroundAlpha(0.5f);
    plot.setRangeGridlinesVisible(true);
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setTickLabelsVisible(false);
    // Customize the renderer...
    // 
    LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    renderer.setBaseShapesVisible(true);
    renderer.setDrawOutlines(true);
    renderer.setUseFillPaint(true);
    renderer.setBaseFillPaint(Color.white);
    renderer.setSeriesStroke(0, new BasicStroke(1.5f));
    renderer.setSeriesOutlineStroke(0, new BasicStroke(1.5f));
    renderer.setSeriesStroke(1, new BasicStroke(2.5f));
    renderer.setSeriesOutlineStroke(1, new BasicStroke(2.5f));
    renderer.setSeriesShape(0, new Ellipse2D.Double(-3.0, -3.0, 6.0, 6.0));
    BufferedImage bufferedImage = chart.createBufferedImage(bounds.width, bounds.height);
    ImageData imageData = ImageUtil.convertToSWT(bufferedImage);
    // 
    if (image != null) {
        image.dispose();
    }
    image = new Image(display, imageData);
    // Draw the image on the canvas...
    // 
    canvas.redraw();
}
Also used : BasicStroke(java.awt.BasicStroke) LineAndShapeRenderer(org.jfree.chart.renderer.category.LineAndShapeRenderer) NumberAxis(org.jfree.chart.axis.NumberAxis) Rectangle(org.eclipse.swt.graphics.Rectangle) ArrayList(java.util.ArrayList) Image(org.eclipse.swt.graphics.Image) BufferedImage(java.awt.image.BufferedImage) JFreeChart(org.jfree.chart.JFreeChart) CategoryPlot(org.jfree.chart.plot.CategoryPlot) Ellipse2D(java.awt.geom.Ellipse2D) BufferedImage(java.awt.image.BufferedImage) CategoryAxis(org.jfree.chart.axis.CategoryAxis) ImageData(org.eclipse.swt.graphics.ImageData) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) StepPerformanceSnapShot(org.pentaho.di.trans.performance.StepPerformanceSnapShot)

Example 89 with CategoryPlot

use of org.jfree.chart.plot.CategoryPlot in project pentaho-kettle by pentaho.

the class TransPerfDelegate method updateCanvas.

private void updateCanvas() {
    Rectangle bounds = canvas.getBounds();
    if (bounds.width <= 0 || bounds.height <= 0) {
        return;
    }
    // The list of snapshots : convert to JFreeChart dataset
    // 
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    String[] selectedSteps = stepsList.getSelection();
    if (selectedSteps == null || selectedSteps.length == 0) {
        // first step
        selectedSteps = new String[] { steps[0] };
        stepsList.select(0);
    }
    int[] dataIndices = dataList.getSelectionIndices();
    if (dataIndices == null || dataIndices.length == 0) {
        dataIndices = new int[] { DATA_CHOICE_WRITTEN };
        dataList.select(0);
    }
    boolean multiStep = stepsList.getSelectionCount() > 1;
    boolean multiData = dataList.getSelectionCount() > 1;
    // A single metric shown for a single step
    boolean calcMoving = !multiStep && !multiData;
    List<Double> movingList = new ArrayList<Double>();
    int movingSize = 10;
    double movingTotal = 0;
    int totalTimeInSeconds = 0;
    for (int t = 0; t < selectedSteps.length; t++) {
        String stepNameCopy = selectedSteps[t];
        List<StepPerformanceSnapShot> snapShotList = stepPerformanceSnapShots.get(stepNameCopy);
        if (snapShotList != null && snapShotList.size() > 1) {
            totalTimeInSeconds = (int) Math.round(((double) (snapShotList.get(snapShotList.size() - 1).getDate().getTime() - snapShotList.get(0).getDate().getTime())) / 1000);
            for (int i = 0; i < snapShotList.size(); i++) {
                StepPerformanceSnapShot snapShot = snapShotList.get(i);
                if (snapShot.getTimeDifference() != 0) {
                    double factor = (double) 1000 / (double) snapShot.getTimeDifference();
                    for (int d = 0; d < dataIndices.length; d++) {
                        String dataType;
                        if (multiStep) {
                            dataType = stepNameCopy;
                        } else {
                            dataType = dataChoices[dataIndices[d]];
                        }
                        String xLabel = Integer.toString(Math.round(i * timeDifference / 1000));
                        Double metric = null;
                        switch(dataIndices[d]) {
                            case DATA_CHOICE_INPUT:
                                metric = snapShot.getLinesInput() * factor;
                                break;
                            case DATA_CHOICE_OUTPUT:
                                metric = snapShot.getLinesOutput() * factor;
                                break;
                            case DATA_CHOICE_READ:
                                metric = snapShot.getLinesRead() * factor;
                                break;
                            case DATA_CHOICE_WRITTEN:
                                metric = snapShot.getLinesWritten() * factor;
                                break;
                            case DATA_CHOICE_UPDATED:
                                metric = snapShot.getLinesUpdated() * factor;
                                break;
                            case DATA_CHOICE_REJECTED:
                                metric = snapShot.getLinesRejected() * factor;
                                break;
                            case DATA_CHOICE_INPUT_BUFFER_SIZE:
                                metric = (double) snapShot.getInputBufferSize();
                                break;
                            case DATA_CHOICE_OUTPUT_BUFFER_SIZE:
                                metric = (double) snapShot.getOutputBufferSize();
                                break;
                            default:
                                break;
                        }
                        if (metric != null) {
                            dataset.addValue(metric, dataType, xLabel);
                            if (calcMoving) {
                                movingTotal += metric;
                                movingList.add(metric);
                                if (movingList.size() > movingSize) {
                                    movingTotal -= movingList.get(0);
                                    movingList.remove(0);
                                }
                                double movingAverage = movingTotal / movingList.size();
                                dataset.addValue(movingAverage, dataType + "(Avg)", xLabel);
                            // System.out.println("moving average = "+movingAverage+", movingTotal="+movingTotal+", m");
                            }
                        }
                    }
                }
            }
        }
    }
    String chartTitle = title;
    if (multiStep) {
        chartTitle += " (" + dataChoices[dataIndices[0]] + ")";
    } else {
        chartTitle += " (" + selectedSteps[0] + ")";
    }
    final JFreeChart chart = // chart title
    ChartFactory.createLineChart(// chart title
    chartTitle, BaseMessages.getString(PKG, "StepPerformanceSnapShotDialog.TimeInSeconds.Label", Integer.toString(totalTimeInSeconds), // domain axis label
    Long.toString(timeDifference)), // range axis label
    BaseMessages.getString(PKG, "StepPerformanceSnapShotDialog.RowsPerSecond.Label"), // data
    dataset, // orientation
    PlotOrientation.VERTICAL, // include legend
    true, // tooltips
    true, // urls
    false);
    chart.setBackgroundPaint(Color.white);
    TextTitle title = new TextTitle(chartTitle);
    // title.setExpandToFitSpace(true);
    // org.eclipse.swt.graphics.Color pentahoColor = GUIResource.getInstance().getColorPentaho();
    // java.awt.Color color = new java.awt.Color(pentahoColor.getRed(), pentahoColor.getGreen(),pentahoColor.getBlue());
    // title.setBackgroundPaint(color);
    title.setFont(new java.awt.Font("SansSerif", java.awt.Font.BOLD, 12));
    chart.setTitle(title);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setForegroundAlpha(0.5f);
    plot.setRangeGridlinesVisible(true);
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setTickLabelsVisible(false);
    // Customize the renderer...
    // 
    LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    renderer.setBaseShapesVisible(true);
    renderer.setDrawOutlines(true);
    renderer.setUseFillPaint(true);
    renderer.setBaseFillPaint(Color.white);
    renderer.setSeriesStroke(0, new BasicStroke(1.5f));
    renderer.setSeriesOutlineStroke(0, new BasicStroke(1.5f));
    renderer.setSeriesStroke(1, new BasicStroke(2.5f));
    renderer.setSeriesOutlineStroke(1, new BasicStroke(2.5f));
    renderer.setSeriesShape(0, new Ellipse2D.Double(-3.0, -3.0, 6.0, 6.0));
    BufferedImage bufferedImage = chart.createBufferedImage(bounds.width, bounds.height);
    ImageData imageData = ImageUtil.convertToSWT(bufferedImage);
    // 
    if (image != null) {
        image.dispose();
    }
    image = new Image(transGraph.getDisplay(), imageData);
    // Draw the image on the canvas...
    // 
    canvas.redraw();
}
Also used : BasicStroke(java.awt.BasicStroke) LineAndShapeRenderer(org.jfree.chart.renderer.category.LineAndShapeRenderer) NumberAxis(org.jfree.chart.axis.NumberAxis) Rectangle(org.eclipse.swt.graphics.Rectangle) ArrayList(java.util.ArrayList) BufferedImage(java.awt.image.BufferedImage) Image(org.eclipse.swt.graphics.Image) Ellipse2D(java.awt.geom.Ellipse2D) BufferedImage(java.awt.image.BufferedImage) ImageData(org.eclipse.swt.graphics.ImageData) JFreeChart(org.jfree.chart.JFreeChart) CategoryPlot(org.jfree.chart.plot.CategoryPlot) TextTitle(org.jfree.chart.title.TextTitle) CategoryAxis(org.jfree.chart.axis.CategoryAxis) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) StepPerformanceSnapShot(org.pentaho.di.trans.performance.StepPerformanceSnapShot)

Example 90 with CategoryPlot

use of org.jfree.chart.plot.CategoryPlot in project qpid-broker-j by apache.

the class BaseChartBuilderTest method setUp.

@Before
public void setUp() throws Exception {
    Plot plot = new CategoryPlot();
    _jFreeChart = new JFreeChart(plot);
    when(_chartingDefinition.getChartTitle()).thenReturn(CHART_TITLE);
    when(_chartingDefinition.getChartSubtitle()).thenReturn(CHART_SUB_TITLE);
    when(_chartingDefinition.getXAxisTitle()).thenReturn(X_TITLE);
    when(_chartingDefinition.getYAxisTitle()).thenReturn(Y_TITLE);
    when(_chartingDefinition.getSeriesDefinitions()).thenReturn(_seriesDefinitions);
}
Also used : CategoryPlot(org.jfree.chart.plot.CategoryPlot) Plot(org.jfree.chart.plot.Plot) CategoryPlot(org.jfree.chart.plot.CategoryPlot) JFreeChart(org.jfree.chart.JFreeChart) Before(org.junit.Before)

Aggregations

CategoryPlot (org.jfree.chart.plot.CategoryPlot)189 JFreeChart (org.jfree.chart.JFreeChart)94 CategoryAxis (org.jfree.chart.axis.CategoryAxis)88 NumberAxis (org.jfree.chart.axis.NumberAxis)80 Test (org.junit.Test)72 DefaultCategoryDataset (org.jfree.data.category.DefaultCategoryDataset)44 CategoryItemRenderer (org.jfree.chart.renderer.category.CategoryItemRenderer)36 ValueAxis (org.jfree.chart.axis.ValueAxis)35 BarRenderer (org.jfree.chart.renderer.category.BarRenderer)32 CategoryDataset (org.jfree.data.category.CategoryDataset)29 StandardCategoryToolTipGenerator (org.jfree.chart.labels.StandardCategoryToolTipGenerator)27 StandardCategoryURLGenerator (org.jfree.chart.urls.StandardCategoryURLGenerator)24 Paint (java.awt.Paint)23 DefaultBoxAndWhiskerCategoryDataset (org.jfree.data.statistics.DefaultBoxAndWhiskerCategoryDataset)16 LegendItem (org.jfree.chart.LegendItem)15 LineAndShapeRenderer (org.jfree.chart.renderer.category.LineAndShapeRenderer)13 RectangleInsets (org.jfree.ui.RectangleInsets)13 ArrayList (java.util.ArrayList)11 ChartRenderingInfo (org.jfree.chart.ChartRenderingInfo)11 XYPlot (org.jfree.chart.plot.XYPlot)11