private void validate(Graphics2D g2d, int x, int y, int width, int height) { fontMetrics = g2d.getFontMetrics(); xTickTexts = xAxis.createTickmarkTexts(); yTickTexts = yAxis.createTickmarkTexts(); // define y-Axis _values final int fontAscent = fontMetrics.getAscent(); maxYTickTextWidth = 0; for (String yTickText : yTickTexts) { int sw = fontMetrics.stringWidth(yTickText); maxYTickTextWidth = Math.max(maxYTickTextWidth, sw); } final int widthMaxX = fontMetrics.stringWidth(xTickTexts[xTickTexts.length - 1]); int x1 = textGap + fontAscent + textGap + maxYTickTextWidth + textGap + majorTickLength; int y1 = textGap + fontAscent / 2; int x2 = x + width - (textGap + widthMaxX / 2); int y2 = y + height - (textGap + fontAscent + textGap + fontAscent + textGap + majorTickLength); final int w = x2 - x1 + 1; final int h = y2 - y1 + 1; graphArea = new Rectangle(x1, y1, w, h); transform = null; if (w > 0 && h > 0) { transform = new RectTransform(new Range(xAxis.getMinValue(), xAxis.getMaxValue()), new Range(yAxis.getMinValue(), yAxis.getMaxValue()), new Range(graphArea.x, graphArea.x + graphArea.width), new Range(graphArea.y + graphArea.height, graphArea.y)); } setValid(w > 0 && h > 0); }
public void testTransform() { Diagram.RectTransform rectTransform = new Diagram.RectTransform(new Range(0, 10), new Range(-1, +1), new Range(100, 200), new Range(100, 0)); Point2D a, b; a = new Point2D.Double(5, 0); b = rectTransform.transformA2B(a, null); assertEquals(new Point2D.Double(150.0, 50.0), b); assertEquals(a, rectTransform.transformB2A(b, null)); a = new Point2D.Double(7.5, -0.25); b = rectTransform.transformA2B(a, null); assertEquals(new Point2D.Double(175.0, 62.5), b); assertEquals(a, rectTransform.transformB2A(b, null)); }