# Code coverage report for lib/CategoryFilterDialog.js

## Statements: 20.93% (9 / 43) Branches: 0% (0 / 16) Functions: 10% (1 / 10) Lines: 20.93% (9 / 43) Ignored: none

All files » lib/ » 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
    92

    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 populateDialog = function (fv, data, wrapper) {
        var index = 0;
        _.each(fv.categoryOrderAndType, function(value, categoryName) {
            if (data[categoryName] && (data[categoryName].features.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');
                            if (fv.selectedFeature) {
                                var key = _.keys(fv.categoryOrderAndType)[myIndex];
                                if (_.contains(fv.categoryOrderAndType[key].ftTypes, fv.selectedFeature.type.name)) {
                                    ViewerHelper.selectFeature(fv.selectedFeature, fv.selectedFeatureElement, fv);
                                }
                            }
                            var displayed = wrapper.selectAll("input:checked");
                            if (displayed[0].length === 1) {
                                displayed.attr('disabled', true);
                            }
                        }
                    });
                div.append('label')
                    .text(data[categoryName].label);
                index++;
            }
        });
    };

    var createDialog = function (fv, data, 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, data, wrapper);
        return wrapper;
    };

    var CategoryFilterDialog = function() {
        var dialog;
        return {
            displayDialog: function(fv, data, container) {
                if (!dialog) {
                    dialog = createDialog(fv, data, 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;