Code coverage report for Model/GraphsModel/MapChart.js

Statements: 100% (132 / 132)      Branches: 66.67% (44 / 66)      Functions: 96.3% (26 / 27)      Lines: 100% (132 / 132)      Ignored: none     

All files » Model/GraphsModel/ » MapChart.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                                                1       1 20 20 20   20 13   20 13   20 20   20 20       20 20 13   20 13   20 13   20 13   20 13   20 13   20 13   20 13       20             1 55 55 55 55 55 55 55 55   55       41 20 20 20 20 20   20 13 13   13 13   13 13   13 13   13 13   13 13   13 13   13 13       20 20 60 60           41 68 68       41 1     41 1       41 4 4 4 4 4 4               41 1 1 1 1 1           41 1 1 1 1 1           41 1 1 1 1 1           41 1   41 12   41 12   41 29   41 1   41 60   41 2   41 2   41 2   41 2   41 2   41 2   41 2   41 2       1   41 55     41  
/*jshint node: true */
'use strict';
 
/*
* Name :  MapChart.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.2.0         2015-05-18  Maria Giovanna Chinellato   Modified general structure, some fixes
*
* 0.1.1         2015-05-15  Francesco Rossetto          Various fix, insert inzializeData
*
* 0.1.0         2015-05-14  Maria Giovanna Chinellato   Add all attributes and methods
*
* 0.0.1         2015-05-14  Maria Giovanna Chinellato   Initial code      
* ===============================================================================================================
*
*/
 
