summaryrefslogtreecommitdiff
path: root/python/gras/stats/chart_factory.js
blob: 1c49717f97c0cffdfe5f59de8798f7398f07f5f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/***********************************************************************
 * One time setup
 **********************************************************************/
function gras_chart_factory_setup(registry)
{
    if (registry.history.length != 1) return;
    var id = $('gras_stats:first', registry.history[0]).attr('id');
    $('#top_name').append(' - ' + id);
    $.each(registry.getBlockIds(), function(index, id)
    {
        var div = $('.chart_designer_blocks').get(index%2);
        $(div).append('<label>' + id + '</label>');
        var input = $('<input />').attr({
            type: 'checkbox',
            name: id
        });
        input.attr('checked', false);
        $(div).append(input);
    });
}

/***********************************************************************
 * chart factory registry (filled in init)
 **********************************************************************/
var gras_chart_factory_registry = new Array();
var gras_chart_active_registry = new Array();

/***********************************************************************
 * chart factory dispatcher
 **********************************************************************/
function gras_chart_factory_dispatcher()
{
    //step 1) get a list of the selected blocks
    var selected_blocks = new Array();
    $.each($('.chart_designer_blocks > :input'), function(index, input)
    {
        var input = $(input);
        if (input.is(':checked'))
        {
            selected_blocks.push(input.attr('name'));
        }
    });

    //step 2) get the type of chart to create
    var chart_type = $('#chart_type_selector').val();

    //step 3) create the chart given options

    //create containers
    var chart_box = $('<table />').attr({class:'chart_container'});
    var tr = $('<tr />');
    var td = $('<td />');
    tr.append(td);

    //call into the factory
    var chart = new gras_chart_factory_registry[chart_type]({
        block_ids:selected_blocks,
        panel:td.get(0),
    });

    //setup the title
    var tr_title = $('<tr />');
    var th_title = $('<th />');
    tr_title.append(th_title);
    th_title.text(chart.title);

    //register the chart
    gras_chart_active_registry.push(chart);
    $('#charts_panel').append(chart_box);

    //finish gui building
    chart_box.append(tr_title);
    chart_box.append(tr);
}

/***********************************************************************
 * chart factory init
 **********************************************************************/
function gras_chart_factory_init()
{
    //install callback for chart factory
    $('#chart_factory_button').click(gras_chart_factory_dispatcher);

    //list of all known chart types
    var chart_options = [
        {key:'overhead_compare', name:'Overhead Compare', factory:GrasChartOverheadCompare},
        {key:'overall_throughput', name:'Overall Throughput', factory:GrasChartOverallThroughput},
        {key:'handler_breakdown', name:'Handler Breakdown', factory:GrasChartHandlerBreakdown},
    ];

    //init the chart selection input
    $.each(chart_options, function(index, options)
    {
        gras_chart_factory_registry[options.key] = options.factory;
        var option = $('<option />').attr({value: options.key});
        option.text(options.name);
        $('#chart_type_selector').append(option);
    });
}