Code coverage report for lib/LegendFactory.js

Statements: 31.82% (7 / 22)      Branches: 100% (0 / 0)      Functions: 20% (1 / 5)      Lines: 31.82% (7 / 22)      Ignored: none     

All files » lib/ » LegendFactory.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          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 LegendFactory = function() {
    var createLegendRow = function(self, background, text) {
        var row = self.dialog.append('div').classed('up_pftv_legend', true);
        row.append('span')
            .classed('up_pftv_legendRect', true)
            .style('background-color', background);
        row.append('span')
            .classed('up_pftv_legendTitle', true)
            .text(text);
    };
    var populateDialog = function(self) {
        self.dialog.append('div')
            .text('Legend')
            .classed('up_pftv_dialog-legend', true);
 
        createLegendRow(self, self.UPDiseaseColor, 'Disease (UniProt)');
        createLegendRow(self, self.getPredictionColor(0), 'Deleterious (Large scale studies)');
 
        var colorScale = self.dialog.append('div');
        colorScale.selectAll('div')
            .data([0.2, 0.4, 0.6, 0.8])
            .enter().append('div')
            .classed('up_pftv_legend', true)
            .append('span')
            .classed('up_pftv_legendRect', true)
            .style('background-color', function(d) {
                return self.getPredictionColor(d);
            })
        ;
 
        createLegendRow(self, self.getPredictionColor(1), 'Benign (Large scale studies)');
        createLegendRow(self, self.UPNonDiseaseColor, 'Non-disease (UniProt)');
        createLegendRow(self, self.othersColor, 'Init codon, stop lost & gained');
    };
 
    return {
        UPDiseaseColor: '#990000',
        deleteriousColor: '#ff3300',
        benignColor: '#009900',
        UPNonDiseaseColor: '#99cc00',
        othersColor: '#0033cc',
        getPredictionColor: d3.scale.linear()
            .domain([0,1])
            .range(['#ff3300','#009900']),
        createLegendDialog: function(container, fv) {
            this.dialog = container.append('div')
                .attr('class','up_pftv_dialog-container');
            populateDialog(this, fv);
            return this.dialog;
        }
    };
}();
 
module.exports = LegendFactory;