Example usage for org.jfree.data.time TimeSeries getRangeDescription

List of usage examples for org.jfree.data.time TimeSeries getRangeDescription

Introduction

In this page you can find the example usage for org.jfree.data.time TimeSeries getRangeDescription.

Prototype

public String getRangeDescription() 

Source Link

Document

Returns the range description.

Usage

From source file:org.gbif.portal.web.controller.dataset.IndexingHistoryController.java

/**
 * Create a time series graphic to display indexing processes.
 * //w w  w.  j  av a2s  . com
 * @param dataProvider
 * @param dataResource
 * @param activities
 * @param fileNamePrefix
 * @return
 */
public String timeSeriesTest(DataProviderDTO dataProvider, DataResourceDTO dataResource,
        List<LoggedActivityDTO> loggedActivities, String fileNamePrefix, int minProcessingTimeToRender) {

    List<LoggedActivityDTO> activities = new ArrayList<LoggedActivityDTO>();
    for (LoggedActivityDTO la : loggedActivities) {
        if (la.getDataResourceKey() != null && la.getDataResourceName() != null && la.getEventName() != null)
            activities.add(la);
    }

    //if no activities to render, return
    if (activities.isEmpty())
        return null;

    Map<String, Integer> drActualCount = new HashMap<String, Integer>();
    Map<String, Integer> drCount = new HashMap<String, Integer>();

    //record the actual counts
    for (LoggedActivityDTO laDTO : activities) {
        if (laDTO.getStartDate() != null && laDTO.getEndDate() != null
                && laDTO.getDurationInMillisecs() > minProcessingTimeToRender) {
            if (drActualCount.get(laDTO.getDataResourceName()) == null) {
                drActualCount.put(laDTO.getDataResourceName(), new Integer(4));
                drCount.put(laDTO.getDataResourceName(), new Integer(0));
            } else {
                Integer theCount = drActualCount.get(laDTO.getDataResourceName());
                theCount = new Integer(theCount.intValue() + 4);
                drActualCount.remove(laDTO.getDataResourceName());
                drActualCount.put(laDTO.getDataResourceName(), theCount);
            }
        }
    }

    StringBuffer fileNameBuffer = new StringBuffer(fileNamePrefix);
    if (dataResource != null) {
        fileNameBuffer.append("-resource-");
        fileNameBuffer.append(dataResource.getKey());
    } else if (dataProvider != null) {
        fileNameBuffer.append("-provider-");
        fileNameBuffer.append(dataProvider.getKey());
    }
    fileNameBuffer.append(".png");

    String fileName = fileNameBuffer.toString();
    String filePath = System.getProperty("java.io.tmpdir") + File.separator + fileName;

    File fileToCheck = new File(filePath);
    if (fileToCheck.exists()) {
        return fileName;
    }

    TimeSeriesCollection dataset = new TimeSeriesCollection();
    boolean generateChart = false;

    int count = 1;
    int dataResourceCount = 1;

    Collections.sort(activities, new Comparator<LoggedActivityDTO>() {
        public int compare(LoggedActivityDTO o1, LoggedActivityDTO o2) {
            if (o1 == null || o2 == null || o1.getDataResourceKey() != null || o2.getDataResourceKey() != null)
                return -1;
            return o1.getDataResourceKey().compareTo(o2.getDataResourceKey());
        }
    });

    String currentDataResourceKey = activities.get(0).getDataResourceKey();

    for (LoggedActivityDTO laDTO : activities) {
        if (laDTO.getStartDate() != null && laDTO.getEndDate() != null
                && laDTO.getDurationInMillisecs() > minProcessingTimeToRender) {

            if (currentDataResourceKey != null && !currentDataResourceKey.equals(laDTO.getDataResourceKey())) {
                dataResourceCount++;
                count = count + 1;
                currentDataResourceKey = laDTO.getDataResourceKey();
            }
            TimeSeries s1 = new TimeSeries(laDTO.getDataResourceName(), "Process time period",
                    laDTO.getEventName(), Hour.class);
            s1.add(new Hour(laDTO.getStartDate()), count);
            s1.add(new Hour(laDTO.getEndDate()), count);
            dataset.addSeries(s1);
            generateChart = true;
        }
    }

    if (!generateChart)
        return null;

    // create a pie chart...
    final JFreeChart chart = ChartFactory.createTimeSeriesChart(null, null, null, dataset, false, false, false);

    XYPlot plot = chart.getXYPlot();
    plot.setWeight(10);
    plot.getRangeAxis().setAutoRange(false);
    plot.getRangeAxis().setRange(0, drCount.size() + 1);
    plot.getRangeAxis().setAxisLineVisible(false);
    plot.getRangeAxis().setAxisLinePaint(Color.WHITE);
    plot.setDomainCrosshairValue(1);
    plot.setRangeGridlinesVisible(false);
    plot.getRangeAxis().setVisible(false);
    plot.getRangeAxis().setLabel("datasets");

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setItemLabelsVisible(true);
    MyXYItemLabelGenerator labelGenerator = new MyXYItemLabelGenerator();
    labelGenerator.setDataResourceActualCount(drActualCount);
    labelGenerator.setDataResourceCount(drCount);
    renderer.setItemLabelGenerator(labelGenerator);

    List<TimeSeries> seriesList = dataset.getSeries();
    for (TimeSeries series : seriesList) {
        if (((String) series.getRangeDescription()).startsWith("extraction")) {
            renderer.setSeriesPaint(seriesList.indexOf(series), Color.RED);
        } else {
            renderer.setSeriesPaint(seriesList.indexOf(series), Color.BLUE);
        }
        renderer.setSeriesStroke(seriesList.indexOf(series), new BasicStroke(7f));
    }

    int imageHeight = 30 * dataResourceCount;
    if (imageHeight < 100) {
        imageHeight = 100;
    } else {
        imageHeight = imageHeight + 100;
    }

    final BufferedImage image = new BufferedImage(900, imageHeight, BufferedImage.TYPE_INT_RGB);
    KeypointPNGEncoderAdapter adapter = new KeypointPNGEncoderAdapter();
    adapter.setQuality(1);
    try {
        adapter.encode(image);
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
    }
    final Graphics2D g2 = image.createGraphics();
    g2.setFont(new Font("Arial", Font.PLAIN, 11));
    final Rectangle2D chartArea = new Rectangle2D.Double(0, 0, 900, imageHeight);

    // draw
    chart.draw(g2, chartArea, null, null);

    //styling
    chart.setPadding(new RectangleInsets(0, 0, 0, 0));
    chart.setBorderVisible(false);
    chart.setBackgroundImageAlpha(0);
    chart.setBackgroundPaint(Color.WHITE);
    chart.setBorderPaint(Color.LIGHT_GRAY);

    try {
        FileOutputStream fOut = new FileOutputStream(filePath);
        ChartUtilities.writeChartAsPNG(fOut, chart, 900, imageHeight);
        return fileName;
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
    }
    return null;
}

