Skip to content

Commit 90e1f22

Browse files
groszewnJamesHollyer
authored andcommitted
Fix projector legend point coloring (#6021)
Fixes a regression where sprites are shown as black squares when first loaded and when any sprite is deselected. This ultimately stemmed from a null check (which colored the legend point white when null) being passed over when `strictNullChecks` was introduced. This allows `legendPointColorer` to take a null value. If `colorOption` does not exist, it doesn't make sense to still go over the full dataSet color assignment. Instead, return early to get `noSelectionColor`. Googlers, see b/255947072.
1 parent 5210ce3 commit 90e1f22

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

tensorboard/plugins/projector/vz_projector/projectorScatterPlotAdapter.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export class ProjectorScatterPlotAdapter {
8888
private neighborsOfFirstSelectedPoint: knn.NearestEntry[];
8989
private renderLabelsIn3D: boolean = false;
9090
private labelPointAccessor: string | null;
91-
private legendPointColorer: (ds: DataSet, index: number) => string;
91+
private legendPointColorer: ((ds: DataSet, index: number) => string) | null;
9292
private distanceMetric: DistanceFunction;
9393
private spriteVisualizer: ScatterPlotVisualizerSprites;
9494
private labels3DVisualizer: ScatterPlotVisualizer3DLabels;
@@ -176,7 +176,7 @@ export class ProjectorScatterPlotAdapter {
176176
this.scatterPlot.render();
177177
}
178178
setLegendPointColorer(
179-
legendPointColorer: (ds: DataSet, index: number) => string
179+
legendPointColorer: ((ds: DataSet, index: number) => string) | null
180180
) {
181181
this.legendPointColorer = legendPointColorer;
182182
}
@@ -477,7 +477,7 @@ export class ProjectorScatterPlotAdapter {
477477
}
478478
generateLineSegmentColorMap(
479479
ds: DataSet,
480-
legendPointColorer: (ds: DataSet, index: number) => string
480+
legendPointColorer: ((ds: DataSet, index: number) => string) | null
481481
): {
482482
[polylineIndex: number]: Float32Array;
483483
} {
@@ -566,7 +566,7 @@ export class ProjectorScatterPlotAdapter {
566566
}
567567
generatePointColorArray(
568568
ds: DataSet,
569-
legendPointColorer: (ds: DataSet, index: number) => string,
569+
legendPointColorer: ((ds: DataSet, index: number) => string) | null,
570570
distFunc: DistanceFunction,
571571
selectedPointIndices: number[],
572572
neighborsOfFirstPoint: knn.NearestEntry[],

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,10 @@ class Projector
465465
}
466466
private getLegendPointColorer(
467467
colorOption: ColorOption
468-
): (ds: DataSet, index: number) => string {
468+
): ((ds: DataSet, index: number) => string) | null {
469+
if (colorOption == null || colorOption.map == null) {
470+
return null;
471+
}
469472
const colorer = (ds: DataSet, i: number) => {
470473
let value = ds.points[i].metadata[this.selectedColorOption.name];
471474
if (value == null) {

0 commit comments

Comments
 (0)