2 * for graphical presentation of phenotype data of a trait
3 * @author Isaak Y Tecle <iyt2@cornell.edu>
7 jQuery(document).ready( function() {
8 plotPhenotypeScatter();
12 function plotPhenotypeScatter () {
13 var popId = jQuery('#model_id').val();
14 var traitId = jQuery('#trait_id').val();
15 var comboPopsId = jQuery('#combo_pops_id').val();
19 params = 'pop_id=' + popId + '&trait_id=' + traitId;
21 params = 'combo_pops_id=' + comboPopsId + '&trait_id=' + traitId;
24 var action = '/solgs/phenotype/graph/';
26 var phenoPlotData = [];
27 phenoPlotData[0] = [];
28 var xAxisTickPhenoValues = [];
29 var yAxisTickPhenoValues = [];
30 var yPhenoValues = [];
32 var phenoDataRenderer = function() {
38 success: function(data) {
39 var phenoData = data.trait_data;
40 var state = data.status;
42 if (state == 'success') {
43 for (var i=0; i < phenoData.length; i++) {
44 var xPD = phenoData[i][0];
46 var yPD = phenoData[i][1];
47 yPD = yPD.replace(/\s/, '');
50 xAxisTickPhenoValues.push([i, xPD]);
51 yAxisTickPhenoValues.push([i, yPD]);
52 yPhenoValues.push(yPD);
54 phenoPlotData[0][i] = [];
55 phenoPlotData[0][i][0] = xPD;
56 phenoPlotData[0][i][1] = yPD;
63 return {'bothAxisPhenoValues' : phenoPlotData,
64 'xAxisPhenoValues' : xAxisTickPhenoValues,
65 'yAxisPhenoValues' : yAxisTickPhenoValues,
66 'yPhenoValues' : yPhenoValues
71 var allPhenoData = phenoDataRenderer();
72 var xAxisPhenoValues = allPhenoData.xAxisPhenoValues;
73 var yAxisPhenoValues = allPhenoData.yAxisPhenoValues;
74 var yPhenoValues = allPhenoData.yPhenoValues;
75 var minYPheno = Math.min.apply(Math, yPhenoValues);
76 var maxYPheno = Math.max.apply(Math, yPhenoValues);
77 var minYPhenoLabel = minYPheno - (0.2*minYPheno);
78 var maxYPhenoLabel = maxYPheno + (0.2*maxYPheno);
79 var plotPhenoData = allPhenoData.bothAxisPhenoValues;
81 if (plotPhenoData == 'undefined') {
82 var message = 'There is no phenotype data to plot. Please report this problem';
83 jQuery('#phenoPlot').append(message).show();
105 tickColor: '#ffffff',
109 axisLabelPadding: 20,
115 axisLabel: 'Phenotype values',
129 var plotPheno = jQuery.plot('#phenoPlot', plotPhenoData, optionsPheno);
131 var overviewPheno = jQuery.plot(jQuery("#phenoPlotOverview"), plotPhenoData, {
147 colors: ["#cc0000", "#0066CC"],
150 jQuery("#phenoPlot").bind("plotselected", function (event, ranges) {
152 plotPheno = jQuery.plot(jQuery("#phenoPlot"), plotPhenoData,
153 jQuery.extend(true, {}, optionsPheno, {
154 xaxis: { min: ranges.xaxis.from, max: ranges.xaxis.to },
155 yaxis: { min: ranges.yaxis.from, max: ranges.yaxis.to },
158 plotPheno.setSelection(ranges, true);
159 overviewPheno.setSelection(ranges, true);
162 //highlight selected area on the overview plot
163 jQuery("#phenoPlotOverview").bind("plotselected", function (event, ranges) {
164 plotPheno.setSelection(ranges);
167 //reset zooming. Need to figure out zooming out
168 jQuery("#phenozoom-reset").click(function (e) {
169 //jQuery.plot("#phenoPlot", plotPhenoData, optionsPheno);
174 //given datapoint position and content, displays a styled tooltip
175 var showTooltipPheno = function(lt, tp, content) {
176 jQuery('<div id="phenotooltip">' + content + '</div>').css({
177 position: 'absolute',
179 'font-weight': 'bold',
182 border: '1px solid #ffaf55',
184 }).appendTo("body").show();
187 var zoomHelp = function (lt, tp) {
188 var help_txt = '<div style="width:140px;height:90px">' +
189 'To zoom in, select an area ' +
190 'on the plot and release or double click at any ' +
191 'point on the plot.' +
194 jQuery('<div id="tooltipZoomPheno">' + help_txt + '</div>').css({
195 position: 'absolute',
197 'font-weight': 'bold',
200 border: '1px solid #C9BE62',
202 }).appendTo("body").show();
205 //calls the tooltip display function and binds the 'plotover' event to
207 var previousPoint = null;
208 var useTooltipPheno = jQuery("#phenoPlot").bind("plothover", function (event, pos, item) {
210 if (previousPoint != item.dataIndex) {
211 previousPoint = item.dataIndex;
213 jQuery("#phenotooltip").remove();
214 jQuery("#tooltipZoomPheno").remove();
216 var x = item.datapoint[0];
217 var y = item.datapoint[1].toFixed(2);
218 var content = xAxisTickPhenoValues[x][1] + ', ' + y;
220 showTooltipPheno(item.pageX, item.pageY, content);
221 zoomHelp(item.pageX, item.pageY);
225 jQuery("#phenotooltip").remove();
226 jQuery("#tooltipZoomPheno").remove();
228 previousPoint = null;