/** Test that the equals() method distinguishes all fields. */
  public void testEquals() {
    GroupedStackedBarRenderer r1 = new GroupedStackedBarRenderer();
    GroupedStackedBarRenderer r2 = new GroupedStackedBarRenderer();
    assertTrue(r1.equals(r2));
    assertTrue(r2.equals(r1));

    // map
    KeyToGroupMap m1 = new KeyToGroupMap("G1");
    m1.mapKeyToGroup("S1", "G2");
    r1.setSeriesToGroupMap(m1);
    assertFalse(r1.equals(r2));
    KeyToGroupMap m2 = new KeyToGroupMap("G1");
    m2.mapKeyToGroup("S1", "G2");
    r2.setSeriesToGroupMap(m2);
    assertTrue(r1.equals(r2));
  }
  /** Comienzo de mètodos básicos. */
  private BufferedImage generarGraficoBarrasApiladas(
      String titulo,
      String ejeHorizontal,
      String ejeVertical,
      ArrayList<Serie> series,
      boolean porcentaje,
      boolean leyenda,
      PlotOrientation orientacion,
      int anchoImagen,
      int altoImagen) {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    for (Serie serie : series) {
      if (serie.valores.length != serie.funciones.length) {
        continue;
      }
      for (int i = 0; i < serie.valores.length; i++) {
        dataset.addValue(serie.valores[i], serie.funciones[i], serie.nombre);
      }
    }
    JFreeChart chart =
        ChartFactory.createStackedBarChart(
            titulo,
            ejeHorizontal,
            ejeVertical,
            dataset,
            orientacion,
            leyenda,
            true, // tooltips
            false // urls
            );

    chart.setBackgroundPaint(null);
    chart.getTitle().setPaint(LookAndFeelEntropy.COLOR_FUENTE_TITULO_PANEL);
    chart.getTitle().setFont(LookAndFeelEntropy.FUENTE_TITULO_GRANDE);
    chart.setBorderVisible(false);
    if (leyenda) {
      chart.getLegend().setItemFont(LookAndFeelEntropy.FUENTE_REGULAR);
      chart.getLegend().setBackgroundPaint(LookAndFeelEntropy.COLOR_TABLA_PRIMARIO);
    }

    GroupedStackedBarRenderer renderer = new GroupedStackedBarRenderer();
    KeyToGroupMap map = new KeyToGroupMap(series.get(0).nombre);
    for (Serie serie : series) {
      map.mapKeyToGroup(serie.nombre, serie.nombre);
    }
    renderer.setSeriesToGroupMap(map);
    renderer.setDrawBarOutline(false);
    renderer.setRenderAsPercentages(porcentaje);
    renderer.setItemLabelsVisible(true);
    renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator());

    for (Serie serie : series) {
      for (int i = 0; i < serie.valores.length; i++) {
        if (Serie.colores.size() - 1 < i || Serie.colores.get(i) == null) {
          Color color = generarColorAleatorio(Color.orange);
          GradientPaint gp = new GradientPaint(0.0f, 0.0f, color, 0.0f, 0.0f, color);
          Serie.colores.add(gp);
        }
        renderer.setSeriesPaint(i, Serie.colores.get(i));
      }
    }

    renderer.setGradientPaintTransformer(
        new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL));

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(null);
    plot.setBackgroundImageAlpha(0.0f);
    plot.setOutlineVisible(false);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    if (porcentaje) {
      rangeAxis.setNumberFormatOverride(NumberFormat.getPercentInstance());
    } else {
      rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    }

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(
        CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));
    domainAxis.setCategoryMargin(0.05);

    plot.setRenderer(renderer);

    // Generamos una imagen
    this.lastChart = chart;
    return chart.createBufferedImage(anchoImagen, altoImagen);
  }