Code coverage report for Model/GraphsModel/BarChart.js

Statements: 100% (141 / 141)      Branches: 71.62% (53 / 74)      Functions: 96.43% (27 / 28)      Lines: 100% (141 / 141)      Ignored: none     

All files » Model/GraphsModel/ » BarChart.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 259 260 261 262 263 264 265 266 267 268                                                    1       1 24 24 24   24 16   24 16   24 24   24 23   24 16     24 24 16   24 16   24 16   24 16   24 16   24 16   24 16   24 16   24 16     24             1   66 66 66 66 66 66 66 66 66 66       47 24 24 24 24 24 24   24 16 16   16 16   16 16   16 16   16 16   16 16   16 16   16 16   16 16       24 23 69 69               47 77 77       47 1     47 1       47 4 4 4 4 6 4               47 1 1 1 1           47 1 1 1 1 1           47 1 1 1 1 1           47 3   47 10   47 10   47 36   47 1   47 187   47 8   47 8   47 5   47 5   47 2   47 2   47 4   47 4   47 2       1   47 66     47    
/*jshint node: true */
'use strict';
 
/*
* Name :  BarChart.js
* Module : FrontEnd::Model::GraphsModel
* Location : /frontend/app/Model/GraphsModel
*
* History :
* Version       Date        Programmer                  Description
* ===============================================================================================================
* 1.0.0         2015-05-21  Francesco Rossetto          Tested
*
* 0.3.0         2015-05-20  Francesco Rossetto          Modified general structure, some fixes
*
* 0.2.1         2015-05-19  Francesco Rossetto          Various fixes, insert inzializeData
*
* 0.2.0         2015-05-18  Maria Giovanna Chinellato   Add all methods and fix class
*
* 0.1.0         2015-05-18  Maria Giovanna Chinellato   Add all attributes, add methods split and updateParameter
*
* 0.0.1         2015-05-18  Maria Giovanna Chinellato   Initial code      
* ===============================================================================================================
*
*/
 
