Package plotter.xy

Examples of plotter.xy.CompressingXYDataset$MinMaxChangeListener


    xAxis.setTickMarkCalculator(new TimeTickMarkCalculator());
    xAxis.setFormat(new DateNumberFormat(new SimpleDateFormat("yyyy-MM-dd\nHH:mm:ss.SSS")));

    final LinearXYPlotLine line = new LinearXYPlotLine(xAxis, yAxis, XYDimension.X);
    line.setForeground(Color.white);
    final CompressingXYDataset d = new CompressingXYDataset(line, new DefaultCompressor());
    d.setTruncationPoint(0);
    d.setXData(line.getXData());
    d.setYData(line.getYData());
    final XYMarkerLine marker = new XYMarkerLine(xAxis, 60);
    marker.setForeground(Color.yellow);
    XYPlotContents contents = frame.getContents();
    contents.add(marker);
    final XYMarkerLine marker2 = new XYMarkerLine(yAxis, .5);
    marker2.setForeground(Color.red);
    contents.add(marker2);
    frame.addPlotLine(line);

    yAxis.setStart(-1.2);
    yAxis.setEnd(1.2);
    xAxis.setStart(0);
    xAxis.setEnd(10);

    frame.getLocationDisplay().setFormat(new MessageFormat("<html><b>X:</b> {0,date,HH:mm:ss} &nbsp; <b>Y:</b> {1}</html>"));
    frame.getSlopeLineDisplay().setFormat(new MessageFormat("<html><b>&Delta;x:</b> {0,date,HH:mm:ss}  <b>&Delta;y:</b> {1}</html>"));

    for(int x = 0; x < 900; x++) {
      double x2 = x / 10.0;
      double y2 = Math.sin(x2 / 10.0);
      d.add(x2, y2);
    }
    timer.schedule(new TimerTask() {
      int x = 0;
      long startTime = System.currentTimeMillis();


      @Override
      public void run() {
        SwingUtilities.invokeLater(new Runnable() {
          @Override
          public void run() {
            long now = System.currentTimeMillis();
            xAxis.setStart(now / 1000 * 1000 - 9000);
            xAxis.setEnd(now / 1000 * 1000 + 1000);
            d.setTruncationPoint(xAxis.getStart());
            for(int i = 0; i < 10; i++) {
              double x2 = now + i;
              double y2 = Math.sin(x2 / 2000.0);
              d.add(x2, y2);
              marker.setValue(x2);
              marker2.setValue(y2);
              x++;
              if(x % 100 == 0) {
                System.out.println("Dataset size: " + d.getPointCount());
                System.out.println("Points per pixel: " + d.getPointCount() / (double) xAxis.getWidth());
                System.out.println("Points per second: " + 1000 * x / (double) (now - startTime));
              }
            }
          }
        });
      }
    }, 10, 10);

    line.addComponentListener(new ComponentAdapter() {
      @Override
      public void componentResized(ComponentEvent e) {
        d.setCompressionOffset(xAxis.getStart());
        d.setCompressionScale((xAxis.getEnd() - xAxis.getStart()) / xAxis.getWidth());
      }
    });

    frame.setSize(400, 300);
    frame.setVisible(true);