From source file:org.jfree.data.time.TimeSeries.java

/**
 * Tests the series for equality with an arbitrary object.
 *
 * @param obj  the object to test against (<code>null</code> permitted).
 *
 * @return A boolean./*  w w w .  ja v  a  2 s  .  c o  m*/
 */
@Override
public boolean equals(Object obj) {
    if (obj == this) {
        return true;
    }
    if (!(obj instanceof TimeSeries)) {
        return false;
    }
    TimeSeries that = (TimeSeries) obj;
    if (!ObjectUtilities.equal(getDomainDescription(), that.getDomainDescription())) {
        return false;
    }
    if (!ObjectUtilities.equal(getRangeDescription(), that.getRangeDescription())) {
        return false;
    }
    if (!ObjectUtilities.equal(this.timePeriodClass, that.timePeriodClass)) {
        return false;
    }
    if (getMaximumItemAge() != that.getMaximumItemAge()) {
        return false;
    }
    if (getMaximumItemCount() != that.getMaximumItemCount()) {
        return false;
    }
    int count = getItemCount();
    if (count != that.getItemCount()) {
        return false;
    }
    if (!ObjectUtilities.equal(this.data, that.data)) {
        return false;
    }
    return super.equals(obj);
}

From source file:org.lmn.fc.frameworks.starbase.plugins.observatory.ui.tabs.charts.ChartHelper.java

