summaryrefslogtreecommitdiffstats
path: root/src/benchmark_template.html
blob: 11efd924263b355e8bc3e91c34e4035cc9aeaff8 (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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
		<title>Title</title>
        <! Javascript Here>
	
        	<script type="text/javascript">

function offsetLabels(labels, offset)
{
    var copy = new Array();
    for (key in labels) {
        copy[key] = new Array(labels[key][0] + 0.25, labels[key][1]);
    }
    return copy;
}

function createLogDataSet(inDataSet)
{
    var logDataSet  = {};
    logDataSet.label = inDataSet.label;
    logDataSet.data = [];

    if (!inDataSet.data)
        return logDataSet;

    var length = inDataSet.data.length;
    
    for (var i = 0; i < length; i++) {
        logDataSet.data[i] = [];
        logDataSet.data[i][0] = inDataSet.data[i][0];
        logDataSet.data[i][1] = Math.log(inDataSet.data[i][1]);
    }
    return logDataSet;
}


function createLogData(inData)
{
    var logData  = [];

    // foreach data set;
    var length = inData.length;
    for (var i = 0; i < length; ++i) {
        logData[i] = createLogDataSet(inData[i]);
    }
    return logData;
}

function createChart() {
//    alert("create chart" + this.chartId)

    var dataSet;

    if (this.useLinearScale)
        dataSet = this.selectedDataset;
    else 
        dataSet = createLogData(this.selectedDataset);

    if (this.useLineChart) {
        var f = Flotr.draw($(this.chartId), 
            dataSet,
            { legend:{ backgroundColor: '#D2E8FF' } 
            , xaxis: { ticks: this.labels, noTicks : 10 }
             , mouse: { 
                 track: true,
                 lineColor: 'purple',
                 sensibility: 1, 
                 trackDecimals: 2,
                 trackFormatter: function(obj){ return 'x = ' + obj.x +', y = ' + obj.y; }
	         }
            });
        
    } else {
        var f = Flotr.draw($(this.chartId), 
            dataSet,
            { legend:{ backgroundColor: '#D2E8FF'}
            ,  bars: { show: true, lineWidth: 1, barWidth: this.barWidth } 
            , xaxis: { ticks: offsetLabels(this.labels, chartOptions.tickOffset), noTicks : 10 }
            });
    }
}

function checkform()
{
//    alert("check form " + this.form.id + " " + this.chartId);    
    var field = this.form.list

    // Apparently list of lenght one is not a list...
    // Display the entire chart if there is only one data series.
    if (!field.length) {
        this.createChart();    
        return;
    }

    this.selectedDataset = [];
    var data = [];
    var index = 0;

    for (i = 0; i < field.length; i++) {
        if (field[i].checked == true) {
            this.selectedDataset[index++] = this.dataset[i];
        } else {
            this.selectedDataset[index++] = [];
        }
    }
    this.createChart();
}

function createFormSelector(form, value, text, type)
{
  var selector = document.createElement('input');
  form.appendChild(selector);
  selector.type = type;
  selector.name = 'list';
  selector.defaultChecked = true;
  selector.value = value;

  form.appendChild(document.createTextNode(text));
  form.appendChild(document.createElement("BR"));
}

function createCheckBox(form, value, text)
{
    createFormSelector(form, value, text, "checkbox");
}

function createRadioButton(form, value, text)
{
    createFormSelector(form, value, text, "radio");
}

function buildSeriesSelector(form, chartOptions)
{
//    alert("form" + form.id + " " + chartOptions.chartId);
    var series = chartOptions.seriesLabels;
    form.onclick = function() { /*alert("fn " + chartOptions.chartId);*/ chartOptions.checkform() };
    for (s = 0; s < series.length; ++s) {
        createCheckBox(form, s, series[s]);
    }
}

function buildChartTypeSelector()
{
    createRadioButton(this.chartTypeForm, 0, "Bar Chart");
    createRadioButton(this.chartTypeForm, 1, "Line Chart");
    
    var field = this.chartTypeForm.list;
    if (this.useLineChart)
        field[1].checked = true;
    else
        field[0].checked = true;

    var chartOptions = this;
    this.chartTypeForm.onclick = function() { 
        var field = chartOptions.chartTypeForm.list;

        chartOptions.useLineChart = (field[1].checked == true);
        chartOptions.checkform();
    };
}

function buildScaleSelector()
{
    createRadioButton(this.scaleForm, 0, "Linear Scale");
    createRadioButton(this.scaleForm, 1, "Logarithmic  Scale");
    
    var field = this.scaleForm.list;
    field[0].checked = true;
    field[1].checked = false;

    var chartOptions = this;
    this.scaleForm.onclick = function() { 
        var field = chartOptions.scaleForm.list;

        chartOptions.useLinearScale = (field[0].checked == true);
        chartOptions.checkform();
    };
}


		</script>
	</head>
	<body>
        <h2>
        <! Title Here>
        </h2>
        <! Description Here>
        <! Chart Here>
	</body>
</html>