コード例 #1
0
ファイル: SVGGeneratorTest.java プロジェクト: mstahv/charts
  @Test
  @Ignore("Phantomjs not installed on our build server")
  public void test() {

    Configuration conf = createConf();

    String generatedSVG = SVGGenerator.getInstance().generate(conf);

    validateSvg(generatedSVG);

    try {
      // Some time to check CPU usage in rest manually
      Thread.sleep(10000);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }

    for (int i = 0; i < 10; i++) {
      generatedSVG = SVGGenerator.getInstance().generate(conf);
      validateSvg(generatedSVG);
    }

    long middle = System.currentTimeMillis();

    // Ensure the same instance still works
    generatedSVG = SVGGenerator.getInstance().generate(conf);

    long spentMillis = System.currentTimeMillis() - middle;
    System.out.println("Time spent for rendering one svg:" + spentMillis);

    Assert.assertTrue(
        "Generating SVG took more than 200ms : " + spentMillis + "ms", spentMillis < 200);

    SVGGenerator.getInstance().destroy();
  }
コード例 #2
0
ファイル: SVGGeneratorTest.java プロジェクト: mstahv/charts
  @Test
  @Ignore("Phantomjs not installed on our build server")
  public void testWide() throws InterruptedException, URISyntaxException {

    Configuration conf = new Configuration();
    conf.getChart().setType(ChartType.COLUMN);
    conf.getChart().setMarginRight(200);
    Legend legend = conf.getLegend();
    legend.setLayout(LayoutDirection.VERTICAL);
    legend.setHorizontalAlign(HorizontalAlign.RIGHT);
    legend.setVerticalAlign(VerticalAlign.MIDDLE);
    legend.setBorderWidth(0);

    Random r = new Random();

    for (int i = 0; i < 20; i++) {
      String name = RandomStringUtils.randomAlphabetic(r.nextInt(20));
      DataSeries dataSeries = new DataSeries(name);
      dataSeries.add(new DataSeriesItem(name, r.nextInt(100)));
      conf.addSeries(dataSeries);
    }

    SVGGenerator instance = SVGGenerator.getInstance();
    String generatedSVG = instance.generate(conf, 1200, 400);

    Assert.assertTrue(generatedSVG.contains("width=\"1200\""));
    Assert.assertTrue(generatedSVG.contains("height=\"400\""));

    SVGGenerator.getInstance().destroy();
  }