blob: ba9218fe687f81ec45526aecd28c1b77bc25ed01 [file] [log] [blame]
Matteo Scandolo7629cc42017-03-13 14:12:15 -07001import {IXosServiceGraph} from '../interfaces';
2
3export interface IXosServiceGraphReducers {
4 coarse: IXosServiceGraphReducer[];
5 finegrained: IXosServiceGraphReducer[];
6}
7
8export interface IXosServiceGraphReducer {
9 name: string;
10 reducer: IXosServiceGraphReducerFn;
11}
12
13export interface IXosServiceGraphReducerFn {
14 (graph: IXosServiceGraph): IXosServiceGraph;
15}
16
17export interface IXosServiceGraphExtender {
18 register(type: 'coarse' | 'finegrained', name: string, reducer: IXosServiceGraphReducerFn): boolean;
19 getCoarse(): IXosServiceGraphReducer[];
20 getFinegrained(): IXosServiceGraphReducer[];
21}
22
23export class XosServiceGraphExtender implements IXosServiceGraphExtender {
24
25 static $inject = ['$log'];
26
27 private reducers: IXosServiceGraphReducers = {
28 coarse: [],
29 finegrained: []
30 };
31
32 constructor (
33 private $log: ng.ILogService
34 ) {
35 }
36
37 public getCoarse(): IXosServiceGraphReducer[] {
38 return this.reducers.coarse;
39 }
40
41 public getFinegrained(): IXosServiceGraphReducer[] {
42 return this.reducers.finegrained;
43 }
44
45 // NOTE
46 // as now extender support:
47 // - nodes property: x, y, d3Class (applied to the group element)
48 // - links propery: d3Class (applied to the line element, there's no group for now)
49 public register(type: 'coarse' | 'finegrained', name: string, reducer: IXosServiceGraphReducerFn): boolean {
50 this.$log.debug(`[XosServiceGraphExtender] Registering ${name} reducer in ${type} list`);
51 this.reducers[type].push({
52 name,
53 reducer
54 });
55 return false;
56 }
57}