Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 59 additions & 66 deletions tensorboard/webapp/widgets/data_table/data_table_component.ng.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,74 +12,67 @@
limitations under the License.
-->

<div>
<table class="data-table">
<thead>
<tr>
<th>
<!-- This header is intentionally left blank for the color column -->
</th>
<ng-container *ngFor="let header of headers;">
<th *ngIf="showColumn(header)" (click)="headerClicked(header.name)">
<div
[draggable]="columnCustomizationEnabled"
(dragstart)="dragStart(header)"
(dragend)="dragEnd()"
(dragenter)="dragEnter(header)"
class="cell"
[ngClass]="getHeaderHighlightStyle(header.name)"
>
<tb-data-table-header [header]="header"></tb-data-table-header>
<div class="data-table">
<div class="header">
<div class="col"></div>
<ng-container *ngFor="let header of headers;">
<div
class="col"
*ngIf="showColumn(header)"
(click)="headerClicked(header.name)"
>
<div
[draggable]="columnCustomizationEnabled"
(dragstart)="dragStart(header)"
(dragend)="dragEnd()"
(dragenter)="dragEnter(header)"
class="cell"
[ngClass]="getHeaderHighlightStyle(header.name)"
>
<tb-data-table-header [header]="header"></tb-data-table-header>

<div class="sorting-icon-container">
<mat-icon
*ngIf="sortingInfo.order === SortingOrder.ASCENDING || header.name !== sortingInfo.name"
[ngClass]="header.name === sortingInfo.name ? 'show' : 'show-on-hover'"
svgIcon="arrow_upward_24px"
></mat-icon>
<mat-icon
*ngIf="sortingInfo.order === SortingOrder.DESCENDING && header.name === sortingInfo.name"
[ngClass]="header.name === sortingInfo.name ? 'show' : 'show-on-hover'"
svgIcon="arrow_downward_24px"
></mat-icon>
</div>
</div>
</th>
</ng-container>
</tr>
</thead>
<tbody>
<ng-container *ngFor="let runData of data;">
<tr class="row">
<td class="row-circle">
<span [style.backgroundColor]="runData['color']"></span>
</td>
<ng-container *ngFor="let header of headers;">
<td *ngIf="showColumn(header)" [ngSwitch]="header.type">
<div *ngSwitchCase="ColumnHeaders.VALUE_CHANGE" class="cell">
<ng-container
*ngTemplateOutlet="arrow; context: {$implicit:runData[header.name]}"
></ng-container>
{{ getFormattedDataForColumn(header.type, runData[header.name])
}}
</div>
<div *ngSwitchCase="ColumnHeaders.PERCENTAGE_CHANGE" class="cell">
<ng-container
*ngTemplateOutlet="arrow; context: {$implicit:runData[header.name]}"
></ng-container>
{{ getFormattedDataForColumn(header.type, runData[header.name])
}}
</div>
<div *ngSwitchDefault class="cell extra-right-padding">
{{ getFormattedDataForColumn(header.type, runData[header.name])
}}
</div>
</td>
</ng-container>
</tr>
<div class="sorting-icon-container">
<mat-icon
*ngIf="sortingInfo.order === SortingOrder.ASCENDING || header.name !== sortingInfo.name"
[ngClass]="header.name === sortingInfo.name ? 'show' : 'show-on-hover'"
svgIcon="arrow_upward_24px"
></mat-icon>
<mat-icon
*ngIf="sortingInfo.order === SortingOrder.DESCENDING && header.name === sortingInfo.name"
[ngClass]="header.name === sortingInfo.name ? 'show' : 'show-on-hover'"
svgIcon="arrow_downward_24px"
></mat-icon>
</div>
</div>
</div>
</ng-container>
</div>
<ng-container *ngFor="let runData of data;">
<div class="row">
<div class="col row-circle">
<span [style.backgroundColor]="runData['color']"></span>
</div>
<ng-container *ngFor="let header of headers;">
<div class="col" *ngIf="showColumn(header)" [ngSwitch]="header.type">
<div *ngSwitchCase="ColumnHeaders.VALUE_CHANGE" class="cell">
<ng-container
*ngTemplateOutlet="arrow; context: {$implicit:runData[header.name]}"
></ng-container>
{{ getFormattedDataForColumn(header.type, runData[header.name]) }}
</div>
<div *ngSwitchCase="ColumnHeaders.PERCENTAGE_CHANGE" class="cell">
<ng-container
*ngTemplateOutlet="arrow; context: {$implicit:runData[header.name]}"
></ng-container>
{{ getFormattedDataForColumn(header.type, runData[header.name]) }}
</div>
<div *ngSwitchDefault class="cell extra-right-padding">
{{ getFormattedDataForColumn(header.type, runData[header.name]) }}
</div>
</div>
</ng-container>
</tbody>
</table>
</div>
</ng-container>
</div>
<ng-template #arrow let-value>
<mat-icon *ngIf="value >= 0" svgIcon="arrow_upward_24px"></mat-icon>
Expand Down
46 changes: 27 additions & 19 deletions tensorboard/webapp/widgets/data_table/data_table_component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,24 @@ $_accent: map-get(mat.get-color-config($tb-theme), accent);
.data-table {
border-spacing: 4px;
font-size: 13px;
display: table;
width: 100%;

th {
.header,
.row {
display: table-row;
}

.col {
display: table-cell;
}

.header {
background-color: mat.get-color-from-palette($tb-background, background);
position: sticky;
text-align: left;
top: 0;
font-weight: bold;
vertical-align: bottom;

&:hover {
Expand All @@ -36,38 +47,39 @@ $_accent: map-get(mat.get-color-config($tb-theme), accent);
@include tb-dark-theme {
background-color: map-get($tb-dark-background, background);
}
.col:hover .show-on-hover {
opacity: 0.3;
}

.col {
vertical-align: bottom;
}
}

.cell {
align-items: center;
display: flex;
.col {
padding: 1px;
}

.extra-right-padding {
// Add artificial padding to keep consistent with icons which have whitespace
padding-right: 1px;
}

.row {
white-space: nowrap;
}

$_circle-size: 12px;

.row-circle {
align-items: center;
display: inline-flex;
height: $_circle-size;
width: $_circle-size;
}

.row-circle > span {
border-radius: 50%;
border: 1px solid rgba(255, 255, 255, 0.4);
display: inline-block;
// Subtract by border width (1px on both sides)
height: $_circle-size - 2px;
width: $_circle-size - 2px;
vertical-align: middle;
}

.cell {
align-items: center;
display: flex;
}

.cell mat-icon {
Expand All @@ -89,10 +101,6 @@ $_accent: map-get(mat.get-color-config($tb-theme), accent);
opacity: 0;
}

th:hover .show-on-hover {
opacity: 0.3;
}

.highlight {
background-color: mat.get-color-from-palette(mat.$gray-palette, 200);
}
Expand Down
44 changes: 31 additions & 13 deletions tensorboard/webapp/widgets/data_table/data_table_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ describe('data table', () => {
],
});
fixture.detectChanges();
const headerElements = fixture.debugElement.queryAll(By.css('th'));
const headerElements = fixture.debugElement.queryAll(
By.css('.header > .col')
);

// The first header should always be blank as it is the run color column.
expect(headerElements[0].nativeElement.innerText).toBe('');
Expand Down Expand Up @@ -258,7 +260,7 @@ describe('data table', () => {
],
});
fixture.detectChanges();
const dataElements = fixture.debugElement.queryAll(By.css('td'));
const dataElements = fixture.debugElement.queryAll(By.css('.row > .col'));

// The first header should always be blank as it is the run color column.
expect(dataElements[0].nativeElement.innerText).toBe('');
Expand Down Expand Up @@ -321,8 +323,10 @@ describe('data table', () => {
],
});
fixture.detectChanges();
const headerElements = fixture.debugElement.queryAll(By.css('th'));
const dataElements = fixture.debugElement.queryAll(By.css('td'));
const headerElements = fixture.debugElement.queryAll(
By.css('.header > .col')
);
const dataElements = fixture.debugElement.queryAll(By.css('.row > .col'));

// The first header should always be blank as it is the run color column.
expect(headerElements[0].nativeElement.innerText).toBe('');
Expand Down Expand Up @@ -366,7 +370,7 @@ describe('data table', () => {
data: [{id: 'someid'}],
});
fixture.detectChanges();
const dataElements = fixture.debugElement.queryAll(By.css('td'));
const dataElements = fixture.debugElement.queryAll(By.css('.row > .col'));

// The first header should always be blank as it is the run color column.
expect(dataElements[0].nativeElement.innerText).toBe('');
Expand Down Expand Up @@ -406,7 +410,9 @@ describe('data table', () => {
],
});
fixture.detectChanges();
const headerElements = fixture.debugElement.queryAll(By.css('th'));
const headerElements = fixture.debugElement.queryAll(
By.css('.header > .col')
);

