Merge branch 'wip-phantomjs' of https://github.com/Connoropolous/metamaps_gen002 into phantom

This commit is contained in:
Connor Turland 2014-10-07 21:30:42 -04:00
commit 4f94f44a1f
3 changed files with 26 additions and 24 deletions

View file

@ -8,6 +8,7 @@ Metamaps.JIT = {
removeSynapse: 'Metamaps:JIT:events:removeSynapse',
pan: 'Metamaps:JIT:events:pan',
zoom: 'Metamaps:JIT:events:zoom'
animationDone: 'Metamaps:JIT:events:animationDone',
},
vizData: [], // contains the visualization-compatible graph
/**
@ -229,6 +230,7 @@ Metamaps.JIT = {
duration: 800,
onComplete: function () {
Metamaps.Visualize.mGraph.busy = false;
$(document).trigger(Metamaps.JIT.events.animationDone, [event]);
}
},
animateFDLayout: {
@ -1679,4 +1681,4 @@ Metamaps.JIT = {
});
}
}
};
};

View file

@ -3,8 +3,15 @@ class GrabMapScreenshotWorker
include Sidekiq::Worker
def perform(map_id)
imgBase64 = ''
Phantomjs.run('./script/phantomjs-save-screenshot.js', map_id.to_s) { |line|
imgBase64 << line
puts line
}
#this doesn't work yet
#map = Map.find(map_id)
#map.add_attachment(imgBase64)
#map.save!
end
end

View file

@ -9,16 +9,8 @@ if (args.length <= 1) {
//configurable variables - CHANGE ME
var mapID = args[1];
var url = 'http://localhost:3000/maps/' + mapID;
var width = 400;
var height = 400;
var thumbsDirRelative = 'app/assets/images/map_thumbnails';
//set up writing to filesystem
var fs = require('fs');
var thumbsDirectory = fs.workingDirectory + '/' + thumbsDirRelative;
if (!fs.isDirectory(thumbsDirectory)) {
fs.makeDirectory(thumbsDirectory);
}//if
var width = 188;
var height = 126;
//set up page and the area we'll render as a PNG
var page = require('webpage').create();
@ -26,29 +18,30 @@ page.viewportSize = {
width: width,
height: height
};
page.clipRect = {
top: 32,
left: 32,
width: width - 32,
height: height - 32
};
page.open(url, function (status) {
if (status === 'success') {
//since this isn't evaluateAsync, it should also ensure the asynchronous
//js stuff is loaded too, hopefully?
page.evaluate(function() {
$(document).ready(function(){
$('.upperLeftUI, .upperRightUI, .mapControls, .infoAndHelp, #barometer_tab, .footer').hide();
});//document.ready
$(document).on(Metamaps.JIT.events.animationDone, function(){
$('.upperLeftUI, .upperRightUI, .mapControls, .infoAndHelp, #barometer_tab').hide();
Metamaps.Famous.logo.hide()
Metamaps.JIT.zoomExtents();
console.log('got here');
});//document.on animationDone
});//page.evaluate
//render page into map_thumbnails directory
var filename = thumbsDirectory + '/map' + mapID + '.png';
page.render(filename, 'PNG');
//pass to ruby
//console.log(page.renderBase64('PNG'));
//render to the metamaps_gen002 directory for debug
page.render('map1.png', 'PNG');
} else {
//failed to load
}//if
phantom.exit();
setTimeout(phantom.exit,5000);
//phantom.exit();
});