Matteo Cantiello edited figures/drake_interactive/drake_output.html  almost 9 years ago

Commit id: 9d475fc211ab64f6b4aaf1c013e710b8d8c8ab4a

deletions | additions      

       

Skip to content   This repository   Explore   Gist   Blog   Help   @matteocantiello matteocantiello     Unwatch 2   Star 0   Fork 0   natejenkins/figures   branch: master figures/drake_output.html   @natejenkinsnatejenkins 10 minutes ago build   1 contributor   RawBlameHistory 731 lines (633 sloc) 26.069 kb     

** Original Code is Copyright © 2007 - 2014 IOLA and Ole Laursen   */  var variables = {  R: {name: "R", min: 1, max: 20, value: 10, step: 1}, fp: {name: "fp", min: 0, max: 1, value: 1.0, step: 0.01},  ne: {name: "ne", min: 0, max: 5, value: 0.2, step: 0.1},  fl: {name: "fl", min: 0, max: 1, value: 0.13, step: 0.01}, 

var template = Handlebars.compile(source);  var html;  var variablesDiv = $(".variables");  var plot;  window.variables = variables;  _.each(variables, function(v){  variablesDiv.append(template(v)); 

axisLabel: "N"  },  xaxis: {  axisLabel: 'L (yr)' 'L'  }  };  updateCalculation(); 

$(this).css('width', $(this).width());  });  var updateCalculationTimeout = null;  var updateLegendTimeout = null;   var latestPosition = null;  function updateCalculation(e){  updateCalculationTimeout = null;  updateVariables(); 

for (var i = 0; i < L.length; i++) {  x.push([L[i], drakeEquation(v.R.value, v.fp.value, v.ne.value, v.fl.value, v.fi.value, v.fc.value, L[i])]);  }  plot =  $.plot("#placeholder", [{data: x, label: "N(L)"}], "N = 0.0"}],  plotOptions); }  $(document).on( "input change", "input[type='range']", function(){   if (!updateCalculationTimeout) {   updateCalculationTimeout = setTimeout(updateCalculation, 50);   }     var legends = $("#placeholder .legendLabel");     legends.each(function () {   // fix the widths so they don't jump around   $(this).css('width', $(this).width());   });     var updateLegendTimeout = null;   var updateCalculationTimeout = null;   var latestPosition = null;     function updateLegend() {  legends = $("#placeholder .legendLabel");  updateLegendTimeout = null;    var pos = latestPosition;    var axes = plot.getAxes();  if (pos.x < axes.xaxis.min || pos.x > axes.xaxis.max ||  pos.y < axes.yaxis.min || pos.y > axes.yaxis.max) {  return;  }    var i, j, dataset = plot.getData();  for (i = 0; i < dataset.length; ++i) {    var series = dataset[i];    // Find the nearest points, x-wise    for (j = 0; j < series.data.length; ++j) {  if (series.data[j][0] > pos.x) {  break;  }  }    // Now Interpolate    var y,  p1 = series.data[j - 1],  p2 = series.data[j];    if (p1 == null) {  y = p2[1];  } else if (p2 == null) { 

} else {  y = p1[1] + (p2[1] - p1[1]) * (pos.x - p1[0]) / (p2[0] - p1[0]);  }    legends.eq(i).text(series.label.replace(/=.*/, "= " + y.toFixed(2)));  }  } 

updateLegendTimeout = setTimeout(updateLegend, 50);  }  });  $(document).on( "input change", "input[type='range']", function(){   if (!updateCalculationTimeout) {   updateCalculationTimeout = setTimeout(updateCalculation, 50);   }  });  });