package org.navalplanner.web.montecarlo;

import java.math.BigDecimal;
import java.util.Map;

import org.joda.time.LocalDate;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zul.CategoryModel;
import org.zkoss.zul.Chart;
import org.zkoss.zul.SimpleCategoryModel;


/**
 * @author Diego Pino Garcia <dpino@igalia.com>
 *
 */
@Component
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class MonteCarloGraphController extends GenericForwardComposer {

    private Chart monteCarloChart;

    public MonteCarloGraphController() {

    }

    public void doAfterCompose(org.zkoss.zk.ui.Component comp) throws Exception {
        super.doAfterCompose(comp);
        self.setVariable("monteCarloGraphController", this, true);
    }

    public void onCancel(Event event) {
        cancel();
    }

    public void cancel() {
        self.setVisible(false);
    }

    public void generateMonteCarloGraph(String orderName, Map<LocalDate, BigDecimal> data) {
        CategoryModel xymodel = new SimpleCategoryModel();

        for (LocalDate each: data.keySet()) {
            String labelDate = each.toString();
            xymodel.setValue(orderName, labelDate, data.get(each));
        }
        monteCarloChart.setModel(xymodel);
    }

}

@@ -81,19 +81,177 @@
 va.util.
-Map
+ArrayList;%0Aimport java.util.Collections;%0Aimport java.util.Comparator;%0Aimport java.util.HashMap;%0Aimport java.util.List;%0Aimport java.util.Map;%0Aimport java.util.Set
 ;%0A%0Aimpor
@@ -1382,16 +1382,111 @@
 del();%0A%0A
+        List%3CLocalDate%3E dates = new ArrayList(data.keySet());%0A        Collections.sort(dates);%0A
         
@@ -1509,26 +1509,18 @@
 ach: dat
-a.keySet()
+es
 ) %7B%0A    

Fix bug sort MonterCarloGraph by date