# Code coverage report for lib/BasicViewer.js

## Statements: 17.65% (6 / 34) Branches: 0% (0 / 4) Functions: 0% (0 / 9) Lines: 17.65% (6 / 34) Ignored: none

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

    1
    1
    1
    1

    1

    1/*jslint node: true */
    /*jshint laxbreak: true */
    "use strict";

    var d3 = require("d3");
    var FeatureFactory = require("./FeatureFactory");
    var NonOverlappingLayout = require("./NonOverlappingLayout");
    var ViewerHelper = require("./ViewerHelper");

    var BasicViewer = function(catTitle, features, container, fv) {
        var height = 40;
        var width = fv.width;

        var layout = new NonOverlappingLayout(features, height);
        layout.calculate();

        var featurePlot = function() {
            var series,
                shapes;

            var featurePlot = function(selection) {
                selection.each(function(data) {
                    series = d3.select(this);
                    shapes = series.selectAll('.up_pftv_feature')
                        .data(data);

                    var newShapes = shapes.enter().append('path')
                        .attr('name', function(d) {
                            return d.internalId;
                        })
                        .attr('class',function(d) {
                            return 'up_pftv_feature up_pftv_' + d.type.name.toLowerCase();
                        })
                    ;

                    shapes
                        .attr('d', function(d) {
                            return FeatureFactory.getFeature(
                                d.type.name,
                                fv.xScale(2) - fv.xScale(1),
                                layout.getFeatureHeight(),
                                (d.end) ? d.end - d.begin + 1 : 1);
                        })
                        .attr('transform',function(d) {
                            return 'translate('+fv.xScale(d.begin)+ ',' + layout.getYPos(d) + ')';
                        })
                    ;
                    ViewerHelper.addEventsClassAndTitle(catTitle, newShapes, fv, container);
                    shapes.exit().remove();
                });
            };
            return featurePlot;
        };

        var series = featurePlot();
        var svg = ViewerHelper.createSVG(container, width, height, fv);

        var drawArea = svg.append('g')
            .classed('up_pftv_category-viewer-group', true);

        var dataSeries = drawArea
            .datum(features)
            .call(series);

        this.update = function() {
            dataSeries.call(series);
            if (fv.selectedFeature) {
                ViewerHelper.updateShadow(fv.selectedFeature, fv);
            }
        };

        return this;
    };

    module.exports = BasicViewer;