From fd6290738b72bf654c27e734aedbbb1be635e3f5 Mon Sep 17 00:00:00 2001 From: Diego Rey <diego.despaux@izundo.com> Date: Mon, 13 Aug 2018 20:12:21 -0300 Subject: [PATCH] Added ghciServiceSub unsubscribe handler --- .../plotter/graph2D/graph2D.component.ts | 65 ++++++++++++++++++- .../layout/plotter/graph2D/graph2D.helper.ts | 25 +++++++ 2 files changed, 87 insertions(+), 3 deletions(-) diff --git a/Frontend Angular 4/src/app/layout/plotter/graph2D/graph2D.component.ts b/Frontend Angular 4/src/app/layout/plotter/graph2D/graph2D.component.ts index 25e86cc7..cb50b9e2 100755 --- a/Frontend Angular 4/src/app/layout/plotter/graph2D/graph2D.component.ts +++ b/Frontend Angular 4/src/app/layout/plotter/graph2D/graph2D.component.ts @@ -13,6 +13,8 @@ import { Animation } from './graph2D.helper'; }) export class Graph2DComponent { + private ghciServiceSub: any; + private instance: null; private animation: Animation = { @@ -25,7 +27,7 @@ export class Graph2DComponent { }; public constructor(private ghciService: GHCIService) { - ghciService.messages.subscribe( + this.ghciServiceSub = ghciService.messages.subscribe( canvas => { switch(canvas.tipo) { case 'graph': { @@ -251,7 +253,7 @@ export class Graph2DComponent { return $circleNormalized; } - /** + /** * @name normalizeTextData * @desc Normalize Text data for Function Plot Library * @param {Object} textData Data of Text to be normalized @@ -273,6 +275,49 @@ export class Graph2DComponent { return $textNormalized; } + /** + * @name normalizeTextData + * @desc Normalize Text data for Function Plot Library + * @param {Object} textData Data of Text to be normalized + * @returns {Object} + */ + // public normalizeLineData = function ($lineData) { + // var $lineNormalized:any = {}; + // var $points = [] + // for (var p of $lineData.pts) { + // $points.push([p[0],p[1]]); + // } + // $lineNormalized.points = $points; + // $lineNormalized.color = $lineData.color; + // $lineNormalized.rotation = $lineData.rot; + // $lineNormalized.fnType = 'points'; + // $lineNormalized.polylineType = 'line'; + // $lineNormalized.graphType = 'polyline'; + + // return $lineNormalized; + // } + /** + * @name normalizeTextData + * @desc Normalize Text data for Function Plot Library + * @param {Object} textData Data of Text to be normalized + * @returns {Object} + */ + // public normalizePolygonData = function ($textData) { + // var $PoligonNormalized:any = {}; + // var $shape:any = {}; + // $shape.text = $textData.text; + // $shape.size = $textData.size; + // $shape.x = $textData.x; + // $shape.y = $textData.y; + // $textData.color && ($shape.fill = $textData.color); + // $textData.rot !== 'undefined' && ($shape.rotation = $textData.rot); + + // $textNormalized.shape = $shape; + // $textNormalized.graphType = 'shape'; + // $textNormalized.shapeType = 'text'; + + // return $textNormalized; + // } /** * @name normalizeShapesData @@ -295,7 +340,15 @@ export class Graph2DComponent { case 'text': { normalized.push(this.normalizeTextData(shape)); break; - } + } + // case 'line': { + // normalized.push(this.normalizeLineData(shape)); + // break; + // } + // case 'polygon': { + // normalized.push(this.normalizePolygonData(shape)); + // break; + // } } } return normalized; @@ -518,5 +571,11 @@ export class Graph2DComponent { return funcionString; } + ngOnDestroy() { + if (this.ghciServiceSub) { + this.ghciServiceSub.unsubscribe(); + } + } + } diff --git a/Frontend Angular 4/src/app/layout/plotter/graph2D/graph2D.helper.ts b/Frontend Angular 4/src/app/layout/plotter/graph2D/graph2D.helper.ts index 9eb99ba7..18bd27ed 100644 --- a/Frontend Angular 4/src/app/layout/plotter/graph2D/graph2D.helper.ts +++ b/Frontend Angular 4/src/app/layout/plotter/graph2D/graph2D.helper.ts @@ -6,3 +6,28 @@ export interface Animation { playing: boolean, init: boolean } + + +// export function toJSON(data: any) : string { +// var $points = data.pts; +// var $pointsJson = []; +// for (var p of $points) { +// $pointsJson.push([p[0],p[1]]); +// } + +// var dataJson = data; +// dataJson.pts +// } + +// return jsonString +// .replace( +// regexRot, (match, x, y, z) => { +// return `"rot": { "x": ${x}, "y": ${y}, "z": ${z} }` +// } +// ) +// .replace( +// regexPts, (match, x1, y1, z1, x2, y2, z2) => { +// return `"pts": [{ "x": ${x1}, "y": ${y1}, "z": ${z1} },{ "x": ${x2}, "y": ${y2}, "z": ${z2} }]` +// } +// ) +// } \ No newline at end of file -- GitLab