Moved graph reducer from graph store to graph components

Change-Id: If0e14068d350a823758d702b0dd0de315351a37d
diff --git a/src/app/service-graph/components/coarse/coarse.component.ts b/src/app/service-graph/components/coarse/coarse.component.ts
index cfbfc32..d02bb23 100644
--- a/src/app/service-graph/components/coarse/coarse.component.ts
+++ b/src/app/service-graph/components/coarse/coarse.component.ts
@@ -1,12 +1,14 @@
 import './coarse.component.scss';
 import * as d3 from 'd3';
 import * as $ from 'jquery';
+import * as _ from 'lodash';
 import {IXosServiceGraphStore} from '../../services/graph.store';
 import {IXosServiceGraph, IXosServiceGraphNode, IXosServiceGraphLink} from '../../interfaces';
 import {XosServiceGraphConfig as config} from '../../graph.config';
 import {IXosDebouncer} from '../../../core/services/helpers/debounce.helper';
 import {Subscription} from 'rxjs';
 import {IXosGraphHelpers} from '../../services/d3-helpers/graph.helpers';
+import {IXosServiceGraphReducer, IXosServiceGraphExtender} from '../../services/graph.extender';
 
 class XosCoarseTenancyGraphCtrl {
 
@@ -14,7 +16,8 @@
     '$log',
     'XosServiceGraphStore',
     'XosDebouncer',
-    'XosGraphHelpers'
+    'XosGraphHelpers',
+    'XosServiceGraphExtender'
   ];
 
   public graph: IXosServiceGraph;
@@ -34,7 +37,8 @@
     private $log: ng.ILogService,
     private XosServiceGraphStore: IXosServiceGraphStore,
     private XosDebouncer: IXosDebouncer,
-    private XosGraphHelpers: IXosGraphHelpers
+    private XosGraphHelpers: IXosGraphHelpers,
+    private XosServiceGraphExtender: IXosServiceGraphExtender
   ) {
 
   }
@@ -44,14 +48,18 @@
 
     this.CoarseGraphSubscription = this.XosServiceGraphStore.getCoarse()
       .subscribe(
-        (res: IXosServiceGraph) => {
-          this.$log.debug(`[XosCoarseTenancyGraph] Coarse Event and render`, res);
+        (graph: IXosServiceGraph) => {
+          this.$log.debug(`[XosCoarseTenancyGraph] Coarse Event and render`, graph);
 
           // id there are no data, do nothing
-          if (!res) {
+          if (graph.nodes.length === 0) {
             return;
           }
-          this.graph = res;
+          this.graph = graph;
+
+          _.forEach(this.XosServiceGraphExtender.getCoarse(), (r: IXosServiceGraphReducer) => {
+            graph = r.reducer(graph);
+          });
           this.renderGraph();
         },
         err => {
diff --git a/src/app/service-graph/components/fine-grained/fine-grained.component.ts b/src/app/service-graph/components/fine-grained/fine-grained.component.ts
index 0fbf411..64955ae 100644
--- a/src/app/service-graph/components/fine-grained/fine-grained.component.ts
+++ b/src/app/service-graph/components/fine-grained/fine-grained.component.ts
@@ -2,6 +2,7 @@
 import './fine-grained.component.scss';
 import * as d3 from 'd3';
 import * as $ from 'jquery';
+import * as _ from 'lodash';
 import {Subscription} from 'rxjs';
 import {XosServiceGraphConfig as config} from '../../graph.config';
 import {IXosDebouncer} from '../../../core/services/helpers/debounce.helper';
@@ -9,6 +10,7 @@
 import {IXosModelDiscovererService} from '../../../datasources/helpers/model-discoverer.service';
 import {IXosSidePanelService} from '../../../core/side-panel/side-panel.service';
 import {IXosGraphHelpers} from '../../services/d3-helpers/graph.helpers';
+import {IXosServiceGraphExtender, IXosServiceGraphReducer} from '../../services/graph.extender';
 
 class XosFineGrainedTenancyGraphCtrl {
   static $inject = [
@@ -17,7 +19,8 @@
     'XosDebouncer',
     'XosModelDiscoverer',
     'XosSidePanel',
-    'XosGraphHelpers'
+    'XosGraphHelpers',
+    'XosServiceGraphExtender'
   ];
 
   public graph: IXosServiceGraph;
@@ -40,12 +43,13 @@
     private XosDebouncer: IXosDebouncer,
     private XosModelDiscoverer: IXosModelDiscovererService,
     private XosSidePanel: IXosSidePanelService,
-    private XosGraphHelpers: IXosGraphHelpers
+    private XosGraphHelpers: IXosGraphHelpers,
+    private XosServiceGraphExtender: IXosServiceGraphExtender
   ) {
     this.handleSvg();
     this.loadDefs();
     this.setupForceLayout();
-    this.renderGraph = this.XosDebouncer.debounce(this._renderGraph, 500, this);
+    this.renderGraph = this.XosDebouncer.debounce(this._renderGraph, 1000, this);
 
     $(window).on('resize', () => {
       this.setupForceLayout();
@@ -61,6 +65,10 @@
             return;
           }
 
+          _.forEach(this.XosServiceGraphExtender.getFinegrained(), (r: IXosServiceGraphReducer) => {
+            graph = r.reducer(graph);
+          });
+
           this.graph = graph;
           this.renderGraph();
         },