package net.sf.jasperreports.charts.util;

import java.util.Map;
import org.jfree.chart.labels.StandardXYItemLabelGenerator;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.data.xy.XYDataset;

public class TimeSeriesLabelGenerator extends StandardXYItemLabelGenerator {
  private static final long serialVersionUID = 10200L;
  
  private Map labelsMap = null;
  
  public TimeSeriesLabelGenerator(Map labelsMap) {
    this.labelsMap = labelsMap;
  }
  
  public String generateLabel(XYDataset dataset, int series, int item) {
    Comparable seriesName = dataset.getSeriesKey(series);
    Map labels = (Map)this.labelsMap.get(seriesName);
    if (labels != null)
      return (String)labels.get(((TimeSeriesCollection)dataset).getSeries(series).getTimePeriod(item)); 
    return super.generateLabel(dataset, series, item);
  }
}
