Example #1
0
  /**
   * Bit of a complex method. It simply tries to leave the data with two axes selected by finding
   * the most likely two dimensions that should be plot axes.
   *
   * @param firstAxis
   * @param secondAxis
   */
  public void setTwoAxesOnly(AxisType firstAxis, AxisType secondAxis) {
    boolean foundFirst = false, foundSecond = false;
    for (DimsData dd : iterable()) {
      if (dd.getPlotAxis() == firstAxis) foundFirst = true;
      if (dd.getPlotAxis() == secondAxis) foundSecond = true;
    }

    if (foundFirst && foundSecond) {
      for (DimsData dd : iterable()) {
        if (dd.getPlotAxis() == firstAxis) continue;
        if (dd.getPlotAxis() == secondAxis) continue;
        if (dd.getPlotAxis() == AxisType.RANGE) continue;
        dd.setPlotAxis(AxisType.SLICE);
      }
      return;
    } else { // We have to decide which of the others is first and second

      if (!foundFirst) foundFirst = processAxis(firstAxis, secondAxis);
      if (!foundSecond) foundSecond = processAxis(secondAxis, firstAxis);

      for (DimsData dd : iterable()) {
        if (dd.getPlotAxis() == firstAxis) continue;
        if (dd.getPlotAxis() == secondAxis) continue;
        if (dd.getPlotAxis() == AxisType.RANGE) continue;
        dd.setPlotAxis(AxisType.SLICE);
      }
      return;
    }
  }
Example #2
0
 public int getRangeCount() {
   int count = 0;
   for (DimsData dd : dimsData) {
     if (dd.getPlotAxis() == AxisType.RANGE) count++;
   }
   return count;
 }
Example #3
0
  /**
   * Probably not best algorithm but we are dealing with very small arrays here. This is simply
   * trying to ensure that only one dimension is selected as an axis because the plot has changed.
   *
   * @param iaxisToFind
   */
  public void setSingleAxisOnly(AxisType iaxisToFind, AxisType iaxisValue) {
    DimsData found = null;
    for (DimsData dd : iterable()) {
      if (dd.getPlotAxis() == iaxisToFind) {
        dd.setPlotAxis(iaxisValue);
        found = dd;
      }
    }

    if (found != null) {
      for (DimsData dd : iterable()) {
        if (dd == found) continue;
        dd.setPlotAxis(AxisType.SLICE);
      }
      return;
    } else { // We have to decide which of the others is x

      for (DimsData dd : iterable()) {
        if (!dd.getPlotAxis().hasValue()) {
          dd.setPlotAxis(iaxisValue);
          found = dd;
        }
      }
      for (DimsData dd : iterable()) {
        if (dd == found) continue;
        dd.setPlotAxis(AxisType.SLICE);
      }
    }
  }
Example #4
0
 public boolean isXFirst() {
   for (DimsData dd : iterable()) {
     if (dd.getPlotAxis().hasValue()) continue;
     return dd.getPlotAxis() == AxisType.X;
   }
   return false;
 }
Example #5
0
 public int getAxisCount() {
   if (dimsData == null) return -1;
   int count = 0;
   for (DimsData dd : dimsData) {
     if (!dd.getPlotAxis().hasValue()) count++;
   }
   return count;
 }
Example #6
0
 public void add(DimsData dimension) {
   if (dimsData == null) dimsData = new ArrayList<DimsData>(3);
   if (dimsData.size() > dimension.getDimension() && dimension.getDimension() > -1) {
     dimsData.set(dimension.getDimension(), dimension);
   } else {
     dimsData.add(dimension);
   }
 }
Example #7
0
 public DimsDataList clone() {
   final DimsDataList clone = new DimsDataList();
   for (DimsData dd : iterable()) {
     DimsData dnew = dd.clone();
     clone.add(dnew);
   }
   clone.expression = expression;
   return clone;
 }
Example #8
0
  public void reverseImage() {
    for (DimsData dd : iterable()) {
      if (dd.getPlotAxis() == AxisType.X) {
        dd.setPlotAxis(AxisType.Y);
        continue;
      }

      if (dd.getPlotAxis() == AxisType.Y) {
        dd.setPlotAxis(AxisType.X);
        continue;
      }
    }
  }
Example #9
0
  public Slice[] toSliceArray(int[] dataShape) {

    final Slice[] ret = new Slice[size()];
    for (int i = 0; i < size(); i++) {
      DimsData dd = getDimsData(i);
      if (dd.isSlice()) {
        ret[i] = new Slice(dd.getSlice(), dd.getSlice() + 1);
      } else {
        ret[i] = new Slice(dataShape[dd.getDimension()]);
      }
    }
    return ret;
  }
