|
20 | 20 | <paper-toolbar id="toolbar">
|
21 | 21 | <div id="toolbar-content">
|
22 | 22 | <div class="toolbar-title">TensorBoard</div>
|
23 |
| - <paper-tabs selected="0" noink class="tabs" id="tabs"> |
24 |
| - <paper-tab data-mode="events" on-click="changeMode">Events</paper-tab> |
25 |
| - <paper-tab data-mode="images" on-click="changeMode">Images</paper-tab> |
26 |
| - <paper-tab data-mode="graphs" on-click="changeMode">Graph</paper-tab> |
27 |
| - <paper-tab data-mode="histograms" on-click="changeMode">Histograms</paper-tab> |
| 23 | + <paper-tabs selected="{{modeIndex}}" noink class="tabs" id="tabs"> |
| 24 | + <paper-tab data-mode="events">Events</paper-tab> |
| 25 | + <paper-tab data-mode="images">Images</paper-tab> |
| 26 | + <paper-tab data-mode="graphs">Graph</paper-tab> |
| 27 | + <paper-tab data-mode="histograms">Histograms</paper-tab> |
28 | 28 | </paper-tabs>
|
29 | 29 | </div>
|
30 | 30 | </paper-toolbar>
|
|
111 | 111 | type: Object,
|
112 | 112 | value: TF.Urls.productionRouter(),
|
113 | 113 | },
|
| 114 | + // Which tab is selected (events, graph, images etc). |
114 | 115 | mode: {
|
115 | 116 | type: String,
|
116 |
| - value: "events", |
| 117 | + computed: '_getModeFromIndex(modeIndex)' |
117 | 118 | },
|
| 119 | + // If true, tab switching in TensorBoard will not update |
| 120 | + // location hash. Hash update interferes with selenium tests. |
| 121 | + noHash: { |
| 122 | + type: Boolean, |
| 123 | + value: false |
| 124 | + } |
118 | 125 | },
|
119 |
| - changeMode: function(ev) { |
120 |
| - var mode = ev.target.parentElement.getAttribute('data-mode'); |
121 |
| - this._changeMode(mode, true); |
| 126 | + _getModeFromIndex: function(modeIndex) { |
| 127 | + var mode = this.tabs[modeIndex]; |
| 128 | + if (!this.noHash) { |
| 129 | + window.location.hash = mode; |
| 130 | + } |
| 131 | + return mode; |
122 | 132 | },
|
123 | 133 | eventDashboard: function(mode) {
|
124 | 134 | return mode === "events";
|
|
132 | 142 | histogramDashboard: function(mode) {
|
133 | 143 | return mode === "histograms";
|
134 | 144 | },
|
135 |
| - loadPreviousMode: function() { |
136 |
| - this._changeMode(this._getMode(), false); |
137 |
| - }, |
138 | 145 | ready: function() {
|
139 |
| - this._changeMode(this._getMode(), true); |
140 |
| - |
141 |
| - var self = this; |
142 |
| - window.addEventListener('hashchange', function(){ |
143 |
| - self.loadPreviousMode(); |
| 146 | + this.tabs = [].slice.call(this.querySelectorAll('paper-tab')).map(function(a) { |
| 147 | + return a.dataset.mode; |
144 | 148 | });
|
| 149 | + this._getModeFromHash(); |
| 150 | + window.addEventListener('hashchange', function() { |
| 151 | + this._getModeFromHash(); |
| 152 | + }.bind(this)); |
145 | 153 | },
|
146 |
| - _changeMode: function(mode, isNewState) { |
147 |
| - this.mode = mode; |
148 |
| - |
149 |
| - // Change the selected tab |
150 |
| - this.$.tabs.selected = this._tabs().indexOf(mode); |
151 |
| - |
152 |
| - if (isNewState){ |
153 |
| - window.location.hash = mode; |
154 |
| - } |
155 |
| - }, |
156 |
| - _getMode: function() { |
| 154 | + _getModeFromHash: function() { |
157 | 155 | // Return the mode as it is stored in the hash.
|
158 |
| - // If no mode can be found, default to the first tab. |
159 |
| - var hash = window.location.hash; |
160 |
| - return hash.length > 0 ? hash.slice(1, hash.length) : this._tabs()[0]; |
161 |
| - }, |
162 |
| - _tabs: function() { |
163 |
| - var elts = Array.prototype.slice.call(this.querySelectorAll('paper-tab')); |
164 |
| - return elts.map(function(elt){ return elt.getAttribute('data-mode')}); |
| 156 | + var tabName = window.location.hash.trim().slice(1); |
| 157 | + var modeIndex = this.tabs.indexOf(tabName); |
| 158 | + if (modeIndex == -1 && this.modeIndex == null) { |
| 159 | + // Selecting the first tab as default. |
| 160 | + this.set('modeIndex', 0); |
| 161 | + } |
| 162 | + if (modeIndex != -1 && modeIndex != this.modeIndex) { |
| 163 | + this.set('modeIndex', modeIndex); |
| 164 | + } |
165 | 165 | },
|
166 | 166 | });
|
167 | 167 | </script>
|
|
0 commit comments