Code coverage report for Model/GraphsModel/LineChart.js

Statements: 100% (135 / 135)      Branches: 82.86% (58 / 70)      Functions: 96.3% (26 / 27)      Lines: 100% (135 / 135)      Ignored: none     

All files » Model/GraphsModel/ » LineChart.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 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258                                                        1       1 22 22 22   22 13   22 13   22 22   22 21   22 14     22 22 14   22 2   22 2   22 14   22 14   22 12   22 12   22 12     22             1 62 62 62 62 62 62 62 62 62       43 22 22 22 22 22 22   22 15 14   15 2   15 2   15 14   15 14   15 12   15 12   15 12       22 21 63 63             43 71 71       43 1     43 1       43 5 5 5 5 7 5               43 1 1 1 1 1           43 1 1 1 1 1           43 1 1 1 1 1           43 3   43 10   43 10   43 36   43 1   43 253   43 10   43 6   43 4   43 2   43 4   43 4   43 2   43 2       1   43 62     43  
/*jshint node: true */
'use strict';
 
/*
* Name :  LineChart.js
* Module : FrontEnd::Model::GraphsModel
* Location : /frontend/app/Model/GraphsModel
*
* History :
* Version       Date        Programmer                  Description
* ===============================================================================================================
* 1.0.0         2015-05-19  Maria Giovanna Chinellato   Tested
*
* 0.3.0         2015-05-18  Francesco Rossetto          Modified general structure, some fixes
*
* 0.2.2			2015-05-15	Francesco Rossetto			Various fixes, insert inzializeData
*
* 0.2.1         2015-05-15  Maria Giovanna Chinellato	Fix all methods
*
* 0.2.0         2015-05-13  Maria Giovanna Chinellato	Add all methods
*
* 0.1.0         2015-05-13  Francesco Rossetto   		Add all attributes and some methods
*
* 0.0.1         2015-05-13  Francesco Rossetto			Initial code      
* ===============================================================================================================
*
*/
 
