package org.knowm.xchart.internal.chartpart;

import java.awt.BasicStroke;
import java.awt.Graphics2D;
import java.awt.Stroke;
import java.awt.geom.Path2D;
import java.awt.geom.Rectangle2D;
import org.knowm.xchart.internal.series.Series;
import org.knowm.xchart.style.Styler;

/** @author timmolter */
public abstract class PlotContent_<ST extends Styler, S extends Series> implements ChartPart {

  final Chart<ST, S> chart;
  ToolTips toolTips;
  ChartZoom chartZoom;

  // TODO create a PlotContent_Axes class to put this in.
  static final Stroke ERROR_BAR_STROKE =
      new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL);

  /**
   * Constructor
   *
   * @param chart - The Chart
   */
  PlotContent_(Chart<ST, S> chart) {

    this.chart = chart;
  }

  protected abstract void doPaint(Graphics2D g);

  @Override
  public void paint(Graphics2D g) {

    Rectangle2D bounds = getBounds();
    // g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
    // g.setColor(Color.red);
    // g.draw(bounds);

    // if the area to draw a chart on is so small, don't even bother
    if (bounds.getWidth() < 30) {
      return;
    }

    java.awt.Shape saveClip = g.getClip();
    // this is for preventing the series to be drawn outside the plot area if min and max is
    // overridden to fall inside the data range
    if (saveClip != null) {
      g.setClip(bounds.createIntersection(saveClip.getBounds2D()));
    } else {
      g.setClip(bounds);
    }

    //    chart.cursor.prepare(bounds, (Map<String, Series>) chart.getSeriesMap());

    doPaint(g);

    // after painting the plot content, paint the tooltip(s) if necessary
    if (chart.getStyler().isToolTipsEnabled()) {
      toolTips.paint(g);
    }
    //    chart.cursor.paint(g);

    // TODO here the annotation classes are added. Refactor this!

    //    for (ChartPart part : chart.getPlotParts()) {
    //      part.paint(g);
    //    }

    chartZoom.paint(g);

    g.setClip(saveClip);
  }

  @Override
  public Rectangle2D getBounds() {

    return chart.getPlot().getBounds();
  }

  /** Closes a path for area charts if one is available. */
  void closePath(
      Graphics2D g, Path2D.Double path, double previousX, Rectangle2D bounds, double yTopMargin) {

    if (path != null) {
      double yBottomOfArea = getBounds().getY() + getBounds().getHeight() - yTopMargin;
      path.lineTo(previousX, yBottomOfArea);
      path.closePath();
      g.fill(path);
    }
  }

  public void setToolTips(ToolTips toolTips) {
    this.toolTips = toolTips;
  }

  public void setChartZoom(ChartZoom chartZoom) {
    this.chartZoom = chartZoom;
  }
}

@@ -182,16 +182,50 @@
 angle2D;
+%0A%0Aimport org.knowm.xchart.XYChart;
 %0Aimport 
@@ -302,16 +302,56 @@
 .Styler;
+%0Aimport org.knowm.xchart.style.XYStyler;
 %0A%0A/** @a
@@ -2019,24 +2019,172 @@
    //    %7D%0A%0A
+    // TODO create a PlotContent_Axes class to put this in.%0A    if (chart instanceof XYChart && ((XYStyler) chart.getStyler()).isZoomEnabled()) %7B%0A  
     chartZoo
@@ -2190,24 +2190,30 @@
 om.paint(g);
+%0A    %7D
 %0A%0A    g.setC

fix broken ChartZoom (2)