3 # Copyright 2013 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
9 from string import Template
15 <script type='text/javascript' src='https://www.google.com/jsapi'></script>
16 <script type='text/javascript'>
17 google.load('visualization', '1', {packages:['corechart', 'table']});
18 google.setOnLoadCallback(drawVisualization);
19 function drawVisualization() {
20 var data = google.visualization.arrayToDataTable(
26 vAxis: {title: 'Timestamp', titleTextStyle: {color: 'red'}},
30 var chart = new google.visualization.BarChart(
31 document.getElementById('chart_div'));
32 chart.draw(data, charOptions);
34 var table = new google.visualization.Table(
35 document.getElementById('table_div'));
41 <div id='chart_div' style="width: 1024px; height: 800px;"></div>
42 <div id='table_div' style="width: 1024px; height: 640px;"></div>
47 def _GenerateGraph(json_data, policy):
48 legends = list(json_data['policies'][policy]['legends'])
49 legends = ['second'] + legends[legends.index('FROM_HERE_FOR_TOTAL') + 1:
50 legends.index('UNTIL_HERE_FOR_TOTAL')]
52 for snapshot in json_data['policies'][policy]['snapshots']:
53 data.append([0] * len(legends))
54 for k, v in snapshot.iteritems():
56 data[-1][legends.index(k)] = v
57 print Template(_HTML_TEMPLATE).safe_substitute(
58 {'JSON_ARRAY': json.dumps([legends] + data)})
62 _GenerateGraph(json.load(file(argv[1], 'r')), argv[2])
65 if __name__ == '__main__':
66 sys.exit(main(sys.argv))