package com.adonis.ui.renta;

import at.downdrown.vaadinaddons.highchartsapi.Colors;
import at.downdrown.vaadinaddons.highchartsapi.HighChart;
import at.downdrown.vaadinaddons.highchartsapi.HighChartFactory;
import at.downdrown.vaadinaddons.highchartsapi.model.ChartConfiguration;
import at.downdrown.vaadinaddons.highchartsapi.model.ChartType;
import at.downdrown.vaadinaddons.highchartsapi.model.data.PieChartData;
import at.downdrown.vaadinaddons.highchartsapi.model.series.PieChartSeries;
import com.adonis.data.service.PersonService;
import com.adonis.data.service.RentaHistoryService;
import com.adonis.data.service.VehicleService;
import com.vaadin.navigator.View;
import com.vaadin.navigator.ViewChangeListener;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.HorizontalLayout;

/**
 * Created by oksdud on 12.04.2017.
 */
public class RentaChartView extends CustomComponent implements View {

    public static final String NAME =  "RENTA CHART VIEW";
    PersonService service;
    RentaHistoryService rentaHistoryService;
    VehicleService vehicleService;
    // The view root layout
    HorizontalLayout viewLayout = new HorizontalLayout();
    ChartConfiguration rentaConfiguration = new ChartConfiguration();

    public RentaChartView(PersonService personService, RentaHistoryService rentaHistoryService, VehicleService vehicleService){
        this.service = personService;
        this.rentaHistoryService = rentaHistoryService;
        this.vehicleService = vehicleService;
        setSizeFull();
        rentaConfiguration.setTitle("TestRenta");
        rentaConfiguration.setChartType(ChartType.PIE);
        rentaConfiguration.setBackgroundColor(Colors.WHITE);
        Double working = Double.valueOf(rentaHistoryService.findAllWorking().size());
        Double active = Double.valueOf(vehicleService.findAllActive().size());
        Double all = Double.valueOf(vehicleService.findAll().size());
        Double notActive = all - active;
        PieChartSeries pieVehicles = new PieChartSeries("Vehicles");
        PieChartData workingVehicles = new PieChartData("Working", Double.valueOf((working/all)*100));
        PieChartData notWorkingVehicles = new PieChartData("Not working", Double.valueOf(((active-working)/all)*100));
        PieChartData notActiveVehicles = new PieChartData("Not active", Double.valueOf((notActive/all)*100));
        pieVehicles.getData().add(workingVehicles);
        pieVehicles.getData().add(notActiveVehicles);
        pieVehicles.getData().add(notWorkingVehicles);


        rentaConfiguration.getSeriesList().add(pieVehicles);
        try {
            HighChart pieChart = HighChartFactory.renderChart(rentaConfiguration);
            pieChart.setHeight(80, Unit.PERCENTAGE);
            pieChart.setWidth(80, Unit.PERCENTAGE);
            System.out.println("PieChart Script : " + rentaConfiguration.getHighChartValue());
            viewLayout.addComponent(pieChart);
            viewLayout.setComponentAlignment(pieChart, Alignment.MIDDLE_CENTER);
        } catch (Exception e) {
            e.printStackTrace();
        }
        viewLayout.setSizeFull();
        setCompositionRoot(viewLayout);

    }

    @Override
    public void enter(ViewChangeListener.ViewChangeEvent event) {

    }
}

@@ -1995,16 +1995,51 @@
 active;%0A
+        if(!all.equals(0.0)) %7B%0A    
         
@@ -2095,24 +2095,28 @@
 Vehicles%22);%0A
+    
         PieC
@@ -2193,29 +2193,37 @@
 (working
-/
+ / 
 all)
-*
+ * 
 100));%0A
+    
         
@@ -2315,17 +2315,19 @@
 tive
--
+ - 
 working)
 /all
@@ -2322,29 +2322,37 @@
 working)
-/
+ / 
 all)
-*
+ * 
 100));%0A
+    
         
@@ -2444,14 +2444,18 @@
 tive
-/
+ / 
 all)
-*
+ * 
 100)
@@ -2457,32 +2457,36 @@
  100));%0A        
+   
+ 
 pieVehicles.getD
@@ -2505,32 +2505,36 @@
 rkingVehicles);%0A
+    
         pieVehic
@@ -2571,32 +2571,36 @@
 icles);%0A        
+   
+ 
 pieVehicles.getD
@@ -2632,16 +2632,20 @@
 les);%0A%0A%0A
+    
         
@@ -2709,14 +2709,22 @@
     
+   
+ 
 try %7B%0A
+    
     
@@ -2806,32 +2806,36 @@
 n);%0A            
+   
+ 
 pieChart.setHeig
@@ -2863,32 +2863,36 @@
 E);%0A            
+    
 pieChart.setWidt
@@ -2927,16 +2927,20 @@
         
+   
+ 
 System.o
@@ -3018,32 +3018,36 @@
 ));%0A            
+    
 viewLayout.addCo
@@ -3069,32 +3069,36 @@
 t);%0A            
+   
+ 
 viewLayout.setCo
@@ -3158,16 +3158,20 @@
         
+    
 %7D catch 
@@ -3198,16 +3198,20 @@
         
+   
+ 
 e.printS
@@ -3219,24 +3219,38 @@
 ackTrace();%0A
+            %7D%0A
         %7D%0A  

add clases