/**
   * A check for the datasetIndex and seriesIndex fields in the LegendItem returned by the
   * getLegendItem() method.
   */
  @Test
  public void testGetLegendItemSeriesIndex() {
    XYSeriesCollection d1 = new XYSeriesCollection();
    XYSeries s1 = new XYSeries("S1");
    s1.add(1.0, 1.1);
    XYSeries s2 = new XYSeries("S2");
    s2.add(1.0, 1.1);
    d1.addSeries(s1);
    d1.addSeries(s2);

    XYSeriesCollection d2 = new XYSeriesCollection();
    XYSeries s3 = new XYSeries("S3");
    s3.add(1.0, 1.1);
    XYSeries s4 = new XYSeries("S4");
    s4.add(1.0, 1.1);
    XYSeries s5 = new XYSeries("S5");
    s5.add(1.0, 1.1);
    d2.addSeries(s3);
    d2.addSeries(s4);
    d2.addSeries(s5);

    XYAreaRenderer r = new XYAreaRenderer();
    XYPlot plot = new XYPlot(d1, new NumberAxis("x"), new NumberAxis("y"), r);
    plot.setDataset(1, d2);
    /*JFreeChart chart =*/ new JFreeChart(plot);
    LegendItem li = r.getLegendItem(1, 2);
    assertEquals("S5", li.getLabel());
    assertEquals(1, li.getDatasetIndex());
    assertEquals(2, li.getSeriesIndex());
  }
 private static JFreeChart createChart() {
   XYDataset xydataset = createDirectionDataset(600);
   JFreeChart jfreechart =
       ChartFactory.createTimeSeriesChart(
           "Time", "Date", "Direction", xydataset, true, true, false);
   XYPlot xyplot = (XYPlot) jfreechart.getPlot();
   xyplot.getDomainAxis().setLowerMargin(0.0D);
   xyplot.getDomainAxis().setUpperMargin(0.0D);
   NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis();
   numberaxis.setAutoRangeIncludesZero(false);
   TickUnits tickunits = new TickUnits();
   tickunits.add(new NumberTickUnit(180D, new CompassFormat()));
   tickunits.add(new NumberTickUnit(90D, new CompassFormat()));
   tickunits.add(new NumberTickUnit(45D, new CompassFormat()));
   tickunits.add(new NumberTickUnit(22.5D, new CompassFormat()));
   numberaxis.setStandardTickUnits(tickunits);
   xyplot.setRangeAxis(numberaxis);
   XYAreaRenderer xyarearenderer = new XYAreaRenderer();
   NumberAxis numberaxis1 = new NumberAxis("Force");
   numberaxis1.setRange(0.0D, 12D);
   xyarearenderer.setSeriesPaint(0, new Color(0, 0, 255, 128));
   xyplot.setDataset(1, createForceDataset(600));
   xyplot.setRenderer(1, xyarearenderer);
   xyplot.setRangeAxis(1, numberaxis1);
   xyplot.mapDatasetToRangeAxis(1, 1);
   return jfreechart;
 }
  private JFreeChart createChart(String chartType) {
    CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new DateAxis("Date"));
    JFreeChart chart = new JFreeChart(getEditorInput().getName(), plot);
    chart.setBackgroundPaint(Color.white);

    TimeSeriesCollection dataset = createTotalDataset();
    StandardXYItemRenderer standardXYItemRenderer = new StandardXYItemRenderer();
    standardXYItemRenderer.setBaseToolTipGenerator(
        StandardXYToolTipGenerator.getTimeSeriesInstance());
    XYPlot subplot1 = new XYPlot(dataset, null, new NumberAxis("Value"), standardXYItemRenderer);
    plot.add(subplot1, 70);
    subplot1.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    subplot1.setDomainCrosshairVisible(true);
    subplot1.setRangeCrosshairVisible(true);

    XYAreaRenderer xyAreaRenderer = new XYAreaRenderer();
    xyAreaRenderer.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());
    XYPlot subplot2 =
        new XYPlot(createGainLossDataset(), null, new NumberAxis("Gain/Loss"), xyAreaRenderer);
    subplot2.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    subplot2.setDomainCrosshairVisible(true);
    subplot2.setRangeCrosshairVisible(true);
    plot.add(subplot2, 30);

    plot.setDrawingSupplier(new PeanutsDrawingSupplier());

    DateAxis axis = (DateAxis) plot.getDomainAxis();
    axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));

    timeChart = new TimeChart(chart, dataset);
    timeChart.setChartType(chartType);

    return chart;
  }
  /** Confirm that cloning works. */
  @Test
  public void testCloning() throws CloneNotSupportedException {
    XYAreaRenderer r1 = new XYAreaRenderer();
    Rectangle2D rect1 = new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0);
    r1.setLegendArea(rect1);
    XYAreaRenderer r2 = (XYAreaRenderer) r1.clone();
    assertTrue(r1 != r2);
    assertTrue(r1.getClass() == r2.getClass());
    assertTrue(r1.equals(r2));

    // check independence
    rect1.setRect(4.0, 3.0, 2.0, 1.0);
    assertFalse(r1.equals(r2));
    r2.setLegendArea(new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0));
    assertTrue(r1.equals(r2));
  }
  /** Two objects that are equal are required to return the same hashCode. */
  @Test
  public void testHashcode() {
    XYAreaRenderer r1 = new XYAreaRenderer();
    XYAreaRenderer r2 = new XYAreaRenderer();
    assertTrue(r1.equals(r2));
    int h1 = r1.hashCode();
    int h2 = r2.hashCode();
    assertEquals(h1, h2);

    r2.setUseFillPaint(true);
    assertFalse(r1.hashCode() == r2.hashCode());
  }
  /** Check that the equals() method distinguishes all fields. */
  @Test
  public void testEquals() {
    XYAreaRenderer r1 = new XYAreaRenderer();
    XYAreaRenderer r2 = new XYAreaRenderer();
    assertEquals(r1, r2);

    r1 = new XYAreaRenderer(XYAreaRenderer.AREA_AND_SHAPES);
    assertFalse(r1.equals(r2));
    r2 = new XYAreaRenderer(XYAreaRenderer.AREA_AND_SHAPES);
    assertTrue(r1.equals(r2));

    r1 = new XYAreaRenderer(XYAreaRenderer.AREA);
    assertFalse(r1.equals(r2));
    r2 = new XYAreaRenderer(XYAreaRenderer.AREA);
    assertTrue(r1.equals(r2));

    r1 = new XYAreaRenderer(XYAreaRenderer.LINES);
    assertFalse(r1.equals(r2));
    r2 = new XYAreaRenderer(XYAreaRenderer.LINES);
    assertTrue(r1.equals(r2));

    r1 = new XYAreaRenderer(XYAreaRenderer.SHAPES);
    assertFalse(r1.equals(r2));
    r2 = new XYAreaRenderer(XYAreaRenderer.SHAPES);
    assertTrue(r1.equals(r2));

    r1 = new XYAreaRenderer(XYAreaRenderer.SHAPES_AND_LINES);
    assertFalse(r1.equals(r2));
    r2 = new XYAreaRenderer(XYAreaRenderer.SHAPES_AND_LINES);
    assertTrue(r1.equals(r2));

    r1.setOutline(true);
    assertFalse(r1.equals(r2));
    r2.setOutline(true);
    assertTrue(r1.equals(r2));

    r1.setLegendArea(new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0));
    assertFalse(r1.equals(r2));
    r2.setLegendArea(new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0));
    assertTrue(r1.equals(r2));

    r1.setUseFillPaint(true);
    assertFalse(r1.equals(r2));
    r2.setUseFillPaint(true);
    assertTrue(r1.equals(r2));

    r1.setGradientTransformer(
        new StandardGradientPaintTransformer(GradientPaintTransformType.CENTER_VERTICAL));
    assertFalse(r1.equals(r2));
    r2.setGradientTransformer(
        new StandardGradientPaintTransformer(GradientPaintTransformType.CENTER_VERTICAL));
    assertTrue(r1.equals(r2));
  }
  static JFreeChart createChart(
      NavigableMap<TimeAxisKey, DiffStat> aggregatedDiffstats,
      DiffStatConfiguration configuration) {

    boolean legend = false;
    boolean tooltips = false;
    boolean urls = false;
    Font helvetica = new Font("Helvetica", Font.PLAIN, 11 * configuration.multiplierInt());

    XYDatasetMinMax datasetMinMax =
        createDeltaDataset("Additions and Delections", aggregatedDiffstats);
    XYDataset dataset = datasetMinMax.dataset;
    JFreeChart chart =
        ChartFactory.createTimeSeriesChart("", "", "", dataset, legend, tooltips, urls);

    chart.setBackgroundPaint(WHITE);
    chart.setBorderVisible(false);

    float strokeWidth = 1.2f * configuration.multiplierFloat();

    XYPlot plot = chart.getXYPlot();
    plot.setOrientation(VERTICAL);
    plot.setBackgroundPaint(WHITE);
    plot.setDomainGridlinesVisible(true);
    plot.setDomainGridlinePaint(AXIS_LINE_COLOR);
    plot.setDomainGridlineStroke(new BasicStroke(1.0f * configuration.multiplierFloat()));
    plot.setRangeGridlinesVisible(false);

    plot.setOutlineVisible(false);

    DateAxis dateAxis = (DateAxis) plot.getDomainAxis();
    dateAxis.setDateFormatOverride(new SimpleDateFormat("MM/yy"));
    dateAxis.setTickLabelFont(helvetica);
    dateAxis.setAxisLineVisible(false);
    dateAxis.setTickUnit(computeDateTickUnit(aggregatedDiffstats));
    RectangleInsets insets =
        new RectangleInsets(
            8.0d * configuration.multiplierDouble(),
            4.0d * configuration.multiplierDouble(),
            4.0d * configuration.multiplierDouble(),
            4.0d * configuration.multiplierDouble());
    dateAxis.setTickLabelInsets(insets);

    NumberAxis additionDeletionAxis = (NumberAxis) plot.getRangeAxis(0);
    additionDeletionAxis.setAxisLineVisible(false);
    additionDeletionAxis.setLabel("Additions and Deletions");
    additionDeletionAxis.setLabelFont(helvetica);
    additionDeletionAxis.setTickLabelFont(helvetica);
    additionDeletionAxis.setRangeType(RangeType.FULL);
    int lowerBound = datasetMinMax.min + (int) (datasetMinMax.min * 0.1d);
    additionDeletionAxis.setLowerBound(lowerBound);
    int upperBound = datasetMinMax.max + (int) (datasetMinMax.max * 0.1d);
    additionDeletionAxis.setUpperBound(upperBound);
    additionDeletionAxis.setNumberFormatOverride(new AbbreviatingNumberFormat());
    additionDeletionAxis.setMinorTickMarksVisible(false);
    additionDeletionAxis.setTickMarkInsideLength(5.0f * configuration.multiplierFloat());
    additionDeletionAxis.setTickMarkOutsideLength(0.0f);
    additionDeletionAxis.setTickMarkStroke(new BasicStroke(2.0f * configuration.multiplierFloat()));
    additionDeletionAxis.setTickUnit(
        new NumberTickUnit(computeTickUnitSize(datasetMinMax.max + abs(datasetMinMax.min))));

    XYAreaRenderer areaRenderer = new XYAreaRenderer(XYAreaRenderer.AREA);
    areaRenderer.setOutline(true);
    areaRenderer.setSeriesOutlinePaint(0, ADDED_STROKE);
    areaRenderer.setSeriesOutlineStroke(0, new BasicStroke(strokeWidth));
    areaRenderer.setSeriesPaint(0, ADDED_FILL);
    areaRenderer.setSeriesOutlinePaint(1, REMOVED_STROKE);
    areaRenderer.setSeriesOutlineStroke(1, new BasicStroke(strokeWidth));
    areaRenderer.setSeriesPaint(1, REMOVED_FILL);
    plot.setRenderer(0, areaRenderer);

    // Total Axis
    NumberAxis totalAxis = new NumberAxis("Total Lines");
    totalAxis.setAxisLineVisible(false);
    totalAxis.setLabelPaint(VALUE_LABEL);
    totalAxis.setTickLabelPaint(TOTAL_LABEL);
    totalAxis.setLabelFont(helvetica);
    totalAxis.setTickLabelFont(helvetica);
    totalAxis.setNumberFormatOverride(new AbbreviatingNumberFormat());
    totalAxis.setMinorTickMarksVisible(false);
    totalAxis.setTickMarkInsideLength(5.0f * configuration.multiplierFloat());
    totalAxis.setTickMarkOutsideLength(0.0f);
    totalAxis.setTickMarkStroke(new BasicStroke(2.0f * configuration.multiplierFloat()));
    totalAxis.setTickMarkPaint(TOTAL_LABEL);
    plot.setRangeAxis(1, totalAxis);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);

    XYDatasetAndTotal datasetAndTotal = createTotalDataset("Total Lines", aggregatedDiffstats);
    XYDataset totalDataSet = datasetAndTotal.dataset;
    plot.setDataset(1, totalDataSet);
    plot.mapDatasetToRangeAxis(1, 1);
    //        XYItemRenderer totalRenderer = new XYSplineRenderer();
    XYItemRenderer totalRenderer = new StandardXYItemRenderer();
    totalRenderer.setSeriesPaint(0, TOTAL_FILL);
    totalRenderer.setSeriesStroke(
        0,
        new BasicStroke(
            strokeWidth,
            CAP_ROUND,
            JOIN_ROUND,
            10.0f * configuration.multiplierFloat(),
            new float[] {
              6.0f * configuration.multiplierFloat(), 3.0f * configuration.multiplierFloat()
            },
            0.0f));
    plot.setRenderer(1, totalRenderer);

    totalAxis.setTickUnit(new NumberTickUnit(computeTickUnitSize(datasetAndTotal.total)));

    return chart;
  }