<commit_before>/*
 *    Debrief - the Open Source Maritime Analysis Application
 *    http://debrief.info
 *
 *    (C) 2000-2014, PlanetMayo Ltd
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the Eclipse Public License v1.0
 *    (http://www.eclipse.org/legal/epl-v10.html)
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 */
package MWC.GUI.JFreeChart;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Paint;
import java.awt.Shape;
import java.awt.Stroke;
import java.awt.geom.Rectangle2D;

import org.jfree.chart.LegendItem;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.entity.EntityCollection;
import org.jfree.chart.labels.XYToolTipGenerator;
import org.jfree.chart.plot.CrosshairState;
import org.jfree.chart.plot.PlotRenderingInfo;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.DefaultXYItemRenderer;
import org.jfree.chart.renderer.xy.XYItemRendererState;
import org.jfree.chart.urls.XYURLGenerator;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.data.time.TimeSeriesDataItem;
import org.jfree.data.xy.XYDataset;

/**
 * Created by IntelliJ IDEA. User: Ian.Mayo Date: Feb 5, 2003 Time: 10:59:40 AM To change this
 * template use Options | File Templates.
 */
// ////////////////////////////////////////////////
// custom renderer, which uses the specified color for the data series
// ////////////////////////////////////////////////
public class ColourStandardXYItemRenderer extends DefaultXYItemRenderer
{

  /**
	 * 
	 */
  private static final long serialVersionUID = 1L;
  /** A working line (to save creating thousands of instances). */
  // private Line2D workingLine = new Line2D.Double(0.0, 0.0, 0.0, 0.0);

  /**
   * the plot whose data we're plotting
   * 
   */
  private XYPlot _myPlot;

  /**
   * Constructs a new renderer.
   * <p>
   * To specify the type of renderer, use one of the constants: SHAPES, LINES or SHAPES_AND_LINES.
   * 
   * @param type
   *          the type of renderer.
   * @param toolTipGenerator
   *          the tooltip generator.
   * @param urlGenerator
   *          the URL generator.
   * @param plot
   */
  public ColourStandardXYItemRenderer(
      final XYToolTipGenerator toolTipGenerator,
      final XYURLGenerator urlGenerator, final XYPlot plot)
  {
    super();
    this.setBaseToolTipGenerator(toolTipGenerator);
    this.setURLGenerator(urlGenerator);
    _myPlot = plot;
  }

  public void setPlot(final XYPlot thePlot)
  {
    super.setPlot(thePlot);
    _myPlot = thePlot;
  }

