/**
 * Copyright (C) 2005-2012 XELOG AG
 */
package ch.spherIC.recurvebowsight.components;

import android.content.Context;

import android.graphics.Color;

import ch.spherIC.recurvebowsight.R;

import org.achartengine.ChartFactory;
import org.achartengine.GraphicalView;

import org.achartengine.model.XYMultipleSeriesDataset;
import org.achartengine.model.XYSeries;

import org.achartengine.renderer.XYMultipleSeriesRenderer;
import org.achartengine.renderer.XYSeriesRenderer;

import java.text.DecimalFormat;


/**
 * @author  FC Smilari
 */
public class FlightCurveChart {

    private XYMultipleSeriesDataset dataSet;
    private XYMultipleSeriesRenderer mRenderer;

    public GraphicalView getView(final Context context) {

        XYSeries series = new XYSeries("Flight Curve");

        this.dataSet = new XYMultipleSeriesDataset(); // collection of series under one object.,there could any
        this.dataSet.addSeries(series);               // number of series

        //customization of the chart

        XYSeriesRenderer renderer = new XYSeriesRenderer(); // one renderer for one series
        renderer.setColor(Color.RED);
        renderer.setDisplayChartValues(false);
        renderer.setLineWidth(2f);

        this.mRenderer = new XYMultipleSeriesRenderer();
        this.mRenderer.addSeriesRenderer(renderer);
        this.mRenderer.setMargins(new int[] { 60, 80, 60, 60 }); // top, left, bottom, right
        this.mRenderer.setShowLegend(true);
        this.mRenderer.setAntialiasing(true);

        // Beschriftungen
        this.mRenderer.setChartTitle("Flight Curve Graph");
        this.mRenderer.setChartTitleTextSize(30);
        this.mRenderer.setAxisTitleTextSize(30);
        this.mRenderer.setLegendTextSize(30);
        this.mRenderer.setLabelFormat(new DecimalFormat("0.##"));
        this.mRenderer.setLabelsTextSize(15);

        this.mRenderer.setXTitle("Distance [m]");
        this.mRenderer.setXLabels(18); /**/
        this.mRenderer.setXLabelsColor(Color.DKGRAY);

        this.mRenderer.setYTitle("h [m]");
        this.mRenderer.setYLabels(10); /**/
        this.mRenderer.setYLabelsPadding(20);
        this.mRenderer.setYLabelsColor(0, Color.DKGRAY);

        this.mRenderer.setYAxisMin(-0.9);
        this.mRenderer.setYAxisMax(0.9);


        // Zoom ausschalten
        this.mRenderer.setZoomEnabled(false, false);
        this.mRenderer.setZoomButtonsVisible(false);

        // Grid
        this.mRenderer.setShowGridX(true);
        this.mRenderer.setShowGridY(true);
        this.mRenderer.setGridColor(Color.DKGRAY);

        // X/Y-Achsen
        this.mRenderer.setShowAxes(true);
        this.mRenderer.setAxesColor(Color.DKGRAY);

        // Hintergrundfarbe
        this.mRenderer.setApplyBackgroundColor(true);
        this.mRenderer.setBackgroundColor(context.getResources().getColor(R.color.qrt_translucent_white));
        this.mRenderer.setMarginsColor(Color.WHITE);

        // Verschiebungen ausschalten
        this.mRenderer.setPanEnabled(false, false);

        GraphicalView v = ChartFactory.getLineChartView(context, this.dataSet, this.mRenderer);
        return v;
    }

    /**
     * @return  the dataSet
     */
    public XYMultipleSeriesDataset getDataSet() {
        return this.dataSet;
    }

    /**
     * @return  the mRenderer
     */
    public XYMultipleSeriesRenderer getMultiRenderer() {
        return this.mRenderer;
    }
}
