var DATETIME_RE = /^(\d\d\d\d)-(\d\d)-(\d\d)[T ](\d\d):(\d\d):(\d\d.?\d*)$/; var DATE_RE = /^(\d\d\d\d)-(\d\d)-(\d\d)$/; var CURRENT_PLOT; function _getValue(s) { // tries to make some kind of number from a string s // if s looks like a datetime, return a julian year // TODO: do something with hours/sexagesimal angles // if s looks like a float number, return a float // else return null. var dm = DATETIME_RE.exec(s); if (dm!=null) { var dt = new Date(parseFloat(dm[1]), parseFloat(dm[2]), parseFloat(dm[3]), parseFloat(dm[4]), parseFloat(dm[5]), parseFloat(dm[6])); return getJYear(dt); } var dm = DATE_RE.exec(s); if (dm!=null) { var dt = new Date(parseFloat(dm[1]), parseFloat(dm[2]), parseFloat(dm[3])); return getJYear(dt); } var num = parseFloat(s); if (num==num) { // not NaN return num; } return null; } function _getFlotSeries(table, xInd, yInd, style, options) { // returns a flot series object for plotting a line/point plot // of xInd vs. yInd from table. // // options, if given, must be a dict pre-filled with series options. // It will be modified and returned. var data = new Array(); if (options===undefined) { options = {}; } table.find('tr.data').each(function(index, row) { var tds = $(row).children(); var x = _getValue(tds[xInd].firstChild.data); var y = _getValue(tds[yInd].firstChild.data); if (x!=null && y!=null) { data.push([x, y]); } }); options["data"] = data; if (style=="Lines") { options["lines"] = {'show': true, 'lineWidth': 1}; data.sort(function(a,b){return a[0]-b[0]}); } else { options["points"] = {'show': true}; } return options; } function _makeHistogram(data, numBins) { if (data.length<2) { return new Array(); } data.sort(function(a,b){return a-b}); var zp = data[0]; var binSize = (data[data.length-1]-zp)/numBins; if (binSize==0) { binSize = 1; } var histo = new Array(); for (var i=0; i

' +'x 

' +'
'); plotElement.draggable(); plotElement.find(".closer").bind("click", function(){ plotElement.remove()}); } var controlPara = $('

'); plotElement.append(controlPara); // Make column selectors from table headings var xsel = $(''); controlPara.append(usingSel); // Set default plot features from options if given there var xselIndex = options.xselIndex || 0; var yselIndex = options.yselIndex || ysel.children().length-1; var style = options.style || 'Points'; xsel.val(xselIndex).trigger('chosen:updated'); ysel.val(yselIndex).trigger('chosen:updated'); usingSel.val(style).trigger('chosen:updated'); // the callback any form items controlling the plot var updatePlot = function() { try { _doFlotPlot(table, xsel, ysel, usingSel, options.xselIndex2, options.yselIndex2, options.style2); } catch (e) { CURRENT_PLOT = jQuery.plot( jQuery('#plotarea'), [{data:[], label: "unplottable"}]); throw e; } } xsel.change(updatePlot); ysel.change(updatePlot); usingSel.change(updatePlot); if (! options.plotContainer) { $("body").prepend(plotElement); } updatePlot(); } function openFlotPlot(tableElement, options) { // opens a div that lets you plot some columns of tableElement if (options==undefined) { options = {}; } $.getScript("/static/js/jquery.flot.js", function() {_plotUsingFlot(tableElement, options)}); }