blob: 467e34b649d27018826bcc78a5bf3d5608422f8e [file] [log] [blame]
Matteo Scandolofb46ae62017-08-08 09:10:50 -07001
2/*
3 * Copyright 2017-present Open Networking Foundation
4
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8
9 * http://www.apache.org/licenses/LICENSE-2.0
10
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18
Matteo Scandolo8cf33a32017-11-14 15:52:29 -080019
20
21import {Graph} from 'graphlib';
Matteo Scandolo7629cc42017-03-13 14:12:15 -070022
23export interface IXosServiceGraphReducers {
24 coarse: IXosServiceGraphReducer[];
25 finegrained: IXosServiceGraphReducer[];
26}
27
28export interface IXosServiceGraphReducer {
29 name: string;
30 reducer: IXosServiceGraphReducerFn;
31}
32
33export interface IXosServiceGraphReducerFn {
Matteo Scandolo8cf33a32017-11-14 15:52:29 -080034 (graph: Graph): Graph;
Matteo Scandolo7629cc42017-03-13 14:12:15 -070035}
36
37export interface IXosServiceGraphExtender {
38 register(type: 'coarse' | 'finegrained', name: string, reducer: IXosServiceGraphReducerFn): boolean;
39 getCoarse(): IXosServiceGraphReducer[];
40 getFinegrained(): IXosServiceGraphReducer[];
41}
42
43export class XosServiceGraphExtender implements IXosServiceGraphExtender {
44
45 static $inject = ['$log'];
46
47 private reducers: IXosServiceGraphReducers = {
48 coarse: [],
49 finegrained: []
50 };
51
52 constructor (
53 private $log: ng.ILogService
54 ) {
55 }
56
57 public getCoarse(): IXosServiceGraphReducer[] {
58 return this.reducers.coarse;
59 }
60
61 public getFinegrained(): IXosServiceGraphReducer[] {
62 return this.reducers.finegrained;
63 }
64
65 // NOTE
66 // as now extender support:
67 // - nodes property: x, y, d3Class (applied to the group element)
68 // - links propery: d3Class (applied to the line element, there's no group for now)
69 public register(type: 'coarse' | 'finegrained', name: string, reducer: IXosServiceGraphReducerFn): boolean {
70 this.$log.debug(`[XosServiceGraphExtender] Registering ${name} reducer in ${type} list`);
71 this.reducers[type].push({
72 name,
73 reducer
74 });
75 return false;
76 }
77}