Code coverage report for app/views/population/populationYearChartView.js

Statements: 100% (12 / 12)      Branches: 100% (4 / 4)      Functions: 100% (4 / 4)      Lines: 100% (12 / 12)      Ignored: none     

All files » app/views/population/ » populationYearChartView.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                  1                                       1                                                       1                         9 8             8 26     8 8   8 8   1      
/*global require, define, console, $ */
/*jslint nomen: true, debug: true, todo: true */
 
/**
 * @module populationYearChartView
 * @extends module:chartView
 */
 
 
define([
    "views/chartView",
    "underscore",
    "utils"
],
    function (chartView, _, utils) {
        "use strict";
 
        /**
         * @name module:populationYearChartView
         * @description Average population chart
         * @requires module:chartView
         * @class Backbone.View
         * @requires module:chartView
         * @requires underscore
         * @requires module:utils
         * @see module:utils
         * @constructor
         * @returns {Function} Backbone.View constructor
         */
        return chartView.extend({
            /**
             * @name module:populationYearChartView#type
             * @description Chart type
             * @type {string}
             */
            type: "column",
            /**
             * @name module:populationYearChartView#options
             * @description Chart config extension object
             * @type {object}
             */
            options: {
                yAxis: {
                    title: {
                        text: "population".toLocaleString()
                    }
                },
                series: [
                    {
                        name: "male".toLocaleString()
                    },
                    {
                        name: "female".toLocaleString()
                    }
                ],
                tooltip: {
                    formatter: function () {
                        return "<b>" + this.series.name + "</b><br/>" + this.x + ": " + this.y.toFixed(0);
                    }
                }
            },
            /**
             * @name module:populationYearChartView#update
             * @description Updates chart state by new data
             * @function
             * @param [data] {array} new data
             * @returns {object|undefined} chart.series or undefined
             */
            update: function (data) {
                //return
                if (this.chart && data) {
                    var view = this,
                        range = _.range(1, 12),
                        series = {
                            male: [].concat(data.male),
                            female: [].concat(data.female)
                        };
 
                    _.each(data, function (s) {
                        s = utils.replace(undefined, null);
                    });
 
                    this.updateCol(series.male, series.female);
                    this.chart.xAxis[0].setCategories(range, false);
 
                    this.redraw();
                    return data;
                }
                return;
            }
        });
    });