Code coverage report for src/CategoryFilterDialog.js

Statements: 23.26% (10 / 43)      Branches: 0% (0 / 12)      Functions: 9.09% (1 / 11)      Lines: 23.26% (10 / 43)      Ignored: none     

All files » src/ » CategoryFilterDialog.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          1 1 1 1   1                                                                     1                                               1 1 1                                     1
/*jslint node: true */
/*jshint laxbreak: true */
/*jshint laxcomma: true */
"use strict";
 
var d3 = require("d3");
var _ = require("underscore");
var ViewerHelper = require("./ViewerHelper");
var Constants = require("./Constants");
 
var populateDialog = function (fv, wrapper) {
    var index = 0;
    _.each(Constants.getCategoryNamesInOrder(), function(category) {
        var catKey = _.keys(category)[0];
        var dataCategory = _.find(fv.data, function(catArray) {
            return catArray[0] === catKey;
        });
        if (dataCategory && (dataCategory[1].length !== 0)) {
            var div = wrapper.append('div');
            div.append('input')
                .attr('type', 'checkbox')
                .property('checked', true)
                .attr('index', index)
                .on('click', function() {
                    var elem = d3.select(this);
                    var myIndex = +elem.attr('index');
                    var allCategory = d3.selectAll('.up_pftv_category');
                    if (elem.property('checked')) {
                        d3.select(allCategory[0][myIndex]).style('display', 'block');
                        wrapper.selectAll('input:disabled').attr('disabled', null);
                    } else {
                        d3.select(allCategory[0][myIndex]).style('display', 'none');
                        var displayed = wrapper.selectAll("input:checked");
                        if (displayed[0].length === 1) {
                            displayed.attr('disabled', true);
                        }
                    }
                });
            div.append('label')
                .text(category[catKey]);
            index++;
        }
    });
};
 
var createDialog = function (fv, container) {
    var wrapper = container.append('div')
        .attr('class','up_pftv_popupDialog-container')
        .style('left', (d3.mouse(container.node())[0] + 10) + 'px')
        .style('top', (d3.mouse(container.node())[1] + 5) + 'px')
        .on('mousedown', function() {
            fv.overCatFilterDialog = true;
        })
        .on('mouseup', function() {
            fv.overCatFilterDialog = false;
        });
    wrapper.append('span')
        .text('x')
        .attr('class','up_pftv_tooltip-close')
        .on('click',function(){
            fv.overCatFilterDialog = false;
            wrapper.transition(20)
                .style('opacity',0)
                .style('display','none');
        });
    populateDialog(fv, wrapper);
    return wrapper;
};
 
var CategoryFilterDialog = function() {
    var dialog;
    return {
        displayDialog: function(fv, container) {
            if (!dialog) {
                dialog = createDialog(fv, container);
            }
            dialog.transition(20)
                .style('opacity',1)
                .style('display','block');
        },
        closeDialog: function() {
            if (dialog) {
                dialog.transition(20)
                    .style('opacity', 0)
                    .style('display', 'none');
            }
        }
    };
}();
 
module.exports = CategoryFilterDialog;