aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/tensorboard/components/tf-tensorboard/tf-tensorboard.html
blob: 4a1925714551466cd96db69fdf2605e8dd1733c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
<!--
@license
Copyright 2016 The TensorFlow Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../iron-icons/iron-icons.html">
<link rel="import" href="../paper-tabs/paper-tabs.html">
<link rel="import" href="../paper-dialog/paper-dialog.html">
<link rel="import" href="../paper-checkbox/paper-checkbox.html">
<link rel="import" href="../paper-toolbar/paper-toolbar.html">
<link rel="import" href="../paper-button/paper-button.html">
<link rel="import" href="../paper-header-panel/paper-header-panel.html">
<link rel="import" href="../tf-globals/tf-globals.html">
<link rel="import" href="../tf-event-dashboard/tf-event-dashboard.html">
<link rel="import" href="../tf-distribution-dashboard/tf-distribution-dashboard.html">
<link rel="import" href="../tf-histogram-dashboard/tf-histogram-dashboard.html">
<link rel="import" href="../tf-image-dashboard/tf-image-dashboard.html">
<link rel="import" href="../tf-audio-dashboard/tf-audio-dashboard.html">
<link rel="import" href="../tf-graph-dashboard/tf-graph-dashboard.html">
<link rel="import" href="../tf-dashboard-common/tensorboard-color.html">
<link rel="import" href="../tf-backend/tf-backend.html">
<link rel="import" href="../tf-storage/tf-storage.html">

<!--
tf-tensorboard is the frontend entry point for TensorBoard.

