Esempio n. 1
0
  // attempt to get about 100 data points on each chart, based on the interval duration rounded to
  // the nearest 15 seconds
  // default to 60s
  public void recalculate() {
    if (!automatic) {
      throw new IllegalStateException(
          "cannot automatically set granularity; call setAutomatic(true) first");
    }

    long duration = 0;

    Interval interval = app.getIntervalManager().getCurrentInterval();

    if (Interval.DEFAULT.equals(interval)) {
      duration = app.getMaxSystemTime() - app.getMinSystemTime();

      // no files parsed yet => default back to 60s
      if (duration == Long.MAX_VALUE) {
        granularity = 60000;
        return;
      }
    } else {
      duration = interval.getDuration();
    }

    long granularity = duration / 100;

    if (granularity >= Integer.MAX_VALUE) {
      granularity = 2147475000; // MAX_VALUE rounded down to nearest 15000
    }

    // round to nearest 15 seconds
    granularity = Math.round(granularity / 15000d) * 15000;

    if (granularity < 1000) {
      granularity = 1000;
    }

    this.granularity = (int) granularity;
  }
Esempio n. 2
0
  /**
   * Create a chart given a definition and some data.
   *
   * @param definition the chart to create
   * @param dataSets the data to use for the chart
   * @return the chart
   * @see LineChartBuilder
   * @see BarChartBuilder
   * @see IntervalChartBuilder
   * @see HistogramChartBuilder
   */
  public JFreeChart createChart(
      BaseChartDefinition definition, Iterable<? extends DataSet> dataSets) {
    long startT = System.nanoTime();

    JFreeChart chart = null;

    if (definition.getClass().equals(LineChartDefinition.class)) {
      LineChartDefinition lineDefinition = (LineChartDefinition) definition;

      lineChartBuilder.initChart(lineDefinition);

      for (DataSet data : dataSets) {
        lineChartBuilder.addLine(data);
      }

      chart = lineChartBuilder.getChart();
    } else if (definition.getClass().equals(IntervalChartDefinition.class)) {
      IntervalChartDefinition lineDefinition = (IntervalChartDefinition) definition;

      intervalChartBuilder.initChart(lineDefinition);

      for (DataSet data : dataSets) {
        // TODO AnalysisRecord cache needed here?
        List<AnalysisRecord> analysis = new java.util.ArrayList<AnalysisRecord>();

        for (Interval i : app.getIntervalManager().getIntervals()) {
          AnalysisRecord record = new AnalysisRecord(data);
          record.setInterval(i);
          record.setGranularity(intervalChartBuilder.getGranularity());

          analysis.add(record);
        }

        intervalChartBuilder.addLine(lineDefinition, analysis);
      }

      chart = intervalChartBuilder.getChart();
    } else if (definition.getClass().equals(BarChartDefinition.class)) {
      BarChartDefinition barDefinition = (BarChartDefinition) definition;

      barChartBuilder.initChart(barDefinition);

      for (DataSet data : dataSets) {
        AnalysisRecord record = app.getAnalysis(data);

        // this check is really a hack for event interactions between the tree and the
        // ReportPanel when removing data with selected charts
        if (record != null) {
          barChartBuilder.addBar(record);
        }
      }

      chart = barChartBuilder.getChart();
    } else if (definition.getClass().equals(HistogramChartDefinition.class)) {
      HistogramChartDefinition histogramDefinition = (HistogramChartDefinition) definition;

      histogramChartBuilder.initChart(histogramDefinition);

      for (DataSet data : dataSets) {
        AnalysisRecord record = app.getAnalysis(data);

        // this check is really a hack for event interactions between the tree and the
        // ReportPanel when removing data with selected charts
        if (record != null) {
          histogramChartBuilder.addHistogram(record);
        }
      }

      chart = histogramChartBuilder.getChart();
    }

    if (LOGGER.isTraceEnabled()) {
      LOGGER.trace(
          "{}: {} chart created in {}ms",
          new Object[] {
            dataSets, definition.getShortName(), (System.nanoTime() - startT) / 1000000.0d
          });
    }

    return chart;
  }