Example #10
0
  public String toString(int[] shape) {

    final StringBuilder buf = new StringBuilder();
    buf.append("[ ");

    int index = 0;
    for (DimsData d : dimsData) {

      final int upper = shape != null ? shape[index] : -1;
      buf.append(d.getUserString(upper));
      if (d != dimsData.get(dimsData.size() - 1)) buf.append(",  ");
      ++index;
    }
    buf.append(" ]");
    return buf.toString();
  }
Example #11
0
  /**
   * Set the current DimsDataList to what is defined in the pass in map.
   *
   * @param map
   * @param shape
   */
  public void fromMap(Map<Integer, String> map, int[] shape) {

    clear();

    for (int i = 0; i < shape.length; i++) {
      add(new DimsData(i));
    }

    if (map.isEmpty()) { // Make one up
      getDimsData(0).setSliceRange("all");
      if (size() == 2) {
        getDimsData(1).setPlotAxis(AxisType.X);

      } else if (size() > 2) {
        getDimsData(1).setPlotAxis(AxisType.Y);
        getDimsData(2).setPlotAxis(AxisType.X);
        for (int i = 3; i < size(); i++) {
          getDimsData(i).setSlice(0);
        }
      }

    } else { // Init one from map saved

      int dim = 0;

      for (DimsData dd : iterable()) {
        String value = map.get(dd.getDimension());
        if (value == null) value = map.get(String.valueOf(dd.getDimension()));
        if (value != null) {
          if ("all".equals(value)) {
            dd.setPlotAxis(AxisType.RANGE);
            continue;
          }

          AxisType at = AxisType.forLabel(value);
          if (at != null) {
            dd.setPlotAxis(at);
            continue;
          }

          try {
            dd.setSlice(Integer.parseInt(value));
          } catch (Exception ne) {
            dd.setSliceRange(value);
          }
        } else {
          AxisType type = AxisType.forAxis(dim);
          dd.setPlotAxis(type);
          ++dim;
        }
      }
    }
  }
Example #12
0
  public void removeLargeStacks(ISliceSystem slicingSystem, int maxStack) {

    for (DimsData dd : getDimsData()) {
      if (dd.getPlotAxis().isStack(slicingSystem)) {
        if (dd.getSliceRange(true) == null
            || "".equals(dd.getSliceRange(true))
            || "all".equals(dd.getSliceRange(true))) {
          final ILazyDataset lz = slicingSystem.getData().getLazySet();
          if (lz != null) {
            final int size = lz.getShape()[dd.getDimension()];
            if (size >= maxStack) { // We set a default slice
              dd.setSliceRange("0:25");
            }
          }
        }
      }
    }
  }
Example #13
0
  private final boolean processAxis(AxisType axis, AxisType... ignoredAxes) {

    final List<Object> ignored = asList(ignoredAxes);
    for (DimsData dd : iterable()) {
      if (!dd.getPlotAxis().hasValue() && !ignored.contains(dd.getPlotAxis())) {
        dd.setPlotAxis(axis);
        return true;
      }
    }

    for (DimsData dd : iterable()) {
      if (!ignored.contains(dd.getPlotAxis())) {
        dd.setPlotAxis(axis);
        return true;
      }
    }

    return false;
  }
Example #14
0
 /**
  * Export to Map from DimsDataList
  *
  * @return
  */
 public Map<Integer, String> toMap() {
   final Map<Integer, String> ret = new HashMap<Integer, String>(size());
   for (DimsData dd : iterable()) {
     if (dd.isSlice()) {
       ret.put(dd.getDimension(), String.valueOf(dd.getSlice()));
     } else if (dd.isTextRange()) {
       ret.put(dd.getDimension(), dd.getSliceRange() != null ? dd.getSliceRange() : "all");
     } else if (dd.getPlotAxis() != null) {
       ret.put(dd.getDimension(), dd.getPlotAxis().getName());
     }
   }
   return ret;
 }
Example #15
0
 /** Sets any axes there are to the axis passed in */
 public void normalise(AxisType axis) {
   for (DimsData dd : iterable()) {
     if (!dd.getPlotAxis().hasValue()) dd.setPlotAxis(axis);
   }
 }
Example #16
0
 public boolean isAdvanced() {
   for (DimsData dd : iterable()) {
     if (dd.getPlotAxis().isAdvanced()) return true;
   }
   return false;
 }
Example #17
0
 public boolean isRangeDefined() {
   for (DimsData data : iterable()) {
     if (data.getSliceRange() != null) return true;
   }
   return false;
 }