It implements a toolbar (via paper-header-panel and paper-toolbar) that
allows the user to toggle between various dashboards.
-->
<script src="autoReloadBehavior.js"></script>
<dom-module id="tf-tensorboard">
  <template>
    <paper-dialog with-backdrop id="settings">
      <h2>Settings</h2>
      <paper-checkbox id="auto-reload-checkbox" checked="{{autoReloadEnabled}}">
        Reload data every <span>[[autoReloadIntervalSecs]]</span>s.
      </paper-checkbox>
    </paper-dialog>
    <paper-header-panel>
      <paper-toolbar id="toolbar">
        <div id="toolbar-content">
          <div class="toolbar-title">TensorBoard</div>
          <paper-tabs selected="{{modeIndex}}" noink class="tabs" id="tabs">
            <template is="dom-repeat" items="[[tabs]]">
              <paper-tab data-mode="[[item]]">[[item]]</paper-tab>
            </template>
          </paper-tabs>
          <div class="global-actions">
            <paper-icon-button
              icon="refresh"
              on-tap="reload"
              disabled$="[[_modeIsGraphs(mode)]]"
              id="reload-button"
            ></paper-icon-button>
            <paper-icon-button
              icon="settings"
              on-tap="openSettings"
              id="settings-button"
            ></paper-icon-button>
            <a href="https://github.com/tensorflow/tensorflow/blob/master/tensorflow/tensorboard/README.md" tabindex="-1">
              <paper-icon-button icon="help-outline"></paper-icon-button>
            </a>
          </div>
        </div>
      </paper-toolbar>

      <div id="content" class="fit">
        <content id="injected-overview"></content>

        <template is="dom-if" if="[[_modeIsEvents(mode)]]">
          <tf-event-dashboard
            id="events"
            backend="[[_backend]]"
            router="[[router]]"
          ></tf-event-dashboard>
        </template>

        <template is="dom-if" if="[[_modeIsImages(mode)]]">
          <tf-image-dashboard
            id="images"
            backend="[[_backend]]"
          ></tf-image-dashboard>
        </template>

        <template is="dom-if" if="[[_modeIsAudio(mode)]]">
          <tf-audio-dashboard
            id="audio"
            backend="[[_backend]]"
          ></tf-audio-dashboard>
        </template>

        <template is="dom-if" if="[[_modeIsGraphs(mode)]]">
          <tf-graph-dashboard
            id="graphs"
            backend="[[_backend]]"
          ></tf-graph-dashboard>
        </template>

        <template is="dom-if" if="[[_modeIsDistributions(mode)]]">
          <tf-distribution-dashboard
            id="distributions"
            backend="[[_backend]]"
          ></tf-distribution-dashboard>
        </template>

        <template is="dom-if" if="[[_modeIsHistograms(mode)]]">
          <tf-histogram-dashboard
            id="histograms"
            backend="[[_backend]]"
          ></tf-histogram-dashboard>
        </template>
      </div>
    </paper-header-panel>

    <style>
      :host {
        height: 100%;
        display: block;
        background-color: var(--paper-grey-100);
      }

      #toolbar {
        background-color: var(--tb-toolbar-background-color, --tb-orange-strong);
        -webkit-font-smoothing: antialiased;
      }

      .toolbar-title {
        font-size: 20px;
        margin-left: 10px;
        text-rendering: optimizeLegibility;
        letter-spacing: -0.025em;
        font-weight: 500;
        flex-grow: 2;
        display: var(--tb-toolbar-title-display, block);
      }

      .tabs {
        flex-grow: 1;
        text-transform: uppercase;
        height: 100%;
      }

      paper-tabs {
        --paper-tabs-selection-bar-color: white;
      }

      .global-actions {
        flex-grow: 2;
        display: inline-flex; /* Ensure that icons stay aligned */
        justify-content: flex-end;
        text-align: right;
        color: white;
      }

      .global-actions a {
        color: white;
      }

      #toolbar-content {
        width: 100%;
        height: 100%;
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
      }

      #content {
        height: 100%;
      }

      [disabled] {
        opacity: 0.2;
        color: white;
      }

    </style>
  </template>
  <script>
    Polymer({
      is: "tf-tensorboard",
      behaviors: [TF.TensorBoard.AutoReloadBehavior],
      properties: {
        router: {
          type: Object,
          value: function() {
            return TF.Backend.router();
          },
        },
        _backend: {
          type: Object,
          computed: "_makeBackend(router, demoDir)",
        },
        // Which tab is selected (events, graph, images etc).
        mode: {
          type: String,
          computed: '_getModeFromIndex(modeIndex)',
          notify: true,
        },
        tabs: {
          type: Array,
          readOnly: true,
          value: TF.Globals.TABS,
        },
        // If this is set to a string, TensorBoard will switch to "demo mode"
        // and attempt to load serialized json data from that directory. You can
        // generate conformant json using
        // tensorboard/scripts/serialize_tensorboard.py
        demoDir: {
          type: String,
          value: null,
        },
        // Set this to true to store state in URI hash. Should be true for all non-test purposes.
        useHash: {
          type: Boolean,
          value: false,
        },
      },
      _getModeFromIndex: function(modeIndex) {
        var mode = this.tabs[modeIndex];
        TF.URIStorage.setString(TF.URIStorage.TAB, mode);
        return mode;
      },
      _makeBackend: function(router, demoDir) {
        // use the demoDir if it is set, otherwise use the provided router
        if (demoDir != null) {
          router = TF.Backend.router(demoDir, true);
        }
        return new TF.Backend.Backend(router);
      },
      _modeIsEvents: function(mode) {
        return mode === "events";
      },
      _modeIsImages: function(mode) {
        return mode === "images";
      },
      _modeIsAudio: function(mode) {
        return mode === "audio";
      },
      _modeIsGraphs: function(mode) {
        return mode === "graphs";
      },
      _modeIsDistributions: function(mode) {
        return mode === "distributions";
      },
      _modeIsHistograms: function(mode) {
        return mode === "histograms";
      },
      selectedDashboard: function() {
        var dashboard = this.$$("#" + this.mode);
        if (dashboard == null) {
          throw new Error(`Unable to find dashboard for mode: ${this.mode}`);
        }
        return dashboard;
      },
      ready: function() {
        TF.Globals.USE_HASH = this.useHash;

        this._getModeFromHash();
        window.addEventListener('hashchange', function() {
          this._getModeFromHash();
        }.bind(this));
      },
      _getModeFromHash: function() {
        var tabName = TF.URIStorage.getString(TF.URIStorage.TAB);
        var modeIndex = this.tabs.indexOf(tabName);
        if (modeIndex == -1 && this.modeIndex == null) {
          // Select the first tab as default.
          this.set('modeIndex', 0);
        }
        if (modeIndex != -1 && modeIndex != this.modeIndex) {
          this.set('modeIndex', modeIndex);
        }
      },
      reload: function() {
        if (this.mode === "graphs") {
          return;
        }
        this.selectedDashboard().reload();
      },
      openSettings: function() {
        this.$.settings.open();
      },
    });
  </script>
</dom-module>