private double getDiagramWidth() { return style.getWidth() - style.getTotalLabelWidth(); }
public GanttChart() { this.style = new GanttChartStyle(); this.settings = new GanttChartSettings(); }
public GanttChartXLabelBarRenderer(final Date fromDate, final Date toDate, final double diagramWidth, final GanttChartStyle style) { this.fromDate = fromDate; this.toDate = toDate; this.diagramWidth = diagramWidth; this.style = style; this.gridScale = style.getXGridScale(); init(); }
final double numberOfMonths = 0.033 * numberOfDays; final double numberOfQuarters = numberOfMonths / 3; if (this.style.getXUnit() == GanttXUnit.AUTO) { if (diagramWidth / numberOfDays > MIN_PIXEL_PER_UNIT) { labelUnit = GanttXUnit.DAY; numberOfUnits = numberOfQuarters; labelScale = style.getXLabelsScale(); ticksScale = style.getXTicksScale(); ticksScale2 = style.getXTicksScale2(); if (labelUnit == GanttXUnit.QUARTER) { if (labelScale < 0) { if (style.isRelativeTimeValues() == true) { if (style.isRelativeTimeValues() == true) { if (style.getXLabel() != null) { label = style.getXLabel(); } else if (style.isRelativeTimeValues() == true) { label = ThreadLocalUserContext.getLocalizedString(labelUnit.getI18nKey()); this.showNonWorkingDays = style.isShowNonWorkingDays(); if (this.showNonWorkingDays == true) { if (diagramWidth / fromToDays < 2) {
height = style.getYScale() * row + GanttChartStyle.HEAD_HEIGHT; final Document doc = SVGHelper.createDocument(style.getWidth(), height); final Element root = doc.getDocumentElement(); if (style.getWorkPackageLabelWidth() > 0) { g2.appendChild(SVGHelper.createText(doc, 0, 0, "WP")); g2.appendChild(SVGHelper.createText(doc, 0, 20, "Code")); g2.appendChild(SVGHelper.createText(doc, style.getWorkPackageLabelWidth(), 10, settings.getTitle())); } else { g2.appendChild(SVGHelper.createText(doc, 0, 10, settings.getTitle())); g1 = SVGHelper.createElement(doc, "g", "transform", "translate(" + style.getTotalLabelWidth() + ",20)", "text-anchor", "middle", "font-family", fontFamily, "font-size", "9pt"); } else { g1 = SVGHelper.createElement(doc, "g", "transform", "translate(" + style.getTotalLabelWidth() + ",20)", "text-anchor", "middle", "font-size", "9pt"); + style.getTotalLabelWidth() + "," + GanttChartStyle.HEAD_HEIGHT if (style.isShowToday() == true) { final DateHolder today = new DateHolder(); if (today.isBetween(fromDate, toDate) == true) { g1.appendChild(SVGHelper.createRect(doc, 0, 0, style.getWidth(), height, "none", "stroke-width", "2")); g1.appendChild(SVGHelper.createLine(doc, 0, 50, style.getWidth(), 50, "stroke-width", "2"));
@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 int getWidth() { return style.getWidth(); }
final double depX1; final double depX2; final double depY1 = depObjectInfo.y + style.getActivityHeight(); final double depY2 = taskInfo.y + style.getActivityHeight(); if (type == GanttRelationType.START_START) { depX1 = depObjectInfo.x1; if (depX1 > 0 && depX1 < diagramWidth && depX2 > 0 && depX2 < diagramWidth) { 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())));
return; final double y = taskInfo.y + style.getActivityHeight() / 2; final double height = style.getActivityHeight(); if (style.isShowCompletion() == true) { Integer completion = node.getProgress(); if (completion == null || completion < 0) {
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())); + style.getActivityHeight()));
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())); } }
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); }
protected void redraw() { final GanttChart ganttChart = createGanttChart(); final Component oldGanttImage = ganttImage; if (ganttChart != null) { final Document document = ganttChart.create(); if (document != null) { ganttImage = new ImagePanel(form.imagePanel.newChildId(), new BatikImage(ImagePanel.IMAGE_ID, document, getGanttChartStyle() .getWidth())); } else { ganttImage = null; } } else { ganttImage = null; } if (oldGanttImage != null) { form.imagePanel.remove(oldGanttImage); } if (ganttImage != null) { form.imagePanel.add(ganttImage); } }
@Override public GanttChartDO newInstance() { return new GanttChartDO().setSettings(new GanttChartSettings()).setStyle(new GanttChartStyle()); }
@Override public void afterLoad(final GanttChartDO obj) { final XmlObjectReader reader = new XmlObjectReader(); reader.initialize(GanttChartStyle.class); reader.initialize(GanttChartSettings.class); final String styleAsXml = obj.getStyleAsXml(); final GanttChartStyle style; if (StringUtils.isEmpty(styleAsXml) == true) { style = new GanttChartStyle(); } else { style = (GanttChartStyle) reader.read(styleAsXml); } obj.setStyle(style); final String settingsAsXml = obj.getSettingsAsXml(); final GanttChartSettings settings; if (StringUtils.isEmpty(settingsAsXml) == true) { settings = new GanttChartSettings(); } else { settings = (GanttChartSettings) reader.read(settingsAsXml); } obj.setSettings(settings); }
@Test public void createImage() throws IOException { final GanttTask root = createTestChart(); final GanttChartStyle style = new GanttChartStyle(); final GanttChartSettings settings = new GanttChartSettings(); final GanttChart diagram = new GanttChart(root, style, settings, "test-chart"); writeFile("ganttTest.jpg", BatikImageRenderer.getByteArray(diagram.create(), 800, ImageFormat.JPEG)); writeFile("ganttTest.png", BatikImageRenderer.getByteArray(diagram.create(), 800, ImageFormat.PNG)); writeFile("ganttTest.svg", BatikImageRenderer.getByteArray(diagram.create(), 800, ImageFormat.SVG)); writeFile("ganttTest.pdf", BatikImageRenderer.getByteArray(diagram.create(), 800, ImageFormat.PDF)); }