1<!DOCTYPE html>
2<!--
3Copyright (c) 2015 The Chromium Authors. All rights reserved.
4Use of this source code is governed by a BSD-style license that can be
5found in the LICENSE file.
6-->
7
8<link rel="import" href="/tracing/base/color_scheme.html">
9<link rel="import" href="/tracing/ui/base/ui.html">
10<link rel="import" href="/tracing/ui/tracks/chart_axis.html">
11<link rel="import" href="/tracing/ui/tracks/chart_point.html">
12<link rel="import" href="/tracing/ui/tracks/chart_series.html">
13<link rel="import" href="/tracing/ui/tracks/chart_track.html">
14
15<style>
16.power-series-track {
17  height: 90px;
18}
19</style>
20
21<script>
22'use strict';
23
24tr.exportTo('tr.ui.tracks', function() {
25
26  var ColorScheme = tr.b.ColorScheme;
27  var ChartTrack = tr.ui.tracks.ChartTrack;
28
29  /**
30   * A track that displays a PowerSeries.
31   *
32   * @constructor
33   * @extends {ChartTrack}
34   */
35  var PowerSeriesTrack = tr.ui.b.define('power-series-track', ChartTrack);
36
37  PowerSeriesTrack.prototype = {
38    __proto__: ChartTrack.prototype,
39
40    decorate: function(viewport) {
41      ChartTrack.prototype.decorate.call(this, viewport);
42      this.classList.add('power-series-track');
43      this.heading = 'Power';
44      this.powerSeries_ = undefined;
45    },
46
47    set powerSeries(powerSeries) {
48      this.powerSeries_ = powerSeries;
49
50      this.series = this.buildChartSeries_();
51      this.autoSetAllAxes({expandMax: true});
52    },
53
54    get hasVisibleContent() {
55      return (this.powerSeries_ && this.powerSeries_.samples.length > 0);
56    },
57
58    addContainersToTrackMap: function(containerToTrackMap) {
59      containerToTrackMap.addContainer(this.powerSeries_, this);
60    },
61
62    buildChartSeries_: function() {
63      if (!this.hasVisibleContent)
64        return [];
65
66      var axis = new tr.ui.tracks.ChartAxis(0, undefined);
67      var pts = this.powerSeries_.samples.map(function(smpl) {
68        return new tr.ui.tracks.ChartPoint(smpl, smpl.start, smpl.power);
69      });
70      var renderingConfig = {
71        chartType: tr.ui.tracks.ChartSeriesType.AREA,
72        colorId: ColorScheme.getColorIdForGeneralPurposeString(this.heading)
73      };
74
75      return [new tr.ui.tracks.ChartSeries(pts, axis, renderingConfig)];
76    }
77  };
78
79  return {
80    PowerSeriesTrack: PowerSeriesTrack
81  };
82});
83</script>
84