/*
 * This file contains some wrapper functions that help with creating charts
 * (using jqPlot).
 */

function opcat_chart(data_url, id, properties) {

    $.getJSON(data_url, 
        function(data){  
            calweekmhplot = $.jqplot(id, [data.values], {
                    title: data.title, 
                    grid: { borderWidth: 0, gridLineColor: '#dddddd', shadow: false },
                    seriesDefaults:{
                        renderer:$.jqplot.BarRenderer, 
                        rendererOptions:{barPadding: 2, barMargin: 2},
                        shadow: false,
                    },
                    axes:{
                        xaxis:{
                            renderer:$.jqplot.CategoryAxisRenderer,
                            rendererOptions: { tickRenderer: $.jqplot.CanvasAxisTickRenderer },
                            ticks: data.ticks,
                            tickOptions: { angle: -45 },
                        },
                        yaxis: { autoscale:true, min:0, tickOptions:{formatString:'%d'} },
                    },
                    highlighter: {sizeAdjust: 7.5, useAxesFormatters:false, tooltipAxes: 'y'},
                });

        });
}


function simple_bar_chart(data_url, id, properties) {

    $.getJSON(data_url,
        function(data){  
            var plot = $.jqplot(id, [data.values], {
                    title: data.title, 
                    grid: { borderWidth: 0, gridLineColor: '#dddddd', shadow: false },
                    seriesDefaults:{
                        renderer:$.jqplot.BarRenderer, 
                        rendererOptions:{barPadding: 2, barMargin: 2},
                        shadow: false,
                    },
                    axes:{
                        xaxis:{
                            renderer:$.jqplot.CategoryAxisRenderer,
                            rendererOptions: { tickRenderer: $.jqplot.CanvasAxisTickRenderer },
                            ticks: data.ticks,
                            tickOptions: { angle: -90 },
                        },
                        yaxis: { autoscale:true, min:0, tickOptions:{formatString:'%d'} },
                    },
                    highlighter: {sizeAdjust: 7.5, useAxesFormatters:false, tooltipAxes: 'y'},
                });
        });
}

function multi_bar_chart(data_url, id, properties) {

    $.getJSON(data_url,
        function(data){  

            var h_series = [];

            $.each(data.series_labels, function(l, v) {
                h_series.push({label:v});
            });

            var plot = $.jqplot(id, data.values, {
                    title: data.title, 
                    grid: { borderWidth: 0, gridLineColor: '#dddddd', shadow: false },
                    series: h_series,
                    seriesDefaults:{
                        renderer:$.jqplot.BarRenderer, 
                        rendererOptions:{barPadding: 2, barMargin: 2},
                        shadow: false,
                    },
                    legend:{show:true},
                    axes:{
                        xaxis:{
                            renderer:$.jqplot.CategoryAxisRenderer,
                            ticks: data.ticks,
                        },
                        yaxis: { autoscale:true, min:0, tickOptions:{formatString:'%d'} },
                    },
                    highlighter: {sizeAdjust: 7.5, useAxesFormatters:false, tooltipAxes: 'y'},
                });
        });
}


function pie_chart(data_url, id, properties) {

    $.getJSON(data_url,
        function(data){  
            var plot = $.jqplot(id, [data.values], {
                    title: data.title,
                    grid: { borderWidth: 0, gridLineColor: '#dddddd', shadow: false },
                    seriesDefaults:{renderer:$.jqplot.PieRenderer, shadow: false, rendererOptions:{sliceMargin:8}},
                    legend:{show:true}
                });

        });
}