/***********************************************************************************************
 * Dump the (partial) contents of each Series in an XYdatset.
 *
 * @param dump//from   w w w.ja v a  2s  . co  m
 * @param calendar
 * @param dataset
 * @param dumprowcount
 * @param title
 */

public static void dumpXYDataset(final boolean dump, final Calendar calendar, final XYDataset dataset,
        final int dumprowcount, final String title) {
    final String SOURCE = "ChartHelper.dumpXYDataset() ";

    if (dump) {
        LOGGER.log(title);

        if ((dataset != null) && (dataset instanceof XYSeriesCollection)) {
            final XYSeriesCollection seriesCollection;

            seriesCollection = (XYSeriesCollection) dataset;

            LOGGER.log("XYSeriesCollection");
            LOGGER.log("    [series.count=" + seriesCollection.getSeriesCount() + "]");
            LOGGER.log("    [domain.lowerbound.interval.true="
                    + (long) seriesCollection.getDomainLowerBound(true) + "]");
            LOGGER.log("    [domain.lowerbound.interval.false="
                    + (long) seriesCollection.getDomainLowerBound(false) + "]");
            LOGGER.log("    [domain.upperbound.interval.true="
                    + (long) seriesCollection.getDomainUpperBound(true) + "]");
            LOGGER.log("    [domain.upperbound.interval.false="
                    + (long) seriesCollection.getDomainUpperBound(false) + "]");
            LOGGER.log("    [domain.order=" + seriesCollection.getDomainOrder() + "]");

            for (int intSeriesIndex = 0; intSeriesIndex < seriesCollection.getSeriesCount(); intSeriesIndex++) {
                final XYSeries xySeries;

                LOGGER.log("");
                LOGGER.log("    [xyseries.index=" + intSeriesIndex + "]");

                xySeries = seriesCollection.getSeries(intSeriesIndex);
                LOGGER.log("    [xyseries.itemcount=" + xySeries.getItemCount() + "]");
                LOGGER.log("    [xyseries.key=" + xySeries.getKey() + "]");
                LOGGER.log("    [xyseries.xmin=" + xySeries.getMinX() + "]");
                LOGGER.log("    [xyseries.xmax=" + xySeries.getMaxX() + "]");
                LOGGER.log("    [xyseries.ymin=" + xySeries.getMinY() + "]");
                LOGGER.log("    [xyseries.ymax=" + xySeries.getMaxY() + "]");
                LOGGER.log("    [xyseries.description=" + xySeries.getDescription() + "]");
                LOGGER.log("    [xyseries.autosort=" + xySeries.getAutoSort() + "]");
                LOGGER.log("    [xyseries.allowduplicatex=" + xySeries.getAllowDuplicateXValues() + "]");

                // Dump the first chunk
                for (int intItemIndex = 0; intItemIndex < (Math.min(dumprowcount,
                        xySeries.getItemCount())); intItemIndex++) {
                    final XYDataItem item;

                    item = xySeries.getDataItem(intItemIndex);

                    LOGGER.log("        [item.index=" + intItemIndex + "] [item.x=" + item.getXValue()
                            + "] [item.y=" + item.getYValue() + "]");
                }

                LOGGER.log("    ...");

                // Dump the last chunk
                for (int intItemIndex = 0; intItemIndex < (Math.min(dumprowcount,
                        xySeries.getItemCount())); intItemIndex++) {
                    final XYDataItem item;
                    final int intIndex;

                    intIndex = Math.max(0, xySeries.getItemCount() - dumprowcount) + intItemIndex;
                    item = xySeries.getDataItem(intIndex);

                    LOGGER.log("        [item.index=" + intIndex + "] [item.x=" + item.getXValue()
                            + "] [item.y=" + item.getYValue() + "]");
                }
            }
        } else if ((dataset != null) && (dataset instanceof TimeSeriesCollection)) {
            final TimeSeriesCollection seriesCollection;

            seriesCollection = (TimeSeriesCollection) dataset;

            LOGGER.log("TimeSeriesCollection");
            LOGGER.log("    [series.count=" + seriesCollection.getSeriesCount() + "]");
            LOGGER.log("    [domain.lowerbound.interval.true="
                    + (long) seriesCollection.getDomainLowerBound(true) + "]");
            LOGGER.log("    [domain.lowerbound.interval.false="
                    + (long) seriesCollection.getDomainLowerBound(false) + "]");
            LOGGER.log("    [domain.upperbound.interval.true="
                    + (long) seriesCollection.getDomainUpperBound(true) + "]");
            LOGGER.log("    [domain.upperbound.interval.false="
                    + (long) seriesCollection.getDomainUpperBound(false) + "]");
            LOGGER.log("    [domain.order=" + seriesCollection.getDomainOrder() + "]");

            for (int intSeriesIndex = 0; intSeriesIndex < seriesCollection.getSeriesCount(); intSeriesIndex++) {
                final TimeSeries timeSeries;

                LOGGER.log("");
                LOGGER.log("    [timeseries.index=" + intSeriesIndex + "]");

                timeSeries = seriesCollection.getSeries(intSeriesIndex);
                LOGGER.log("    [timeseries.itemcount=" + timeSeries.getItemCount() + "]");
                LOGGER.log("    [timeseries.key=" + timeSeries.getKey() + "]");
                LOGGER.log("    [timeseries.ymin=" + timeSeries.getMinY() + "]");
                LOGGER.log("    [timeseries.ymax=" + timeSeries.getMaxY() + "]");
                LOGGER.log("    [timeseries.domain=" + timeSeries.getDomainDescription() + "]");
                LOGGER.log("    [timeseries.range=" + timeSeries.getRangeDescription() + "]");
                LOGGER.log(
                        "    [timeseries.timeperiodclass=" + timeSeries.getTimePeriodClass().getName() + "]");

                for (int intItemIndex = 0; intItemIndex < (Math.min(dumprowcount,
                        timeSeries.getItemCount())); intItemIndex++) {
                    final TimeSeriesDataItem item;

                    item = timeSeries.getDataItem(intItemIndex);

                    LOGGER.log("        [item.index=" + intItemIndex + "] [item.period.serialindex="
                            + item.getPeriod().getSerialIndex() + "] [item.period.firstmillis="
                            + item.getPeriod().getFirstMillisecond(calendar) + "] [item.value="
                            + item.getValue() + "]");
                }

                LOGGER.log("    ...");

                for (int intItemIndex = 0; intItemIndex < (Math.min(dumprowcount,
                        timeSeries.getItemCount())); intItemIndex++) {
                    final TimeSeriesDataItem item;
                    final int intIndex;

                    intIndex = Math.max(0, timeSeries.getItemCount() - dumprowcount) + intItemIndex;
                    item = timeSeries.getDataItem(intIndex);

                    LOGGER.log("        [item.index=" + intIndex + "] [item.period.serialindex="
                            + item.getPeriod().getSerialIndex() + "] [item.period.firstmillis="
                            + item.getPeriod().getFirstMillisecond(calendar) + "] [item.value="
                            + item.getValue() + "]");
                }
            }
        } else {
            LOGGER.error(SOURCE + "Unsupported XYDataset type");
        }
    }
}