angular.module('norris-nrti')
.factory('BarChartFactory', ['GraphFactory','AxisFactory', 'BarChartFlowFactory', function(GraphFactory, AxisFactory, BarChartFlowFactory){
 
    // 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 barJson = {};
        if (json.xAxis !== undefined) {
            barJson.xAxis = json.xAxis;
        }
        if (json.yAxis !== undefined) {
            barJson.yAxis = json.yAxis;
        }
        if (json.barOrientation !== undefined) {
            barJson.barOrientation = json.barOrientation;
        }
        if (json.headers !== undefined) {
            barJson.headers = json.headers;
        }
        if (json.backgroundColor !== undefined) {
            barJson.backgroundColor = json.backgroundColor;
        }
        if (json.sortable !== undefined) {
            barJson.sortable = json.sortable;
        }
        if (json.groupingControl !== undefined) {
            barJson.groupingControl = json.groupingControl;
        }
        if (json.legendOnPoint !== undefined) {
            barJson.legendOnPoint = json.legendOnPoint;
        }
        if (json.grid !== undefined) {
            barJson.grid = json.grid;
        }
 
        return {
            'graphJson' : graphJson,
            'barJson' : barJson
        };
    }
 
    // costruttore di default di un BarChart
    function BarChart(info) {
        // campi dati di un bar chart e valori di default
        this._axisX = null;
        this._axisY = null;
        this._barOrientation = 'V';
        this._headers = [];
        this._background = '#FFF';
        this._sortable = true;
        this._groupingControl = true;
        this._legendOnPoint = false;
        this._horizontalGrid = false;
        this._graph = GraphFactory.build(info);
    }
 
    // funzione che ha lo scopo di aggiornare i campi dati del bar chart
    BarChart.prototype.updateParameters = function(info) {
        Eif (info !== undefined) {
            var json = split(info);
            var gJson = json.graphJson;
            var bJson = json.barJson;
            Eif (Object.keys(gJson).length !== 0) {
                this._graph.updateParameters(gJson);
            } 
            if (Object.keys(bJson).length !== 0) {
                Eif (bJson.xAxis !== undefined) {
                    this._axisX = AxisFactory.build(bJson.xAxis);
                }
                Eif (bJson.yAxis !== undefined) {
                    this._axisY = AxisFactory.build(bJson.yAxis);
                }
                Eif (bJson.barOrientation !== undefined) {
                    this._barOrientation = bJson.barOrientation;
                }
                Eif (bJson.headers !== undefined) {
                    this._headers = bJson.headers;
                }
                Eif (bJson.backgroundColor !== undefined) {
                    this._background = bJson.backgroundColor;
                }
                Eif (bJson.sortable !== undefined) {
                    this._sortable = bJson.sortable;
                }
                Eif (bJson.groupingControl !== undefined) {
                    this._groupingControl = bJson.groupingControl;
                }
                Eif (bJson.legendOnPoint !== undefined) {
                    this._legendOnPoint = bJson.legendOnPoint;
                }
                Eif (bJson.grid !== undefined) {
                    this._horizontalGrid = bJson.grid;
                }
            }
            // aggiunge i flussi relativi all'istanza di bar chart
            if (info.flows !== undefined) {
                for (var i=0; i<info.flows.length; i++) {
                    var newflow = BarChartFlowFactory.build(info.flows[i]);
                    this.addFlow(info.flows[i].ID, newflow);
                }
            }
        }
        
    };
 
    // aggiunge un nuovo flusso alla lista di flussi
    BarChart.prototype.addFlow = function(newId, newFlow) {
        Eif (newFlow.constructor.name === 'BarChartFlow') { // controlla che il flusso da inserire sia del tipo giusto
            this._graph.addFlow(newId, newFlow);
        }
    };
    // elimina il flusso con id === ID
    BarChart.prototype.deleteFlow = function(ID) {
        this._graph.deleteFlow(ID);
    };
    // rimpiazza i dati di un flusso con altri dati
    BarChart.prototype.replaceData = function(newData){
        this._graph.replaceData(newData);
    };
 
    // inizializza i dati dei flussi presenti nella lista
    BarChart.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
    BarChart.prototype.inPlaceUpdate = function(newData) {
        Eif (newData !== undefined) {
            for (var j=0; j<this._graph.getFlowList().length; j++) {
                Eif (this._graph.getFlowList()[j].id === newData.ID) {
                    this._graph.getFlowList()[j].flow.inPlaceUpdate(newData);
                }
            }
        }   
    };
    // funzione che permette di aggiongere un record ad un flusso esistente
    BarChart.prototype.addRecords = 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.addRecords(newData);
                }
            }
        }
    };
    // funzione che permette di eliminare i dati di un flusso
    BarChart.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);
                }
            }
        }
    };
 
    BarChart.prototype.getTitle = function() {
        return this._graph.getTitle(); // ritorna il titolo del grafico
    };
    BarChart.prototype.getHeight = function() {
        return this._graph.getHeight(); // ritorna l'altezza del grafico
    };
    BarChart.prototype.getWidth = function() {
        return this._graph.getWidth(); // ritorna la larghezza del grafico
    };
    BarChart.prototype.getLegend = function() {
        return this._graph.getLegend(); // ritorna la legenda del grafico se questa è disponibile
    };
    BarChart.prototype.getUrl = function() {
        return this._graph.getUrl(); // ritorna l'url relativo al grafico
    };
    BarChart.prototype.getFlowList = function() {
        return this._graph.getFlowList(); // ritorna la lista dei flussi presenti nel grafico
    };
    BarChart.prototype.getX = function() {
        return this._axisX; // ritorna l'asse X
    };
    BarChart.prototype.getY = function() {
        return this._axisY; // ritorna l'asse Y
    };
    BarChart.prototype.getBarOrientation = function() {
        return this._barOrientation; // ritorna l'orientamento delle barre del bar chart (verticale: V, orizzontale: H)
    };
    BarChart.prototype.getHeaders = function() {
        return this._headers; // ritorna gli header relativi alle barre
    };
    BarChart.prototype.getBackground = function() {
        return this._background; // ritorna il colore di background del grafico
    };
    BarChart.prototype.getSortable = function() {
        return this._sortable; // ritorna true se è possibile ordinare il grafico dalla view
    };
    BarChart.prototype.getGroupingControl = function() {
        return this._groupingControl; // ritorna true se è data la possibilità di cambiare la posizine delle barre da grouped a stacked e viceversa
    };
    BarChart.prototype.getLegendOnPoint = function() {
        return this._legendOnPoint; // ritorna true se è disponibile la funzionalità legend on point
    };
    BarChart.prototype.getHGrid = function() {
        return this._horizontalGrid; // ritorna se deve essere visualizzata la griglia orizzontale
    };
 
    // costruttore di default di BarChartFactory
    function BarChartFactory(){}
 
    BarChartFactory.build = function(info) {
        return new BarChart(info); // ritorna un'istanza di BarChart
    };
 
    return BarChartFactory;
 
}]);