/** * Set the base coordinate space. */ public Axis setBase(Base base) { this.base = base; if (getAxisLabel() != null) { setAxisLabel(getAxisLabel()); } init(); return this; }
/** * Sets the axis to its default initial value. */ private void init() { initOrigin(); setSlice(); initGridLines(); initGridLabels(); }
/** * Returns if the frame visible. */ public boolean isFrameVisible() { return axis[0].isGridVisible(); }
/** * Constructor. */ public Axis(Base base, int index, String label) { this.base = base; this.index = index; setAxisLabel(label); init(); }
canvas.add(new Heatmap(rowLabels, columnLabels, z)); canvas.getAxis(0).setFrameVisible(false); canvas.getAxis(0).setGridVisible(false); canvas.getAxis(0).setRotation(-Math.PI / 2); canvas.getAxis(1).setFrameVisible(false); canvas.getAxis(1).setGridVisible(false); locations[i] = z.length - i - 0.5; canvas.getAxis(1).addLabel(rowLabels, locations); locations[i] = i + 0.5; canvas.getAxis(0).addLabel(columnLabels, locations);
/** * Add a label to the axis at given location. */ public Axis addLabel(String label, double location) { if (labels == null) { labels = new HashMap<>(); } labels.put(label, location); setSlice(); initGridLines(); initGridLabels(); return this; }
canvas.getAxis(0).addLabel(labels, locations); canvas.getAxis(0).setGridVisible(false); canvas.getAxis(0).setRotation(-Math.PI / 2);
/** * Remove a label from the axis. */ public Axis removeLabel(String label) { if (labels == null) { throw new IllegalStateException(); } labels.remove(label); setSlice(); initGridLabels(); return this; }
/** * Get axis label. */ public String[] getAxisLabel() { String[] array = new String[axis.length]; for (int i = 0; i < array.length; i++) { array[i] = axis[i].getAxisLabel(); } return array; }
/** * Create a plot canvas with the bar plot of given data. * @param id the id of the plot. * @param data a vector of which values will determine the heights of bars. * @param labels the labels for each bar. */ public static PlotCanvas plot(String id, double[] data, String[] labels) { if (data.length != labels.length) { throw new IllegalArgumentException("Data size and label size don't match."); } double[] lowerBound = {0, Math.min(data)}; double[] upperBound = {data.length, Math.max(data)}; PlotCanvas canvas = new PlotCanvas(lowerBound, upperBound); BarPlot plot = new BarPlot(labels, data); plot.setID(id); canvas.add(plot); double[] locations = new double[labels.length]; for (int i = 0; i < labels.length; i++) { locations[i] = i + 0.5; } canvas.getAxis(0).addLabel(labels, locations); canvas.getAxis(0).setGridVisible(false); return canvas; }
@Override public void mouseWheelMoved(MouseWheelEvent e) { if (e.getWheelRotation() == 0) { return; } for (int i = 0; i < base.dimension; i++) { int s = baseGrid.getAxis(i).getLinearSlices(); double r = e.getWheelRotation() > 0 ? 1.0 / s : -1.0 / s; if (r > -0.5) { double d = (base.upperBound[i] - base.lowerBound[i]) * r; base.lowerBound[i] -= d; base.upperBound[i] += d; } } for (int i = 0; i < base.dimension; i++) { base.setPrecisionUnit(i); } base.initBaseCoord(); graphics.projection.reset(); baseGrid.setBase(base); repaint(); e.consume(); }
/** * Constructor. */ public BaseGrid(Base base) { this.base = base; axis = new Axis[base.getDimension()]; for (int i = 0; i < base.getDimension(); i++) { axis[i] = new Axis(base, i); } }
/** * Returns if labels and tickmarks are visible. */ public boolean isLabelVisible(int i) { return axis[i].isLabelVisible(); }
plot.setLegend('@'); canvas.add(plot); canvas.getAxis(0).addLabel(labels, x);
canvas.add(new Heatmap(rowLabels, columnLabels, z, palette)); canvas.getAxis(0).setFrameVisible(false); canvas.getAxis(0).setGridVisible(false); canvas.getAxis(0).setRotation(-Math.PI / 2); canvas.getAxis(1).setFrameVisible(false); canvas.getAxis(1).setGridVisible(false); locations[i] = z.length - i - 0.5; canvas.getAxis(1).addLabel(rowLabels, locations); locations[i] = i + 0.5; canvas.getAxis(0).addLabel(columnLabels, locations);
/** * Add a label to the axis at given location. */ public Axis addLabel(String[] label, double[] location) { if (label.length != location.length) { throw new IllegalArgumentException("Label size and location size don't match."); } if (labels == null) { labels = new HashMap<>(); } for (int i = 0; i < label.length; i++) { labels.put(label[i], location[i]); } setSlice(); initGridLines(); initGridLabels(); return this; }
/** * Get axis label. */ public String getAxisLabel(int i) { return axis[i].getAxisLabel(); }
double x = mouseClickX - e.getX(); if (Math.abs(x) > 20) { int s = baseGrid.getAxis(0).getLinearSlices(); x = x > 0 ? 1.0 / s : -1.0 / s; x *= (backupBase.upperBound[0] - backupBase.lowerBound[0]); int s = baseGrid.getAxis(1).getLinearSlices(); y = y > 0 ? -1.0 / s : 1.0 / s; y *= (backupBase.upperBound[1] - backupBase.lowerBound[1]);
/** * Constructor. */ public BaseGrid(Base base, String... axisLabels) { if (axisLabels.length != base.getDimension()) { throw new IllegalArgumentException("Axis label size don't match base dimension."); } this.base = base; axis = new Axis[base.getDimension()]; for (int i = 0; i < base.getDimension(); i++) { axis[i] = new Axis(base, i, axisLabels[i]); } }
/** * Returns the labels/legends of axes. */ public String[] getAxisLabels() { String[] labels = new String[base.dimension]; for (int i = 0; i < base.dimension; i++) { labels[i] = baseGrid.getAxis(i).getAxisLabel(); } return labels; }