00001
00002
00003
00004
00005
00006
00007 package org.swtchart.internal.compress;
00008
00009 import java.util.ArrayList;
00010
00014 public class CompressScatterSeries extends Compress {
00015
00017 private boolean isLineVisible;
00018
00020 private boolean occupied[][];
00021
00022
00023
00024
00025 @Override
00026 protected void addNecessaryPlots(ArrayList<Double> xList,
00027 ArrayList<Double> yList, ArrayList<Integer> indexList) {
00028
00029 if (isLineVisible) {
00030 for (int i = 0; i < xSeries.length && i < ySeries.length; i++) {
00031 if (!isInSameGridAsPrevious(xSeries[i], ySeries[i])) {
00032 addToList(xList, yList, indexList, xSeries[i], ySeries[i],
00033 i);
00034 }
00035 }
00036 } else {
00037 int width = (int) config.getWidthInPixel();
00038 int height = (int) config.getHeightInPixel();
00039
00040 if (width <= 0 || height <= 0) {
00041 return;
00042 }
00043
00044
00045 occupied = new boolean[width][height];
00046
00047 for (int i = 0; i < xSeries.length && i < ySeries.length; i++) {
00048 if (xSeries[i] >= xLower && xSeries[i] <= xUpper
00049 && ySeries[i] >= yLower && ySeries[i] <= yUpper
00050 && !isOccupied(xSeries[i], ySeries[i])) {
00051 addToList(xList, yList, indexList, xSeries[i], ySeries[i],
00052 i);
00053 }
00054 }
00055 }
00056 }
00057
00067 private boolean isOccupied(double x, double y) {
00068 int xGridIndex;
00069 int yGridIndex;
00070
00071
00072 if (config.isXLogScale()) {
00073 double lower = Math.log10(config.getXLowerValue());
00074 double upper = Math.log10(config.getXUpperValue());
00075 xGridIndex = (int) ((Math.log10(x) - lower) / (upper - lower) * config
00076 .getWidthInPixel());
00077 } else {
00078 xGridIndex = (int) ((x - config.getXLowerValue())
00079 / (config.getXUpperValue() - config.getXLowerValue()) * config
00080 .getWidthInPixel());
00081 }
00082
00083
00084 if (config.isYLogScale()) {
00085 double lower = Math.log10(config.getYLowerValue());
00086 double upper = Math.log10(config.getYUpperValue());
00087 yGridIndex = (int) ((Math.log10(y) - lower) / (upper - lower) * config
00088 .getHeightInPixel());
00089 } else {
00090 yGridIndex = (int) ((y - config.getYLowerValue())
00091 / (config.getYUpperValue() - config.getYLowerValue()) * config
00092 .getHeightInPixel());
00093 }
00094
00095 boolean isOccupied = occupied[xGridIndex][yGridIndex];
00096
00097 occupied[xGridIndex][yGridIndex] = true;
00098
00099 return isOccupied;
00100 }
00101
00108 public void setLineVisible(boolean visible) {
00109 isLineVisible = visible;
00110 }
00111 }