summaryrefslogtreecommitdiff
path: root/query/chart_port_downtime.js
blob: 2de421d2ecebb4319ddbdbba4111aacd2667f37a (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
function GrasChartPortDowntime(args, panel)
{
    //input checking
    if (args.block_ids.length != 1) throw gras_error_dialog(
        "GrasChartPortDowntime",
        "Error making port downtime chart.\n"+
        "Specify only one block for this chart."
    );

    //save enable
    this.block_id = args.block_ids[0];

    //make new chart
    this.chart = new google.visualization.PieChart(panel);

    this.title = "Port Downtime - " + this.block_id;
    this.default_width = GRAS_CHARTS_STD_WIDTH;
}

GrasChartPortDowntime.prototype.update = function(point)
{
    var block_data = point.blocks[this.block_id];
    if (!block_data) return;

    var raw_data = new Array();
    raw_data.push(['Port', 'Percent']); //key

    //now add input and output port data
    $.each(block_data.inputs_idle, function(index, downtime)
    {
        raw_data.push(['Input'+index.toString(), downtime/block_data.tps]);
    });
    $.each(block_data.outputs_idle, function(index, downtime)
    {
        raw_data.push(['Output'+index.toString(), downtime/block_data.tps]);
    });

    //update the chart from raw data
    var data = google.visualization.arrayToDataTable(raw_data);
    var options = {
        chartArea:{left:5,top:0,right:5,bottom:0,width:"100%",height:"100%"},
    };
    if (this.gc_resize) options.width = 50;
    if (this.gc_resize) options.height = 50;

    this.chart.draw(data, options);
};