/** Confirm that cloning works. */
 @Test
 public void testCloning() throws CloneNotSupportedException {
   StackedXYAreaRenderer2 r1 = new StackedXYAreaRenderer2();
   StackedXYAreaRenderer2 r2 = (StackedXYAreaRenderer2) r1.clone();
   assertNotSame(r1, r2);
   assertSame(r1.getClass(), r2.getClass());
   assertEquals(r1, r2);
 }
 /** Two objects that are equal are required to return the same hashCode. */
 @Test
 public void testHashcode() {
   StackedXYAreaRenderer2 r1 = new StackedXYAreaRenderer2();
   StackedXYAreaRenderer2 r2 = new StackedXYAreaRenderer2();
   assertEquals(r1, r2);
   int h1 = r1.hashCode();
   int h2 = r2.hashCode();
   assertEquals(h1, h2);
 }
  /** Check that the renderer is calculating the range bounds correctly. */
  @Test
  public void testFindRangeBounds() {
    TableXYDataset dataset = RendererXYPackageTests.createTestTableXYDataset();
    JFreeChart chart = ChartFactory.createStackedXYAreaChart("Test Chart", "X", "Y", dataset);
    XYPlot plot = (XYPlot) chart.getPlot();
    StackedXYAreaRenderer2 renderer = new StackedXYAreaRenderer2();
    plot.setRenderer(renderer);
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    Range bounds = rangeAxis.getRange();
    assertTrue(bounds.contains(6.0));
    assertTrue(bounds.contains(8.0));

    // try null argument
    assertNull(renderer.findRangeBounds(null));

    // try empty dataset
    assertNull(renderer.findRangeBounds(new DefaultTableXYDataset()));
  }
  /** Test that the equals() method distinguishes all fields. */
  @Test
  public void testEquals() {
    StackedXYAreaRenderer2 r1 = new StackedXYAreaRenderer2();
    StackedXYAreaRenderer2 r2 = new StackedXYAreaRenderer2();
    assertEquals(r1, r2);
    assertEquals(r2, r1);

    r1.setRoundXCoordinates(!r1.getRoundXCoordinates());
    assertFalse(r1.equals(r2));
    r2.setRoundXCoordinates(r1.getRoundXCoordinates());
    assertEquals(r1, r2);
  }
Пример #5
0
  public JFreeChart makegraph(Second g_start, Second g_end) {
    // used
    XYDataset xydataset1 = this.createused();
    XYPlot subplot1;
    NumberAxis usedaxis = new NumberAxis("% used cpu");
    if (mysar.show100axiscpu) {
      usedaxis.setRange(0.0D, 100D);
    }

    if (mysar.showstackedcpu) {
      StackedXYAreaRenderer2 renderer = new StackedXYAreaRenderer2();
      renderer.setSeriesPaint(0, kSarConfig.color1);
      renderer.setSeriesPaint(1, kSarConfig.color2);
      renderer.setSeriesPaint(2, kSarConfig.color3);
      renderer.setSeriesPaint(3, kSarConfig.color4);
      subplot1 = new XYPlot(stacked_used, new DateAxis(null), usedaxis, renderer);

    } else {
      XYItemRenderer minichart1 = new StandardXYItemRenderer();
      minichart1.setBaseStroke(kSarConfig.DEFAULT_STROKE);
      minichart1.setSeriesPaint(0, kSarConfig.color1);
      minichart1.setSeriesPaint(1, kSarConfig.color2);
      minichart1.setSeriesPaint(2, kSarConfig.color3);
      minichart1.setSeriesPaint(2, kSarConfig.color4);
      subplot1 = new XYPlot(xydataset1, null, usedaxis, minichart1);
    }
    // idle
    XYDataset idleset = this.createidle();
    XYItemRenderer minichart2 = new StandardXYItemRenderer();
    minichart2.setSeriesPaint(0, kSarConfig.color5);
    minichart2.setBaseStroke(kSarConfig.DEFAULT_STROKE);
    XYPlot subplot2 = new XYPlot(idleset, null, new NumberAxis("% idle"), minichart2);
    // nice
    XYDataset niceset = this.createnice();
    XYItemRenderer minichart3 = new StandardXYItemRenderer();
    minichart3.setSeriesPaint(0, kSarConfig.color6);
    minichart3.setBaseStroke(kSarConfig.DEFAULT_STROKE);
    XYPlot subplot3 = new XYPlot(niceset, null, new NumberAxis("% niced"), minichart3);

    // the graph
    CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new DateAxis(""));
    plot.add(subplot1, 2);
    plot.add(subplot3, 1);
    plot.add(subplot2, 1);
    plot.setOrientation(PlotOrientation.VERTICAL);
    // the graph
    JFreeChart mychart = new JFreeChart(this.getGraphTitle(), kSarConfig.DEFAULT_FONT, plot, true);
    if (g_start != null) {
      DateAxis dateaxis1 = (DateAxis) mychart.getXYPlot().getDomainAxis();
      dateaxis1.setRange(g_start.getStart(), g_end.getEnd());
    }
    if (setbackgroundimage(mychart) == 1) {
      subplot1.setBackgroundPaint(null);
      subplot2.setBackgroundPaint(null);
      subplot3.setBackgroundPaint(null);
    }

    // idle trigger
    cpuidletrigger.setTriggerValue(kSarConfig.linuxcpuidletrigger);
    cpuidletrigger.tagMarker(subplot2);
    // system trigger
    cpusystemtrigger.setTriggerValue(kSarConfig.linuxcpusystemtrigger);
    cpusystemtrigger.tagMarker(subplot1);
    // wio trigger
    if (cpuOpt.equals("%iowait") || cpuOpt.equals("%steal")) {
      cpuwiotrigger.setTriggerValue(kSarConfig.linuxcpuwiotrigger);
      cpuwiotrigger.tagMarker(subplot1);
    }
    // usr trigger
    cpuusrtrigger.setTriggerValue(kSarConfig.linuxcpuusrtrigger);
    cpuusrtrigger.tagMarker(subplot1);
    //
    return mychart;
  }