  @Override
  public boolean getItemShapeVisible(int row, int column)
  {
    final XYDataset data = _myPlot.getDataset();

    boolean res = super.getItemShapeVisible(row, column);

    if (data instanceof TimeSeriesCollection)
    {
      final TimeSeriesCollection tsc = (TimeSeriesCollection) data;
      // get the data series
      final TimeSeries bts = tsc.getSeries(row);
      final TimeSeriesDataItem tsdp = bts.getDataItem(column);
      if (tsdp instanceof ColouredDataItem)
      {
        final ColouredDataItem cdi = (ColouredDataItem) tsdp;
        // is the base renderer set to show all
        if (this.getBaseShapesVisible() && cdi.isParentSymVisible())
          res = true;
        else
          res = false;
      }
    }<commit_msg>provide modified accessor that scales the provided symbol to the custom size<commit_after>/*
 *    Debrief - the Open Source Maritime Analysis Application
 *    http://debrief.info
 *
 *    (C) 2000-2014, PlanetMayo Ltd
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the Eclipse Public License v1.0
 *    (http://www.eclipse.org/legal/epl-v10.html)
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 */
package MWC.GUI.JFreeChart;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Paint;
import java.awt.Polygon;
import java.awt.Shape;
import java.awt.Stroke;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;

import org.jfree.chart.LegendItem;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.entity.EntityCollection;
import org.jfree.chart.labels.XYToolTipGenerator;
import org.jfree.chart.plot.CrosshairState;
import org.jfree.chart.plot.PlotRenderingInfo;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.DefaultXYItemRenderer;
import org.jfree.chart.renderer.xy.XYItemRendererState;
import org.jfree.chart.urls.XYURLGenerator;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.data.time.TimeSeriesDataItem;
import org.jfree.data.xy.XYDataset;

/**
 * Created by IntelliJ IDEA. User: Ian.Mayo Date: Feb 5, 2003 Time: 10:59:40 AM To change this
 * template use Options | File Templates.
 */
// ////////////////////////////////////////////////
// custom renderer, which uses the specified color for the data series
// ////////////////////////////////////////////////
public class ColourStandardXYItemRenderer extends DefaultXYItemRenderer
{

  /**
	 * 
	 */
  private static final long serialVersionUID = 1L;
  /** A working line (to save creating thousands of instances). */
  // private Line2D workingLine = new Line2D.Double(0.0, 0.0, 0.0, 0.0);

  /**
   * the plot whose data we're plotting
   * 
   */
  private XYPlot _myPlot;
  
  private double _symbolSize = 6;

  /**
   * Constructs a new renderer.
   * <p>
   * To specify the type of renderer, use one of the constants: SHAPES, LINES or SHAPES_AND_LINES.
   * 
   * @param type
   *          the type of renderer.
   * @param toolTipGenerator
   *          the tooltip generator.
   * @param urlGenerator
   *          the URL generator.
   * @param plot
   */
  public ColourStandardXYItemRenderer(
      final XYToolTipGenerator toolTipGenerator,
      final XYURLGenerator urlGenerator, final XYPlot plot)
  {
    super();
    this.setBaseToolTipGenerator(toolTipGenerator);
    this.setURLGenerator(urlGenerator);
    _myPlot = plot;
  }

  public void setPlot(final XYPlot thePlot)
  {
    super.setPlot(thePlot);
    _myPlot = thePlot;
  }

  public void setSymbolSize(double size)
  {
    _symbolSize = size;
  }
  
  public double getSymbolSize()
  {
    return _symbolSize;
  }
  
  
  @Override
  public Shape getSeriesShape(int series)
  {
    Shape theShape = super.getSeriesShape(series);
    final double defaultScale = 6;
    
    final Shape newShape;
    if(theShape instanceof Rectangle2D)
    {
      Rectangle2D rect = (Rectangle2D) theShape;
      double ht = rect.getHeight() / defaultScale * _symbolSize;
      double wid = rect.getWidth() / defaultScale * _symbolSize;
      newShape = new Rectangle2D.Double( -wid/2, -ht/2, wid, ht);
    }
    else if(theShape instanceof Ellipse2D)
    {
      Ellipse2D ell = (Ellipse2D) theShape;
      double ht = ell.getHeight() / defaultScale * _symbolSize;
      double wid = ell.getWidth() / defaultScale * _symbolSize;
      newShape = new Ellipse2D.Double(-wid/2,  -ht/2, wid, ht);
    }
    else if(theShape instanceof Polygon)
    {
      Polygon helloPoly = (Polygon) theShape;
      
      // retrieve the points
      int[] xp = helloPoly.xpoints;
      int[] yp = helloPoly.ypoints;
      int np = helloPoly.npoints;
      
      // create a new array, to store the data
      int[] newX = new int[np];
      int[] newY = new int[np];
      
      for(int i=0;i<np;i++)
      {
        newX[i] = (int) (((double)xp[i]) / defaultScale * _symbolSize);
        newY[i] = (int) (((double)yp[i]) / defaultScale * _symbolSize);
      }
      
      newShape = new Polygon(newX, newY, np);
    }
    else
    {
      newShape = theShape;
    }
    
    // ok, scale this shape;
    return newShape;
  }

  @Override
  public boolean getItemShapeVisible(int row, int column)
  {
    final XYDataset data = _myPlot.getDataset();

    boolean res = super.getItemShapeVisible(row, column);

    if (data instanceof TimeSeriesCollection)
    {
      final TimeSeriesCollection tsc = (TimeSeriesCollection) data;
      // get the data series
      final TimeSeries bts = tsc.getSeries(row);
      final TimeSeriesDataItem tsdp = bts.getDataItem(column);
      if (tsdp instanceof ColouredDataItem)
      {
        final ColouredDataItem cdi = (ColouredDataItem) tsdp;
        // is the base renderer set to show all
        if (this.getBaseShapesVisible() && cdi.isParentSymVisible())
          res = true;
        else
          res = false;
      }
    }
{'fraction_non_alphanumeric': 0.1163184641445511, 'fraction_numerical': 0.009937888198757764, 'mean_word_length': 2.743026204564666, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3112272', 'n_tokens_mistral': 2839, 'n_tokens_neox': 2722, 'n_words': 751}