From 4d5e607075548da5ebe3c638c59a3988e72476d9 Mon Sep 17 00:00:00 2001 From: Carlos Scheidegger Date: Wed, 20 Mar 2013 09:33:25 -0400 Subject: [PATCH] more cleanup --- htdocs/js/rcloud_bundle.js | 14 -------------- htdocs/js/rcloud_bundle.min.js | 2 +- htdocs/main.html | 2 -- htdocs/test_cookies.html | 9 --------- htdocs/test_cookies.js | 10 ---------- rcloud.support/R/rcloud.support.R | 6 ------ 6 files changed, 1 insertion(+), 42 deletions(-) delete mode 100644 htdocs/test_cookies.html delete mode 100644 htdocs/test_cookies.js diff --git a/htdocs/js/rcloud_bundle.js b/htdocs/js/rcloud_bundle.js index ef3dfbb6dc..6f694350b3 100644 --- a/htdocs/js/rcloud_bundle.js +++ b/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 = ""; - // else - // this.post_div("
"); - } return cmds[cmd].call(this, data.json()[1]); }, diff --git a/htdocs/js/rcloud_bundle.min.js b/htdocs/js/rcloud_bundle.min.js index 0af9545a5d..b17da9aaf2 100644 --- a/htdocs/js/rcloud_bundle.min.js +++ b/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")[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=$("
")[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")[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")[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]*([\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($("
").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=$("
").text(a);$("#output").append(b),window.scrollTo(0,document.body.scrollHeight)},post_response:function(a){var b=$("
").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"),d=$("").tooltip({title:"source"}),e=$("").tooltip({title:"result"}),f=$("").tooltip({title:"hide"}),g=$("").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=$("
"),m=$("
"),n=$("
");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=$("
"),p=$("
");c.append(o),c.append(p);var q=$('
'),r=$('
'),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=$('
');o.append(q),q.append(t);var u=$('');t.append(u),u.keypress(function(a){if(a.which===13){k(),a.preventDefault();return!1}return!0});var v=$('
');o.append(v);var w=$("");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=$("
"),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=$("
"),n=$("
"),o=$("
");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=$("
"),q=$("
");c.append(p),c.append(q);var r=$('
'),s=$('
'),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=$('
');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=$('
Not evaluated
');p.append(z);var A=$("");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 $("").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} \ No newline at end of file +(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")[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=$("
")[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")[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")[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]*([\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($("
").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=$("
").text(a);$("#output").append(b),window.scrollTo(0,document.body.scrollHeight)},post_response:function(a){var b=$("
").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"),d=$("").tooltip({title:"source"}),e=$("").tooltip({title:"result"}),f=$("").tooltip({title:"hide"}),g=$("").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=$("
"),m=$("
"),n=$("
");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=$("
"),p=$("
");c.append(o),c.append(p);var q=$('
'),r=$('
'),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=$('
');o.append(q),q.append(t);var u=$('');t.append(u),u.keypress(function(a){if(a.which===13){k(),a.preventDefault();return!1}return!0});var v=$('
');o.append(v);var w=$("");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=$("
"),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=$("
"),n=$("
"),o=$("
");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=$("
"),q=$("
");c.append(p),c.append(q);var r=$('
'),s=$('
'),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=$('
');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=$('
Not evaluated
');p.append(z);var A=$("");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 $("").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} \ No newline at end of file diff --git a/htdocs/main.html b/htdocs/main.html index e8ab2040c7..75d36093dc 100644 --- a/htdocs/main.html +++ b/htdocs/main.html @@ -42,8 +42,6 @@ "HTML-CSS": { minScaleAdjust: 125 } }); - - diff --git a/htdocs/test_cookies.html b/htdocs/test_cookies.html deleted file mode 100644 index 15aaaea6eb..0000000000 --- a/htdocs/test_cookies.html +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/htdocs/test_cookies.js b/htdocs/test_cookies.js deleted file mode 100644 index 580a9968ed..0000000000 --- a/htdocs/test_cookies.js +++ /dev/null @@ -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"); - } -})(); diff --git a/rcloud.support/R/rcloud.support.R b/rcloud.support/R/rcloud.support.R index 618a0f2f1c..29cf983af0 100644 --- a/rcloud.support/R/rcloud.support.R +++ b/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))) {