public void initializeLimits(Graphics2D g2d) { FontRenderContext frc = g2d.getFontRenderContext(); ImageParameters im = new ImageParameters(); int summaryLines = withSummary ? 5 : 0; im.xsize = getWidth(); im.ysize = getHeight(); im.unitslength = DEFAULT_UNITS_LENGTH; im.xorigin = (int) (PADDING_LEFT + im.unitslength * getSmallFontCharWidth(frc)); im.xorigin += getSmallFontHeight(frc); im.yorigin = PADDING_TOP + im.ysize; if(graphTitle != null && !"".equals(graphTitle)) im.yorigin += getLargeFontHeight(frc) + PADDING_TITLE; im.xgif = PADDING_RIGHT + im.xsize + im.xorigin; im.ygif = im.yorigin + (int) (PADDING_PLOT * getSmallFontHeight(frc)); im.ygif += ((int) getSmallLeading(frc) + summaryLines) * (getLegendLines() + summaryLines); im.ygif += PADDING_BOTTOM; setDimension(im.ygif, im.xgif); }
Assert.assertEquals("graph title failed", "graphTitle", gd.getGraphTitle()); Assert.assertEquals("graph name failed", "graphdesctest", gd.getName()); Assert.assertEquals("legend count failed", 5, gd.getLegendLines()); Assert.assertFalse("Graph unit should be binary", gd.isSiUnit()); Assert.assertEquals("Graph unit scale should be fixed", 0, gd.getUnitExponent().intValue());
@Test public void testCustomGraph() throws Exception { JrdsDocument d = Tools.parseRessource("customgraph.xml"); GraphDescBuilder gdbuild = new GraphDescBuilder(); gdbuild.setPm(Tools.makePm(testFolder)); GraphDesc gd = gdbuild.makeGraphDesc(d); Assert.assertEquals("graph name failed", "graphName", gd.getGraphName()); Assert.assertEquals("graph title failed", "", gd.getGraphTitle()); Assert.assertEquals("graph name failed", "name", gd.getName()); Assert.assertEquals("graph height invalid", 800, gd.getHeight()); Assert.assertEquals("graph width invalid", 600, gd.getWidth()); Assert.assertTrue("Lower limit is a number (not a NaN)" + gd.getUpperLimit(), Double.isNaN(gd.getUpperLimit())); Assert.assertEquals("graph lower limit is invalid", 1000, gd.getLowerLimit(), 0.1); Assert.assertFalse("graph is with legend", gd.withLegend()); Assert.assertFalse("graph is with summary", gd.withSummary()); Assert.assertEquals("legend count failed", 0, gd.getLegendLines()); }