/** * 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; } }
public int getRangeCount() { int count = 0; for (DimsData dd : dimsData) { if (dd.getPlotAxis() == AxisType.RANGE) count++; } return count; }
/** * 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); } } }
public boolean isXFirst() { for (DimsData dd : iterable()) { if (dd.getPlotAxis().hasValue()) continue; return dd.getPlotAxis() == AxisType.X; } return false; }
public int getAxisCount() { if (dimsData == null) return -1; int count = 0; for (DimsData dd : dimsData) { if (!dd.getPlotAxis().hasValue()) count++; } return count; }
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); } }
public DimsDataList clone() { final DimsDataList clone = new DimsDataList(); for (DimsData dd : iterable()) { DimsData dnew = dd.clone(); clone.add(dnew); } clone.expression = expression; return clone; }
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; } } }
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; }
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(); }
/** * 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; } } } }
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"); } } } } } }
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; }
/** * 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; }
/** 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); } }
public boolean isAdvanced() { for (DimsData dd : iterable()) { if (dd.getPlotAxis().isAdvanced()) return true; } return false; }
public boolean isRangeDefined() { for (DimsData data : iterable()) { if (data.getSliceRange() != null) return true; } return false; }