Matteo Scandolo | 7629cc4 | 2017-03-13 14:12:15 -0700 | [diff] [blame] | 1 | import {IXosServiceGraph} from '../interfaces'; |
| 2 | |
| 3 | export interface IXosServiceGraphReducers { |
| 4 | coarse: IXosServiceGraphReducer[]; |
| 5 | finegrained: IXosServiceGraphReducer[]; |
| 6 | } |
| 7 | |
| 8 | export interface IXosServiceGraphReducer { |
| 9 | name: string; |
| 10 | reducer: IXosServiceGraphReducerFn; |
| 11 | } |
| 12 | |
| 13 | export interface IXosServiceGraphReducerFn { |
| 14 | (graph: IXosServiceGraph): IXosServiceGraph; |
| 15 | } |
| 16 | |
| 17 | export interface IXosServiceGraphExtender { |
| 18 | register(type: 'coarse' | 'finegrained', name: string, reducer: IXosServiceGraphReducerFn): boolean; |
| 19 | getCoarse(): IXosServiceGraphReducer[]; |
| 20 | getFinegrained(): IXosServiceGraphReducer[]; |
| 21 | } |
| 22 | |
| 23 | export 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 | } |