public static Element createPath(final Document document, final String fill, final double strokeWidth, final String stroke, final String path, final String... attributes) { checkPositiveValues("strokeWidth", strokeWidth); final Element el = createElement(document, "path", prepend(attributes, "fill", fill, "stroke-width", strokeWidth, "stroke", stroke, "d", path)); return el; }
public static String drawArrow(final ArrowDirection direction, final double x, final double y, final double size) { checkNonNegativeValues("x, y", x, y); checkPositiveValues("size", size); final StringBuffer buf = new StringBuffer(); if (direction == ArrowDirection.LEFT) { buf.append("M ").append(round(x)).append(" ").append(round(y)); // (x, y) buf.append(" L ").append(round(x + size)).append(" ").append(round(y + size)); // (x + size, y + size) buf.append(" L ").append(round(x + size)).append(" ").append(round(y - size)); // (x + size, y - size) } else if (direction == ArrowDirection.RIGHT) { buf.append("M ").append(round(x)).append(" ").append(round(y)); // (x, y) buf.append(" L ").append(round(x - size)).append(" ").append(round(y - size)); // (x - size, y - size) buf.append(" L ").append(round(x - size)).append(" ").append(round(y + size)); // (x - size, y + size) } else { log.error("Unsupported arrow direction: " + direction); } buf.append(" z"); return buf.toString(); }
checkPositiveValues("mixXDist", minXDist); final double xHalf = (x2 - x1) / 2; final double yHalf = (y2 - y1) / 2;
@Test public void checkPositiveValues() { SVGHelper.checkPositiveValues("vars", 1.0, 0.1); try { SVGHelper.checkPositiveValues("vars", 1.0, 0.1, -0.1); fail("Exception expected"); } catch (final IllegalArgumentException ex) { assertEquals("Values should be positive or zero and valid: {vars}=1.0, 0.1, -0.1", ex.getMessage()); } try { SVGHelper.checkPositiveValues("vars", 1.0, 0.1, Double.NaN); fail("Exception expected"); } catch (final IllegalArgumentException ex) { assertEquals("Values should be positive or zero and valid: {vars}=1.0, 0.1, NaN", ex.getMessage()); } try { SVGHelper.checkPositiveValues("vars", 1.0, 0.1, Double.POSITIVE_INFINITY); fail("Exception expected"); } catch (final IllegalArgumentException ex) { assertEquals("Values should be positive or zero and valid: {vars}=1.0, 0.1, Infinity", ex.getMessage()); } try { SVGHelper.checkPositiveValues("vars", Double.NEGATIVE_INFINITY); fail("Exception expected"); } catch (final IllegalArgumentException ex) { assertEquals("Values should be positive or zero and valid: {vars}=-Infinity", ex.getMessage()); } } }
public static Element createRect(final Document document, final double x, final double y, final double width, final double height, final String fill, final String... attributes) { checkPositiveValues("width, height", width, height); checkNonNegativeValues("x, y", x, y); if (log.isDebugEnabled() == true) { log.debug("createRect: x=" + x + ", y=" + y + ", width=" + width + ", height=" + height + ", fill=" + fill + ", attributes=" + StringHelper.listToString(",", StringHelper.listToString(",", attributes))); } final Element el = createElement(document, "rect", prepend(attributes, "x", round(x), "y", round(y), "width", round(width), "height", round(height), "fill", fill)); return el; }