/** * Updates tick label for date axis. * * @param length the length of axis */ private void updateTickLabelForDateAxis(int length) { double min = axis.getRange().lower; double max = axis.getRange().upper; double gridStepHint = Math.abs(max - min) / length * axis.getTick().getTickMarkStepHint(); timeUnit = getTimeUnit(gridStepHint); if (timeUnit == Calendar.MILLISECOND || timeUnit == Calendar.SECOND || timeUnit == Calendar.MINUTE || timeUnit == Calendar.HOUR_OF_DAY || timeUnit == Calendar.DATE) { Integer[] steps = possibleTickSteps.get(timeUnit); for (int i = 0; i < steps.length - 1; i++) { if (gridStepHint < (getPeriodInMillis(timeUnit, steps[i]) + getPeriodInMillis(timeUnit, steps[i + 1])) / 2d) { BigDecimal gridStep = new BigDecimal(Long.valueOf(getPeriodInMillis(timeUnit, steps[i])).toString()); updateTickLabelForLinearScale(length, gridStep); break; } } } else if (timeUnit == Calendar.MONTH || timeUnit == Calendar.YEAR) { updateTickLabelForMonthOrYear(length, gridStepHint, timeUnit); } }
/** * Return the axis values for the given pixel location on this graph. * * @param x The x pixel location on the graph. * @param y The y pixel location on the graph. * @return the x and y values for the given pixel location. */ public double[] getValueAt(int x, int y) { Insets insets = getInsets(); double v[] = new double[2]; v[0] = xAxis != null ? xAxis.getValue(x - insets.left) : 0.; v[1] = yAxis != null ? yAxis.getValue(getHeight() - y - insets.bottom) : 0.; return v; }
/** * Sets the bins to the x and y axes and creates the buffer of the histogram * * @param bx number of bins on the x axis * @param xmin the minimum value on the x axis * @param xmax the maximum value on the x axis * @param by number of bins on the y axis * @param ymin the minimum value on the y axis * @param ymax the maximum value on the y axis */ public final void set(int bx, double xmin, double xmax, int by, double ymin, double ymax) { xAxis.set(bx, xmin, xmax); yAxis.set(by, ymin, ymax); offset = new MultiIndex(bx, by); int buff = offset.getArraySize(); hBuffer = new double[buff]; }
@Override public Axis createXAxis() { Axis newAxis = new Axis("X-Axis", false); newAxis.setOrientation(Orientation.HORIZONTAL); newAxis.setTickLableSide(LabelSide.Primary); return newAxis; }
/** * Returns the state indicating if there is a space to draw tick label. * * @param previousPosition the previously drawn tick label position. * @param tickLabelPosition the tick label position. * @param tickLabel the tick label text * @return true if there is a space to draw tick label */ private boolean hasSpaceToDraw(int previousPosition, int tickLabelPosition, String tickLabel) { Point p = Util.getExtentInGC(axis.getTick().getFont(), tickLabel); int interval = tickLabelPosition - previousPosition; int textLength = axis.isHorizontalAxis() ? p.x : p.y; return interval > textLength; }
public H2D() { offset = new MultiIndex(xAxis.getNBins(), yAxis.getNBins()); hBuffer = new double[offset.getArraySize()]; this.attr.getProperties().setProperty("title", ""); this.attr.getProperties().setProperty("xtitle", ""); this.attr.getProperties().setProperty("ytitle", ""); }
/** Calculate the rectangle occupied by the data */ protected Rectangle getDataRectangle(Graphics g, Rectangle r) { Axis a; int waxis; int x = r.x; int y = r.y; int width = r.width; int height = r.height; for (int i = 0; i < axis.size(); i++) { a = ((Axis) axis.elementAt(i)); waxis = a.getAxisWidth(g); switch (a.getAxisPos()) { case Axis.LEFT: x += waxis; width -= waxis; break; case Axis.RIGHT: width -= waxis; break; case Axis.TOP: y += waxis; height -= waxis; break; case Axis.BOTTOM: height -= waxis; break; } } return new Rectangle(x, y, width, height); }
public String getDomainCode() { if (xAxis.getDomain() != null) domainCode = "x.domain(" + xAxis.getDomain() + ");\n"; else domainCode = "x.domain(d3.extent(data, function(d) { return d.x; }));\n"; if (yAxis.getDomain() != null) domainCode += "y.domain(" + yAxis.getDomain() + ");\n"; else domainCode += "y.domain(d3.extent(data, function(d) { return d.y; }));\n"; return domainCode; }
/** Return a list of active dimensions on the slicer */ public static Set getActiveSlicerHierarchies(OlapModel model) throws OlapException { Set active = new HashSet(); Axis slicer = model.getResult().getSlicer(); Hierarchy[] hiers = slicer.getHierarchies(); for (int j = 0; j < hiers.length; j++) active.add(hiers[j]); return active; }
/** * Finds which bin has that value. * * @param x The x value to search for * @param y The y value to search for * @return The bin, in array indexing format, which holds that x-y value */ public int findBin(double x, double y) { int bx = xAxis.getBin(x); int by = yAxis.getBin(y); if (this.isValidBins(bx, by)) { return (offset.getArrayIndex(bx, by)); } return -1; }
@Override public Axis createYAxis() { Axis newAxis = new Axis("Y-Axis", true); newAxis.setOrientation(Orientation.VERTICAL); newAxis.setTickLableSide(LabelSide.Primary); newAxis.setAutoScaleThreshold(0.1); return newAxis; }
/** * Detach a previously attached Axis. * * @param the Axis to dettach. */ public void detachAxis(Axis a) { if (a != null) { a.detachAll(); a.g2d = null; axis.removeElement(a); } }
@Override public String toString() { return new StringBuffer() .append("horizontal=") .append(horizontal.toString()) .append("vertical=") .append(vertical.toString()) .toString(); }
/** * Creates an error buffer with each element being 0.0 * * @return a double 2D array with a size of xAxis * yAxis with each element being 0.0 */ public double[][] getErrorBuffer() { double[][] buff = new double[xAxis.getNBins()][yAxis.getNBins()]; for (int xloop = 0; xloop < xAxis.getNBins(); xloop++) { for (int yloop = 0; yloop < yAxis.getNBins(); yloop++) { buff[xloop][yloop] = 0.0; } } return buff; }
/** * Generates a 2D array with the content in the histogram * * @return a 2D array with each bin in its array index */ public double[][] getContentBuffer() { double[][] buff = new double[xAxis.getNBins()][yAxis.getNBins()]; for (int xloop = 0; xloop < xAxis.getNBins(); xloop++) { for (int yloop = 0; yloop < yAxis.getNBins(); yloop++) { buff[xloop][yloop] = this.getBinContent(xloop, yloop); } } return buff; }
/** * Check the value of an axis, by name * * @param name * @return The value of the axis form -1 to 1 */ public static float checkAxis(String name) { if (axes.get(name) != null) { for (Axis a : axes.get(name)) { if (Math.abs(a.check()) > 0.2) return a.check(); } } return 0; }
/** * メジャーを求める。 メジャーを持たない場合は、nullを戻す。 * * @return メジャーオブジェクト */ public Measure getMeasure() { Iterator<Axis> it = this.axisList.iterator(); while (it.hasNext()) { Axis axis = it.next(); if (axis.isMeasure()) { return (Measure) axis; } } return null; }
/** * Returns the nth point in this graph (coordinates measured in pixels with respect to the canvas * provided). * * @throws IndexOutOfBoundsException if the graph does not have an nth point. */ public Point getPoint(Component canvas, int n) { // subtract 1 so that everything actually fits *within* the canvas int width = canvas.getSize().width - 1; int height = canvas.getSize().height - 1; int x = xAxis.rescaleDataValue(this.getXValue(n), 0, width); int y = yAxis.rescaleDataValue(this.getYValue(n), height, 0); return new Point(x, y); }
/** * Checks if the design is inside the filters for a given Axis. * * @param axis the axis * @return true, if is inside filters */ private boolean isInsideBounds(Axis axis) { double lower = axis.getLowerFilter().getValue(); double upper = axis.getUpperFilter().getValue(); double value = this.getDoubleValue(axis.getParameter()); if (lower <= value && value <= upper) { return true; } else { return false; } }
private double[][] ticks(double start, double end) { LinearTickMarkCalculator c = new LinearTickMarkCalculator(); Axis axis = new Axis() { private static final long serialVersionUID = 1L; }; axis.setStart(start); axis.setEnd(end); double[][] data = c.calculateTickMarks(axis); return data; }
// returns the number of points in this graph (equal to the // *maximum* length of an axis, or zero if at least one axis is // completely empty) private int getNumberOfPoints() { int xSize = xAxis.getData().length; int ySize = yAxis.getData().length; if (xSize == 0 || ySize == 0) { return 0; } else if (xSize > ySize) { return xSize; } else { return ySize; } }
/** * Creates a 1-D Histogram slice of the specified y Bin * * @param xBin the bin on the y axis to create a slice of * @return a slice of the x bins on the specified y bin as a 1-D Histogram */ public H1D sliceX(int xBin) { String name = "Slice of " + xBin + " X Bin"; double xMin = yAxis.min(); double xMax = yAxis.max(); int xNum = yAxis.getNBins(); H1D sliceX = new H1D(name, name, xNum, xMin, xMax); for (int x = 0; x < xNum; x++) { sliceX.setBinContent(x, this.getBinContent(xBin, x)); } return sliceX; }
/** * 時間軸を持つ場合true、持たない場合falseを戻す。 * * @return 時間軸を持つか */ public boolean investigateTimeDimension() { Iterator<Axis> it = this.axisList.iterator(); while (it.hasNext()) { Axis axis = it.next(); if (!axis.isMeasure()) { Dimension dim = (Dimension) axis; if (dim.isTimeDimension()) { return true; } } } return false; }
/** * 与えられた軸を持つ場合true、持たない場合falseを戻す。 * * @param oAxis 軸をあらわすオブジェクト * @return 軸を持つかどうか */ public boolean hasThisAxis(Axis oAxis) { if (oAxis == null) { return false; } Iterator<Axis> it = this.getAxisList().iterator(); while (it.hasNext()) { Axis axis = it.next(); if (axis.getId().equals(oAxis.getId())) { return true; } } return false; }
/* * @see PaintListener#paintControl(PaintEvent) */ public void paintControl(PaintEvent e) { if (!axis.getTick().isVisible()) { return; } e.gc.setBackground(chart.getBackground()); e.gc.setForeground(getForeground()); if (axis.isHorizontalAxis()) { drawXTick(e.gc); } else { drawYTick(e.gc); } }
/** * Creates a 1-D Histogram slice of the specified x Bin * * @param yBin the bin on the x axis to create a slice of * @return a slice of the y bins on the specified x bin as a 1-D Histogram */ public H1D sliceY(int yBin) { String name = "Slice of " + yBin + " Y Bin"; double xMin = xAxis.min(); double xMax = xAxis.max(); int xNum = xAxis.getNBins(); H1D sliceY = new H1D(name, name, xNum, xMin, xMax); for (int y = 0; y < xNum; y++) { sliceY.setBinContent(y, this.getBinContent(y, yBin)); } return sliceY; }
public String convertData(int s[]) { dataCode = ""; if (xAxis.getDataLen() != s.length) return ""; // dataCode += "var "+varName+"=["; dataCode += "["; for (int i = 0; i < s.length; i++) { if (xAxis.getDateLen() > -1) dataCode += "{x:parseDate(\"" + xAxis.getData(i) + "\"),y:" + s[i] + "},"; else dataCode += "{x:" + xAxis.getData(i) + ",y:" + s[i] + "},"; } dataCode += "]\n"; return dataCode; }
/** Updates the visibility of tick labels. */ private void updateTickVisibility() { // initialize the array of tick label visibility state tickVisibilities.clear(); for (int i = 0; i < tickLabelPositions.size(); i++) { tickVisibilities.add(Boolean.TRUE); } if (tickLabelPositions.size() == 0 || axis.getTick().getTickLabelAngle() != 0) { return; } // set the tick label visibility int previousPosition = 0; for (int i = 0; i < tickLabelPositions.size(); i++) { // check if there is enough space to draw tick label boolean hasSpaceToDraw = true; if (i != 0) { hasSpaceToDraw = hasSpaceToDraw(previousPosition, tickLabelPositions.get(i), tickLabels.get(i)); } // check if the tick label value is major boolean isMajorTick = true; if (!axis.isValidCategoryAxis()) { if (axis.isLogScaleEnabled()) { isMajorTick = isMajorTick(tickLabelValues.get(i)); } // check if the same tick label is repeated String currentLabel = tickLabels.get(i); try { double value = Double.parseDouble(currentLabel); if (value != tickLabelValues.get(i)) { isMajorTick = false; } } catch (NumberFormatException e) { // label is not decimal value but string } } if (hasSpaceToDraw && isMajorTick) { previousPosition = tickLabelPositions.get(i); } else { tickVisibilities.set(i, Boolean.FALSE); } } }
/** * 与えられた軸のエッジにおけるインデックスを求める。 与えられた軸がエッジにない場合は、-1を戻す。 * * @param axisId 軸ID * @return 軸のエッジにおけるインデックス */ public int getAxisIndexInEdge(String axisId) { if (axisId == null) { return -1; } Iterator<Axis> it = this.getAxisList().iterator(); int i = 0; while (it.hasNext()) { Axis axis = it.next(); if (axis.getId().equals(axisId)) { return i; } i++; } return -1; }
/** * Create and attach an Axis to the graph. The position of the axis is one of Axis.TOP, * Axis.BOTTOM, Axis.LEFT or Axis.RIGHT. * * @param position Position of the axis in the drawing window. */ public Axis createAxis(int position) { Axis a; try { a = new Axis(position); a.g2d = this; axis.addElement(a); } catch (Exception e) { System.out.println("Failed to create Axis"); e.printStackTrace(); return null; } return a; }