protected void selectHorizontalAutoTickUnit( Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) { double tickLabelWidth = estimateMaximumTickLabelWidth(g2, getTickUnit()); TickUnitSource tickUnits = getStandardTickUnits(); TickUnit unit1 = tickUnits.getCeilingTickUnit(getTickUnit()); NumberTickUnit unit2 = (NumberTickUnit) tickUnits.getCeilingTickUnit( (tickLabelWidth / lengthToJava2D(unit1.getSize(), dataArea, edge)) * unit1.getSize()); if (estimateMaximumTickLabelWidth(g2, unit2) > lengthToJava2D(unit2.getSize(), dataArea, edge)) { unit2 = (NumberTickUnit) tickUnits.getLargerTickUnit(unit2); } setTickUnit(unit2, DEFAULT_VERTICAL_TICK_LABELS, DEFAULT_VERTICAL_TICK_LABELS); }
protected void selectVerticalAutoTickUnit( Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) { double tickLabelHeight = estimateMaximumTickLabelHeight(g2); TickUnitSource tickUnits = getStandardTickUnits(); TickUnit unit1 = tickUnits.getCeilingTickUnit(getTickUnit()); double unitHeight = lengthToJava2D(unit1.getSize(), dataArea, edge); double guess = unit1.getSize(); if (unitHeight > 0.0d) { guess = (tickLabelHeight / unitHeight) * unit1.getSize(); } NumberTickUnit unit2 = (NumberTickUnit) tickUnits.getCeilingTickUnit(guess); if (estimateMaximumTickLabelHeight(g2) > lengthToJava2D(unit2.getSize(), dataArea, edge)) { unit2 = (NumberTickUnit) tickUnits.getLargerTickUnit(unit2); } setTickUnit(unit2, DEFAULT_VERTICAL_TICK_LABELS, DEFAULT_VERTICAL_TICK_LABELS); }
protected double estimateMaximumTickLabelWidth(Graphics2D g2, TickUnit unit) { RectangleInsets tickLabelInsets = getTickLabelInsets(); double result = tickLabelInsets.getLeft() + tickLabelInsets.getRight(); if (isVerticalTickLabels()) { FontRenderContext frc = g2.getFontRenderContext(); return result + ((double) getTickLabelFont().getLineMetrics("0", frc).getHeight()); } String lowerStr; String upperStr; FontMetrics fm = g2.getFontMetrics(getTickLabelFont()); Range range = getRange(); double lower = range.getLowerBound(); double upper = range.getUpperBound(); NumberFormat formatter = getNumberFormatOverride(); if (formatter != null) { lowerStr = formatter.format(lower); upperStr = formatter.format(upper); } else { lowerStr = unit.valueToString(lower); upperStr = unit.valueToString(upper); } return result + Math.max((double) fm.stringWidth(lowerStr), (double) fm.stringWidth(upperStr)); }
/** * Returns a tick unit that is larger than the supplied unit. * * @param unit the unit. * @return A tick unit that is larger than the supplied unit. */ public TickUnit getLargerTickUnit(TickUnit unit) { double x = unit.getSize(); double log = Math.log(x) / LOG_10_VALUE; double higher = Math.ceil(log); return new NumberTickUnit(Math.pow(10, higher), new DecimalFormat("0.0E0")); }
protected List refreshTicksVertical(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) { List result = new ArrayList(); result.clear(); g2.setFont(getTickLabelFont()); if (isAutoTickUnitSelection()) { selectAutoTickUnit(g2, dataArea, edge); } TickUnit tu = getTickUnit(); double size = tu.getSize(); int count = calculateVisibleTickCount(); double lowestTickValue = calculateLowestVisibleTickValue(); if (count <= 500) { int minorTick; double minorTickValue; int minorTickSpaces = getMinorTickCount(); if (minorTickSpaces <= 0) { minorTickSpaces = tu.getMinorTickCount(); } for (minorTick = 1; minorTick < minorTickSpaces; minorTick++) { minorTickValue = lowestTickValue - ((((double) minorTick) * size) / ((double) minorTickSpaces)); if (getRange().contains(minorTickValue)) { result.add( new NumberTick( TickType.MINOR, minorTickValue, "", TextAnchor.TOP_CENTER, TextAnchor.CENTER, 0.0d)); } } for (int i = 0; i < count; i++) { String tickLabel; TextAnchor anchor; TextAnchor rotationAnchor; double currentTickValue = lowestTickValue + (((double) i) * size); NumberFormat formatter = getNumberFormatOverride(); if (formatter != null) { tickLabel = formatter.format(currentTickValue); } else { tickLabel = getTickUnit().valueToString(currentTickValue); } double angle = 0.0d; if (isVerticalTickLabels()) { if (edge == RectangleEdge.LEFT) { anchor = TextAnchor.BOTTOM_CENTER; rotationAnchor = TextAnchor.BOTTOM_CENTER; angle = -1.5707963267948966d; } else { anchor = TextAnchor.BOTTOM_CENTER; rotationAnchor = TextAnchor.BOTTOM_CENTER; angle = 1.5707963267948966d; } } else if (edge == RectangleEdge.LEFT) { anchor = TextAnchor.CENTER_RIGHT; rotationAnchor = TextAnchor.CENTER_RIGHT; } else { anchor = TextAnchor.CENTER_LEFT; rotationAnchor = TextAnchor.CENTER_LEFT; } result.add( new NumberTick(new Double(currentTickValue), tickLabel, anchor, rotationAnchor, angle)); double nextTickValue = lowestTickValue + (((double) (i + 1)) * size); for (minorTick = 1; minorTick < minorTickSpaces; minorTick++) { double d = (double) minorTickSpaces; minorTickValue = currentTickValue + (((nextTickValue - currentTickValue) * ((double) minorTick)) / r0); if (getRange().contains(minorTickValue)) { result.add( new NumberTick( TickType.MINOR, minorTickValue, "", TextAnchor.TOP_CENTER, TextAnchor.CENTER, 0.0d)); } } } } return result; }