Roll src/third_party/skia 43315bb:4b195e5
[chromium-blink-merge.git] / tools / perf / utils / results_viewer / src / results_viewer.js
blob06783c4dce23a57e798a58968ba7f69c11b34206
1 /**
2 * Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file.
5 */
6 'use strict';
8 /**
9 * Main entry point for the rendering of the Viewer component.
10 * @param {Event} evt File select event.
12 function handleFileSelectEvent(evt) {
13 var file = evt.target.files[0];
14 var fileReader = new FileReader();
16 fileReader.onload = (function(theFile) {
17 return function(e) {
18 var dataSet = createViewerDataset(e.target.result);
19 var viewer = new Viewer({ownerDocument:window.document});
20 viewer.id = 'csvContentsDataTable';
21 viewer.dataSet = dataSet;
22 viewer.barChartElementId = 'barChart';
23 viewer.render();
25 })(file);
26 fileReader.readAsText(file);
29 /**
30 * Splits the csv file contents, and creates a square array of strings for
31 * each token in the line.
32 * @param fileContents
33 * @return {String[][]} The data set with the contents of the csv file.
35 function createViewerDataset(fileContents) {
36 var rows = fileContents.split('\n');
37 var dataset = [];
38 rows.forEach(function (row, index, array) {
39 if (row.trim().length == 0) {
40 //Ignore empty lines
41 return;
43 var newRow = [];
44 var columns = row.split(',');
45 columns.forEach(function (element, index, array) {
46 newRow.push(element);
47 });
48 dataset.push(newRow);
49 });
50 return dataset;