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/ui/tracks/container_track.html">
9<link rel="import" href="/tracing/ui/tracks/power_series_track.html">
10<link rel="import" href="/tracing/ui/tracks/spacing_track.html">
11
12<script>
13'use strict';
14
15tr.exportTo('tr.ui.tracks', function() {
16
17  var ContainerTrack = tr.ui.tracks.ContainerTrack;
18
19  // TODO(charliea): Make this track collapsible.
20  /**
21   * Track to visualize the device model.
22   *
23   * @constructor
24   * @extends {ContainerTrack}
25   */
26  var DeviceTrack = tr.ui.b.define('device-track', ContainerTrack);
27
28  DeviceTrack.prototype = {
29
30    __proto__: ContainerTrack.prototype,
31
32    decorate: function(viewport) {
33      ContainerTrack.prototype.decorate.call(this, viewport);
34
35      this.classList.add('device-track');
36      this.device_ = undefined;
37      this.powerSeriesTrack_ = undefined;
38    },
39
40    get device() {
41      return this.device_;
42    },
43
44    set device(device) {
45      this.device_ = device;
46      this.updateContents_();
47    },
48
49    get powerSeriesTrack() {
50      return this.powerSeriesTrack_;
51    },
52
53    get hasVisibleContent() {
54      return (this.powerSeriesTrack_ &&
55          this.powerSeriesTrack_.hasVisibleContent);
56    },
57
58    addContainersToTrackMap: function(containerToTrackMap) {
59      tr.ui.tracks.ContainerTrack.prototype.addContainersToTrackMap.call(
60        this, containerToTrackMap);
61      containerToTrackMap.addContainer(this.device, this);
62    },
63
64    addEventsToTrackMap: function(eventToTrackMap) {
65      this.tracks_.forEach(function(track) {
66        track.addEventsToTrackMap(eventToTrackMap);
67      });
68    },
69
70    appendPowerSeriesTrack_: function() {
71      this.powerSeriesTrack_ = new tr.ui.tracks.PowerSeriesTrack(this.viewport);
72      this.powerSeriesTrack_.powerSeries = this.device.powerSeries;
73
74      if (this.powerSeriesTrack_.hasVisibleContent) {
75        this.appendChild(this.powerSeriesTrack_);
76        this.appendChild(new tr.ui.tracks.SpacingTrack(this.viewport));
77      }
78    },
79
80    updateContents_: function() {
81      this.clearTracks_();
82      this.appendPowerSeriesTrack_();
83    }
84  };
85
86  return {
87    DeviceTrack: DeviceTrack
88  };
89});
90</script>
91