Matteo Scandolo | fb46ae6 | 2017-08-08 09:10:50 -0700 | [diff] [blame] | 1 | |
| 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 Scandolo | 8cf33a3 | 2017-11-14 15:52:29 -0800 | [diff] [blame] | 19 | |
| 20 | |
| 21 | import {Graph} from 'graphlib'; |
Matteo Scandolo | 7629cc4 | 2017-03-13 14:12:15 -0700 | [diff] [blame] | 22 | |
| 23 | export interface IXosServiceGraphReducers { |
| 24 | coarse: IXosServiceGraphReducer[]; |
| 25 | finegrained: IXosServiceGraphReducer[]; |
| 26 | } |
| 27 | |
| 28 | export interface IXosServiceGraphReducer { |
| 29 | name: string; |
| 30 | reducer: IXosServiceGraphReducerFn; |
| 31 | } |
| 32 | |
| 33 | export interface IXosServiceGraphReducerFn { |
Matteo Scandolo | 8cf33a3 | 2017-11-14 15:52:29 -0800 | [diff] [blame] | 34 | (graph: Graph): Graph; |
Matteo Scandolo | 7629cc4 | 2017-03-13 14:12:15 -0700 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | export interface IXosServiceGraphExtender { |
| 38 | register(type: 'coarse' | 'finegrained', name: string, reducer: IXosServiceGraphReducerFn): boolean; |
| 39 | getCoarse(): IXosServiceGraphReducer[]; |
| 40 | getFinegrained(): IXosServiceGraphReducer[]; |
| 41 | } |
| 42 | |
| 43 | export 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 | } |