package vismon.plot;

import vismon.data.DataItem;
import vismon.data.Indicator;
import vismon.data.Session;
import vismon.gui.OverviewPanel;
import vismon.gui.Vismon;

import java.awt.*;
import java.util.List;
import java.util.ArrayList;

public class ProbabilityPlot extends HistogramPlot{

    private Indicator indicator;
    protected List<Integer> probBinHeights;

    public ProbabilityPlot(Indicator indicator) {
        this.indicator = indicator;
        probBinHeights = new ArrayList<Integer>();
        mainColor = Color.LIGHT_GRAY;
    }

    @Override
    public void paint(Graphics g) {
        setBinHeights();
        super.paint(g);
    }

    private void setBinHeights() {
        if (Vismon.getVismonInstance().getOverviewPanel().getDensityFunc() == OverviewPanel.PDF)
            binHeights = probBinHeights;
        else
            binHeights = getCDFBinHeights(probBinHeights);
    }

    public void calcFullfilments() {
        List<Integer> binHeightList = new ArrayList<Integer>();
        double percentGap = 1.0 / pdfBinNumber;
        for (double p = 0; p <= 1; p += percentGap) {
            int binH = 0;
            for (DataItem dataItem : Session.getDataItems())
                if (dataItem.isFullFillsProbability(indicator, p))
                    ++binH;
            binHeightList.add(binH);
        }

        probBinHeights.clear();
        for (int i = 0; i < binHeightList.size(); ++i)
            probBinHeights.add(binHeightList.get(i));
    }

}