headerElements[3].triggerEventHandler('click', {});
expect(sortDataBySpy).toHaveBeenCalledOnceWith({
Expand Down Expand Up @@ -451,7 +457,9 @@ describe('data table', () => {
},
});
fixture.detectChanges();
const headerElements = fixture.debugElement.queryAll(By.css('th'));
const headerElements = fixture.debugElement.queryAll(
By.css('.header > .col')
);

headerElements[3].triggerEventHandler('click', {});
expect(sortDataBySpy).toHaveBeenCalledOnceWith({
Expand Down Expand Up @@ -490,7 +498,9 @@ describe('data table', () => {
},
});
fixture.detectChanges();
const headerElements = fixture.debugElement.queryAll(By.css('th'));
const headerElements = fixture.debugElement.queryAll(
By.css('.header > .col')
);

expect(
headerElements[1]
Expand Down Expand Up @@ -553,7 +563,9 @@ describe('data table', () => {
},
});
fixture.detectChanges();
const headerElements = fixture.debugElement.queryAll(By.css('th'));
const headerElements = fixture.debugElement.queryAll(
By.css('.header > .col')
);

expect(
headerElements[1]
Expand Down Expand Up @@ -616,7 +628,9 @@ describe('data table', () => {
},
});
fixture.detectChanges();
const headerElements = fixture.debugElement.queryAll(By.css('th'));
const headerElements = fixture.debugElement.queryAll(
By.css('.header > .col')
);

headerElements[2].query(By.css('.cell')).triggerEventHandler('dragstart');
headerElements[1].query(By.css('.cell')).triggerEventHandler('dragenter');
Expand Down Expand Up @@ -684,7 +698,9 @@ describe('data table', () => {
},
});
fixture.detectChanges();
const headerElements = fixture.debugElement.queryAll(By.css('th'));
const headerElements = fixture.debugElement.queryAll(
By.css('.header > .col')
);

headerElements[2].query(By.css('.cell')).triggerEventHandler('dragstart');
headerElements[3].query(By.css('.cell')).triggerEventHandler('dragenter');
Expand Down Expand Up @@ -763,8 +779,10 @@ describe('data table', () => {
smoothingEnabled: false,
});
fixture.detectChanges();
const headerElements = fixture.debugElement.queryAll(By.css('th'));
const dataElements = fixture.debugElement.queryAll(By.css('td'));
const headerElements = fixture.debugElement.queryAll(
By.css('.header > .col')
);
const dataElements = fixture.debugElement.queryAll(By.css('.row > .col'));

// The first header should always be blank as it is the run color column.
expect(headerElements[0].nativeElement.innerText).toBe('');
Expand Down