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; }
public static Element createLine(final Document document, final double x1, final double y1, final double x2, final double y2, final SVGColor strokeColor, final String... attributes) { return createLine(document, x1, y1, x2, y2, prepend(attributes, "stroke", strokeColor.getName())); }
public static Element createRect(final Document document, final double x, final double y, final double width, final double height, final SVGColor fillColor, final SVGColor strokeColor, final String... attributes) { return createRect(document, x, y, width, height, fillColor.getName(), prepend(attributes, "stroke", strokeColor.getName())); }
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 Element createUse(final Document document, final String id, final double x, final double y, final String... attributes) { checkNonNegativeValues("x, y", x, y); final Element el = createElement(document, "use", prepend(attributes, "xlink:href", id, "x", round(x), "y", round(y))); return el; }
public static Element createElement(final Document document, final String tag, final SVGColor fillColor, final String... attributes) { return createElement(document, tag, prepend(attributes, "fill", fillColor.getName())); }
final Document doc = SVGHelper.createDocument(style.getWidth(), height); final Element root = doc.getDocumentElement(); g1 = SVGHelper.createElement(doc, "g", "font-size", "9pt"); root.appendChild(g1); g1.appendChild(SVGHelper.createText(doc, 0, 0, "TO SMALL")); return doc; e = SVGHelper.createElement(doc, "defs"); root.appendChild(e); e.appendChild(SVGHelper.createElement(doc, "path", SVGColor.DARK_RED, "d", "M 0 0 L " + GanttChartStyle.SUMMARY_ARROW_SIZE + " 0 L 0 " + GanttChartStyle.SUMMARY_ARROW_SIZE + " z", "id", "redLeftArrow")); e.appendChild(SVGHelper.createElement(doc, "path", SVGColor.DARK_RED, "d", "M 0 0 L " + GanttChartStyle.SUMMARY_ARROW_SIZE + " 0 L " + GanttChartStyle.SUMMARY_ARROW_SIZE + " z", "id", "redRightArrow")); e.appendChild(SVGHelper.createElement(doc, "path", SVGColor.BLACK, "d", "M -5 0 L 0 5 L 5 0 L 0 -5 z", "id", "diamond")); e = SVGHelper.createElement(doc, "defs"); root.appendChild(e); g1 = SVGHelper.createElement(doc, "g", "transform", "translate(5,20)"); root.appendChild(g1); if (fontFamily != null) { g2 = SVGHelper.createElement(doc, "g", "font-family", fontFamily, "font-size", "9pt");
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(); }
g1.appendChild(SVGHelper.createText(doc, diagramWidth / 2, 0, label)); final Element ticks = SVGHelper.createElement(doc, "g", "stroke", SVGColor.BLACK.getName(), "stroke-width", "1", "transform", "translate(0,10)"); g1.appendChild(ticks); final DayHolder day = new DayHolder(fromDate); label = String.valueOf(quarterCounter); g1.appendChild(SVGHelper.createText(doc, getXValue(day.getDate()), 22, label, "text-anchor", "middle")); ticks.appendChild(SVGHelper.createLine(doc, getXValue(day.getDate()), 12, getXValue(day.getDate()), 20)); } else if (drawTick == true) { ticks.appendChild(SVGHelper.createLine(doc, getXValue(day.getDate()), 15, getXValue(day.getDate()), 20)); } else if (drawTick2 == true) { ticks.appendChild(SVGHelper.createLine(doc, getXValue(day.getDate()), 18, getXValue(day.getDate()), 20)); grid.appendChild(SVGHelper.createLine(doc, getXValue(day.getDate()), 0, getXValue(day.getDate()), xGridHeight)); ticks.appendChild(SVGHelper.createLine(doc, 0, 0, diagramWidth, 0)); ticks.appendChild(SVGHelper.createLine(doc, 0, 0, 0, 20));
diagram.appendChild(SVGHelper.createPath(doc, SVGColor.NONE, 1, SVGColor.BLACK, SVGHelper.drawHorizontalConnectionLine(type, depX1, depY1, depX2, depY2, style.getArrowMinXDist() + dist))); if (type.isIn(GanttRelationType.FINISH_START, GanttRelationType.START_START) == true) { diagram.appendChild(SVGHelper.createPath(doc, SVGColor.BLACK, 1, SVGColor.BLACK, SVGHelper.drawArrow(ArrowDirection.RIGHT, depX2 - dist, depY2, style.getArrowSize()))); } else { diagram.appendChild(SVGHelper.createPath(doc, SVGColor.BLACK, 1, SVGColor.BLACK, SVGHelper.drawArrow(ArrowDirection.LEFT, depX2 + dist / 2, depY2, style.getArrowSize())));
@Test public void prepend() { assertArrayEquals(new String[] {}, SVGHelper.prepend(new String[] {}, (Object[]) null)); assertArrayEquals(new String[] { "1" }, SVGHelper.prepend(new String[] {}, new Object[] { 1 })); assertArrayEquals(new String[] { "1", "zwei" }, SVGHelper.prepend(new String[] {}, new Object[] { 1, "zwei" })); assertArrayEquals(new String[] { "3" }, SVGHelper.prepend(new String[] { "3" }, new Object[] {})); assertArrayEquals(new String[] { "1", "3" }, SVGHelper.prepend(new String[] { "3" }, new Object[] { 1 })); assertArrayEquals(new String[] { "1", "zwei", "3" }, SVGHelper.prepend(new String[] { "3" }, new Object[] { 1, "zwei" })); assertArrayEquals(new String[] { "1", "zwei", "3", "vier" }, SVGHelper.prepend(new String[] { "3", "vier" }, new Object[] { 1, "zwei" })); }
return; diagram.appendChild(SVGHelper.createRect(doc, x1, taskInfo.y + 0.2 * style.getActivityHeight(), width, 0.8 * style.getActivityHeight(), SVGColor.DARK_RED, "stroke", "none")); if (drawLeftArrow == true) { diagram.appendChild(SVGHelper.createUse(doc, "#redLeftArrow", taskInfo.x1, taskInfo.y + style.getActivityHeight())); diagram.appendChild(SVGHelper.createUse(doc, "#redRightArrow", (taskInfo.x2 - GanttChartStyle.SUMMARY_ARROW_SIZE), taskInfo.y + style.getActivityHeight()));
private void drawLabelBar(final Document doc, final Element el, final int row, final Date fromDate, final Date toDate, final GanttChartStyle style) { final Element g = SVGHelper.createElement(doc, "g", "transform", "translate(0," + (row * ROW_HEIGHT) + ")"); el.appendChild(g); final Element grid = SVGHelper.createElement(doc, "g", "stroke", "green", "stroke-width", "1", "stroke-dasharray", "5,5"); g.appendChild(grid); final Element g1 = SVGHelper.createElement(doc, "g", "text-anchor", "middle", "font-family", "Verdana", "font-size", "9pt"); g.appendChild(g1); final GanttChartXLabelBarRenderer renderer = new GanttChartXLabelBarRenderer(fromDate, toDate, style.getWidth(), style); renderer.draw(doc, g1, grid, 10); log.info("GanttChartXLabelBarRenderer: fromToDays=" + renderer.fromToDays + ", labelUnit=" + renderer.labelUnit + ", labelScale=" + renderer.labelScale + ", ticksUnit=" + renderer.ticksUnit + ", ticksScale=" + renderer.ticksScale); }
@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()); } } }
@Test public void test() { final GanttChartStyle style = new GanttChartStyle(); style.setWidth(800); final double height = 1000; final Document doc = SVGHelper.createDocument(style.getWidth(), height); final Element root = doc.getDocumentElement(); int row = -2; drawBothLabelBars(doc, root, row += 2, date(2010, Calendar.JANUARY, 1), date(2010, Calendar.JANUARY, 31), style); drawBothLabelBars(doc, root, row += 2, date(2010, Calendar.JANUARY, 1), date(2010, Calendar.MAY, 31), style); drawBothLabelBars(doc, root, row += 2, date(2010, Calendar.JANUARY, 1), date(2010, Calendar.JULY, 31), style); drawBothLabelBars(doc, root, row += 2, date(2010, Calendar.JANUARY, 1), date(2010, Calendar.OCTOBER, 31), style); drawBothLabelBars(doc, root, row += 2, date(2010, Calendar.JANUARY, 1), date(2010, Calendar.DECEMBER, 31), style); drawBothLabelBars(doc, root, row += 2, date(2010, Calendar.JANUARY, 1), date(2012, Calendar.DECEMBER, 31), style); drawBothLabelBars(doc, root, row += 2, date(2010, Calendar.JANUARY, 1), date(2015, Calendar.DECEMBER, 31), style); drawBothLabelBars(doc, root, row += 2, date(2010, Calendar.JANUARY, 1), date(2018, Calendar.DECEMBER, 31), style); final byte[] ba = BatikImageRenderer.getByteArray(doc, style.getWidth(), ImageFormat.PNG); final File file = WorkFileHelper.getWorkFile("ganttXBarTest.png"); log.info("Writing Gantt test image to work directory: " + file.getAbsolutePath()); try { final FileOutputStream out = new FileOutputStream(file); out.write(ba); out.close(); } catch (final FileNotFoundException ex) { log.error("Exception encountered " + ex, ex); } catch (final IOException ex) { log.error("Exception encountered " + ex, ex); } }
public static Element createRect(final Document document, final double x, final double y, final double width, final double height, final SVGColor fillColor, final String... attributes) { return createRect(document, x, y, width, height, fillColor.getName(), attributes); }
public static Element createPath(final Document document, final SVGColor fillColor, final double strokeWidth, final SVGColor strokeColor, final String path, final String... attributes) { return createPath(document, fillColor.getName(), strokeWidth, strokeColor.getName(), path, attributes); }
@Test public void append() { assertArrayEquals(new String[] {}, SVGHelper.append(new String[] {}, (Object[]) null)); assertArrayEquals(new String[] { "3" }, SVGHelper.append(new String[] {}, new Object[] { 3 })); assertArrayEquals(new String[] { "3", "vier" }, SVGHelper.append(new String[] {}, new Object[] { 3, "vier" })); assertArrayEquals(new String[] { "1" }, SVGHelper.append(new String[] { "1" }, new Object[] {})); assertArrayEquals(new String[] { "1", "3" }, SVGHelper.append(new String[] { "1" }, new Object[] { 3 })); assertArrayEquals(new String[] { "1", "3", "vier" }, SVGHelper.append(new String[] { "1" }, new Object[] { 3, "vier" })); assertArrayEquals(new String[] { "1", "2", "3", "vier" }, SVGHelper.append(new String[] { "1", "2" }, new Object[] { 3, "vier" })); }
private void drawLabel(final GanttTask node, final Document doc, final Element labels) { int indent = 0; GanttTask n = node; while (true) { n = rootNode.findParent(n.getId()); if (n == rootNode || n == null) { break; } if (n.isVisible() == true) { ++indent; } } final ObjectInfo taskInfo = getObjectInfo(node); if (StringUtils.isNotBlank(node.getWorkpackageCode()) == true && style.getWorkPackageLabelWidth() > 0) { labels.appendChild(SVGHelper.createText(doc, 0 + indent * 5, taskInfo.y, node.getWorkpackageCode())); } if (StringUtils.isNotBlank(node.getTitle()) == true) { labels.appendChild(SVGHelper.createText(doc, style.getWorkPackageLabelWidth() + indent * 10, taskInfo.y, node.getTitle())); } }
first = false; } else { grid.appendChild(SVGHelper.createLine(doc, 0, taskInfo.y, getDiagramWidth(), taskInfo.y));