Skip to content

Instantly share code, notes, and snippets.

@nathanathan

nathanathan/download.js

Last active Dec 28, 2015
Embed
What would you like to do?
Macro for downloading [spectral workbench](http://spectralworkbench.org/) curves as csvs
setup: function() {
$('#myModal').remove();
$('body').append('<div class="modal fade" id="myModal" role="dialog"><div class="modal-content dl-btns"></div></div>');
$.each($W.data, function(idx, data){
var $dlBtn = $('<a class="btn btn-success dl-btn">Download ' + (data.label || "") + ' csv<a>');
$dlBtn.css('margin', 5);
$('.dl-btns').append($dlBtn);
var csv = $.map(data.data, function(row, idx){
return row.join(',');
}).join('\n');
console.log(csv);
$dlBtn.attr('href', window.URL.createObjectURL(new Blob([csv])));
$dlBtn.attr('download', (data.label || "data") + ".csv");
});
$('#myModal').modal('show');
},
draw: function() {
// code to run every frame
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment