aboutsummaryrefslogtreecommitdiff
path: root/web/javascript/networkGraph.js
blob: 2621dde1e995c7b172110feba307e028858848c7 (plain)
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
var searchResults = document.getElementById('searchResult').value.split("\t");
var symbolList = document.getElementById('symbolList').value.split("\t");
var originalThreshold = document.getElementById('kValue').value;
addTraitSelection();
		
function addTraitSelection()
{
    var gType = document.getElementById('gType').value;
    var nodeSelect = document.getElementById('nodeSelect');
    var newDropDown = document.createElement('newDrop');
        
    newDropDown.innerHTML = generateDropdownHtml();
    
    if (gType == "radial"){         
        nodeSelect.appendChild(newDropDown);
        originalLock = document.getElementById('lock').value;
        document.getElementById('lock').value = "yes";
        if ( originalThreshold == "undefined"){
            originalThreshold = document.getElementById('kValue').value;
        }
        document.getElementById('kValue').value = "0.0";
        
    }
    else{   
        try{
            nodeSelect.removeChild(nodeSelect.childNodes[0]);
            document.getElementById('lock').value = originalLock;
            document.getElementById('kValue').value = originalThreshold;
        } catch(err){
            originalLock = document.getElementById('lock').value;
            originalThreshold = document.getElementById('kValue').value;
        }
    }
}

function generateDropdownHtml(){
    var html = "";
    
    html += "<td align='right'>&nbsp;<select name='traitNode' id='traitNode'>";
    
    html += "<option value='none'>Select Central Node</option>";
    html += "<option value='auto'>Auto</option>";
    
    for (var i=0, len=searchResults.length; i<len; ++i)
    {
        html += "<option value='" + searchResults[i] + "'>" + symbolList[i] + ": " + searchResults[i] + "</option>";
    }
    
    html += "</select>";
    html += "</td>";
    
    return html;
}

function sortSearchResults(myForm)
{
    var newSearchResults = searchResults
    
    if (document.getElementById('traitNode')){
        var selectedNode = document.getElementById('traitNode').value;
        
        if (selectedNode == "none")
        {
            alert("Please select a central node for your radial graph.");
            return false;
        }
    
        else if (selectedNode == "auto")
        {
            var newSelectedNode = String(searchResults[parseInt(document.getElementById('optimalNode').value)]);
        }
        
        else
        {
            var newSelectedNode = selectedNode;
        }
        
        newSearchResults.splice(searchResults.indexOf(newSelectedNode), 1);
    
        newSearchResults.splice(0, 0, newSelectedNode);      
    }
    
    var gType = document.getElementById('gType').value;
    
    if (gType == "none")
    {
        alert("Please select a graph method.");
        return false;
    }
           
    document.getElementById('searchResult').value = newSearchResults.join("\t"); 
    
    databaseFunc(myForm, 'networkGraph');
    
}

function changeThreshold(){
    var lock = document.getElementById('lock').value;
    var threshold = document.getElementById('kValue').value;
    
    if (lock == "yes"){
        if(threshold != 0){
            originalThreshold = threshold;
            document.getElementById('kValue').value = "0.0";
        }
    }
    
    else if (lock == "no" && originalThreshold != 0){
        document.getElementById('kValue').value = originalThreshold;
    }
}