1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 google.load("visualization", "1", {packages:["treemap"]});
6 google.setOnLoadCallback(drawChart);
8 var data = google.visualization.arrayToDataTable(g_raw_data);
10 tree = new google.visualization.TreeMap(
11 document.getElementById('chart_div'));
21 maxColorValue: g_maxval,
22 generateTooltip: tooltip
25 // Update from 'Loading'.
26 document.getElementById('title').innerText = g_dllname;
29 var doc_head = document.getElementsByTagName('head')[0];
30 var new_link = document.createElement('link');
31 new_link.rel = 'shortcut icon';
32 new_link.href = 'data:image/png;base64,'+g_favicon;
33 doc_head.appendChild(new_link);
35 var cur_line_sizes = null;
36 function nodeSelect() {
38 var selected = tree.getSelection();
39 if (selected.length > 0) {
40 var filename = data.getValue(selected[0].row, 0);
41 var size = data.getValue(selected[0].row, 2);
44 cur_line_sizes = g_line_data[filename];
45 var body = g_file_contents[filename];
46 editor.setValue(body);
48 for (var line in cur_line_sizes) {
49 maximum_size = Math.max(maximum_size, cur_line_sizes[line][0]);
51 for (var line in cur_line_sizes) {
52 var symbol_indices = cur_line_sizes[line][1];
54 for (var i = 0; i < symbol_indices.length; ++i) {
55 symbols.push(g_symbol_list[symbol_indices[i]]);
57 var size = cur_line_sizes[line][0];
59 var line_num = parseInt(line, 10) - 1;
60 if (size >= maximum_size * 0.9)
61 editor.addLineClass(line_num, 'gutter', 'linebg-top10');
62 else if (size >= maximum_size * 0.75)
63 editor.addLineClass(line_num, 'gutter', 'linebg-top25');
64 else if (size >= maximum_size * 0.5)
65 editor.addLineClass(line_num, 'gutter', 'linebg-top50');
67 var line_num = parseInt(line, 10);
68 var symbols_tooltip = symbols.join('\n');
69 var num_syms = symbols.length;
70 // markText wants 0-based lines.
71 var mark = editor.markText({line: line_num - 1, ch: 0},
72 {line: line_num, ch: 0},
73 { className: 'symbol-tag' });
74 CodeMirror.on(mark, 'beforeCursorEnter', function(e) {
75 symlist.setValue(num_syms +
76 ' symbol(s) contributing to line ' +
86 google.visualization.events.addListener(tree, 'select', nodeSelect);
88 editor = CodeMirror.fromTextArea(
89 document.getElementById('source_view'), {
91 mode: { name: 'text/x-c++src' },
93 lineNumberFormatter: weightGetter
95 editor.setSize(850, 600);
97 symlist = CodeMirror.fromTextArea(
98 document.getElementById('symlist_view'), {
100 mode: { name: 'none' },
103 symlist.setSize(850, 150);
105 function tooltip(row, size, value) {
106 return '<div style="background:#fd9;' +
107 ' padding:10px; border-style:solid"><b>' +
108 data.getValue(row, 0) + '</b><br>' +
109 data.getColumnLabel(2) +
110 ' (total value of this cell and its children): ' + size +
114 function weightGetter(line) {
115 if (cur_line_sizes && cur_line_sizes.hasOwnProperty('' + line)) {
116 return cur_line_sizes['' + line][0] + ' bytes ' + line;