Manually select nodes and links

This commit is contained in:
ziajka 2018-03-23 11:29:35 +01:00
parent 28ead48c40
commit b819e106fc
2 changed files with 19 additions and 1 deletions

View File

@ -1,6 +1,7 @@
import { Subject} from "rxjs/Subject";
import { Node } from "../models/node";
import { Link } from "../models/link";
import { Rectangle } from "../models/rectangle";
import { SelectionManager } from "./selection-manager";
import { NodesDataSource } from "../datasources/nodes-datasource";
@ -54,4 +55,13 @@ describe('SelectionManager', () => {
expect(manager.getSelectedLinks().length).toEqual(0);
});
it('nodes should be manually selected', () => {
manager.setSelectedNodes([new Node()]);
expect(manager.getSelectedNodes().length).toEqual(1);
});
it('links should be manually selected', () => {
manager.setSelectedLinks([new Link()]);
expect(manager.getSelectedLinks().length).toEqual(1);
});
});

View File

@ -44,6 +44,14 @@ export class SelectionManager {
return this.selectedLinks;
}
public setSelectedNodes(nodes: Node[]) {
this.selectedNodes = nodes;
}
public setSelectedLinks(links: Link[]) {
this.selectedLinks = links;
}
private getSelectedItemsInRectangle<T extends Selectable>(dataSource: DataSource<T>, rectangle: Rectangle) {
const items: T[] = [];
dataSource.getItems().forEach((item: T) => {