Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

more cleanup

  • Loading branch information...
commit 4d5e607075548da5ebe3c638c59a3988e72476d9 1 parent a0b76c0
Carlos Scheidegger authored
View
14 htdocs/js/rcloud_bundle.js
@@ -753,8 +753,6 @@ RClient = {
});
},
// FIXME: I couldn't get this.post_* to work from here so this is just to avoid the error ... it's nonsensical, obviously
- "img.url.update": function(v) { return v; },
- "img.url.final": function(v) { return v; },
"dev.new": function(v) { return ""; },
"dev.close": function(v) { return ""; },
"internal_cmd": function(v) { return ""; },
@@ -790,18 +788,6 @@ RClient = {
if (cmds[cmd] === undefined) {
return this.post_error("Unknown command " + cmd);
}
- if (cmd == "img.url.update" || cmd == "img.url.final") {
- throw "Who's doing this?";
- // FIXME: this is a bad hack storing in the window - do something more reasonable ;)
- // var ix = window.devImgIndex;
- // if (!ix) window.devImgIndex = ix = 1;
- // if (cmd == "img.url.final") window.devImgIndex++;
- // var div = document.getElementById("dimg"+ix);
- // if (div) // FIXME: we may want to move the div down as well -- maybe just remove the old one and add a new one?
- // div.innerHTML = "<img src="+data.value[1].value[0]+">";
- // else
- // this.post_div("<div id=dimg"+ix+"><img src="+data.value[1].value[0]+"></div>");
- }
return cmds[cmd].call(this, data.json()[1]);
},
View
2  htdocs/js/rcloud_bundle.min.js
@@ -1,2 +1,2 @@
// bare-bones d3 charting facilities
-(function(){function g(a){return typeof a=="function"?a:function(a){return function(){return a}}(a)}function e(a,b){if(_.isUndefined(c[b])){var e=new Uint8Array(a.data().length);d[b]=e,c[b]=[a]}else c[b].push(a)}function b(a,b,c){var d=a.slice((c||b)+1||a.length);a.length=b<0?a.length+b:b;return a.push.apply(a,d)}function a(a,b){return"translate("+a+","+b+")"}Chart={};var c={},d={};Chart.get_selections=function(a){return d[this.group_id]},Chart.set_selections=function(a,b){for(var e=0;e<b.length;e++)d[a][e]=b[e];_.each(c[a],function(a){_.each(a.views,function(a){a.selection_changed()})})},Chart.data_model=function(a,b){var f=a.length,g={views:{},group_id:b,data:function(){return a},selection:function(){return d[this.group_id]},register_view:function(a){this.views[a._view_index]=a},deregister_view:function(a){delete this.views[a._view_index]},notify:function(){_.each(c[this.group_id],function(a){_.each(a.views,function(a){a.selection_changed()})})},clear_brushes:function(a){_.each(c[this.group_id],function(b){_.each(b.views,function(b){b._view_index!==a._view_index&&(console.log("clearing brush on view",b._view_index,b,a),b.clear_brush())})})}};e(g,b);return g};var f=0;Chart.scatterplot=function(b){function J(){v.empty()&&F(y)}function I(a){var c=v.extent(),d=h.selection();y.each(function(a){var e=i[a],f=c[0][0]<=b.x(e)&&b.x(e)<=c[1][0]&&c[0][1]<=b.y(e)&&b.y(e)<=c[1][1];d[a]=f}),h.notify()}function H(a){h.clear_brushes(s)}function G(c){c.attr("d",d3.svg.symbol().type("circle")).attr("size",5).attr("transform",function(c){c=i[c];return a(p(b.x(c)),q(b.y(c)))}).style("stroke-width",function(a){return s.opts.stroke_width(i[a])})}function F(){var a=h.selection();z.attr("display",function(b){return a[b]?null:"none"})}b=_.defaults(b,{width:400,height:400,padding:20,n_xticks:10,n_yticks:10,stroke:"white",stroke_width:"1.5px",fill:"black",stroke_opacity:1,fill_opacity:1}),b.stroke=g(b.stroke),b.stroke_opacity=g(b.stroke_opacity),b.stroke_width=g(b.stroke_width),b.fill=g(b.fill),b.fill_opacity=g(b.fill_opacity);var c=b.width,d=b.height,e=b.padding,h=b.data,i=h.data(),j=_.map(i,b.x),k=_.map(i,b.y),l=_.min(j),m=_.max(j),n=_.min(k),o=_.max(k),p=d3.scale.linear().domain([l,m]).range([0,c]),q=d3.scale.linear().domain([n,o]).range([d,0]),r=$("<div></div>")[0],s={_view_index:++f,opts:b,plot:r,clear_brush:function(){u.call(v.clear())},selection_changed:function(){F()},deleted:function(){h.deregister_view(this)}};h.register_view(s);var t=d3.select(r).append("svg").attr("width",c+2*e).attr("height",d+2*e),u=t.append("g").attr("transform",a(e,e)),v=d3.svg.brush().on("brushstart",H).on("brush",I).on("brushend",J);u.append("rect").attr("width",c).attr("height",d).attr("fill","#eee");var w=u.selectAll("g.x").data(p.ticks(b.n_xticks)).enter().append("g").attr("class","x");w.append("line").attr("x1",p).attr("x2",p).attr("y1",0).attr("y2",d),w.append("text").attr("x",p).attr("y",d+3).attr("dy",".71em").attr("text-anchor","middle").attr("class","rule-text").text(p.tickFormat(b.n_xticks));var x=u.selectAll("g.y").data(q.ticks(b.n_yticks)).enter().append("g").attr("class","x");x.append("line").attr("x1",0).attr("x2",c).attr("y1",q).attr("y2",q),x.append("text").attr("x",-3).attr("y",q).attr("dy",".35em").attr("text-anchor","end").attr("class","rule-text").text(q.tickFormat(b.n_yticks));var y=u.selectAll("path.dot").data(_.range(i.length)).enter().append("path"),z=u.selectAll("pathasdkf.dot").data(_.range(i.length)).enter().append("path"),A=function(a){return i[a]};y.style("fill",_.compose(b.fill,A)).style("stroke",_.compose(b.stroke,A)).style("fill-opacity",_.compose(b.fill_opacity,A)).style("stroke-opacity",_.compose(b.stroke_opacity,A)),u.call(v.x(p).y(q));var B=function(){return"red"},C=function(){return"red"},D=function(){return 1},E=function(){return 1};z.style("fill",_.compose(B,A)).style("stroke",_.compose(C,A)).style("fill-opacity",_.compose(D,A)).style("stroke-opacity",_.compose(E,A)),t.on("keydown",function(a){console.log(a)}),G(y),G(z),F();return s},Chart.histogram=function(a){a=_.defaults(a,{width:400,height:400,padding:20,n_bins:10,stroke:"white",stroke_width:"1.5px",fill:"black",stroke_opacity:1,fill_opacity:1}),a.stroke=g(a.stroke),a.stroke_opacity=g(a.stroke_opacity),a.stroke_width=g(a.stroke_width),a.fill=g(a.fill),a.fill_opacity=g(a.fill_opacity);var b=a.width,c=a.height,d=a.padding,e=a.data,h=e.data(),i=_.map(h,a.x),j=_.min(i),k=_.max(i),l=$("<div></div>")[0],m=d3.scale.linear().domain([j,k]).range([0,b]),n=d3.layout.histogram().range([j,k]).bins(a.n_bins),o=n(a.x),p={_view_index:++f,opts:a,plot:l,clear_brush:function(){vis.call(brush.clear())},selection_changed:function(){update_selection()},deleted:function(){e.deregister_view(this)}}}})(),FacetChart={},FacetChart.facet_tour_plot=function(a){function l(a){var b=[],c=[],d=0,e=0;for(var f=0;f<a;++f)b[f]=Math.random()*2-1,c[f]=Math.random()*2-1,d+=b[f]*b[f],e+=c[f]*c[f];d=Math.sqrt(d),e=Math.sqrt(e);if(d===0||e===0)return l(a);var g=0;for(f=0;f<a;++f)b[f]/=d,c[f]/=e,g+=b[f]*c[f];var h=0;for(f=0;f<a;++f)c[f]=c[f]-g*b[f],h+=c[f]*c[f];h=Math.sqrt(h);if(h===0)return l(a);for(f=0;f<a;++f)c[f]/=h;return[b,c]}function k(){Facet.set_context(m),f=j();var a=10,b=2.5,c=1;g=[],h=[];var d,i,k=[],l=Shade.vec(0,0),n=Shade.vec(0,0),o=Shade.vec(0,0);for(var p=0;p<f.columns.length;++p){var q=f[f.columns[p]];g.push(Shade.parameter("float")),h.push(Shade.parameter("float"));var r=Shade.vec(g[p],h[p]);d=_.min(q.array),i=_.max(q.array),k=(i+d)/2,l=l.add(r.mul(q)),n=n.add(r.mul(k)),o=o.add(r.mul(k-d).abs())}var s=Shade.color("red");e=Facet.Marks.scatterplot({elements:f[f.columns[0]].numItems,xy:l,xy_scale:Shade.Utils.linear(n.sub(o),n.add(o),Shade.vec(0,0),Shade.vec(1,1)),fill_color:s,stroke_color:Shade.mix(Shade.color("black"),s,.5),stroke_width:b,point_diameter:a})}function j(){var b={},c=[];for(var d=0;d<a.length;++d)b["dim_"+d]=Facet.attribute_buffer({vertex_array:a[d],item_size:1,keep_array:!0}),c.push("dim_"+d);b.columns=c;return b}function i(){m.viewport(0,0,m.viewportWidth,m.viewportHeight),m.clearDepth(1),m.clearColor(0,0,0,0),m.clear(m.COLOR_BUFFER_BIT|m.DEPTH_BUFFER_BIT),e.draw()}var b=600,c=600,d=$("<canvas width='"+b+"' height='"+c+"'></canvas>")[0],e,f,g,h,m=Facet.init(d,{clearColor:[1,1,1,1]});k();var n=l(f.columns.length),o=l(f.columns.length),p=(new Date).getTime(),q=1,r=function(){var a=((new Date).getTime()-p)/1e3,b=a/3;b-=Math.floor(b),b<q&&(n=o,o=l(4)),q=b;for(var c=0;c<f.columns.length;++c)g[c].set(b*o[0][c]+(1-b)*n[0][c]),h[c].set(b*o[1][c]+(1-b)*n[1][c]);window.requestAnimFrame(r,d),i()};r();return d},FacetChart.facet_osm_plot=function(a,b,c,d,e){var f=$("<canvas width='"+d+"' height='"+e+"'></canvas>")[0],g=Facet.init(f,{clearColor:[1,1,1,1],mousedown:function(a){var b=j.mousedown(a);return b},mousemove:function(a){var b=j.mousemove(a);return b},mouseup:function(a){var b=j.mouseup(a);return b}}),h=Shade.parameter("float",3),i=Shade.Camera.perspective({look_at:[Shade.vec(0,0,6),Shade.vec(0,0,-1),Shade.vec(0,1,0)],field_of_view_y:Shade.div(20,h)}),j=Facet.Marks.globe({view_proj:i,zoom:h});a=Facet.attribute_buffer({vertex_array:a,item_size:1}),b=Facet.attribute_buffer({vertex_array:b,item_size:1}),console.log(c),c.length===3?c=Shade.vec(c[0],c[1],c[2],1):c.length>1&&(c=Shade.vec(Facet.attribute_buffer({vertex_array:c,item_size:3}),1));var k=Facet.model({type:"points",lats:a,lons:b}),l=Facet.bake(k,{color:c,point_size:2,position:j.lat_lon_position(k.lats.radians(),k.lons.radians())});Facet.Scene.add(j),Facet.Scene.add(l);return f},function(){function c(){throw new b}function b(){this.name="NoCallbackError"}function a(a){return'"'+a.replace(/\\/g,"\\\\").replace(/"/g,'\\"')+'"'}b.prototype=Object.create(Error),b.prototype.constructor=b,RClient={create:function(d){function h(a){n.post_error("Socket was closed. Goodbye!"),f()}function g(a,b){b===65?n.post_error("Authentication failed. Login first!"):n.post_error(a),f()}function f(){$("#input-div").hide()}function e(){n.running=!0,n.send("rcloud.support::session.init(username="+a(rcloud.username())+")"),d.on_connect&&d.on_connect.call(n)}var i=$.cookies.get().token,j=Rserve.create({host:d.host,on_connect:e,on_error:g,on_close:h,login:i+"\n"+i}),k=d.debug||!1,l=!1,m=undefined,n;n={handlers:{eval:function(a){n.post_response(a);return a},"markdown.eval":function(a){n.display_markdown_response(a);return a},browsePath:function(a){$.ajax({url:"http://127.0.0.1:8080"+a}).done(function(a){var b=/[\s\S]*<body>([\s\S]*)<\/body>/g.exec(a)[1];$("#help-output").html(b)})},"img.url.update":function(a){return a},"img.url.final":function(a){return a},"dev.new":function(a){return""},"dev.close":function(a){return""},internal_cmd:function(a){return""},"boot.failure":function(a){n.running=!1}},running:!1,eval:function(a){var b=this;if(a.type!=="sexp")return this.post_error("Bad protocol, should always be sexp.");a=a.value;if(a.type==="string_array")return this.post_error(a.value[0]);if(a.type==="null")return null;if(a.type!=="vector")return this.post_error("Protocol error, unexpected value of type "+a.type);if(a.value[0].type!=="string_array"||a.value[0].value.length!==1){console.log("Protocol error?! ",a.value[0]);return undefined}var c=a.value[0].value[0],d=this.handlers;if(d[c]===undefined)return this.post_error("Unknown command "+c);if(c=="img.url.update"||c=="img.url.final")throw"Who's doing this?";return d[c].call(this,a.json()[1])},register_handler:function(a,b){this.handlers[a]=b},post_div:function(a){return shell.post_div(a)},display_markdown_response:function(a){a&&($("#output").append($("<div></div>").html(a.value[0])).find("pre code").each(function(a,b){hljs.highlightBlock(b)}),MathJax.Hub.Queue(["Typeset",MathJax.Hub]))},post_error:function(a){var b=$("<div class='alert alert-error'></div>").text(a);$("#output").append(b),window.scrollTo(0,document.body.scrollHeight)},post_response:function(a){var b=$("<pre></pre>").html(a);$("#output").append(b),window.scrollTo(0,document.body.scrollHeight)},capture_answers:function(a,b){function d(d){c.push(d),a--,a===0&&(l=!1,m=undefined,b(c))}if(l)throw"Still waiting for previous answers...";l=!0;var c=[];m=d},wrap_command:function(a,b){b===undefined&&(b=!1);return"rcloud.support::session.eval({"+a+"}, "+(b?"TRUE":"FALSE")+")"},markdown_wrap_command:function(b,c){return"rcloud.support::session.markdown.eval({markdownToHTML(text=paste(knit(text="+a(b+"\n")+'), collapse="\\n"), fragment=TRUE)}, '+(c?"TRUE":"FALSE")+")"},log:function(a){a='rcloud.support::session.log("'+rcloud.username()+'", "'+a.replace(/\\/g,"\\\\").replace(/"/g,'\\"')+'")',this.send(a)},record_cell_execution:function(a){var b=JSON.stringify(a.json()),c=this.r_funcall("rcloud.record.cell.execution",rcloud.username(),b);j.eval(c)},send:function(a,b){this.send_and_callback(a,c,b)},send_and_callback:function(a,d,e){function h(a){a=a.value.json(),k&&(debugger,console.log(a));try{d(a[1])}catch(c){c.constructor===b&&f.handlers[a[0]](a[1])}}var f=this;_.isUndefined(d)&&(d=c);var g;e?a=e(a):a=this.wrap_command(a,!0),k&&console.log(a),j.eval(a,h)},r_funcall:function(b){var c=[b,"("];for(var d=1;d<arguments.length;++d){var e=typeof arguments[d];e==="string"?c.push(a(arguments[d])):c.push(String(arguments[d])),d<arguments.length-1&&c.push(",")}c.push(")");var f=c.join("");return f}};return n}}}(),rcloud={},rcloud.init_client_side_data=function(){var a=this;rcloud.get_user_filenames(function(b){a.user_filenames=b;var c=b,d=d3.select("#internals-user-files");d.append("h3").text("User files"),d.append("ul").selectAll("li").data(c).enter().append("li").text(function(a){return a})}),rclient.send_and_callback("rcloud.prefix.uuid()",function(b){a.wplot_uuid=b})},rcloud.username=function(){return $.cookies.get("user")},rcloud.get_user_filenames=function(a){_.isUndefined(a)&&(a=_.identity),rclient.send_and_callback(rclient.r_funcall("rcloud.list.initial.filenames",this.username()),a)},rcloud.search=function(a,b){var c=this;_.isUndefined(b)&&(b=_.identity),rclient.send_and_callback(rclient.r_funcall("rcloud.search",a),b)},rcloud.get_all_user_filenames=function(a){var b=this;_.isUndefined(a)&&(a=_.identity),rclient.send_and_callback(rclient.r_funcall("rcloud.list.all.initial.filenames"),a)},rcloud.load_user_file=function(a,b,c){rclient.send_and_callback(rclient.r_funcall("rcloud.load.user.file",a,b),c)},rcloud.save_to_user_file=function(a,b,c,d){rclient.send_and_callback(rclient.r_funcall("rcloud.save.to.user.file",a,b,c),d)},rcloud.create_user_file=function(a,b){rclient.send_and_callback(rclient.r_funcall("rcloud.create.user.file",rcloud.username(),a),b)},rcloud.resolve_deferred_result=function(a,b){var c=rclient.r_funcall("rcloud.fetch.deferred.result",a);rclient.send_and_callback(c,b)},Notebook={},Notebook.Cell={},function(){function c(b){function k(){v.html("Computing..."),h(),y.show_result(),b.controller.execute()}function j(a){a.addClass("button-disabled")}function i(a){a.removeClass("button-disabled")}function h(){b.content($(u).val())}var c=$("<div class='notebook-cell'></div>"),d=$("<span class='fontawesome-button'><i class='icon-edit'></i></span>").tooltip({title:"source"}),e=$("<span class='fontawesome-button'><i class='icon-picture'></i></span>").tooltip({title:"result"}),f=$("<span class='fontawesome-button'><i class='icon-resize-small'></i></span>").tooltip({title:"hide"}),g=$("<span class='fontawesome-button'><i class='icon-trash'></i></span>").tooltip({title:"remove"});d.click(function(a){$(a.currentTarget).hasClass("button-disabled")||y.show_source()}),e.click(function(a){$(a.currentTarget).hasClass("button-disabled")||y.show_result()}),f.click(function(a){$(a.currentTarget).hasClass("button-disabled")||y.hide_all()}),g.click(function(a){$(a.currentTarget).hasClass("button-disabled")||(b.parent_model.controller.remove_cell(b),$(".tooltip").remove())});var l=$("<div style='position:relative; float: right; z-index:10000'></div>"),m=$("<div style='margin:0.5em;'></div>"),n=$("<div style='margin:0.5em;'></div>");m.append(d),m.append(e),m.append(f),m.append(g),l.append(m),n.hide(),l.append(n),c.append(l);var o=$("<div></div>"),p=$("<div style='clear:both;'></div>");c.append(o),c.append(p);var q=$('<div style="position: relative; width:100%;"></div>'),r=$('<div style="position: absolute; right:-0.5em; top:-0.5em"></div>'),s=a("icon-plus-sign","insert cell");o.append(r),r.append(s),s.click(function(a){var b=c.index(),d=b;shell.insert_markdown_cell_before(d)});var t=$('<div style="width:100%; margin-left: 0.5em; margin-top: 0.5em"></div>');o.append(q),q.append(t);var u=$('<input type="text" style="width:88%"/>');t.append(u),u.keypress(function(a){if(a.which===13){k(),a.preventDefault();return!1}return!0});var v=$('<div class="r-result-div"></div>');o.append(v);var w=$("<span></span>");o.append(w);var x,y={content_updated:function(){u.val(b.content())},self_removed:function(){c.remove()},result_updated:function(a){v.hide(),v.html(a),v.slideDown(150);var b=rcloud.wplot_uuid;o.find("pre code").contents().filter(function(){return this.nodeValue.indexOf(b)!==-1}).parent().parent().each(function(){var a=this.childNodes[0].childNodes[0].data.substr(8,73).split("|"),b=this;rcloud.resolve_deferred_result(a[1],function(a){$(b).replaceWith(function(){return shell.handle(a[0],a)})})}),o.find("pre code").each(function(a,b){hljs.highlightBlock(b)}),_.isUndefined(MathJax)||MathJax.Hub.Queue(["Typeset",MathJax.Hub]),this.show_result(),w[0].scrollIntoView()},hide_buttons:function(){l.css("display","none"),r.css("display","none")},show_buttons:function(){l.css("display",null),r.css("display",null)},show_source:function(){c.css({height:""}),j(d),i(e),i(f),i(g),n.show(),q.show(),v.hide(),u.focus(),x="source"},show_result:function(){c.css({height:""}),i(d),j(e),i(f),i(g),n.hide(),q.hide(),v.slideDown(150,function(){w[0].scrollIntoView()}),x="result"},hide_all:function(){c.css({height:""}),i(d),i(e),j(f),i(g),n.hide(),x==="result"?v.slideUp(150):q.slideUp(150)},remove_self:function(){b.parent_model.remove_cell(b),c.remove()},div:function(){return c},update_model:function(){h()},focus:function(){u.focus()}};y.show_result(),y.content_updated();return y}function b(b){function l(){z.html("Computing..."),i(),C.show_result(),b.controller.execute()}function k(a){a.addClass("button-disabled")}function j(a){a.removeClass("button-disabled")}function i(){b.content(v.getSession().getValue())}var c=$("<div class='notebook-cell'></div>"),d=a("icon-edit","source"),e=a("icon-picture","result"),f=a("icon-resize-small","hide"),g=a("icon-trash","remove"),h=a("icon-repeat","run");d.click(function(a){$(a.currentTarget).hasClass("button-disabled")||C.show_source()}),e.click(function(a){$(a.currentTarget).hasClass("button-disabled")||C.show_result()}),f.click(function(a){$(a.currentTarget).hasClass("button-disabled")||C.hide_all()}),g.click(function(a){$(a.currentTarget).hasClass("button-disabled")||(b.parent_model.controller.remove_cell(b),$(".tooltip").remove())}),h.click(function(a){l()});var m=$("<div style='position:relative; float: right; z-index:10000'></div>"),n=$("<div style='margin:0.5em;'></div>"),o=$("<div style='margin:0.5em;'></div>");n.append(d),n.append(e),n.append(f),n.append(g),m.append(n),o.append(h),o.hide(),m.append(o),c.append(m);var p=$("<div></div>"),q=$("<div style='clear:both;'></div>");c.append(p),c.append(q);var r=$('<div style="position: relative; width:100%; height:100%"></div>'),s=$('<div style="position: absolute; right:-0.5em; top:-0.5em"></div>'),t=a("icon-plus-sign","insert cell");p.append(s),s.append(t),t.click(function(a){var b=c.index(),d=b;shell.insert_markdown_cell_before(d)});var u=$('<div style="width:100%; height:100%"></div>');p.append(r),r.append(u);var v=ace.edit(u[0]),w=require("mode/rmarkdown").Mode,x=v.getSession(),y=x.doc;v.getSession().setMode(new w(!1,y,x)),v.setTheme("ace/theme/chrome"),v.getSession().setUseWrapMode(!0),v.resize(),v.commands.addCommand({name:"sendToR",bindKey:{win:"Ctrl-Return",mac:"Command-Return",sender:"editor"},exec:function(a,b,c){l()}});var z=$('<div class="r-result-div"><span style="opacity:0.5">Not evaluated</span></div>');p.append(z);var A=$("<span></span>");p.append(A);var B,C={content_updated:function(){v.getSession().setValue(b.content())},self_removed:function(){c.remove()},result_updated:function(a){z.hide(),z.html(a),z.slideDown(150);var b=rcloud.wplot_uuid;p.find("pre code").contents().filter(function(){return this.nodeValue.indexOf(b)!==-1}).parent().parent().each(function(){var a=this.childNodes[0].childNodes[0].data.substr(8,73).split("|"),b=this;rcloud.resolve_deferred_result(a[1],function(a){$(b).replaceWith(function(){return shell.handle(a[0],a)})})}),p.find("pre code").each(function(a,b){hljs.highlightBlock(b)}),_.isUndefined(MathJax)||MathJax.Hub.Queue(["Typeset",MathJax.Hub]),this.show_result(),A[0].scrollIntoView()},hide_buttons:function(){m.css("display","none"),s.css("display","none")},show_buttons:function(){m.css("display",null),s.css("display",null)},show_source:function(){c.css({height:"70%"}),k(d),j(e),j(f),j(g),o.show(),r.show(),z.hide(),v.resize(),v.focus(),B="source"},show_result:function(){c.css({height:""}),j(d),k(e),j(f),j(g),o.hide(),r.hide(),z.slideDown(150,function(){A[0].scrollIntoView()}),B="result"},hide_all:function(){c.css({height:""}),j(d),j(e),k(f),j(g),o.hide(),B==="result"?z.slideUp(150):r.slideUp(150)},remove_self:function(){b.parent_model.remove_cell(b),c.remove()},div:function(){return c},update_model:function(){i()},focus:function(){v.focus()}};C.show_result(),C.content_updated();return C}function a(a,b){return $("<span class='fontawesome-button'><i class='"+a+"'></i></span>").tooltip({title:b,delay:{show:250,hide:0}})}var d={markdown:b,interactive:c};Notebook.Cell.create_html_view=function(a){return d[a.type()](a)}}(),Notebook.Cell.create_model=function(a,b){function d(){_.each(c.views,function(a){a.content_updated()})}var c={views:[],type:function(){return b},content:function(b){_.isUndefined(b)||(a=b,d());return a},json:function(){return{content:a,type:b}}};return c},Notebook.Cell.create_controller=function(a){var b={execute:function(){function d(b){_.each(a.views,function(a){a.result_updated(b)})}var b=this,c=a.type();rclient.record_cell_execution(a);if(c==="markdown"){var e=rclient.markdown_wrap_command(a.content());rclient.send_and_callback(e,d,_.identity)}else if(c==="interactive"){var e=rclient.markdown_wrap_command("```{r}\n"+a.content()+"\n```\n");rclient.send_and_callback(e,d,_.identity)}else alert("Can only do markdown or interactive for now!")}};return b},Notebook.create_html_view=function(a,b){var c={model:a,sub_views:[],cell_appended:function(a){var c=Notebook.Cell.create_html_view(a);a.views.push(c),b.append(c.div()),this.sub_views.push(c);return c},cell_inserted:function(a,c){var d=Notebook.Cell.create_html_view(a);a.views.push(d),b.append(d.div()),$(d.div()).insertBefore(b.children()[c]),this.sub_views.splice(c,0,d),d.show_source();return d},cell_removed:function(a,b){_.each(a.views,function(a){a.self_removed()}),this.sub_views.splice(b,1)},update_model:function(){_.each(this.sub_views,function(a){a.update_model()})}};a.views.push(c);return c},Notebook.create_model=function(){return{notebook:[],views:[],clear:function(){while(this.notebook.length)this.remove_cell(this.notebook[this.notebook.length-1])},append_cell:function(a){a.parent_model=this,this.notebook.push(a),_.each(this.views,function(b){b.cell_appended(a)})},insert_cell:function(a,b){a.parent_model=this,this.notebook.splice(b,0,a),_.each(this.views,function(c){c.cell_inserted(a,b)})},json:function(){return _.map(this.notebook,function(a){return a.json()})},remove_cell:function(a){var b=this.notebook.indexOf(a);if(b===-1)throw"cell_model not in notebook model?!";_.each(this.views,function(c){c.cell_removed(a,b)}),this.notebook.splice(b,1)}}},Notebook.create_controller=function(a){var b={append_cell:function(b,c){var d=Notebook.Cell.create_model(b,c),e=Notebook.Cell.create_controller(d);d.controller=e,a.append_cell(d);return e},insert_cell:function(b,c,d){var e=Notebook.Cell.create_model(b,c),f=Notebook.Cell.create_controller(e);e.controller=f,a.insert_cell(e,d);return f},remove_cell:function(b){a.remove_cell(b)},clear:function(){a.clear()},load_from_file:function(a,b,c){var d=this;rcloud.load_user_file(a,b,function(a){var b=JSON.parse(a.join("\n"));d.clear(),_.each(b,function(a){var b=d.append_cell(a.content,a.type)}),c()})},save_file:function(b,c,d){var e=this,f=JSON.stringify(a.json());rcloud.load_user_file(b,c,function(a){a=a.join("\n"),f!==a?rcloud.save_to_user_file(b,c,f,function(){d&&d()}):d&&d()})},run_all:function(){_.each(a.notebook,function(a){a.controller.execute()})}};a.controller=b;return b}
+(function(){function g(a){return typeof a=="function"?a:function(a){return function(){return a}}(a)}function e(a,b){if(_.isUndefined(c[b])){var e=new Uint8Array(a.data().length);d[b]=e,c[b]=[a]}else c[b].push(a)}function b(a,b,c){var d=a.slice((c||b)+1||a.length);a.length=b<0?a.length+b:b;return a.push.apply(a,d)}function a(a,b){return"translate("+a+","+b+")"}Chart={};var c={},d={};Chart.get_selections=function(a){return d[this.group_id]},Chart.set_selections=function(a,b){for(var e=0;e<b.length;e++)d[a][e]=b[e];_.each(c[a],function(a){_.each(a.views,function(a){a.selection_changed()})})},Chart.data_model=function(a,b){var f=a.length,g={views:{},group_id:b,data:function(){return a},selection:function(){return d[this.group_id]},register_view:function(a){this.views[a._view_index]=a},deregister_view:function(a){delete this.views[a._view_index]},notify:function(){_.each(c[this.group_id],function(a){_.each(a.views,function(a){a.selection_changed()})})},clear_brushes:function(a){_.each(c[this.group_id],function(b){_.each(b.views,function(b){b._view_index!==a._view_index&&(console.log("clearing brush on view",b._view_index,b,a),b.clear_brush())})})}};e(g,b);return g};var f=0;Chart.scatterplot=function(b){function J(){v.empty()&&F(y)}function I(a){var c=v.extent(),d=h.selection();y.each(function(a){var e=i[a],f=c[0][0]<=b.x(e)&&b.x(e)<=c[1][0]&&c[0][1]<=b.y(e)&&b.y(e)<=c[1][1];d[a]=f}),h.notify()}function H(a){h.clear_brushes(s)}function G(c){c.attr("d",d3.svg.symbol().type("circle")).attr("size",5).attr("transform",function(c){c=i[c];return a(p(b.x(c)),q(b.y(c)))}).style("stroke-width",function(a){return s.opts.stroke_width(i[a])})}function F(){var a=h.selection();z.attr("display",function(b){return a[b]?null:"none"})}b=_.defaults(b,{width:400,height:400,padding:20,n_xticks:10,n_yticks:10,stroke:"white",stroke_width:"1.5px",fill:"black",stroke_opacity:1,fill_opacity:1}),b.stroke=g(b.stroke),b.stroke_opacity=g(b.stroke_opacity),b.stroke_width=g(b.stroke_width),b.fill=g(b.fill),b.fill_opacity=g(b.fill_opacity);var c=b.width,d=b.height,e=b.padding,h=b.data,i=h.data(),j=_.map(i,b.x),k=_.map(i,b.y),l=_.min(j),m=_.max(j),n=_.min(k),o=_.max(k),p=d3.scale.linear().domain([l,m]).range([0,c]),q=d3.scale.linear().domain([n,o]).range([d,0]),r=$("<div></div>")[0],s={_view_index:++f,opts:b,plot:r,clear_brush:function(){u.call(v.clear())},selection_changed:function(){F()},deleted:function(){h.deregister_view(this)}};h.register_view(s);var t=d3.select(r).append("svg").attr("width",c+2*e).attr("height",d+2*e),u=t.append("g").attr("transform",a(e,e)),v=d3.svg.brush().on("brushstart",H).on("brush",I).on("brushend",J);u.append("rect").attr("width",c).attr("height",d).attr("fill","#eee");var w=u.selectAll("g.x").data(p.ticks(b.n_xticks)).enter().append("g").attr("class","x");w.append("line").attr("x1",p).attr("x2",p).attr("y1",0).attr("y2",d),w.append("text").attr("x",p).attr("y",d+3).attr("dy",".71em").attr("text-anchor","middle").attr("class","rule-text").text(p.tickFormat(b.n_xticks));var x=u.selectAll("g.y").data(q.ticks(b.n_yticks)).enter().append("g").attr("class","x");x.append("line").attr("x1",0).attr("x2",c).attr("y1",q).attr("y2",q),x.append("text").attr("x",-3).attr("y",q).attr("dy",".35em").attr("text-anchor","end").attr("class","rule-text").text(q.tickFormat(b.n_yticks));var y=u.selectAll("path.dot").data(_.range(i.length)).enter().append("path"),z=u.selectAll("pathasdkf.dot").data(_.range(i.length)).enter().append("path"),A=function(a){return i[a]};y.style("fill",_.compose(b.fill,A)).style("stroke",_.compose(b.stroke,A)).style("fill-opacity",_.compose(b.fill_opacity,A)).style("stroke-opacity",_.compose(b.stroke_opacity,A)),u.call(v.x(p).y(q));var B=function(){return"red"},C=function(){return"red"},D=function(){return 1},E=function(){return 1};z.style("fill",_.compose(B,A)).style("stroke",_.compose(C,A)).style("fill-opacity",_.compose(D,A)).style("stroke-opacity",_.compose(E,A)),t.on("keydown",function(a){console.log(a)}),G(y),G(z),F();return s},Chart.histogram=function(a){a=_.defaults(a,{width:400,height:400,padding:20,n_bins:10,stroke:"white",stroke_width:"1.5px",fill:"black",stroke_opacity:1,fill_opacity:1}),a.stroke=g(a.stroke),a.stroke_opacity=g(a.stroke_opacity),a.stroke_width=g(a.stroke_width),a.fill=g(a.fill),a.fill_opacity=g(a.fill_opacity);var b=a.width,c=a.height,d=a.padding,e=a.data,h=e.data(),i=_.map(h,a.x),j=_.min(i),k=_.max(i),l=$("<div></div>")[0],m=d3.scale.linear().domain([j,k]).range([0,b]),n=d3.layout.histogram().range([j,k]).bins(a.n_bins),o=n(a.x),p={_view_index:++f,opts:a,plot:l,clear_brush:function(){vis.call(brush.clear())},selection_changed:function(){update_selection()},deleted:function(){e.deregister_view(this)}}}})(),FacetChart={},FacetChart.facet_tour_plot=function(a){function l(a){var b=[],c=[],d=0,e=0;for(var f=0;f<a;++f)b[f]=Math.random()*2-1,c[f]=Math.random()*2-1,d+=b[f]*b[f],e+=c[f]*c[f];d=Math.sqrt(d),e=Math.sqrt(e);if(d===0||e===0)return l(a);var g=0;for(f=0;f<a;++f)b[f]/=d,c[f]/=e,g+=b[f]*c[f];var h=0;for(f=0;f<a;++f)c[f]=c[f]-g*b[f],h+=c[f]*c[f];h=Math.sqrt(h);if(h===0)return l(a);for(f=0;f<a;++f)c[f]/=h;return[b,c]}function k(){Facet.set_context(m),f=j();var a=10,b=2.5,c=1;g=[],h=[];var d,i,k=[],l=Shade.vec(0,0),n=Shade.vec(0,0),o=Shade.vec(0,0);for(var p=0;p<f.columns.length;++p){var q=f[f.columns[p]];g.push(Shade.parameter("float")),h.push(Shade.parameter("float"));var r=Shade.vec(g[p],h[p]);d=_.min(q.array),i=_.max(q.array),k=(i+d)/2,l=l.add(r.mul(q)),n=n.add(r.mul(k)),o=o.add(r.mul(k-d).abs())}var s=Shade.color("red");e=Facet.Marks.scatterplot({elements:f[f.columns[0]].numItems,xy:l,xy_scale:Shade.Utils.linear(n.sub(o),n.add(o),Shade.vec(0,0),Shade.vec(1,1)),fill_color:s,stroke_color:Shade.mix(Shade.color("black"),s,.5),stroke_width:b,point_diameter:a})}function j(){var b={},c=[];for(var d=0;d<a.length;++d)b["dim_"+d]=Facet.attribute_buffer({vertex_array:a[d],item_size:1,keep_array:!0}),c.push("dim_"+d);b.columns=c;return b}function i(){m.viewport(0,0,m.viewportWidth,m.viewportHeight),m.clearDepth(1),m.clearColor(0,0,0,0),m.clear(m.COLOR_BUFFER_BIT|m.DEPTH_BUFFER_BIT),e.draw()}var b=600,c=600,d=$("<canvas width='"+b+"' height='"+c+"'></canvas>")[0],e,f,g,h,m=Facet.init(d,{clearColor:[1,1,1,1]});k();var n=l(f.columns.length),o=l(f.columns.length),p=(new Date).getTime(),q=1,r=function(){var a=((new Date).getTime()-p)/1e3,b=a/3;b-=Math.floor(b),b<q&&(n=o,o=l(4)),q=b;for(var c=0;c<f.columns.length;++c)g[c].set(b*o[0][c]+(1-b)*n[0][c]),h[c].set(b*o[1][c]+(1-b)*n[1][c]);window.requestAnimFrame(r,d),i()};r();return d},FacetChart.facet_osm_plot=function(a,b,c,d,e){var f=$("<canvas width='"+d+"' height='"+e+"'></canvas>")[0],g=Facet.init(f,{clearColor:[1,1,1,1],mousedown:function(a){var b=j.mousedown(a);return b},mousemove:function(a){var b=j.mousemove(a);return b},mouseup:function(a){var b=j.mouseup(a);return b}}),h=Shade.parameter("float",3),i=Shade.Camera.perspective({look_at:[Shade.vec(0,0,6),Shade.vec(0,0,-1),Shade.vec(0,1,0)],field_of_view_y:Shade.div(20,h)}),j=Facet.Marks.globe({view_proj:i,zoom:h});a=Facet.attribute_buffer({vertex_array:a,item_size:1}),b=Facet.attribute_buffer({vertex_array:b,item_size:1}),console.log(c),c.length===3?c=Shade.vec(c[0],c[1],c[2],1):c.length>1&&(c=Shade.vec(Facet.attribute_buffer({vertex_array:c,item_size:3}),1));var k=Facet.model({type:"points",lats:a,lons:b}),l=Facet.bake(k,{color:c,point_size:2,position:j.lat_lon_position(k.lats.radians(),k.lons.radians())});Facet.Scene.add(j),Facet.Scene.add(l);return f},function(){function c(){throw new b}function b(){this.name="NoCallbackError"}function a(a){return'"'+a.replace(/\\/g,"\\\\").replace(/"/g,'\\"')+'"'}b.prototype=Object.create(Error),b.prototype.constructor=b,RClient={create:function(d){function h(a){n.post_error("Socket was closed. Goodbye!"),f()}function g(a,b){b===65?n.post_error("Authentication failed. Login first!"):n.post_error(a),f()}function f(){$("#input-div").hide()}function e(){n.running=!0,n.send("rcloud.support::session.init(username="+a(rcloud.username())+")"),d.on_connect&&d.on_connect.call(n)}var i=$.cookies.get().token,j=Rserve.create({host:d.host,on_connect:e,on_error:g,on_close:h,login:i+"\n"+i}),k=d.debug||!1,l=!1,m=undefined,n;n={handlers:{eval:function(a){n.post_response(a);return a},"markdown.eval":function(a){n.display_markdown_response(a);return a},browsePath:function(a){$.ajax({url:"http://127.0.0.1:8080"+a}).done(function(a){var b=/[\s\S]*<body>([\s\S]*)<\/body>/g.exec(a)[1];$("#help-output").html(b)})},"dev.new":function(a){return""},"dev.close":function(a){return""},internal_cmd:function(a){return""},"boot.failure":function(a){n.running=!1}},running:!1,eval:function(a){var b=this;if(a.type!=="sexp")return this.post_error("Bad protocol, should always be sexp.");a=a.value;if(a.type==="string_array")return this.post_error(a.value[0]);if(a.type==="null")return null;if(a.type!=="vector")return this.post_error("Protocol error, unexpected value of type "+a.type);if(a.value[0].type!=="string_array"||a.value[0].value.length!==1){console.log("Protocol error?! ",a.value[0]);return undefined}var c=a.value[0].value[0],d=this.handlers;return d[c]===undefined?this.post_error("Unknown command "+c):d[c].call(this,a.json()[1])},register_handler:function(a,b){this.handlers[a]=b},post_div:function(a){return shell.post_div(a)},display_markdown_response:function(a){a&&($("#output").append($("<div></div>").html(a.value[0])).find("pre code").each(function(a,b){hljs.highlightBlock(b)}),MathJax.Hub.Queue(["Typeset",MathJax.Hub]))},post_error:function(a){var b=$("<div class='alert alert-error'></div>").text(a);$("#output").append(b),window.scrollTo(0,document.body.scrollHeight)},post_response:function(a){var b=$("<pre></pre>").html(a);$("#output").append(b),window.scrollTo(0,document.body.scrollHeight)},capture_answers:function(a,b){function d(d){c.push(d),a--,a===0&&(l=!1,m=undefined,b(c))}if(l)throw"Still waiting for previous answers...";l=!0;var c=[];m=d},wrap_command:function(a,b){b===undefined&&(b=!1);return"rcloud.support::session.eval({"+a+"}, "+(b?"TRUE":"FALSE")+")"},markdown_wrap_command:function(b,c){return"rcloud.support::session.markdown.eval({markdownToHTML(text=paste(knit(text="+a(b+"\n")+'), collapse="\\n"), fragment=TRUE)}, '+(c?"TRUE":"FALSE")+")"},log:function(a){a='rcloud.support::session.log("'+rcloud.username()+'", "'+a.replace(/\\/g,"\\\\").replace(/"/g,'\\"')+'")',this.send(a)},record_cell_execution:function(a){var b=JSON.stringify(a.json()),c=this.r_funcall("rcloud.record.cell.execution",rcloud.username(),b);j.eval(c)},send:function(a,b){this.send_and_callback(a,c,b)},send_and_callback:function(a,d,e){function h(a){a=a.value.json(),k&&(debugger,console.log(a));try{d(a[1])}catch(c){c.constructor===b&&f.handlers[a[0]](a[1])}}var f=this;_.isUndefined(d)&&(d=c);var g;e?a=e(a):a=this.wrap_command(a,!0),k&&console.log(a),j.eval(a,h)},r_funcall:function(b){var c=[b,"("];for(var d=1;d<arguments.length;++d){var e=typeof arguments[d];e==="string"?c.push(a(arguments[d])):c.push(String(arguments[d])),d<arguments.length-1&&c.push(",")}c.push(")");var f=c.join("");return f}};return n}}}(),rcloud={},rcloud.init_client_side_data=function(){var a=this;rcloud.get_user_filenames(function(b){a.user_filenames=b;var c=b,d=d3.select("#internals-user-files");d.append("h3").text("User files"),d.append("ul").selectAll("li").data(c).enter().append("li").text(function(a){return a})}),rclient.send_and_callback("rcloud.prefix.uuid()",function(b){a.wplot_uuid=b})},rcloud.username=function(){return $.cookies.get("user")},rcloud.get_user_filenames=function(a){_.isUndefined(a)&&(a=_.identity),rclient.send_and_callback(rclient.r_funcall("rcloud.list.initial.filenames",this.username()),a)},rcloud.search=function(a,b){var c=this;_.isUndefined(b)&&(b=_.identity),rclient.send_and_callback(rclient.r_funcall("rcloud.search",a),b)},rcloud.get_all_user_filenames=function(a){var b=this;_.isUndefined(a)&&(a=_.identity),rclient.send_and_callback(rclient.r_funcall("rcloud.list.all.initial.filenames"),a)},rcloud.load_user_file=function(a,b,c){rclient.send_and_callback(rclient.r_funcall("rcloud.load.user.file",a,b),c)},rcloud.save_to_user_file=function(a,b,c,d){rclient.send_and_callback(rclient.r_funcall("rcloud.save.to.user.file",a,b,c),d)},rcloud.create_user_file=function(a,b){rclient.send_and_callback(rclient.r_funcall("rcloud.create.user.file",rcloud.username(),a),b)},rcloud.resolve_deferred_result=function(a,b){var c=rclient.r_funcall("rcloud.fetch.deferred.result",a);rclient.send_and_callback(c,b)},Notebook={},Notebook.Cell={},function(){function c(b){function k(){v.html("Computing..."),h(),y.show_result(),b.controller.execute()}function j(a){a.addClass("button-disabled")}function i(a){a.removeClass("button-disabled")}function h(){b.content($(u).val())}var c=$("<div class='notebook-cell'></div>"),d=$("<span class='fontawesome-button'><i class='icon-edit'></i></span>").tooltip({title:"source"}),e=$("<span class='fontawesome-button'><i class='icon-picture'></i></span>").tooltip({title:"result"}),f=$("<span class='fontawesome-button'><i class='icon-resize-small'></i></span>").tooltip({title:"hide"}),g=$("<span class='fontawesome-button'><i class='icon-trash'></i></span>").tooltip({title:"remove"});d.click(function(a){$(a.currentTarget).hasClass("button-disabled")||y.show_source()}),e.click(function(a){$(a.currentTarget).hasClass("button-disabled")||y.show_result()}),f.click(function(a){$(a.currentTarget).hasClass("button-disabled")||y.hide_all()}),g.click(function(a){$(a.currentTarget).hasClass("button-disabled")||(b.parent_model.controller.remove_cell(b),$(".tooltip").remove())});var l=$("<div style='position:relative; float: right; z-index:10000'></div>"),m=$("<div style='margin:0.5em;'></div>"),n=$("<div style='margin:0.5em;'></div>");m.append(d),m.append(e),m.append(f),m.append(g),l.append(m),n.hide(),l.append(n),c.append(l);var o=$("<div></div>"),p=$("<div style='clear:both;'></div>");c.append(o),c.append(p);var q=$('<div style="position: relative; width:100%;"></div>'),r=$('<div style="position: absolute; right:-0.5em; top:-0.5em"></div>'),s=a("icon-plus-sign","insert cell");o.append(r),r.append(s),s.click(function(a){var b=c.index(),d=b;shell.insert_markdown_cell_before(d)});var t=$('<div style="width:100%; margin-left: 0.5em; margin-top: 0.5em"></div>');o.append(q),q.append(t);var u=$('<input type="text" style="width:88%"/>');t.append(u),u.keypress(function(a){if(a.which===13){k(),a.preventDefault();return!1}return!0});var v=$('<div class="r-result-div"></div>');o.append(v);var w=$("<span></span>");o.append(w);var x,y={content_updated:function(){u.val(b.content())},self_removed:function(){c.remove()},result_updated:function(a){v.hide(),v.html(a),v.slideDown(150);var b=rcloud.wplot_uuid;o.find("pre code").contents().filter(function(){return this.nodeValue.indexOf(b)!==-1}).parent().parent().each(function(){var a=this.childNodes[0].childNodes[0].data.substr(8,73).split("|"),b=this;rcloud.resolve_deferred_result(a[1],function(a){$(b).replaceWith(function(){return shell.handle(a[0],a)})})}),o.find("pre code").each(function(a,b){hljs.highlightBlock(b)}),_.isUndefined(MathJax)||MathJax.Hub.Queue(["Typeset",MathJax.Hub]),this.show_result(),w[0].scrollIntoView()},hide_buttons:function(){l.css("display","none"),r.css("display","none")},show_buttons:function(){l.css("display",null),r.css("display",null)},show_source:function(){c.css({height:""}),j(d),i(e),i(f),i(g),n.show(),q.show(),v.hide(),u.focus(),x="source"},show_result:function(){c.css({height:""}),i(d),j(e),i(f),i(g),n.hide(),q.hide(),v.slideDown(150,function(){w[0].scrollIntoView()}),x="result"},hide_all:function(){c.css({height:""}),i(d),i(e),j(f),i(g),n.hide(),x==="result"?v.slideUp(150):q.slideUp(150)},remove_self:function(){b.parent_model.remove_cell(b),c.remove()},div:function(){return c},update_model:function(){h()},focus:function(){u.focus()}};y.show_result(),y.content_updated();return y}function b(b){function l(){z.html("Computing..."),i(),C.show_result(),b.controller.execute()}function k(a){a.addClass("button-disabled")}function j(a){a.removeClass("button-disabled")}function i(){b.content(v.getSession().getValue())}var c=$("<div class='notebook-cell'></div>"),d=a("icon-edit","source"),e=a("icon-picture","result"),f=a("icon-resize-small","hide"),g=a("icon-trash","remove"),h=a("icon-repeat","run");d.click(function(a){$(a.currentTarget).hasClass("button-disabled")||C.show_source()}),e.click(function(a){$(a.currentTarget).hasClass("button-disabled")||C.show_result()}),f.click(function(a){$(a.currentTarget).hasClass("button-disabled")||C.hide_all()}),g.click(function(a){$(a.currentTarget).hasClass("button-disabled")||(b.parent_model.controller.remove_cell(b),$(".tooltip").remove())}),h.click(function(a){l()});var m=$("<div style='position:relative; float: right; z-index:10000'></div>"),n=$("<div style='margin:0.5em;'></div>"),o=$("<div style='margin:0.5em;'></div>");n.append(d),n.append(e),n.append(f),n.append(g),m.append(n),o.append(h),o.hide(),m.append(o),c.append(m);var p=$("<div></div>"),q=$("<div style='clear:both;'></div>");c.append(p),c.append(q);var r=$('<div style="position: relative; width:100%; height:100%"></div>'),s=$('<div style="position: absolute; right:-0.5em; top:-0.5em"></div>'),t=a("icon-plus-sign","insert cell");p.append(s),s.append(t),t.click(function(a){var b=c.index(),d=b;shell.insert_markdown_cell_before(d)});var u=$('<div style="width:100%; height:100%"></div>');p.append(r),r.append(u);var v=ace.edit(u[0]),w=require("mode/rmarkdown").Mode,x=v.getSession(),y=x.doc;v.getSession().setMode(new w(!1,y,x)),v.setTheme("ace/theme/chrome"),v.getSession().setUseWrapMode(!0),v.resize(),v.commands.addCommand({name:"sendToR",bindKey:{win:"Ctrl-Return",mac:"Command-Return",sender:"editor"},exec:function(a,b,c){l()}});var z=$('<div class="r-result-div"><span style="opacity:0.5">Not evaluated</span></div>');p.append(z);var A=$("<span></span>");p.append(A);var B,C={content_updated:function(){v.getSession().setValue(b.content())},self_removed:function(){c.remove()},result_updated:function(a){z.hide(),z.html(a),z.slideDown(150);var b=rcloud.wplot_uuid;p.find("pre code").contents().filter(function(){return this.nodeValue.indexOf(b)!==-1}).parent().parent().each(function(){var a=this.childNodes[0].childNodes[0].data.substr(8,73).split("|"),b=this;rcloud.resolve_deferred_result(a[1],function(a){$(b).replaceWith(function(){return shell.handle(a[0],a)})})}),p.find("pre code").each(function(a,b){hljs.highlightBlock(b)}),_.isUndefined(MathJax)||MathJax.Hub.Queue(["Typeset",MathJax.Hub]),this.show_result(),A[0].scrollIntoView()},hide_buttons:function(){m.css("display","none"),s.css("display","none")},show_buttons:function(){m.css("display",null),s.css("display",null)},show_source:function(){c.css({height:"70%"}),k(d),j(e),j(f),j(g),o.show(),r.show(),z.hide(),v.resize(),v.focus(),B="source"},show_result:function(){c.css({height:""}),j(d),k(e),j(f),j(g),o.hide(),r.hide(),z.slideDown(150,function(){A[0].scrollIntoView()}),B="result"},hide_all:function(){c.css({height:""}),j(d),j(e),k(f),j(g),o.hide(),B==="result"?z.slideUp(150):r.slideUp(150)},remove_self:function(){b.parent_model.remove_cell(b),c.remove()},div:function(){return c},update_model:function(){i()},focus:function(){v.focus()}};C.show_result(),C.content_updated();return C}function a(a,b){return $("<span class='fontawesome-button'><i class='"+a+"'></i></span>").tooltip({title:b,delay:{show:250,hide:0}})}var d={markdown:b,interactive:c};Notebook.Cell.create_html_view=function(a){return d[a.type()](a)}}(),Notebook.Cell.create_model=function(a,b){function d(){_.each(c.views,function(a){a.content_updated()})}var c={views:[],type:function(){return b},content:function(b){_.isUndefined(b)||(a=b,d());return a},json:function(){return{content:a,type:b}}};return c},Notebook.Cell.create_controller=function(a){var b={execute:function(){function d(b){_.each(a.views,function(a){a.result_updated(b)})}var b=this,c=a.type();rclient.record_cell_execution(a);if(c==="markdown"){var e=rclient.markdown_wrap_command(a.content());rclient.send_and_callback(e,d,_.identity)}else if(c==="interactive"){var e=rclient.markdown_wrap_command("```{r}\n"+a.content()+"\n```\n");rclient.send_and_callback(e,d,_.identity)}else alert("Can only do markdown or interactive for now!")}};return b},Notebook.create_html_view=function(a,b){var c={model:a,sub_views:[],cell_appended:function(a){var c=Notebook.Cell.create_html_view(a);a.views.push(c),b.append(c.div()),this.sub_views.push(c);return c},cell_inserted:function(a,c){var d=Notebook.Cell.create_html_view(a);a.views.push(d),b.append(d.div()),$(d.div()).insertBefore(b.children()[c]),this.sub_views.splice(c,0,d),d.show_source();return d},cell_removed:function(a,b){_.each(a.views,function(a){a.self_removed()}),this.sub_views.splice(b,1)},update_model:function(){_.each(this.sub_views,function(a){a.update_model()})}};a.views.push(c);return c},Notebook.create_model=function(){return{notebook:[],views:[],clear:function(){while(this.notebook.length)this.remove_cell(this.notebook[this.notebook.length-1])},append_cell:function(a){a.parent_model=this,this.notebook.push(a),_.each(this.views,function(b){b.cell_appended(a)})},insert_cell:function(a,b){a.parent_model=this,this.notebook.splice(b,0,a),_.each(this.views,function(c){c.cell_inserted(a,b)})},json:function(){return _.map(this.notebook,function(a){return a.json()})},remove_cell:function(a){var b=this.notebook.indexOf(a);if(b===-1)throw"cell_model not in notebook model?!";_.each(this.views,function(c){c.cell_removed(a,b)}),this.notebook.splice(b,1)}}},Notebook.create_controller=function(a){var b={append_cell:function(b,c){var d=Notebook.Cell.create_model(b,c),e=Notebook.Cell.create_controller(d);d.controller=e,a.append_cell(d);return e},insert_cell:function(b,c,d){var e=Notebook.Cell.create_model(b,c),f=Notebook.Cell.create_controller(e);e.controller=f,a.insert_cell(e,d);return f},remove_cell:function(b){a.remove_cell(b)},clear:function(){a.clear()},load_from_file:function(a,b,c){var d=this;rcloud.load_user_file(a,b,function(a){var b=JSON.parse(a.join("\n"));d.clear(),_.each(b,function(a){var b=d.append_cell(a.content,a.type)}),c()})},save_file:function(b,c,d){var e=this,f=JSON.stringify(a.json());rcloud.load_user_file(b,c,function(a){a=a.join("\n"),f!==a?rcloud.save_to_user_file(b,c,f,function(){d&&d()}):d&&d()})},run_all:function(){_.each(a.notebook,function(a){a.controller.execute()})}};a.controller=b;return b}
View
2  htdocs/main.html
@@ -42,8 +42,6 @@
"HTML-CSS": { minScaleAdjust: 125 } });
</script>
- <!-- <script type="text/javascript" src="test_cookies.js"></script> -->
-
<script type="text/javascript" src="js/rcloud_bundle.js"></script>
<script type="text/javascript" src="main.js"></script>
View
9 htdocs/test_cookies.html
@@ -1,9 +0,0 @@
-<html>
- <head>
- <script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
- <script type="text/javascript" src="js/jquery.cookies.2.2.0.js"></script>
- <script type="text/javascript" src="test_cookies.js"></script>
- </head>
- <body>
- </body>
-</html>
View
10 htdocs/test_cookies.js
@@ -1,10 +0,0 @@
-(function() {
- if (!$.cookies.test()) {
- window.location.replace("cookies_required.html");
- return;
- }
- var cookies = $.cookies.get();
- if (cookies.user === undefined) {
- window.location.replace("login.R");
- }
-})();
View
6 rcloud.support/R/rcloud.support.R
@@ -91,10 +91,6 @@ rcloud.record.cell.execution <- function(user, json.string) {
# everything that is common to all connections
# the per-connection setup is done by start.rcloud()
configure.rcloud <- function () {
- ## FIXME: the defaults should be configurable
- .session$WSdev.width <- 300
- .session$WSdev.height <- 300
-
## it is useful to have access to the root of your
## installation from R scripts -- for RCloud this is *mandatory*
.rc.conf$root <- Sys.getenv("ROOT")
@@ -149,8 +145,6 @@ configure.rcloud <- function () {
if (exists("CairoFonts"))
CairoFonts("Arial:style=Regular","Arial:style=Bold","Arial:style=Italic","Helvetica","Symbol")
- options(device=WSdev)
-
## Load any data you want
.rc.conf$data.fn <- file.path(.rc.conf$configuration.root, "data.RData")
if (isTRUE(file.exists(.rc.conf$data.fn))) {
Please sign in to comment.
Something went wrong with that request. Please try again.