aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/tensorboard/components/tf-histogram-dashboard/tf-histogram-dashboard.html
blob: 8f8f159964228ea576fb239e42b1987178be2d2e (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
<link rel="import" href="../../bower_components/polymer/polymer.html">
<link rel="import" href="../tf-event-dashboard/tf-data-coordinator.html">
<link rel="import" href="../tf-event-dashboard/tf-tooltip-coordinator.html">
<link rel="import" href="../tf-event-dashboard/tf-run-selector.html">
<link rel="import" href="../tf-event-dashboard/tf-x-type-selector.html">
<link rel="import" href="../tf-dashboard-common/tf-run-generator.html">
<link rel="import" href="../tf-event-dashboard/tf-color-scale.html">
<link rel="import" href="../tf-dashboard-common/tf-url-generator.html">
<link rel="import" href="../tf-dashboard-common/tf-dashboard-layout.html">
<link rel="import" href="../tf-dashboard-common/dashboard-style.html">
<link rel="import" href="../tf-dashboard-common/warning-style.html">
<link rel="import" href="../tf-categorizer/tf-categorizer.html">
<link rel="import" href="../tf-event-dashboard/tf-chart.html">
<link rel="import" href="../tf-collapsable-pane/tf-collapsable-pane.html">
<link rel="import" href="../../bower_components/iron-collapse/iron-collapse.html">
<link rel="import" href="../../bower_components/paper-icon-button/paper-icon-button.html">
<link rel="import" href="../imports/lodash.html">

<!--
tf-histogram-dashboard is a complete frontend that loads runs from a backend,
and creates chart panes that display data for those runs.

It provides a categorizer, run selector, and x type selector, by which the user
can customize how data is organized and displayed.

Each chart has a button that can toggle whether it is "selected"; selectedRuns
charts are larger.

Organizationally, the #plumbing div contains components that have no concrete
manifestation and just effect data bindings or data loading. The #sidebar contains
shared controls like the tf-categorizer, tf-run-selector, and tf-x-type-selector.
The #center div contains tf-charts embedded inside tf-collapsable-panes.
-->
<dom-module id="tf-histogram-dashboard">
  <template>
    <div id="plumbing">
      <tf-url-generator
        out-runs-url="{{runsUrl}}"
        out-compressed-histograms-url-generator="{{compressedHistogramsUrlGen}}"
        id="urlGenerator"
      ></tf-url-generator>

      <tf-data-coordinator
        id="dataCoordinator"
        url-generator="[[compressedHistogramsUrlGen]]"
        run-to-tag="[[runToCompressedHistograms]]"
        color-scale="[[colorScale]]"
        out-data-coordinator="{{dataCoordinator}}"
      /></tf-data-coordinator>

      <tf-run-generator
        id="runGenerator"
        url="[[runsUrl]]"
        out-run-to-compressed-histograms="{{runToCompressedHistograms}}"
      /></tf-run-generator>

      <tf-color-scale
        id="colorScale"
        runs="[[_runs]]"
        out-color-scale="{{colorScale}}"
        out-class-scale="{{classScale}}"
      ></tf-color-scale>

      <tf-tooltip-coordinator
        id="tooltipCoordinator"
        out-tooltip-updater="{{tooltipUpdater}}"
        out-tooltip-map="{{tooltipMap}}"
        out-x-value="{{tooltipXValue}}"
        out-closest-run="{{closestRun}}"
      ></tf-tooltip-coordinator>
    </div>

    <tf-dashboard-layout>
      <div class="sidebar">

        <tf-categorizer
          id="categorizer"
          tags="[[_visibleTags]]"
          categories="{{categories}}"
        ></tf-categorizer>

        <tf-x-type-selector
          id="xTypeSelector"
          out-x-type="{{xType}}"
        ></tf-x-type-selector>

        <tf-run-selector
          id="runSelector"
          runs="[[_runs]]"
          class-scale="[[classScale]]"
          out-selected="{{selectedRuns}}"
          tooltips="[[tooltipMap]]"
          closest-run="[[closestRun]]"
          x-value="[[tooltipXValue]]"
          x-type="[[xType]]"
        ></tf-run-selector>

      </div>

      <div class="center">
        <template is="dom-if" if="[[!categories.length]]">
          <div class="warning">
            <p>
              No histogram tags were found.
            </p>
            <p>
              Maybe data hasn't loaded yet, or maybe you need
              to add some <code>tf.histogram_summary</code> ops to your graph, and
              serialize them using the <code>tf.training.summary_io.SummaryWriter</code>.
            </p>
          </div>
        </template>
        <template is="dom-repeat" items="[[categories]]">
          <tf-collapsable-pane name="[[item.name]]" count="[[_count(item.tags, selectedRuns.*, runToCompressedHistograms.*)]]">
            <div class="layout horizontal wrap">
              <template is="dom-repeat" items="[[item.tags]]" as="tag">
                <template is="dom-repeat" items="[[selectedRuns]]" as="run">
                  <template is="dom-if" if="[[_exists(run, tag, runToCompressedHistograms.*)]]">
                    <div class="card">
                      <span class="card-title">[[tag]]</span>
                      <div class="card-content">
                        <tf-chart
                          tag="[[tag]]"
                          type="compressedHistogram"
                          id="chart"
                          selected-runs="[[_array(run)]]"
                          x-type="[[xType]]"
                          data-coordinator="[[dataCoordinator]]"
                          color-scale="[[colorScale]]"
                          on-keyup="toggleSelected"
                          tabindex="2"
                          tooltip-updater="[[tooltipUpdater]]"
                        ></tf-chart>
                        <paper-icon-button
                          class="expand-button"
                          icon="fullscreen"
                          on-tap="toggleSelected"
                        ></paper-icon-button>
                      </div>
                    </div>
                  </template>
                </template>
              </template>
            </div>
          </tf-collapsable-pane>
        </template>
      </div>
    </tf-dashboard-layout>

    <style include="dashboard-style"></style>
    <style include="warning-style"></style>
  </template>

  <script>
    Polymer({
      is: "tf-histogram-dashboard",
      properties: {
        _runs: {
          type: Array,
          computed: "_getRuns(runToCompressedHistograms)",
        },
        _visibleTags: {
          type: Array,
          computed: "_getVisibleTags(selectedRuns.*, runToCompressedHistograms.*)"
        }
      },
      _exists: function(run, tag, runToCompressedHistogramsChange) {
        var runToCompressedHistograms = runToCompressedHistogramsChange.base;
        return runToCompressedHistograms[run].indexOf(tag) !== -1;
      },
      _array: function(x) {
        return [x];
      },
      _count: function(tags, selectedRunsChange, runToCompressedHistogramsChange) {
        var selectedRuns = selectedRunsChange.base;
        var runToCompressedHistograms = runToCompressedHistogramsChange.base;
        var targetTags = {};
        tags.forEach(function(t) {
          targetTags[t] = true;
        });
        var count = 0;
        selectedRuns.forEach(function(r) {
          runToCompressedHistograms[r].forEach(function(t) {
            if (targetTags[t]) {
              count++;
            }
          });
        });
        return count;
      },
      _getRuns: function(runToCompressedHistograms) {
        return _.keys(runToCompressedHistograms);
      },
      _getVisibleTags: function(selectedRunsChange, runToCompressedHistogramsChange) {
        var keys = selectedRunsChange.base;
        var dict = runToCompressedHistogramsChange.base;
        return _.union.apply(null, keys.map(function(k) {return dict[k]}));
      },
      toggleSelected: function(e) {
        var currentTarget = Polymer.dom(e.currentTarget);
        var parentDiv = currentTarget.parentNode.parentNode;
        parentDiv.classList.toggle("selected");
        var chart = currentTarget.previousElementSibling;
        if (chart) {
          chart.redraw();
        }
      },
    });
  </script>
</dom-module>