Skip to content

Commit 742520c

Browse files
Embedding Projector: fix gradient color map (#6310)
## Motivation for features / changes Fix errors for gradient color map ## Technical description of changes When colorby gradient metadata is selected the UI currently not working as expected due to multiple errors that causes exceptions/bugs in UI. This fixes: - gradient not getting rendered at all when there are no items - a race condition where the gradient color map would not get rendered - linearGraident children does not get attached - rendering issue with the end label when switching away to a categorical coloring ## Screenshots of UI changes Before: <img width="295" alt="Screenshot 2023-04-17 at 8 53 44 PM" src="https://user-images.githubusercontent.com/31378877/232666984-daee9298-0df5-41c5-9cc3-f98391137c61.png"> After: ![image](https://user-images.githubusercontent.com/31378877/232666802-cfe81b50-ad2d-43f3-a91d-49e0d49302ce.png) ## Detailed steps to verify changes work correctly (as executed by you) Use the default Word2Vec 10k dataset change `color by` from "No Color Map" to `count` ## Alternate designs / implementations considered --------- Co-authored-by: Riley Jones <[email protected]>
1 parent 4f0cd50 commit 742520c

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

tensorboard/plugins/projector/vz_projector/vz-projector-data-panel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ class DataPanel extends LegacyElementMixin(PolymerElement) {
540540
this.showForceCategoricalColorsCheckbox = !!colorOption.tooManyUniqueValues;
541541
if (colorOption.map == null) {
542542
this.colorLegendRenderInfo = null!;
543-
} else if (colorOption.items) {
543+
} else if (colorOption.items?.length) {
544544
let items = colorOption.items.map((item) => {
545545
return {
546546
color: colorOption?.map?.(item.label) as string,

tensorboard/plugins/projector/vz_projector/vz-projector-legend.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class Legend extends LegacyElementMixin(PolymerElement) {
7878
</div>
7979
</template>
8080
81-
<template is="dom-if" if="[[renderInfo.thresholds]]">
81+
<template is="dom-if" if="[[renderInfo.thresholds?.length]]">
8282
<svg class="gradient">
8383
<defs>
8484
<linearGradient
@@ -105,14 +105,14 @@ class Legend extends LegacyElementMixin(PolymerElement) {
105105
if (this.renderInfo == null) {
106106
return;
107107
}
108-
if (this.renderInfo.thresholds) {
108+
if (this.renderInfo.thresholds?.length) {
109109
// <linearGradient> is under dom-if so we should wait for it to be
110110
// inserted in the dom tree using async().
111-
this.async(() => this.setupLinearGradient());
111+
this.async(() => this.setupLinearGradient(), 150);
112112
}
113113
}
114114
_getLastThreshold(): number | undefined {
115-
if (this.renderInfo == null || this.renderInfo.thresholds == null) {
115+
if (this.renderInfo == null || !this.renderInfo.thresholds?.length) {
116116
return;
117117
}
118118
return this.renderInfo.thresholds[this.renderInfo.thresholds.length - 1]
@@ -139,6 +139,7 @@ class Legend extends LegacyElementMixin(PolymerElement) {
139139
);
140140
stopElement.setAttribute('offset', this.getOffset(t.value));
141141
stopElement.setAttribute('stop-color', t.color);
142+
linearGradient.appendChild(stopElement);
142143
});
143144
}
144145
}

0 commit comments

Comments
 (0)