Skip to content

Commit a5e7c68

Browse files
authored
Fixed some shrunk histogram issue (#1465)
Repro step --- 1. launch with an empty tag regex 2. type a character (that'd result in few matches) then delete it quickly 3. after few moment, type the character again Cause --- dom-if has issue where if="false" does not remove the DOM but rather simply hides the slot. https://github.com/Polymer/polymer/blob/1.x/src/lib/template/dom-if.html#L127 While the pane is briefly shown in step #2, histogram-loader fetches data and before it has chance to draw the series, dom-if can hide the DOM. As data comes back, histogram tries to draw based on the bounding box that is shrunken to 0x0 since its container is no longer displayed. To work around these issues, we now listen to category-pane show event to redraw all histogram.
1 parent 7eeb09b commit a5e7c68

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

tensorboard/components/tf_categorization_utils/tf-category-pane.html

+19-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
<dom-module id="tf-category-pane">
2222
<template>
23-
<template is="dom-if" if="[[_rendered]]">
23+
<template is="dom-if" if="[[_rendered]]" id="ifRendered">
2424
<button class="heading"
2525
on-tap="_togglePane"
2626
open-button$="[[opened]]">
@@ -52,7 +52,7 @@
5252
</button>
5353
<iron-collapse opened="[[opened]]">
5454
<div class="content">
55-
<template is="dom-if" if="[[opened]]" restamp="[[restamp]]">
55+
<template is="dom-if" if="[[opened]]" id="ifOpened">
5656
<slot></slot>
5757
</template>
5858
</div>
@@ -172,6 +172,23 @@
172172
},
173173
},
174174

175+
listeners: {
176+
// Q: Why listen to dom-change when you know which property change
177+
// triggered dom-if to change?
178+
// A: https://github.com/Polymer/polymer/blob/1.x/src/lib/template/dom-if.html#L131
179+
// `render` in dom-if is debounced and visibility of content does not
180+
// change until it has been invoked.
181+
'dom-change': '_notifyVisibilityChange',
182+
},
183+
184+
_notifyVisibilityChange(event) {
185+
if (event.target.id == 'ifRendered' ||
186+
event.target.id == 'ifOpened') {
187+
this.fire(
188+
'content-visibility-changed', this._rendered && this.opened);
189+
}
190+
},
191+
175192
_computeCount() {
176193
return this.category.items.length;
177194
},

tensorboard/plugins/histogram/tf_histogram_dashboard/tf-histogram-dashboard.html

+19-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,11 @@ <h3>No histogram data was found.</h3>
9191
<template is="dom-if" if="[[!_dataNotFound]]">
9292
<tf-tag-filterer tag-filter="{{_tagFilter}}"></tf-tag-filterer>
9393
<template is="dom-repeat" items="[[_categories]]" as="category">
94-
<tf-category-pane category="[[category]]" opened="[[_shouldOpen(index)]]">
94+
<tf-category-pane
95+
category="[[category]]"
96+
opened="[[_shouldOpen(index)]]"
97+
restamp="[[_restamp]]"
98+
>
9599
<tf-paginated-view
96100
items="[[category.items]]"
97101
pages="{{category._pages}}"
@@ -148,6 +152,10 @@ <h3>No histogram data was found.</h3>
148152
_runToTagInfo: Object,
149153
_dataNotFound: Boolean,
150154
_tagFilter: String,
155+
_restamp: {
156+
type: Boolean,
157+
value: false,
158+
},
151159

152160
// Categories must only be computed after _dataNotFound is found to be
153161
// true and then polymer DOM templating responds to that finding. We
@@ -165,6 +173,16 @@ <h3>No histogram data was found.</h3>
165173
},
166174
},
167175

176+
listeners: {
177+
'content-visibility-changed': '_redrawCategoryPane',
178+
},
179+
180+
_redrawCategoryPane(event, val) {
181+
if (!val) return;
182+
event.target.querySelectorAll('tf-histogram-loader')
183+
.forEach(histogram => histogram.redraw());
184+
},
185+
168186
ready() {
169187
this.reload();
170188
},

0 commit comments

Comments
 (0)