Refactors the power sample table into a separate class.
We're factoring as much logic as possible out of the power sample sub
view. This will allow us to add the per-frame power graph to the sub
view without making the class horrendously complex.
BUG=#1108
R=beaudoin@chromium.org, petrcermak@chromium.org
Review URL: https://codereview.appspot.com/253550043.
diff --git a/tracing/trace_viewer.gypi b/tracing/trace_viewer.gypi
index c7b141e..4972912 100644
--- a/tracing/trace_viewer.gypi
+++ b/tracing/trace_viewer.gypi
@@ -249,6 +249,7 @@
'tracing/ui/analysis/multi_thread_time_slice_sub_view.html',
'tracing/ui/analysis/object_instance_view.html',
'tracing/ui/analysis/object_snapshot_view.html',
+ 'tracing/ui/analysis/power_sample_table.html',
'tracing/ui/analysis/related_events.html',
'tracing/ui/analysis/selection_summary_table.html',
'tracing/ui/analysis/single_async_slice_sub_view.html',
diff --git a/tracing/tracing/ui/analysis/multi_power_sample_sub_view.html b/tracing/tracing/ui/analysis/multi_power_sample_sub_view.html
index 08b28be..95e6452 100644
--- a/tracing/tracing/ui/analysis/multi_power_sample_sub_view.html
+++ b/tracing/tracing/ui/analysis/multi_power_sample_sub_view.html
@@ -1,12 +1,12 @@
<!DOCTYPE html>
<!--
-Copyright (c) 2013 The Chromium Authors. All rights reserved.
+Copyright 2015 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<link rel="import" href="/ui/analysis/analysis_sub_view.html">
-<link rel="import" href="/ui/base/table.html">
+<link rel="import" href="/ui/analysis/power_sample_table.html">
<polymer-element name="tr-ui-a-multi-power-sample-sub-view"
extends="tr-ui-a-sub-view">
@@ -14,65 +14,31 @@
<style>
:host {
display: flex;
- flex-direction: column;
- }
- #table {
- flex: 1 1 auto;
- align-self: stretch;
}
</style>
- <tr-ui-b-table id="table"></tr-ui-b-table>
+ <tr-ui-a-power-sample-table id="table"></tr-ui-a-power-sample-table>
</template>
- <script>
- 'use strict';
-
- Polymer({
- ready: function() {
- this.currentSelection_ = undefined;
-
- this.$.table.tableColumns = [
- {
- title: 'Time',
- width: '150px',
- value: function(row) { return row.start; }
- },
- {
- title: 'Power (mW)',
- width: '100%',
- value: function(row) { return row.power; }
- }
- ];
- },
-
- get selection() {
- return this.currentSelection_;
- },
-
- set selection(selection) {
- this.currentSelection_ = selection;
- this.updateContents_();
- },
-
- updateContents_: function() {
- if (this.currentSelection_ === undefined) {
- this.$.table.rows = [];
- this.$.table.rebuild();
- return;
- }
-
- var powerSamples = this.currentSelection_;
- this.$.table.tableRows = this.getRowsForPowerSamples_(powerSamples);
- this.$.table.rebuild();
- },
-
- getRowsForPowerSamples_: function(powerSamples) {
- return powerSamples.map(function(powerSample) {
- return {
- start: powerSample.start,
- power: powerSample.power
- };
- });
- }
- });
- </script>
</polymer-element>
+
+<script>
+'use strict';
+
+Polymer('tr-ui-a-multi-power-sample-sub-view', {
+ ready: function() {
+ this.currentSelection_ = undefined;
+ },
+
+ get selection() {
+ return this.currentSelection_;
+ },
+
+ set selection(selection) {
+ this.currentSelection_ = selection;
+ this.updateContents_();
+ },
+
+ updateContents_: function() {
+ this.$.table.samples = this.currentSelection_;
+ }
+});
+</script>
diff --git a/tracing/tracing/ui/analysis/multi_power_sample_sub_view_test.html b/tracing/tracing/ui/analysis/multi_power_sample_sub_view_test.html
index 4903f8b..55a755b 100644
--- a/tracing/tracing/ui/analysis/multi_power_sample_sub_view_test.html
+++ b/tracing/tracing/ui/analysis/multi_power_sample_sub_view_test.html
@@ -7,7 +7,6 @@
<link rel="import" href="/model/event_set.html">
<link rel="import" href="/model/model.html">
-<link rel="import" href="/model/power_sample.html">
<link rel="import" href="/model/power_series.html">
<link rel="import" href="/ui/analysis/multi_power_sample_sub_view.html">
@@ -20,7 +19,6 @@
var model = new tr.Model();
var series = new tr.model.PowerSeries(model.device);
model.device.powerSeries = series;
- var selection = new tr.model.EventSet();
series.addPowerSample(0, 1000);
series.addPowerSample(1, 2000);
@@ -28,7 +26,7 @@
series.addPowerSample(3, 4000);
var viewEl = document.createElement('tr-ui-a-multi-power-sample-sub-view');
- viewEl.selection = series.samples;
+ viewEl.selection = new tr.model.EventSet(series.samples);
this.addHTMLOutput(viewEl);
});
});
diff --git a/tracing/tracing/ui/analysis/power_sample_table.html b/tracing/tracing/ui/analysis/power_sample_table.html
new file mode 100644
index 0000000..cc5d85e
--- /dev/null
+++ b/tracing/tracing/ui/analysis/power_sample_table.html
@@ -0,0 +1,57 @@
+<!DOCTYPE html>
+<!--
+Copyright 2015 The Chromium Authors. All rights reserved.
+Use of this source code is governed by a BSD-style license that can be
+found in the LICENSE file.
+-->
+
+<link rel="import" href="/model/event_set.html">
+<link rel="import" href="/ui/base/table.html">
+
+<polymer-element name="tr-ui-a-power-sample-table">
+ <template>
+ <style>
+ :host {
+ display: flex;
+ }
+ </style>
+ <tr-ui-b-table id="table"></tr-ui-b-table>
+ </template>
+</polymer-element>
+
+<script>
+'use strict';
+var EventSet = tr.model.EventSet;
+
+Polymer('tr-ui-a-power-sample-table', {
+ ready: function() {
+ this.$.table.tableColumns = [
+ {
+ title: 'Time',
+ width: '150px',
+ value: function(row) { return row.start; }
+ },
+ {
+ title: 'Power (mW)',
+ width: '100%',
+ value: function(row) { return row.power; }
+ }
+ ];
+ this.samples = new EventSet();
+ },
+
+ get samples() {
+ return this.samples_;
+ },
+
+ set samples(samples) {
+ this.samples_ = (samples === undefined) ? new EventSet() : samples;
+ this.updateContents_();
+ },
+
+ updateContents_: function() {
+ this.$.table.tableRows = this.samples.toArray();
+ this.$.table.rebuild();
+ }
+});
+</script>
diff --git a/tracing/tracing/ui/analysis/power_sample_table_test.html b/tracing/tracing/ui/analysis/power_sample_table_test.html
new file mode 100644
index 0000000..1f36b2c
--- /dev/null
+++ b/tracing/tracing/ui/analysis/power_sample_table_test.html
@@ -0,0 +1,67 @@
+<!DOCTYPE html>
+<!--
+Copyright 2015 The Chromium Authors. All rights reserved.
+Use of this source code is governed by a BSD-style license that can be
+found in the LICENSE file.
+-->
+
+<link rel="import" href="/model/event_set.html">
+<link rel="import" href="/model/model.html">
+<link rel="import" href="/model/power_series.html">
+<link rel="import" href="/ui/analysis/power_sample_table.html">
+
+<script>
+'use strict';
+
+tr.b.unittest.testSuite(function() {
+
+ var EventSet = tr.model.EventSet;
+ var Model = tr.Model;
+ var PowerSeries = tr.model.PowerSeries;
+
+ test('instantiate_undefinedPowerSamples', function() {
+ var table = document.createElement('tr-ui-a-power-sample-table');
+ table.samples = undefined;
+
+ this.addHTMLOutput(table);
+
+ assert.lengthOf(table.$.table.tableRows, 0);
+ });
+
+ test('instantiate_noPowerSamples', function() {
+ var table = document.createElement('tr-ui-a-power-sample-table');
+ table.samples = new EventSet([]);
+
+ this.addHTMLOutput(table);
+
+ assert.lengthOf(table.$.table.tableRows, 0);
+ });
+
+ test('instantiate_onePowerSample', function() {
+ var series = new PowerSeries(new Model().device);
+
+ series.addPowerSample(0, 1000);
+
+ var table = document.createElement('tr-ui-a-power-sample-table');
+ table.samples = new EventSet(series.samples);
+
+ this.addHTMLOutput(table);
+
+ assert.lengthOf(table.$.table.tableRows, 1);
+ });
+
+ test('instantiate_twoPowerSamples', function() {
+ var series = new PowerSeries(new Model().device);
+
+ series.addPowerSample(0, 1000);
+ series.addPowerSample(1, 2000);
+
+ var table = document.createElement('tr-ui-a-power-sample-table');
+ table.samples = new EventSet(series.samples);
+
+ this.addHTMLOutput(table);
+
+ assert.lengthOf(table.$.table.tableRows, 2);
+ });
+});
+</script>