PlotDataManager implements AbstractPlotDataManager { void setupCompressionRatio() { AbstractAxis axis = plot.getTimeAxis(); double start = axis.getStart(); double end = axis.getEnd(); assert start != end; XYPlotContents contents = plot.getPlotView().getContents(); 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(); 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); } } } PlotDataManager(PlotterPlot thePlot); @Override void addDataSet(String dataSetName, Color plottingColor); @Override void addData(String feed, SortedMap<Long, Double> points); void resizeAndReloadPlotBuffer(); @Override void informUpdateCacheDataStreamStarted(); void informResizeEvent(); @Override PlotDataSeries getNamedDataSeries(String name); void setDataSeries(Map<String, PlotDataSeries> dataSeries); Map<String, PlotDataSeries> getDataSeries(); void setPlot(PlotterPlot plot); AbstractPlottingPackage getPlot();  }
@Test public void testSetupCompressionRatioNotUserInteraction() { GregorianCalendar minTime = new GregorianCalendar(); GregorianCalendar maxTime = new GregorianCalendar(); minTime.setTimeInMillis(0); maxTime.setTimeInMillis(minTime.getTimeInMillis()); maxTime.add(Calendar.HOUR, 1); PlotSettings settings = new PlotSettings(); settings.setMinTime(minTime.getTimeInMillis()); settings.setMaxTime(maxTime.getTimeInMillis()); settings.setTimeAxisSubsequentSetting(TimeAxisSubsequentBoundsSetting.JUMP); PlotAbstraction testPlot = new PlotView.Builder(PlotterPlot.class) .plotSettings(settings) .isCompressionEnabled(true) .build(); PlotterPlot plotPackage = (PlotterPlot) testPlot.returnPlottingPackage(); ((PlotDataManager)plotPackage.getPlotDataManager()).setupCompressionRatio(); }
@Test public void testSetupCompressionRatioUserInteraction() { GregorianCalendar minTime = new GregorianCalendar(); GregorianCalendar maxTime = new GregorianCalendar(); minTime.setTimeInMillis(0); maxTime.setTimeInMillis(minTime.getTimeInMillis()); maxTime.add(Calendar.HOUR, 1); PlotSettings settings = new PlotSettings(); settings.setMinTime(minTime.getTimeInMillis()); settings.setMaxTime(maxTime.getTimeInMillis()); settings.setTimeAxisSubsequentSetting(TimeAxisSubsequentBoundsSetting.JUMP); PlotAbstraction testPlot = new PlotView.Builder(PlotterPlot.class) .plotSettings(settings) .isCompressionEnabled(true) .build(); PlotterPlot plotPackage = (PlotterPlot) testPlot.returnPlottingPackage(); ((PlotDataManager)plotPackage.getPlotDataManager()).setupCompressionRatio(); }
@Test public void testSetupCompressionRatioNoCompression() { GregorianCalendar minTime = new GregorianCalendar(); GregorianCalendar maxTime = new GregorianCalendar(); minTime.setTimeInMillis(0); maxTime.setTimeInMillis(minTime.getTimeInMillis()); maxTime.add(Calendar.HOUR, 1); PlotSettings settings = new PlotSettings(); settings.setMinTime(minTime.getTimeInMillis()); settings.setMaxTime(maxTime.getTimeInMillis()); settings.setTimeAxisSubsequentSetting(TimeAxisSubsequentBoundsSetting.JUMP); PlotAbstraction testPlot = new PlotView.Builder(PlotterPlot.class) .plotSettings(settings) .isCompressionEnabled(false) .build(); PlotterPlot plotPackage = (PlotterPlot) testPlot.returnPlottingPackage(); ((PlotDataManager)plotPackage.getPlotDataManager()).setupCompressionRatio(); }