angular.module('norris-nrti')
.factory('LineChartFactory', ['GraphFactory', 'AxisFactory', 'LineChartFlowFactory', function(GraphFactory, AxisFactory, LineChartFlowFactory){
 
    // funzione di utilità che ha lo scopo di separare le proprietà legate al grafico generale da quelle legate al bar chart
	function split(json) {
		var graphJson = {};
		Eif (json.title !== undefined) {
			graphJson.title = json.title;
		}
		if (json.height !== undefined) {
			graphJson.height = json.height;
		}
		if (json.width !== undefined) {
			graphJson.width = json.width;
		}
		Eif (json.enableLegend !== undefined) {
			graphJson.enableLegend = json.enableLegend;
		}
        if (json.legend !== undefined) {
            graphJson.legend = json.legend;
        }
        if (json.socketURL !== undefined) {
            graphJson.socketURL = json.socketURL;
        }
 
		var lineJson = {};
        if (json.legendOnPoint !== undefined) {
            lineJson.legendOnPoint = json.legendOnPoint;
        }
		if (json.xAxis !== undefined) {
			lineJson.xAxis = json.xAxis;
		}
		if (json.yAxis !== undefined) {
			lineJson.yAxis = json.yAxis;
		}
		if (json.viewFinder !== undefined) {
			lineJson.viewFinder = json.viewFinder;
		}
		if (json.backgroundColor !== undefined) {
			lineJson.backgroundColor = json.backgroundColor;
		}
        if (json.interpolation !== undefined) {
            lineJson.interpolation = json.interpolation;
        }
        if (json.horizontalGrid !== undefined) {
            lineJson.horizontalGrid = json.horizontalGrid;
        }
        if (json.verticalGrid !== undefined) {
            lineJson.verticalGrid = json.verticalGrid;
        }
 
		return {
			'graphJson' : graphJson,
			'lineJson' : lineJson
		};
	}
 
    // costruttore di default di un LineChart
    function LineChart(info) {
        this._legendOnPoint = false;
        this._axisX = null;
        this._axisY = null;
        this._viewFinder = false;
        this._backgroundColor = '#FFF';
        this._interpolation = 'linear';
        this._horizontalGrid = false;
        this._verticalGrid = false;
        this._graph = GraphFactory.build(info);
    }
 
    // funzione che ha lo scopo di aggiornare i campi dati del line chart
    LineChart.prototype.updateParameters = function(info) {
        Eif (info !== undefined) {
            var json = split(info);
            var gJson = json.graphJson;
            var lJson = json.lineJson;
            Eif (Object.keys(gJson).length !== 0) {
                this._graph.updateParameters(gJson);
            }
            if (Object.keys(lJson).length !== 0) {
                if (lJson.legendOnPoint !== undefined) {
                    this._legendOnPoint = lJson.legendOnPoint;
                }
                if (lJson.xAxis !== undefined) {
                    this._axisX = AxisFactory.build(lJson.xAxis);
                }
                if (lJson.yAxis !== undefined) {
                    this._axisY = AxisFactory.build(lJson.yAxis);
                }
                if (lJson.viewFinder !== undefined) {
                    this._viewFinder = lJson.viewFinder;
                }
                if (lJson.backgroundColor !== undefined) {
                    this._backgroundColor = lJson.backgroundColor;
                }
                if (lJson.interpolation !== undefined) {
                    this._interpolation = lJson.interpolation;
                }
                if (lJson.horizontalGrid !== undefined) {
                    this._horizontalGrid = lJson.horizontalGrid;
                }
                if (lJson.verticalGrid !== undefined) {
                    this._verticalGrid = lJson.verticalGrid;
                }
            }
            // aggiunge i flussi relativi all'istanza di line chart
            if (info.flows !== undefined) {
                for (var i=0; i<info.flows.length; i++) {
                    var newflow = LineChartFlowFactory.build(info.flows[i]);
                    this.addFlow(info.flows[i].ID, newflow);
                }
            }
        }
    };
 
    // aggiunge un nuovo flusso alla lista di flussi
    LineChart.prototype.addFlow = function(newId, newFlow) {
        Eif (newFlow.constructor.name === 'LineChartFlow') { // controlla che il flusso da inserire sia del tipo giusto
            this._graph.addFlow(newId, newFlow);
        }
    };
    // elimina il flusso con id === ID
    LineChart.prototype.deleteFlow = function(ID) {
        this._graph.deleteFlow(ID);
    };
    // rimpiazza i dati di un flusso con altri dati
    LineChart.prototype.replaceData = function(newData){
        this._graph.replaceData(newData);
    };
 
    // inizializza i dati dei flussi presenti nella lista
    LineChart.prototype.initializeData = function(newData) {  //inizialization data of flows
        Eif (newData !== undefined) {
            var fList = this._graph.getFlowList();
            for (var i=0; i<newData.length; i++) {
                for (var j=0; j<fList.length; j++) {
                    if (fList[j].id === newData[i].ID) {
                        fList[j].flow.initializeData(newData[i]);
                    }
                }
            }
        }
    };
    
    // funzione che permette l'aggiornamento di tipo in place dei dati
    LineChart.prototype.inPlaceUpdate = function(newData) {
        Eif (newData !== undefined) {
            var fList = this._graph.getFlowList();
            for (var j=0; j<fList.length; j++) {
                Eif (fList[j].id === newData.ID) {
                    fList[j].flow.inPlaceUpdate(newData);
                }
            }
        }
    };
    // funzione che permette l'aggiornamento di tipo stream dei dati
    LineChart.prototype.streamUpdate = function(newData) {
        Eif (newData !== undefined) {
           var fList = this._graph.getFlowList();
            for (var j=0; j<fList.length; j++) {
                Eif (fList[j].id === newData.ID) {
                    fList[j].flow.streamUpdate(newData);
                }
            }
        }
    };
    // funzione che permette di eliminare i dati di un flusso
    LineChart.prototype.deleteData = function(delData) {
        Eif (delData !== undefined){
            var fList = this._graph.getFlowList();
            for (var j=0; j<fList.length; j++) {
                Eif (fList[j].id === delData.ID) {
                    fList[j].flow.deleteData(delData);
                }
            }
        }
    };
 
    LineChart.prototype.getTitle = function() {
        return this._graph.getTitle(); // ritorna il titolo del grafico
    };
    LineChart.prototype.getHeight = function() {
        return this._graph.getHeight(); // ritorna l'altezza del grafico
    };
    LineChart.prototype.getWidth = function() {
        return this._graph.getWidth(); // ritorna la larghezza del grafico
    };
    LineChart.prototype.getLegend = function() {
        return this._graph.getLegend(); // ritorna la legenda del grafico se questa è disponibile
    };
    LineChart.prototype.getUrl = function() {
        return this._graph.getUrl(); // ritorna l'url relativo al grafico
    };
    LineChart.prototype.getFlowList = function() {
        return this._graph.getFlowList(); // ritorna la lista dei flussi presenti nel grafico
    };
    LineChart.prototype.getX = function() {
        return this._axisX; // ritorna l'asse X
    };
    LineChart.prototype.getY = function() {
        return this._axisY; // ritorna l'asse Y
    };
    LineChart.prototype.getViewFinder = function() {
        return this._viewFinder; // ritorna true se il grafico deve essere creato con il view finder
    };
    LineChart.prototype.getBackground = function() {
        return this._backgroundColor; // ritorna il colore di background del grafico
    };
    LineChart.prototype.getLegendOnPoint = function() {
        return this._legendOnPoint; // ritorna true se è disponibile la legend on point
    };
    LineChart.prototype.getInterpolation = function() {
        return this._interpolation; // ritorna il tipo di iterpolazione del grafico
    };
    LineChart.prototype.getHGrid = function() {
        return this._horizontalGrid; // ritorna true se deve essere visibile la griglia orizzontale del line chart
    };
    LineChart.prototype.getVGrid = function() {
        return this._verticalGrid; // ritorna true se deve essere visibile la griglia verticale del line chart
    };
 
    // costruttore di default del LineChartFactory
    function LineChartFactory(){}
 
    LineChartFactory.build = function(info) {
        return new LineChart(info); // ritorna una nuova istanza di LineChart
    };
 
    return LineChartFactory;
}]);