Merge branch 'QA_3_4'
[phpmyadmin.git] / js / tbl_zoom_plot.js
blobce3de9daaea945b82d4bc5ac403046552f292ac6
1 /* vim: set expandtab sw=4 ts=4 sts=4: */
2 /**
3  ** @fileoverview JavaScript functions used on tbl_select.php
4  **
5  ** @requires    jQuery
6  ** @requires    js/functions.js
7  **/
10 /**
11  **  Display Help/Info
12  **/
13 function displayHelp() {
14     var msgbox = PMA_ajaxShowMessage(PMA_messages['strDisplayHelp'], 10000);
15     msgbox.click(function() {
16         PMA_ajaxRemoveMessage(msgbox);
17     });
20 /**
21  ** Extend the array object for max function
22  ** @param array
23  **/
24 Array.max = function (array) {
25     return Math.max.apply( Math, array );
28 /**
29  ** Extend the array object for min function
30  ** @param array
31  **/
32 Array.min = function (array) {
33     return Math.min.apply( Math, array );
36 /**
37  ** Checks if a string contains only numeric value
38  ** @param n: String (to be checked)
39  **/
40 function isNumeric(n) {
41     return !isNaN(parseFloat(n)) && isFinite(n);
44 /**
45  ** Checks if an object is empty
46  ** @param n: Object (to be checked)
47  **/
48 function isEmpty(obj) {
49     var name;
50     for (name in obj) {
51         return false;
52     }
53     return true;
56 /**
57  ** Converts a timestamp into the format of its field type
58  ** @param val  Integer Timestamp
59  ** @param type String  Field type(datetime/timestamp/time/date)
60  **/
61 function getDate(val, type) {
62     if (type.toString().search(/datetime/i) != -1 || type.toString().search(/timestamp/i) != -1) {
63         return Highcharts.dateFormat('%Y-%m-%e %H:%M:%S', val);
64     }
65     else if (type.toString().search(/time/i) != -1) {
66         return Highcharts.dateFormat('%H:%M:%S', val);
67     }
68     else if (type.toString().search(/date/i) != -1) {
69         return Highcharts.dateFormat('%Y-%m-%e', val);
70     }
73 /**
74  ** Converts a date/time into timestamp
75  ** @param val  String Date
76  ** @param type Sring  Field type(datetime/timestamp/time/date)
77  **/
78 function getTimeStamp(val, type) {
79     if (type.toString().search(/datetime/i) != -1 || type.toString().search(/timestamp/i) != -1) {
80         return getDateFromFormat(val, 'yyyy-MM-dd HH:mm:ss', val);
81     }
82     else if (type.toString().search(/time/i) != -1) {
83         return getDateFromFormat('1970-01-01 ' + val, 'yyyy-MM-dd HH:mm:ss');
84     }
85     else if (type.toString().search(/date/i) != -1) {
86         return getDateFromFormat(val, 'yyyy-MM-dd');
87     }
90 /**
91  ** Classifies the field type into numeric,timeseries or text
92  ** @param field: field type (as in database structure)
93  **/
94 function getType(field) {
95     if (field.toString().search(/int/i) != -1 || field.toString().search(/decimal/i) != -1
96         || field.toString().search(/year/i) != -1) {
97         return 'numeric';
98     } else if (field.toString().search(/time/i) != -1 || field.toString().search(/date/i) != -1) {
99         return 'time';
100     } else {
101         return 'text';
102     }
105  ** Converts a categorical array into numeric array
106  ** @param array categorical values array
107  **/
108 function getCord(arr) {
109     var newCord = new Array();
110     var original = $.extend(true, [], arr);
111     var arr = jQuery.unique(arr).sort();
112     $.each(original, function(index, value) {
113         newCord.push(jQuery.inArray(value, arr));
114     });
115     return [newCord, arr, original];
119  ** Scrolls the view to the display section
120  **/
121 function scrollToChart() {
122    var x = $('#dataDisplay').offset().top - 100; // 100 provides buffer in viewport
123    $('html,body').animate({scrollTop: x}, 500);
127  ** Handlers for panning feature
128  **/
129 function includePan(currentChart) {
130     var mouseDown;
131     var lastX;
132     var lastY;
133     var chartWidth = $('#resizer').width() - 3;
134     var chartHeight = $('#resizer').height() - 20;
135     $('#querychart').mousedown(function() {
136         mouseDown = 1;
137     });
139     $('#querychart').mouseup(function() {
140         mouseDown = 0;
141     });
142     $('#querychart').mousemove(function(e) {
143         if (mouseDown == 1) {
144             if (e.pageX > lastX) {
145                 var xExtremes = currentChart.xAxis[0].getExtremes();
146                 var diff = (e.pageX - lastX) * (xExtremes.max - xExtremes.min) / chartWidth;
147                 currentChart.xAxis[0].setExtremes(xExtremes.min - diff, xExtremes.max - diff);
148             } else if (e.pageX < lastX) {
149                 var xExtremes = currentChart.xAxis[0].getExtremes();
150                 var diff = (lastX - e.pageX) * (xExtremes.max - xExtremes.min) / chartWidth;
151                 currentChart.xAxis[0].setExtremes(xExtremes.min + diff, xExtremes.max + diff);
152             }
154             if (e.pageY > lastY) {
155                 var yExtremes = currentChart.yAxis[0].getExtremes();
156                 var ydiff = 1.0 * (e.pageY - lastY) * (yExtremes.max - yExtremes.min) / chartHeight;
157                 currentChart.yAxis[0].setExtremes(yExtremes.min + ydiff, yExtremes.max + ydiff);
158             } else if (e.pageY < lastY) {
159                 var yExtremes = currentChart.yAxis[0].getExtremes();
160                 var ydiff = 1.0 * (lastY - e.pageY) * (yExtremes.max - yExtremes.min) / chartHeight;
161                 currentChart.yAxis[0].setExtremes(yExtremes.min - ydiff, yExtremes.max - ydiff);
162             }
163         }
164         lastX = e.pageX;
165         lastY = e.pageY;
166     });
169 $(document).ready(function() {
171    /**
172     ** Set a parameter for all Ajax queries made on this page.  Don't let the
173     ** web server serve cached pages
174     **/
175     $.ajaxSetup({
176         cache: 'false'
177     });
179     var cursorMode = ($("input[name='mode']:checked").val() == 'edit') ? 'crosshair' : 'pointer';
180     var currentChart = null;
181     var currentData = null;
182     var xLabel = $('#tableid_0').val();
183     var yLabel = $('#tableid_1').val();
184     var xType = $('#types_0').val();
185     var yType = $('#types_1').val();
186     var dataLabel = $('#dataLabel').val();
187     var lastX;
188     var lastY;
189     var zoomRatio = 1;
192     // Get query result
193     var data = jQuery.parseJSON($('#querydata').html());
195     /**
196      ** Input form submit on field change
197      **/
198     $('#tableid_0').change(function() {
199           $('#zoom_search_form').submit();
200     });
202     $('#tableid_1').change(function() {
203           $('#zoom_search_form').submit();
204     });
206     $('#tableid_2').change(function() {
207           $('#zoom_search_form').submit();
208     });
210     $('#tableid_3').change(function() {
211           $('#zoom_search_form').submit();
212     });
214     /**
215      * Input form validation
216      **/
217     $('#inputFormSubmitId').click(function() {
218         if ($('#tableid_0').get(0).selectedIndex == 0 || $('#tableid_1').get(0).selectedIndex == 0) {
219             PMA_ajaxShowMessage(PMA_messages['strInputNull']);
220         } else if (xLabel == yLabel) {
221             PMA_ajaxShowMessage(PMA_messages['strSameInputs']);
222         }
223     });
225     /**
226       ** Prepare a div containing a link, otherwise it's incorrectly displayed
227       ** after a couple of clicks
228       **/
229     $('<div id="togglesearchformdiv"><a id="togglesearchformlink"></a></div>')
230         .insertAfter('#zoom_search_form')
231         // don't show it until we have results on-screen
232         .hide();
234     $('#togglesearchformlink')
235         .html(PMA_messages['strShowSearchCriteria'])
236         .bind('click', function() {
237             var $link = $(this);
238             $('#zoom_search_form').slideToggle();
239             if ($link.text() == PMA_messages['strHideSearchCriteria']) {
240                 $link.text(PMA_messages['strShowSearchCriteria']);
241             } else {
242                 $link.text(PMA_messages['strHideSearchCriteria']);
243             }
244          // avoid default click action
245         return false;
246      });
248     /**
249      ** Set dialog properties for the data display form
250      **/
251     $("#dataDisplay").dialog({
252         autoOpen: false,
253         title: 'Data point content',
254         modal: false, //false otherwise other dialogues like timepicker may not function properly
255         height: $('#dataDisplay').height() + 80,
256         width: $('#dataDisplay').width() + 80
257     });
259     /*
260      * Handle submit of zoom_display_form
261      */
263     $("#submitForm").click(function(event) {
265         //Prevent default submission of form
266         event.preventDefault();
268         //Find changed values by comparing form values with selectedRow Object
269         var newValues = new Object();//Stores the values changed from original
270         var sqlTypes = new Object();
271         var it = 4;
272         var xChange = false;
273         var yChange = false;
274         for (key in selectedRow) {
275             var oldVal = selectedRow[key];
276             var newVal = ($('#fields_null_id_' + it).attr('checked')) ? null : $('#fieldID_' + it).val();
277             if (newVal instanceof Array) { // when the column is of type SET
278                 newVal =  $('#fieldID_' + it).map(function(){
279                     return $(this).val();
280                 }).get().join(",");
281             }
282             if (oldVal != newVal) {
283                 selectedRow[key] = newVal;
284                 newValues[key] = newVal;
285                 if (key == xLabel) {
286                     xChange = true;
287                     data[currentData][xLabel] = newVal;
288                 } else if (key == yLabel) {
289                     yChange = true;
290                     data[currentData][yLabel] = newVal;
291                 }
292             }
293             var $input = $('#fieldID_' + it);
294             if ($input.hasClass('bit')) {
295                 sqlTypes[key] = 'bit';
296             }
297             it++;
298         } //End data update
300         //Update the chart series and replot
301         if (xChange || yChange) {
302             var newSeries = new Array();
303             newSeries[0] = new Object();
304             newSeries[0].marker = {
305                 symbol: 'circle'
306             };
307             //Logic similar to plot generation, replot only if xAxis changes or yAxis changes. 
308             //Code includes a lot of checks so as to replot only when necessary
309             if (xChange) {
310                 xCord[currentData] = selectedRow[xLabel];
311                 if (xType == 'numeric') {
312                     currentChart.series[0].data[currentData].update({ x : selectedRow[xLabel] });
313                     currentChart.xAxis[0].setExtremes(Array.min(xCord) - 6, Array.max(xCord) + 6);
314                 } else if (xType == 'time') {
315                     currentChart.series[0].data[currentData].update({ 
316                         x : getTimeStamp(selectedRow[xLabel], $('#types_0').val())
317                     });
318                 } else {
319                     var tempX = getCord(xCord);
320                     var tempY = getCord(yCord);
321                     var i = 0;
322                     newSeries[0].data = new Array();
323                     xCord = tempX[2];
324                     yCord = tempY[2];
326                     $.each(data, function(key, value) {
327                         if (yType != 'text') {
328                             newSeries[0].data.push({ 
329                                 name: value[dataLabel], 
330                                 x: tempX[0][i], 
331                                 y: value[yLabel], 
332                                 marker: {fillColor: colorCodes[i % 8]}, 
333                                 id: i 
334                             });
335                         } else {
336                             newSeries[0].data.push({ 
337                                 name: value[dataLabel], 
338                                 x: tempX[0][i], 
339                                 y: tempY[0][i], 
340                                 marker: {fillColor: colorCodes[i % 8]}, 
341                                 id: i 
342                             });
343                         }
344                         i++;
345                     });
346                     currentSettings.xAxis.labels = {
347                         formatter : function() {
348                             if (tempX[1][this.value] && tempX[1][this.value].length > 10) {
349                                 return tempX[1][this.value].substring(0, 10);
350                             } else {
351                                 return tempX[1][this.value];
352                             }
353                         }
354                      };
355                      currentSettings.series = newSeries;
356                      currentChart = PMA_createChart(currentSettings);
357                  }
359             }
360             if (yChange) {
361                 yCord[currentData] = selectedRow[yLabel];
362                 if (yType == 'numeric') {
363                     currentChart.series[0].data[currentData].update({ y : selectedRow[yLabel] });
364                     currentChart.yAxis[0].setExtremes(Array.min(yCord) - 6, Array.max(yCord) + 6);
365                 } else if (yType == 'time') {
366                     currentChart.series[0].data[currentData].update({ 
367                         y : getTimeStamp(selectedRow[yLabel], $('#types_1').val())
368                     });
369                 } else {
370                     var tempX = getCord(xCord);
371                     var tempY = getCord(yCord);
372                     var i = 0;
373                     newSeries[0].data = new Array();
374                     xCord = tempX[2];
375                     yCord = tempY[2];
377                     $.each(data, function(key, value) {
378                         if (xType != 'text' ) {
379                             newSeries[0].data.push({ 
380                                 name: value[dataLabel], 
381                                 x: value[xLabel], 
382                                 y: tempY[0][i], 
383                                 marker: {fillColor: colorCodes[i % 8]}, 
384                                 id: i 
385                             });
386                         } else {
387                             newSeries[0].data.push({ 
388                                 name: value[dataLabel], 
389                                 x: tempX[0][i], 
390                                 y: tempY[0][i], 
391                                 marker: {fillColor: colorCodes[i % 8]}, 
392                                 id: i 
393                             });
394                         }
395                         i++;
396                     });
397                     currentSettings.yAxis.labels = {
398                         formatter : function() {
399                             if (tempY[1][this.value] && tempY[1][this.value].length > 10) {
400                                 return tempY[1][this.value].substring(0, 10);
401                             } else {
402                                 return tempY[1][this.value];
403                             }
404                         }
405                      };
406                      currentSettings.series = newSeries;
407                      currentChart = PMA_createChart(currentSettings);
408                 }
409             }
410             currentChart.series[0].data[currentData].select();
411         } //End plot update
413         //Generate SQL query for update
414         if (!isEmpty(newValues)) {
415             var sql_query = 'UPDATE `' + window.parent.table + '` SET ';
416             for (key in newValues) {
417                 sql_query += '`' + key + '`=' ;
418                 var value = newValues[key];
420                 // null
421                 if (value == null) {
422                     sql_query += 'NULL, ';
424                 // empty
425                 } else if ($.trim(value) == '') {
426                     sql_query += "'', ";
428                 // other
429                 } else {
430                     // type explicitly identified
431                     if (sqlTypes[key] != null) {
432                         if (sqlTypes[key] == 'bit') {
433                             sql_query += "b'" + value + "', ";
434                         }
435                     // type not explicitly identified
436                     } else {
437                         if (!isNumeric(value)) {
438                             sql_query += "'" + value + "', ";
439                         } else {
440                             sql_query += value + ', ';
441                         }
442                     }
443                 }
444             }
445             sql_query = sql_query.substring(0, sql_query.length - 2);
446             sql_query += ' WHERE ' + PMA_urldecode(data[currentData]['where_clause']);
448             //Post SQL query to sql.php
449             $.post('sql.php', {
450                     'token' : window.parent.token,
451                     'db' : window.parent.db,
452                     'ajax_request' : true,
453                     'sql_query' : sql_query,
454                     'inline_edit' : false
455                 }, function(data) {
456                     if (data.success == true) {
457                         $('#sqlqueryresults').html(data.sql_query);
458                         $("#sqlqueryresults").trigger('appendAnchor');
459                     } else {
460                         PMA_ajaxShowMessage(data.error);
461                     }
462             }); //End $.post
463         }//End database update
464         $("#dataDisplay").dialog("close");
465     });//End submit handler
467     /*
468      * Generate plot using Highcharts
469      */
471     if (data != null) {
472         $('#zoom_search_form')
473          .slideToggle()
474          .hide();
475         $('#togglesearchformlink')
476          .text(PMA_messages['strShowSearchCriteria']);
477         $('#togglesearchformdiv').show();
478         var selectedRow;
479         var colorCodes = ['#FF0000', '#00FFFF', '#0000FF', '#0000A0', '#FF0080', '#800080', '#FFFF00', '#00FF00', '#FF00FF'];
480         var series = new Array();
481         var xCord = new Array();
482         var yCord = new Array();
483         var tempX, tempY;
484         var it = 0;
485         var xMax; // xAxis extreme max
486         var xMin; // xAxis extreme min
487         var yMax; // yAxis extreme max
488         var yMin; // yAxis extreme min
490         // Set the basic plot settings
491         var currentSettings = {
492             chart: {
493                 renderTo: 'querychart',
494                 type: 'scatter',
495                 //zoomType: 'xy',
496                 width:$('#resizer').width() - 3,
497                 height:$('#resizer').height() - 20
498             },
499             credits: {
500                 enabled: false
501             },
502             exporting: { enabled: false },
503             label: { text: $('#dataLabel').val() },
504             plotOptions: {
505                 series: {
506                     allowPointSelect: true,
507                     cursor: 'pointer',
508                     showInLegend: false,
509                     dataLabels: {
510                         enabled: false
511                     },
512                     point: {
513                         events: {
514                             click: function() {
515                                 var id = this.id;
516                                 var fid = 4;
517                                 currentData = id;
518                                 // Make AJAX request to tbl_zoom_select.php for getting the complete row info
519                                 var post_params = {
520                                     'ajax_request' : true,
521                                     'get_data_row' : true,
522                                     'db' : window.parent.db,
523                                     'table' : window.parent.table,
524                                     'where_clause' : data[id]['where_clause'],
525                                     'token' : window.parent.token
526                                 };
527                                 $.post('tbl_zoom_select.php', post_params, function(data) {
528                                     // Row is contained in data.row_info, now fill the displayResultForm with row values
529                                     for (key in data.row_info) {
530                                         $field = $('#fieldID_' + fid);
531                                         $field_null = $('#fields_null_id_' + fid);
532                                         if (data.row_info[key] == null) {
533                                             $field_null.attr('checked', true);
534                                             $field.val('');
535                                         } else {
536                                             $field_null.attr('checked', false);
537                                             if ($field.attr('multiple')) { // when the column is of type SET
538                                                 $field.val(data.row_info[key].split(','));
539                                             } else {
540                                                 $field.val(data.row_info[key]);
541                                             }
542                                         }
543                                         fid++;
544                                     }
545                                     selectedRow = new Object();
546                                     selectedRow = data.row_info;
547                                 });
549                                 $("#dataDisplay").dialog("open");
550                             }
551                         }
552                     }
553                 }
554             },
555             tooltip: {
556                 formatter: function() {
557                     return this.point.name;
558                 }
559             },
560             title: { text: 'Query Results' },
561             xAxis: {
562                 title: { text: $('#tableid_0').val() },
563                 events: {
564                     setExtremes: function(e) {
565                         this.resetZoom.show();
566                     }
567                 }
569             },
570             yAxis: {
571                 min: null,
572                 title: { text: $('#tableid_1').val() },
573                 endOnTick: false,
574                 startOnTick: false,
575                 events: {
576                     setExtremes: function(e) {
577                         this.resetZoom.show();
578                     }
579                 }
580             }
581         };
583         // If data label is not set, do not show tooltips
584         if (dataLabel == '') {
585              currentSettings.tooltip.enabled = false;
586         }
588         $('#resizer').resizable({
589             resize: function() {
590                 currentChart.setSize(
591                     this.offsetWidth - 3,
592                     this.offsetHeight - 20,
593                     false
594                 );
595             }
596         });
598         // Classify types as either numeric,time,text
599         xType = getType(xType);
600         yType = getType(yType);
602         //Set the axis type based on the field
603         currentSettings.xAxis.type = (xType == 'time') ? 'datetime' : 'linear';
604         currentSettings.yAxis.type = (yType == 'time') ? 'datetime' : 'linear';
606         // Formulate series data for plot
607         series[0] = new Object();
608         series[0].data = new Array();
609         series[0].marker = {
610             symbol: 'circle'
611         };
612         if (xType != 'text' && yType != 'text') {
613             $.each(data, function(key, value) {
614                 var xVal = (xType == 'numeric') ? value[xLabel] : getTimeStamp(value[xLabel], $('#types_0').val());
615                 var yVal = (yType == 'numeric') ? value[yLabel] : getTimeStamp(value[yLabel], $('#types_1').val());
616                 series[0].data.push({ 
617                     name: value[dataLabel], 
618                     x: xVal, 
619                     y: yVal, 
620                     marker: {fillColor: colorCodes[it % 8]}, 
621                     id: it 
622                 });
623                 xCord.push(value[xLabel]);
624                 yCord.push(value[yLabel]);
625                 it++;
626             });
627             if (xType == 'numeric') {
628                 currentSettings.xAxis.max = Array.max(xCord) + 6;
629                 currentSettings.xAxis.min = Array.min(xCord) - 6;
630             } else {
631                 currentSettings.xAxis.labels = { formatter : function() {
632                     return getDate(this.value, $('#types_0').val());
633                 }};
634             }
635             if (yType == 'numeric') {
636                 currentSettings.yAxis.max = Array.max(yCord) + 6;
637                 currentSettings.yAxis.min = Array.min(yCord) - 6;
638             } else {
639                 currentSettings.yAxis.labels = { formatter : function() {
640                      return getDate(this.value, $('#types_1').val());
641                 }};
642             }
644         } else if (xType == 'text' && yType != 'text') {
645             $.each(data, function(key, value) {
646                 xCord.push(value[xLabel]);
647                 yCord.push(value[yLabel]);
648             });
650             tempX = getCord(xCord);
651             $.each(data, function(key, value) {
652                 var yVal = (yType == 'numeric') ? value[yLabel] : getTimeStamp(value[yLabel], $('#types_1').val());
653                 series[0].data.push({ 
654                     name: value[dataLabel], 
655                     x: tempX[0][it], 
656                     y: yVal, 
657                     marker: {fillColor: colorCodes[it % 8]}, 
658                     id: it 
659                 });
660                 it++;
661             });
663             currentSettings.xAxis.labels = {
664                 formatter : function() {
665                     if (tempX[1][this.value] && tempX[1][this.value].length > 10) {
666                         return tempX[1][this.value].substring(0, 10);
667                     } else {
668                         return tempX[1][this.value];
669                     }
670                 }
671             };
672             if (yType == 'numeric') {
673                 currentSettings.yAxis.max = Array.max(yCord) + 6;
674                 currentSettings.yAxis.min = Array.min(yCord) - 6;
675             } else {
676                 currentSettings.yAxis.labels = {
677                     formatter : function() {
678                         return getDate(this.value, $('#types_1').val());
679                     }
680                 };
681             }
682             xCord = tempX[2];
684         } else if (xType != 'text' && yType == 'text') {
685             $.each(data, function(key, value) {
686                 xCord.push(value[xLabel]);
687                 yCord.push(value[yLabel]);
688             });
689             tempY = getCord(yCord);
690             $.each(data, function(key, value) {
691                 var xVal = (xType == 'numeric') ? value[xLabel] : getTimeStamp(value[xLabel], $('#types_0').val());
692                 series[0].data.push({ 
693                     name: value[dataLabel], 
694                     y: tempY[0][it], 
695                     x: xVal, 
696                     marker: {fillColor: colorCodes[it % 8]}, 
697                     id: it 
698                 });
699                 it++;
700             });
701             if (xType == 'numeric') {
702                 currentSettings.xAxis.max = Array.max(xCord) + 6;
703                 currentSettings.xAxis.min = Array.min(xCord) - 6;
704             } else {
705                 currentSettings.xAxis.labels = {
706                     formatter : function() {
707                         return getDate(this.value, $('#types_0').val());
708                     }
709                 };
710             }
711             currentSettings.yAxis.labels = {
712                 formatter : function() {
713                     if (tempY[1][this.value] && tempY[1][this.value].length > 10) {
714                         return tempY[1][this.value].substring(0, 10);
715                     } else {
716                         return tempY[1][this.value];
717                     }
718                 }
719             };
720             yCord = tempY[2];
722         } else if (xType == 'text' && yType == 'text') {
723             $.each(data, function(key, value) {
724                 xCord.push(value[xLabel]);
725                 yCord.push(value[yLabel]);
726             });
727             tempX = getCord(xCord);
728             tempY = getCord(yCord);
729             $.each(data, function(key, value) {
730                 series[0].data.push({ 
731                     name: value[dataLabel], 
732                     x: tempX[0][it], 
733                     y: tempY[0][it], 
734                     marker: {fillColor: colorCodes[it % 8]}, 
735                     id: it 
736                 });
737                 it++;
738             });
739             currentSettings.xAxis.labels = {
740                 formatter : function() {
741                     if (tempX[1][this.value] && tempX[1][this.value].length > 10) {
742                         return tempX[1][this.value].substring(0, 10);
743                     } else {
744                         return tempX[1][this.value];
745                     }
746                 }
747             };
748             currentSettings.yAxis.labels = {
749                 formatter : function() {
750                     if (tempY[1][this.value] && tempY[1][this.value].length > 10) {
751                         return tempY[1][this.value].substring(0, 10);
752                     } else {
753                         return tempY[1][this.value];
754                     }
755                 }
756             };
757             xCord = tempX[2];
758             yCord = tempY[2];
759         }
761         currentSettings.series = series;
762         currentChart = PMA_createChart(currentSettings);
763         xMin = currentChart.xAxis[0].getExtremes().min;
764         xMax = currentChart.xAxis[0].getExtremes().max;
765         yMin = currentChart.yAxis[0].getExtremes().min;
766         yMax = currentChart.yAxis[0].getExtremes().max;
767         includePan(currentChart); //Enable panning feature
768         var setZoom = function() {
769             var newxm = xMin + (xMax - xMin) * (1 - zoomRatio) / 2;
770             var newxM = xMax - (xMax - xMin) * (1 - zoomRatio) / 2;
771             var newym = yMin + (yMax - yMin) * (1 - zoomRatio) / 2;
772             var newyM = yMax - (yMax - yMin) * (1 - zoomRatio) / 2;
773             currentChart.xAxis[0].setExtremes(newxm, newxM);
774             currentChart.yAxis[0].setExtremes(newym, newyM);
775         };
777         //Enable zoom feature
778         $("#querychart").mousewheel(function(objEvent, intDelta) {
779             if (intDelta > 0) {
780                 if (zoomRatio > 0.1) {
781                     zoomRatio = zoomRatio - 0.1;
782                     setZoom();
783                 }
784             } else if (intDelta < 0) {
785                 zoomRatio = zoomRatio + 0.1;
786                 setZoom();
787             }
788         });
790         //Add reset zoom feature
791         currentChart.yAxis[0].resetZoom = currentChart.xAxis[0].resetZoom = $('<a href="#">Reset zoom</a>')
792             .appendTo(currentChart.container)
793             .css({
794                 position: 'absolute',
795                 top: 10,
796                 right: 20,
797                 display: 'none'
798             })
799             .click(function() {
800                 currentChart.xAxis[0].setExtremes(null, null);
801                 currentChart.yAxis[0].setExtremes(null, null);
802                 this.style.display = 'none';
803             });
804         scrollToChart();
805     }