angular.module('norris-nrti')
.factory('MapChartFactory',['GraphFactory', 'MapChartFlowFactory', function(GraphFactory, MapChartFlowFactory){
 
    // 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;
        }
        Eif (json.legend !== undefined) {
            graphJson.legend = json.legend;
        }
 
 
        var mapJson = {};
        if (json.legendOnPoint !== undefined) {
            mapJson.legendOnPoint = json.legendOnPoint;
        }
        if (json.latitude !== undefined) {
            mapJson.latitude = json.latitude;
        }
        if (json.longitude !== undefined) {
            mapJson.longitude = json.longitude;
        }
        if (json.mapType !== undefined) {
            mapJson.mapType = json.mapType;
        }
        if (json.zoom !== undefined) {
            mapJson.zoom = json.zoom;
        }
        if (json.drag !== undefined) {
            mapJson.drag = json.drag;
        }
        if (json.mapWidth !== undefined) {
            mapJson.mapWidth = json.mapWidth;
        }
        if (json.mapHeight !== undefined) {
            mapJson.mapHeight = json.mapHeight;
        }
 
 
        return {
            'graphJson' : graphJson,
            'mapJson' : mapJson
        };
    }
 
    // costruttore di default di un MapChart
    function MapChart(info) {
        this._legendOnPoint = false;
        this._latitude = 45.4113311;
        this._longitude = 11.8876318;
        this._mapType = 'roadmap';
        this._zoom = true;
        this._drag = true;
        this._mapWidth = 0;
        this._mapHeight = 0;
 
        this._graph = GraphFactory.build(info);
    }
 
    // funzione che ha lo scopo di aggiornare i campi dati del map chart
    MapChart.prototype.updateParameters = function(info) {
        var json = split(info);
        var gJson = json.graphJson;
        var mJson = json.mapJson;
        Eif (Object.keys(gJson).length !== 0) {
            this._graph.updateParameters(gJson);
        } 
        if (Object.keys(mJson).length !== 0) {
            Eif (mJson.legendOnPoint !== undefined) {
                this._legendOnPoint = mJson.legendOnPoint;
            }
            Eif (mJson.latitude !== undefined) {
                this._latitude = mJson.latitude;
            }
            Eif (mJson.longitude !== undefined) {
                this._longitude = mJson.longitude;
            }
            Eif (mJson.mapType !== undefined) {
                this._mapType = mJson.mapType;
            }
            Eif (mJson.zoom !== undefined) {
                this._zoom = mJson.zoom;
            }
            Eif (mJson.drag !== undefined) {
                this._drag = mJson.drag;
            }
            Eif (mJson.mapWidth !== undefined) {
                this._mapWidth = mJson.mapWidth;
            }
            Eif (mJson.mapHeight !== undefined) {
                this._mapHeight = mJson.mapHeight;
            }
        }
        // aggiunge i flussi relativi all'istanza di map chart
        Eif (info.flows !== undefined) {
            for (var i=0; i<info.flows.length; i++) {
                var newflow = MapChartFlowFactory.build(info.flows[i]);
                this.addFlow(info.flows[i].ID, newflow);
            }
        }
    };
 
    // aggiunge un nuovo flusso alla lista di flussi
    MapChart.prototype.addFlow = function(ID, newFlow) {
        Eif (newFlow.constructor.name === 'MapChartFlow') { // controlla che il flusso da inserire sia del tipo giusto
            this._graph.addFlow(ID, newFlow);
        }
    };
    // elimina il flusso con id === ID
    MapChart.prototype.deleteFlow = function(ID) {
        this._graph.deleteFlow(ID);
    };
    // rimpiazza i dati di un flusso con altri dati
    MapChart.prototype.replaceData = function(newData){
        this._graph.replaceData(newData);
    };
 
    // inizializza i dati dei flussi presenti nella lista
    MapChart.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++) {
                    Eif (fList[j].id === newData[i].ID) {
                        fList[j].flow.initializeData(newData[i]);
                    }
                }
            }
        }
    };
 
    // funzione che permette l'aggiornamento di tipo in place dei dati
    MapChart.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
    MapChart.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
    MapChart.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);
                }
            }
        }
    };
 
    MapChart.prototype.getTitle = function() {
        return this._graph.getTitle(); // ritorna il titolo del grafico
    };
    MapChart.prototype.getHeight = function() {
        return this._graph.getHeight(); // ritorna l'altezza del grafico
    };
    MapChart.prototype.getWidth = function() {
        return this._graph.getWidth(); // ritorna la larghezza del grafico
    };
    MapChart.prototype.getLegend = function() {
        return this._graph.getLegend(); // ritorna la legenda del grafico se questa è disponibile
    };
    MapChart.prototype.getUrl = function() {
        return this._graph.getUrl(); // ritorna l'url relativo al grafico
    };
    MapChart.prototype.getFlowList = function() {
        return this._graph.getFlowList(); // ritorna la lista dei flussi presenti nel grafico
    };
    MapChart.prototype.getLegendOnPoint = function() {
        return this._legendOnPoint; // ritorna true se è disponibile la legend on point
    };
    MapChart.prototype.getLatitude = function() {
        return this._latitude; // ritorna la latitudine del centro della mappa
    };
    MapChart.prototype.getLongitude = function() {
        return this._longitude; // ritorna la longitudine del centro della mappa
    };
    MapChart.prototype.getMapType = function() {
        return this._mapType; // ritorna il tipo della mappa (roadmap, terrain, satellite, hybrid)
    };
    MapChart.prototype.getZoomable = function() {
        return this._zoom; // ritorna true se è disponibile la funzionalità 'zoom' sulla mappa
    };
    MapChart.prototype.getDraggable = function() {
        return this._drag; // ritorna true se è disponibile la funzionalità 'drag' sulla mappa
    };    
    MapChart.prototype.getMapWidth = function() {
        return this._mapWidth; // ritorna la larghezza (in metri) della mappa (quanti metri devono essere visilìbili)
    };
    MapChart.prototype.getMapHeight = function() {
        return this._mapHeight; // ritorna l'altezza (in metri) della mappa (quanti metri devono essere visilìbili)
    };
 
    // costruttore di default di MapChartFactory
    function MapChartFactory() {}
 
    MapChartFactory.build = function(info) {
        return new MapChart(info); // ritorna una nuova istanza di MapChart
    };
 
    return MapChartFactory;
}]);