View Full Code Here


    if(points.isEmpty()) {
      return;
    }

    CompressingXYDataset dataset = dataSeries.get(feed).getData();
    double min;
    double max;
    if(plot.getAxisOrientationSetting() == AxisOrientationSetting.X_AXIS_AS_TIME) {
      min = dataset.getMinX();
      max = dataset.getMaxX();
    } else {
      min = dataset.getMinY();
      max = dataset.getMaxY();
    }
    double datasetMinTime = Math.min(min, max);
    double datasetMaxTime = Math.max(min, max);

    if(dataset.getPointCount() == 0 || points.firstKey() >= datasetMaxTime) {
      // TODO: Change this to use an aggregate add method
      if(plot.getAxisOrientationSetting() == AxisOrientationSetting.X_AXIS_AS_TIME) {
        for(Entry<Long, Double> point : points.entrySet()) {
          dataset.add(point.getKey(), point.getValue());

        }
      } else {
        for(Entry<Long, Double> point : points.entrySet()) {
          dataset.add(point.getValue(), point.getKey());
        }
      }
      if (plot.getMaxTime() >= datasetMaxTime) {
        dataSeries.get(feed).setUpdateRegressionLine(true);
      }
    } else if(points.lastKey() <= datasetMinTime) {
      // TODO: Make this efficient
      double[] x = new double[points.size()];
      double[] y = new double[x.length];
      int i = 0;
      for(Entry<Long, Double> p : points.entrySet()) {
        x[i] = p.getKey();
        y[i] = p.getValue();
        i++;
      }
      if(plot.getAxisOrientationSetting() == AxisOrientationSetting.Y_AXIS_AS_TIME) {
        double[] tmp = x;
        x = y;
        y = tmp;
      }
      dataset.prepend(x, 0, y, 0, x.length);
    } else {
      // Data appearing in the middle of the dataset.
      // Assume that it's caused by the last second of data arriving twice,
      // once from the initial historical request and once from the once-per-second update.
      // It may also be values for predictive data we already loaded.
      // In either case, the overlapping data should be identical to what we already have, so ignore it.

      // Append the data that isn't redundant.
      SortedMap<Long, Double> before = points.subMap(0L, (long) datasetMinTime);
      SortedMap<Long, Double> after = points.subMap((long) datasetMaxTime, Long.MAX_VALUE);
      SortedMap<Long, Double> overlap = points.subMap((long) datasetMinTime, (long) datasetMaxTime);
      if(!overlap.isEmpty()) {
        if(overlap.lastKey() - overlap.firstKey() > 10000) {
          logger.warn("Cannot currently insert into the middle of a dataset: minX = " + datasetMinTime + ", maxX = " + datasetMaxTime
              + ", firstKey = " + points.firstKey() + ", lastKey = " + points.lastKey());
        }
      }
      // TODO: Change this to use an aggregate add method
       if(plot.getAxisOrientationSetting() == AxisOrientationSetting.X_AXIS_AS_TIME) {
        if(!before.isEmpty()) {
          double[] x = new double[before.size()];
          double[] y = new double[x.length];
          int i = 0;
          for(Entry<Long, Double> point : before.entrySet()) {
            x[i] = point.getKey();
            y[i] = point.getValue();
            i++;
          }
          dataset.prepend(x, 0, y, 0, x.length);
        }
        for(Entry<Long, Double> point : after.entrySet()) {
                    dataset.add(point.getKey(), point.getValue());
         }
       } else {
        if(!before.isEmpty()) {
          double[] x = new double[before.size()];
          double[] y = new double[x.length];
          int i = 0;
          for(Entry<Long, Double> point : before.entrySet()) {
            y[i] = point.getKey();
            x[i] = point.getValue();
            i++;
          }
          dataset.prepend(x, 0, y, 0, x.length);
        }

        for(Entry<Long, Double> point : after.entrySet()) {
           dataset.add(point.getValue(), point.getKey());
         }
       }
    }
    dataSeries.get(feed).updateRegressionLine();
    for(Entry<Long, Double> point : points.entrySet()) {
View Full Code Here

    // closed
    double width = Math.max(0,plot.getAxisOrientationSetting() == AxisOrientationSetting.X_AXIS_AS_TIME ? contents.getWidth() : contents.getHeight());
    double compressionScale = width == 0 ? Double.MAX_VALUE : Math.abs(end - start) / width;
    if(plot.getTimeAxisSubsequentSetting() == TimeAxisSubsequentBoundsSetting.SCRUNCH) {
      for(PlotDataSeries s : dataSeries.values()) {
        CompressingXYDataset d = s.getData();
        double scale = d.getCompressionScale();
        // Compress by integral factors to minimize artifacts from multiple compression runs
        if(scale == 0) {
          scale = compressionScale;
        } else {
          while(scale < compressionScale / 2) {
            scale *= 2;
          }
        }
        if(scale > d.getCompressionScale()) {
          d.setCompressionOffset(start);
          d.setCompressionScale(scale);
          d.recompress();
        }
      }
    } else {
      for(PlotDataSeries s : dataSeries.values()) {
        CompressingXYDataset d = s.getData();
        d.setCompressionOffset(start);
        d.setCompressionScale(compressionScale);
      }
    }
  }
