Skip to content

Commit c8bf970

Browse files
Google AI Edgecopybara-github
authored andcommitted
Add support for custom legends with colors.
PiperOrigin-RevId: 865980035
1 parent a8e8543 commit c8bf970

File tree

4 files changed

+67
-0
lines changed

4 files changed

+67
-0
lines changed

src/ui/src/components/visualizer/common/types.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,43 @@ export declare interface LegendConfig {
912912
* If set, rename the "outputs" label to this string.
913913
*/
914914
renameOutputsTo?: string;
915+
916+
/**
917+
* If set, add custom legend items to the legend panel.
918+
*
919+
* Each item has a color block and a label.
920+
*/
921+
customLegendItems?: CustomLegendItem[];
922+
}
923+
924+
/** A custom legend item. */
925+
export declare interface CustomLegendItem {
926+
label: string;
927+
928+
/**
929+
* The background color of the color block. Default is transparent.
930+
*/
931+
backgroundColor?: string;
932+
933+
/**
934+
* The border width of the color block. Default is 0.
935+
*/
936+
borderWidth?: number;
937+
938+
/**
939+
* The border color of the color block. Default is transparent.
940+
*/
941+
borderColor?: string;
942+
943+
/**
944+
* The border style of the color block. Default is solid.
945+
*/
946+
borderStyle?: string;
947+
948+
/**
949+
* The border radius of the color block. Default is 0.
950+
*/
951+
borderRadius?: number;
915952
}
916953

917954
/** Config for "View on node" menu. */

src/ui/src/components/visualizer/legends_panel.ng.html

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,25 @@
7373
</tr>
7474
}
7575
</ng-container>
76+
<!-- Custom legend items -->
77+
@for (item of customLegendItems; track item) {
78+
<tr>
79+
<td>
80+
<div class="key custom-key"
81+
[style.background-color]="item.backgroundColor ?? 'transparent'"
82+
[style.border-width.px]="item.borderWidth ?? 0"
83+
[style.border-color]="item.borderColor ?? 'transparent'"
84+
[style.border-style]="item.borderStyle ?? 'solid'"
85+
[style.border-radius.px]="item.borderRadius ?? 0">
86+
</div>
87+
</td>
88+
<td>
89+
<div class="label">
90+
{{item.label}}
91+
</div>
92+
</td>
93+
</tr>
94+
}
7695
@if (!hideShortcuts) {
7796
@if (showDivider()) {
7897
<tr><td colspan="2"><div class="divider"></div></td></tr>

src/ui/src/components/visualizer/legends_panel.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ $block_height: 14px;
9494
border: 2px solid var(--me-outgoing-edge-color);
9595
}
9696

97+
.custom-key {
98+
width: $block_height;
99+
height: $block_height;
100+
margin-left: auto;
101+
}
102+
97103
.shortcut {
98104
color: var(--me-on-surface-variant-color);
99105
font-size: 10px;

src/ui/src/components/visualizer/legends_panel.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
import {MatIconModule} from '@angular/material/icon';
3030

3131
import {AppService} from './app_service';
32+
import {CustomLegendItem} from './common/types';
3233

3334
/**
3435
* The panel that shows the lengends.
@@ -148,4 +149,8 @@ export class LegendsPanel {
148149
get hideShortcuts(): boolean {
149150
return this.appService.config()?.legendConfig?.hideShortcuts ?? false;
150151
}
152+
153+
get customLegendItems(): CustomLegendItem[] {
154+
return this.appService.config()?.legendConfig?.customLegendItems ?? [];
155+
}
151156
}

0 commit comments

Comments
 (0)