Skip to content

Commit a8ba1b5

Browse files
Googlercopybara-github
authored andcommitted
Add click event for edge label
PiperOrigin-RevId: 757674869
1 parent ec6ff5c commit a8ba1b5

6 files changed

Lines changed: 24 additions & 0 deletions

src/app/directed_acyclic_graph.ng.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
(mouseleave)="mousedown = false"
7171
[class.animate-movement]="animateMove && !graphPanning"
7272
[resolveReference]="resolveReference"
73+
(edgeLabelClick)="edgeLabelClick.emit($event)"
7374
/>
7475
</section>
7576
</figure>

src/app/directed_acyclic_graph.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ export class DirectedAcyclicGraph implements OnInit, OnDestroy {
254254
@Output() selectedNodeChange = new EventEmitter<SelectedNode|null>();
255255
@Output() groupIterationChanged = new EventEmitter<GroupIterationRecord>();
256256
@Output() onGroupExpandToggled = new EventEmitter<GroupToggleEvent>();
257+
@Output() edgeLabelClick = new EventEmitter<DagEdge>();
257258

258259
@Input() hoveredEdge?: DagEdge;
259260

src/app/directed_acyclic_graph_raw.ng.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,10 @@
7676
*ngFor="let l of getEdgeLabels(); trackBy: edgeLabelTrack"
7777
(mouseenter)="setEdgeHover(l.edge, true)"
7878
(mouseleave)="setEdgeHover(l.edge, false)"
79+
(click)="edgeLabelClick.emit(l.edge)"
7980
[style.transform]="l.mid?.cssTransform"
8081
[style.color]="getEdgeLabelColor(l.edge)"
82+
[attr.edge-label]="l.label"
8183
>
8284
{{ l.label }}
8385
</figcaption>

src/app/directed_acyclic_graph_raw.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,18 @@ describe('Directed Acyclic Graph Raw', () => {
151151
expect(fixture.componentInstance.dagRaw.groups[1].expanded).toBe(true);
152152
}));
153153

154+
it('Correctly sends click events for edge labels',
155+
waitForAsync(async () => {
156+
const spy = jasmine.createSpy('edgeLabelClick');
157+
fixture.componentInstance.dagRaw.edgeLabelClick.subscribe(spy);
158+
const edgeLabel = await harness.getEdgeLabel('storage (red-edge)');
159+
160+
await edgeLabel.click();
161+
162+
expect(spy).toHaveBeenCalledWith(
163+
jasmine.objectContaining({from: 'BigTable', to: 'AutoML Tables'}));
164+
}));
165+
154166
// SKIP-PUBLIC
155167
xit('Groups with expanded attribute are expanded on load',
156168
waitForAsync(async () => {

src/app/directed_acyclic_graph_raw.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ export class DagRaw implements DoCheck, OnInit, OnDestroy {
406406
return this.$selectedNode;
407407
}
408408
@Output() selectedNodeChange = new EventEmitter<SelectedNode|null>();
409+
@Output() edgeLabelClick = new EventEmitter<DagEdge>();
409410

410411
@Input() features = createDAGFeatures();
411412
@Input('collapsed')

src/app/test_resources/directed_acyclic_graph_raw_harness.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,11 @@ export class DagRawHarness extends ComponentHarness {
158158
async getEdges(selector = '') {
159159
return this.locatorForAll('.edge-group' + selector)();
160160
}
161+
162+
/**
163+
* Get an edge label by its text content.
164+
*/
165+
async getEdgeLabel(labelText: string) {
166+
return this.locatorFor(`.edge-label[edge-label="${labelText}"]`)();
167+
}
161168
}

0 commit comments

Comments
 (0)