
package de.ivu.elect.jee.presentation.charts;

import org.primefaces.model.chart.BarChartModel;
import org.primefaces.model.chart.ChartSeries;
import org.primefaces.model.chart.LegendPlacement;

public class BarChartModelBuilder extends AbstractChartModelBuilder<BarChartModel, BarChartModelBuilder> {

  private final BarChartModel model = new BarChartModel();

  public BarChartModelBuilder() {
    super();

    // model.getAxis(AxisType.Y).setMin(0);
    model.setLegendPosition(LEGEND_POSITION_EAST);
    model.setLegendPlacement(LegendPlacement.OUTSIDEGRID);
    model.setAnimate(true);
    model.setShowDatatip(false);
    model.setShadow(true);
    model.setLegendCols(1);
    model.setShowPointLabels(false);
  }

  @Override
  protected void addValue(String label, Number data) {
    ChartSeries chartSeries = new ChartSeries();
    chartSeries.setLabel(label);
    chartSeries.set(" ", data);

    model.addSeries(chartSeries);

    if (model.getSeries().size() % 10 == 0) {
      model.setLegendCols(model.getLegendCols() + 1);
    }
  }

  @Override
  protected BarChartModel getModel() {
    return model;
  }
}