View Full Code Here

   * @param endTime time in millisecs.
   */
  public void setTimeAxisStartAndStop(long startTime, long endTime) {
    assert startTime != endTime;
    for(PlotDataSeries d : plotDataManager.getDataSeries().values()) {
      CompressingXYDataset data = d.getData();
      // if the min and max are reversed on the time axis, then the end may be < start time
      data.setTruncationPoint(Math.min(startTime,endTime));
    }
    theTimeAxis.setStart(startTime);
    theTimeAxis.setEnd(endTime);
  }
View Full Code Here

  void minMaxChanged() {
    double minNonTime = Double.POSITIVE_INFINITY;
    double maxNonTime = Double.NEGATIVE_INFINITY;
    if(getAxisOrientationSetting() == AxisOrientationSetting.X_AXIS_AS_TIME) {
      for(PlotDataSeries d : plotDataManager.getDataSeries().values()) {
        CompressingXYDataset data = d.getData();
        minNonTime = Math.min(minNonTime, data.getMinY());
        maxNonTime = Math.max(maxNonTime, data.getMaxY());
      }
    } else {
      for(PlotDataSeries d : plotDataManager.getDataSeries().values()) {
        CompressingXYDataset data = d.getData();
        minNonTime = Math.min(minNonTime, data.getMinX());
        maxNonTime = Math.max(maxNonTime, data.getMaxX());
      }
    }

    if ((minNonTime != oldMinNonTime || maxNonTime != oldMaxNonTime)
        && !isPaused && !nonTimeAxis.isPinned()) {
View Full Code Here


  @Override
  public void setTruncationPoint(double min) {
    for(PlotDataSeries d : plotDataManager.getDataSeries().values()) {
      CompressingXYDataset data = d.getData();
      data.setTruncationPoint(min);
    }
  }
View Full Code Here

  private void setupDataSet(String dataSetName) {

    assert plot.getPlotView() != null : "Plot Object not initalized";
    assert linePlot != null;

    dataset = new CompressingXYDataset(linePlot, new DefaultCompressor());
    // Listen for min/max changes on the non-time axis
    if(plot.getAxisOrientationSetting() == AxisOrientationSetting.X_AXIS_AS_TIME) {
      dataset.addYMinMaxChangeListener(this);
    } else {
      dataset.addXMinMaxChangeListener(this);
View Full Code Here

  }
 
  @Override
  public PlotLine createLine() {
    LinearXYPlotLine plotLine = new LinearXYPlotLine(plot.getXAxis(), plot.getYAxis(), rotated ? XYDimension.Y : XYDimension.X);
    XYDataset data = new CompressingXYDataset(plotLine, new DefaultCompressor());
    return new PlotterPlotLine(plotLine, data, rotated);
  }
View Full Code Here

        time[0] = i;
      }
      Method m = testPlot.getPlotAbstraction().getClass().getDeclaredMethod("timeReachedEnd", new Class[0]);
      m.setAccessible(true);
      m.invoke(testPlot.getPlotAbstraction(), new Object[0]);
      CompressingXYDataset dataset = ((PlotDataSeries)testPlot.getPlotDataManager().getNamedDataSeries("feed")).dataset;
      int size = dataset.getPointCount();

      // We can have 4 points per pixel, and it can nearly double before recompressing, so we can have almost 8 points per pixel
      int max = testPlot.getPlotView().getContents().getWidth() * 8;
      Assert.assertTrue(size < max, "size = " + size + ", max = " + max);
    } finally {
View Full Code Here

    Field f = plot.getClass().getDeclaredField("plotDataManager");
    f.setAccessible(true);
    PlotDataManager dataManager =  (PlotDataManager) f.get(plot);
    dataManager.addDataSet("test", Color.black);
    PlotDataSeries pds = dataManager.getDataSeries().values().iterator().next();
    CompressingXYDataset data = pds.getData();
    plot.setTimeAxisStartAndStop(start, stop);
    Assert.assertEquals(axis.getStartAsLong(), start);
    Assert.assertEquals(axis.getEndAsLong(), stop);
    Assert.assertEquals(Double.valueOf(expected),data.getTruncationPoint());
  }
View Full Code Here

TOP

Related Classes of plotter.xy.CompressingXYDataset$MinMaxChangeListener

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.