/** Two objects that are equal are required to return the same hashCode. */
 public void testHashcode() {
   XYLine3DRenderer r1 = new XYLine3DRenderer();
   XYLine3DRenderer r2 = new XYLine3DRenderer();
   assertTrue(r1.equals(r2));
   int h1 = r1.hashCode();
   int h2 = r2.hashCode();
   assertEquals(h1, h2);
 }
  /** Serialize an instance, restore it, and check for equality. */
  public void testSerialization() {

    XYLine3DRenderer r1 = new XYLine3DRenderer();
    r1.setWallPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.blue));
    XYLine3DRenderer r2 = null;

    try {
      ByteArrayOutputStream buffer = new ByteArrayOutputStream();
      ObjectOutput out = new ObjectOutputStream(buffer);
      out.writeObject(r1);
      out.close();

      ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
      r2 = (XYLine3DRenderer) in.readObject();
      in.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
    assertEquals(r1, r2);
  }
 /** Confirm that cloning works. */
 public void testCloning() {
   XYLine3DRenderer r1 = new XYLine3DRenderer();
   r1.setWallPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.blue));
   XYLine3DRenderer r2 = null;
   try {
     r2 = (XYLine3DRenderer) r1.clone();
   } catch (CloneNotSupportedException e) {
     e.printStackTrace();
   }
   assertTrue(r1 != r2);
   assertTrue(r1.getClass() == r2.getClass());
   assertTrue(r1.equals(r2));
 }
예제 #4
0
  @Override
  protected ModelAndView handleRequestInternal(
      HttpServletRequest request, HttpServletResponse response) throws Exception {

    final int seriesMaxCount = 9; // the max number of series

    // get Series Color from the request
    int[] seriesColor = new int[seriesMaxCount];
    seriesColor[0] = Utils.toIntHex(request.getParameter("s1c"), 0x9bd2fb);
    seriesColor[1] = Utils.toIntHex(request.getParameter("s2c"), 0xFF0606);
    for (int i = 2; i < seriesMaxCount; i++) {
      seriesColor[i] = Utils.toIntHex(request.getParameter("s" + (i + 1) + "c"), -1);
    }

    // get Series Outline Color from the request
    int[] seriesOutlineColor = new int[seriesMaxCount];
    seriesOutlineColor[0] = Utils.toIntHex(request.getParameter("s1o"), 0x0665aa);
    seriesOutlineColor[1] = Utils.toIntHex(request.getParameter("s2o"), 0x9d0000);
    for (int i = 2; i < seriesMaxCount; i++) {
      seriesOutlineColor[i] = Utils.toIntHex(request.getParameter("s" + (i + 1) + "o"), -1);
    }

    // background color
    int backgroundColor = Utils.toIntHex(request.getParameter("bc"), 0xFFFFFF);

    // grid color
    int gridColor = Utils.toIntHex(request.getParameter("gc"), 0);

    // X axis title
    String labelX = ServletRequestUtils.getStringParameter(request, "xl", "");

    // Y axis title
    String labelY = ServletRequestUtils.getStringParameter(request, "yl", "");

    // image width
    int width = ServletRequestUtils.getIntParameter(request, "xz", 800);

    // image height
    int height = ServletRequestUtils.getIntParameter(request, "yz", 400);

    // show legend?
    boolean showLegend = ServletRequestUtils.getBooleanParameter(request, "l", true);

    // Series provider
    String provider = ServletRequestUtils.getStringParameter(request, "p", null);

    // Chart type
    String chartType = ServletRequestUtils.getStringParameter(request, "ct", "area");

    DefaultTableXYDataset ds = new DefaultTableXYDataset();

    if (provider != null) {
      Object series = getApplicationContext().getBean(provider);
      if (series instanceof SeriesProvider) {
        ((SeriesProvider) series).populate(ds, statsCollection, request);
      } else {
        logger.error(
            "SeriesProvider \"" + provider + "\" does not implement " + SeriesProvider.class);
      }
    }

    // Build series data from the give statistic
    JFreeChart chart = null;
    if ("area".equals(chartType)) {
      chart =
          ChartFactory.createXYAreaChart(
              "", labelX, labelY, ds, PlotOrientation.VERTICAL, showLegend, false, false);

      ((XYAreaRenderer) chart.getXYPlot().getRenderer()).setOutline(true);

    } else if ("stacked".equals(chartType)) {
      chart =
          ChartFactory.createStackedXYAreaChart(
              "", labelX, labelY, ds, PlotOrientation.VERTICAL, showLegend, false, false);

    } else if ("line".equals(chartType)) {
      chart =
          ChartFactory.createXYLineChart(
              "", labelX, labelY, ds, PlotOrientation.VERTICAL, showLegend, false, false);

      final XYLine3DRenderer renderer = new XYLine3DRenderer();
      renderer.setDrawOutlines(true);
      renderer.setLinesVisible(true);
      renderer.setShapesVisible(true);
      renderer.setStroke(new BasicStroke(2));
      renderer.setXOffset(1);
      renderer.setYOffset(1);
      chart.getXYPlot().setRenderer(renderer);
    }

    if (chart != null) {
      chart.setAntiAlias(true);
      chart.setBackgroundPaint(new Color(backgroundColor));
      for (int i = 0; i < seriesMaxCount; i++) {
        if (seriesColor[i] >= 0) {
          chart.getXYPlot().getRenderer().setSeriesPaint(i, new Color(seriesColor[i]));
        }
        if (seriesOutlineColor[i] >= 0) {
          chart
              .getXYPlot()
              .getRenderer()
              .setSeriesOutlinePaint(i, new Color(seriesOutlineColor[i]));
        }
      }
      chart.getXYPlot().setDomainGridlinePaint(new Color(gridColor));
      chart.getXYPlot().setRangeGridlinePaint(new Color(gridColor));
      chart.getXYPlot().setDomainAxis(0, new DateAxis());
      chart.getXYPlot().setDomainAxis(1, new DateAxis());
      chart.getXYPlot().setInsets(new RectangleInsets(-15, 0, 0, 10));

      response.setHeader("Content-type", "image/png");
      response
          .getOutputStream()
          .write(ChartUtilities.encodeAsPNG(chart.createBufferedImage(width, height)));
    }

    return null;
  }
  /** Check that the equals() method distinguishes all fields. */
  public void testEquals() {
    XYLine3DRenderer r1 = new XYLine3DRenderer();
    XYLine3DRenderer r2 = new XYLine3DRenderer();
    assertEquals(r1, r2);

    r1.setXOffset(11.1);
    assertFalse(r1.equals(r2));
    r2.setXOffset(11.1);
    assertTrue(r1.equals(r2));

    r1.setYOffset(11.1);
    assertFalse(r1.equals(r2));
    r2.setYOffset(11.1);
    assertTrue(r1.equals(r2));

    r1.setWallPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.blue));
    assertFalse(r1.equals(r2));
    r2.setWallPaint(new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f, Color.blue));
    assertTrue(r1.equals(r2));
  }