Skip to content

Commit 7b6c1a6

Browse files
committed
Move supervise by to projection panel
initialize input fix lint bookmark
1 parent b72d751 commit 7b6c1a6

File tree

6 files changed

+134
-144
lines changed

6 files changed

+134
-144
lines changed

tensorboard/plugins/projector/vz_projector/data.ts

+3
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,9 @@ export class State {
668668
tSNEIteration: number = 0;
669669
tSNEPerplexity: number = 0;
670670
tSNELearningRate: number = 0;
671+
tSNESuperviseFactor: number = 0;
672+
tSNESuperviseInput: string;
673+
tSNESuperviseColumn: string;
671674
tSNEis3d: boolean = true;
672675
/** UMAP parameters */
673676
umapIs3d: boolean = true;

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

-35
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ export const template = html`
122122
}
123123
124124
.metadata-editor,
125-
.supervise-settings,
126125
.colorlabel-container {
127126
display: flex;
128127
}
@@ -140,15 +139,6 @@ export const template = html`
140139
display: none;
141140
}
142141
143-
.supervise-settings paper-dropdown-menu {
144-
width: 100px;
145-
margin-right: 10px;
146-
}
147-
148-
.supervise-settings paper-input {
149-
width: calc(100% - 110px);
150-
}
151-
152142
.metadata-editor paper-dropdown-menu {
153143
width: 100px;
154144
margin-right: 10px;
@@ -354,31 +344,6 @@ export const template = html`
354344
</template>
355345
</div>
356346
<template is="dom-if" if="[[_hasChoice(labelOptions)]]">
357-
<!-- Supervise by -->
358-
<div hidden$="[[!showSuperviseSettings]]" class="supervise-settings">
359-
<paper-dropdown-menu no-animations label="Supervise with">
360-
<paper-listbox
361-
attr-for-selected="value"
362-
class="dropdown-content"
363-
on-selected-item-changed="superviseColumnChanged"
364-
selected="{{superviseColumn}}"
365-
slot="dropdown-content"
366-
>
367-
<template is="dom-repeat" items="[[metadataFields]]">
368-
<paper-item value="[[item]]" label="[[item]]">
369-
[[item]]
370-
</paper-item>
371-
</template>
372-
</paper-listbox>
373-
</paper-dropdown-menu>
374-
<paper-input
375-
value="{{superviseInput}}"
376-
label="{{superviseInputLabel}}"
377-
on-change="superviseInputChange"
378-
on-input="superviseInputTyping"
379-
>
380-
</paper-input>
381-
</div>
382347
<!-- Edit by -->
383348
<div class="metadata-editor">
384349
<paper-dropdown-menu no-animations label="Edit by">

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

+1-90
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,7 @@ import {PolymerElement} from '@polymer/polymer';
1717
import '../../../components/polymer/irons_and_papers';
1818
import {LegacyElementMixin} from '../../../components/polymer/legacy_element_mixin';
1919
import * as d3 from '../../../webapp/third_party/d3';
20-
import {
21-
ColorOption,
22-
ColumnStats,
23-
Projection,
24-
SpriteAndMetadataInfo,
25-
} from './data';
20+
import {ColorOption, ColumnStats, SpriteAndMetadataInfo} from './data';
2621
import {
2722
DataProvider,
2823
EmbeddingInfo,
@@ -63,22 +58,13 @@ class DataPanel extends LegacyElementMixin(PolymerElement) {
6358
metadataEditorColumn: string;
6459
@property({type: Boolean})
6560
metadataEditorButtonDisabled: boolean;
66-
@property({type: String})
67-
superviseInput: string;
68-
@property({type: String})
69-
superviseInputLabel: string = 'Ignored label';
70-
@property({type: String})
71-
superviseColumn: string;
72-
@property({type: Boolean})
73-
showSuperviseSettings: boolean = false;
7461

7562
@property({type: String})
7663
readonly _wordDelimiter = '[/=_,-]';
7764

7865
private labelOptions: string[];
7966
private colorOptions: ColorOption[];
8067
forceCategoricalColoring: boolean = false;
81-
private superviseInputSelected: string;
8268
private selectedPointIndices: number[];
8369
private neighborsOfFirstPoint: knn.NearestEntry[];
8470
private dataProvider: DataProvider;
@@ -97,7 +83,6 @@ class DataPanel extends LegacyElementMixin(PolymerElement) {
9783
ready() {
9884
super.ready();
9985
this.normalizeData = true;
100-
this.superviseInputSelected = '';
10186
}
10287
initialize(projector: any, dp: DataProvider) {
10388
this.projector = projector;
@@ -180,27 +165,6 @@ class DataPanel extends LegacyElementMixin(PolymerElement) {
180165
// Make the default label the first non-numeric column.
181166
this.metadataEditorColumn = this.metadataFields[Math.max(0, labelIndex)];
182167
}
183-
if (
184-
this.superviseColumn == null ||
185-
this.metadataFields.filter((name) => name === this.superviseColumn)
186-
.length === 0
187-
) {
188-
// Make the default supervise class the first non-numeric column.
189-
this.superviseColumn = this.metadataFields[Math.max(0, labelIndex)];
190-
this.superviseInput = '';
191-
}
192-
this.superviseInputChange();
193-
}
194-
projectionChanged(projection: Projection) {
195-
if (projection) {
196-
switch (projection.projectionType) {
197-
case 'tsne':
198-
this.set('showSuperviseSettings', true);
199-
break;
200-
default:
201-
this.set('showSuperviseSettings', false);
202-
}
203-
}
204168
}
205169
onProjectorSelectionChanged(
206170
selectedPointIndices: number[],
@@ -381,59 +345,6 @@ class DataPanel extends LegacyElementMixin(PolymerElement) {
381345
anyDownloadMetadataLink.click();
382346
}
383347
}
384-
private superviseInputTyping() {
385-
let value = this.superviseInput.trim();
386-
if (value == null || value.trim() === '') {
387-
if (this.superviseInputSelected === '') {
388-
this.superviseInputLabel = 'No ignored label';
389-
} else {
390-
this.superviseInputLabel = `Supervising without '${this.superviseInputSelected}'`;
391-
}
392-
return;
393-
}
394-
if (this.projector && this.projector.dataSet) {
395-
let numMatches = this.projector.dataSet.points.filter(
396-
(p) => p.metadata[this.superviseColumn].toString().trim() === value
397-
).length;
398-
if (numMatches === 0) {
399-
this.superviseInputLabel = 'Label not found';
400-
} else {
401-
if (this.projector.dataSet.superviseInput != value) {
402-
this.superviseInputLabel = `Supervise without '${value}' [${numMatches} points]`;
403-
}
404-
}
405-
}
406-
}
407-
private superviseInputChange() {
408-
let value = this.superviseInput.trim();
409-
if (value == null || value.trim() === '') {
410-
this.superviseInputSelected = '';
411-
this.superviseInputLabel = 'No ignored label';
412-
this.setSupervision(this.superviseColumn, '');
413-
return;
414-
}
415-
if (this.projector && this.projector.dataSet) {
416-
let numMatches = this.projector.dataSet.points.filter(
417-
(p) => p.metadata[this.superviseColumn].toString().trim() === value
418-
).length;
419-
if (numMatches === 0) {
420-
this.superviseInputLabel = `Supervising without '${this.superviseInputSelected}'`;
421-
} else {
422-
this.superviseInputSelected = value;
423-
this.superviseInputLabel = `Supervising without '${value}' [${numMatches} points]`;
424-
this.setSupervision(this.superviseColumn, value);
425-
}
426-
}
427-
}
428-
private superviseColumnChanged() {
429-
this.superviseInput = '';
430-
this.superviseInputChange();
431-
}
432-
private setSupervision(superviseColumn: string, superviseInput: string) {
433-
if (this.projector && this.projector.dataSet) {
434-
this.projector.dataSet.setSupervision(superviseColumn, superviseInput);
435-
}
436-
}
437348
setNormalizeData(normalizeData: boolean) {
438349
this.normalizeData = normalizeData;
439350
}

tensorboard/plugins/projector/vz_projector/vz-projector-projections-panel.html.ts

+38
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,19 @@ export const template = html`
8787
margin-bottom: -8px;
8888
}
8989
90+
.supervise-settings {
91+
display: flex;
92+
}
93+
94+
.supervise-settings paper-dropdown-menu {
95+
width: 100px;
96+
margin-right: 10px;
97+
}
98+
99+
.supervise-settings paper-input {
100+
width: calc(100% - 110px);
101+
}
102+
90103
#z-container {
91104
display: flex;
92105
align-items: center;
@@ -379,6 +392,31 @@ export const template = html`
379392
</paper-slider>
380393
<span></span>
381394
</div>
395+
<!-- Supervise by -->
396+
<div class="supervise-settings">
397+
<paper-dropdown-menu no-animations label="Supervise with">
398+
<paper-listbox
399+
attr-for-selected="value"
400+
class="dropdown-content"
401+
on-selected-item-changed="superviseColumnChanged"
402+
selected="{{superviseColumn}}"
403+
slot="dropdown-content"
404+
>
405+
<template is="dom-repeat" items="[[metadataFields]]">
406+
<paper-item value="[[item]]" label="[[item]]">
407+
[[item]]
408+
</paper-item>
409+
</template>
410+
</paper-listbox>
411+
</paper-dropdown-menu>
412+
<paper-input
413+
value="{{superviseInput}}"
414+
label="{{superviseInputLabel}}"
415+
on-change="superviseInputChange"
416+
on-input="superviseInputTyping"
417+
>
418+
</paper-input>
419+
</div>
382420
<p>
383421
<button class="run-tsne ink-button" title="Re-run t-SNE">
384422
Run

0 commit comments

Comments
 (0)