Code coverage report for Model/FlowsModel/MapChartFlow.js

Statements: 100% (76 / 76)      Branches: 80.56% (29 / 36)      Functions: 93.75% (15 / 16)      Lines: 100% (76 / 76)      Ignored: none     

All files » Model/FlowsModel/ » MapChartFlow.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163                                                    1     1 91 91   91 71 9     71 9   71 10   71 30       91               1 88 88 88 88   88 88 88   88   88 29 6   29 7   29 27         61 3 3 3 3   3 3   3 3 3   3 3   3 3           61 14 24 22     2 2       61 2   61 2 2 2         61 2   61 2 2 2         61 2   61 38   61 3   61 3   61 3     1   61 88     61    
/*jshint node: true */
'use strict';
 
/*
* Name :  MapChartFlow.js
* Module : FrontEnd::Model::FlowsModel
* Location : /frontend/app/Model/FlowsModel
*
* History :
* Version       Date        Programmer                  Description
* =================================================================================================
* 1.0.1         2015-06-25  Maria Giovanna Chinellato	Fix initializeData
*
* 1.0.0			2015-05-19	Francesco Rossetto			Tested
*
* 0.2.0			2015-05-18	Francesco Rossetto			Modified general structure, some fixes
*
* 0.1.1         2015-05-15  Maria Giovanna Chinellato	Various fixes
*
* 0.1.0         2015-05-12  Maria Giovanna Chinellato	Add attributes and methods
*
* 0.0.1         2015-05-12  Maria Giovanna Chinellato	Initial code
* =================================================================================================
*
*/
 
angular.module('norris-nrti')
.factory('MapChartFlowFactory', ['FlowFactory', function(FlowFactory){
 
	function split(json) {
        var flowJson = {};
        var mapFlowJson = {};
 
        if (json !== undefined) {
	        if (json.name !== undefined) {
	            flowJson.name = json.name;
	        }
 
	        if (json.marker !== undefined) {
	            mapFlowJson.marker = json.marker;
	        }
	        if (json.trailLength !== undefined) {
	            mapFlowJson.trailLength = json.trailLength;
	        }
	        if (json.trace !== undefined) {
	            mapFlowJson.trace = json.trace;
	        }
	    }
 
        return {
            'flowJson' : flowJson,
            'mapFlowJson' : mapFlowJson
        };
    }
 
    //MapChartFlow.prototype.test = function _Test(expressionStr) { return eval(expressionStr); };
 
    function MapChartFlow(info) {
    	this._data = [];
		this._marker = null;
		this._trailLength = null;
		this._trace = null;
 
		var json = split(info);
		var fJson = json.flowJson;
		var mfJson = json.mapFlowJson;
 
		this._flow = FlowFactory.build(fJson);
 
		if (Object.keys(mfJson).length !== 0) {
	        if (mfJson.marker !== undefined) {
	            this._marker = mfJson.marker;
	        }
	        if (mfJson.trailLength !== undefined) {
	            this._trailLength = mfJson.trailLength;
	        }
	        if (mfJson.trace !== undefined) {
	        	this._trace = mfJson.trace;
	        }
 	    }
	}
 
	MapChartFlow.prototype.updateParameters = function(info) { //abstract
		Eif (info !== undefined) {
	    	var json = split(info);
			var fJson = json.flowJson;
			var mfJson = json.mapFlowJson;
 
			this._flow = FlowFactory.build(fJson);
			this._flow.updateParameters(fJson);
	
			Eif (Object.keys(mfJson).length !== 0) {
				Eif (mfJson.marker !== undefined) {
		            this._marker = mfJson.marker;
		        }
		        Eif (mfJson.trailLength !== undefined) {
		            this._trailLength = mfJson.trailLength;
		        }
		        Eif (mfJson.trace !== undefined) {
	        		this._trace = mfJson.trace;
	        	}
		    }
		}
	};
 
	MapChartFlow.prototype.initializeData = function(newData) {
		for (var i=0; i<newData.records.length; i++) {
			if (this._trailLength === null || this._data.length < this._trailLength){
				this._data.push(newData.records[i]);
			}
			else{
				this._data.splice(0,1);
				this._data.push(newData.records[i]);
			}
		}
	};
	MapChartFlow.prototype.emptyData = function() {
		this._data.splice(0);
	};
	MapChartFlow.prototype.inPlaceUpdate = function(newData) {
		for (var i = 0; i<this._data.length; i++){
            Eif (this._data[i].norrisRecordID === newData.norrisRecordID){
            	this._data[i] = newData;
                //this._data[i] = { 'norrisRecordID' : newData.norrisRecordID, 'value' : newData.value };
            }
        }
    };
	MapChartFlow.prototype.streamUpdate = function(newData) {
		this.initializeData(newData);
    };
    MapChartFlow.prototype.deleteData = function(delData) {
    	for (var i = 0; i<this._data.length; i++){
            Eif (this._data[i].norrisRecordID === delData.norrisRecordID){
                this._data.splice(i,1);
            }
        }
    };
 
    MapChartFlow.prototype.getName = function() {
    	return this._flow.getName();
    };
	MapChartFlow.prototype.getData = function() {
		return this._data;
	};
	MapChartFlow.prototype.getMarker = function() {
		return this._marker;
	};
	MapChartFlow.prototype.getMaxItem = function() {
		return this._trailLength;
	};
	MapChartFlow.prototype.getTrace = function() {
		return this._trace;
	};
 
	function MapChartFlowFactory() {}
 
	MapChartFlowFactory.build = function(info) {
		return new MapChartFlow(info);
	};
 
	return MapChartFlowFactory;
 
}]);