Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

adding baseline file with inlets to use for sanity testing

  • Loading branch information...
commit 285a1c7e4c4b1c91977b36974bbaf78599051555 1 parent b4cd18b
@enjalot authored
View
5 README.md
@@ -64,9 +64,9 @@ tributary.ctx
tributary.t
tributary.dt
tributary.loop
+tributary.loop_type
tributary.autoinit
tributary.pause
-tributary.loop_type
tributary.bv
tributary.nclones
tributary.clone_opacity
@@ -91,5 +91,8 @@ tributary.render
+ Make BV button work for any of the renders (not just svg)
+#### Contexts
+
++ enable number scrubbing for text mode (csv and tsv files)
View
42 deploy/BASELINE.md
@@ -0,0 +1,42 @@
+# A set of inlets to test baseline functionality
+
+# Basics
+
+simple svg rect
+/inlet/4582399
+
+
+# Multiple files
+
+crossfilter with .csv
+/inlet/4101924/
+
+
+# HTML view
+
+parcoords (several files and external lib)
+/inlet/4101682/
+
+
+# Delta (time controls)
+
+simple square, time controls
+/inlet/2958511/
+
+
+# Bigfish (svg + restart)
+
+mouse + boids
+/inlet/3127156/
+
+
+# Canvas
+
+phylotaxis pacman (play button)
+/inlet/3125866/
+
+
+# WebGL
+
+Simple curiosity
+/inlet/3395030/
View
2  src/config.js
@@ -23,7 +23,7 @@ tributary.Config = Backbone.Model.extend({
clone_opacity: 0.4,
duration: 3000,
ease: "linear",
- dt: 0.01,
+ dt: 0.01
},
View
1  src/context.js
@@ -526,7 +526,6 @@ tributary.CoffeeContext = tributary.Context.extend({
});
-
//The CSV context evaluates js in the global namespace
tributary.CSVContext = tributary.Context.extend({
initialize: function() {
View
1  src/editor.js
@@ -81,7 +81,6 @@ tributary.Editor = Backbone.View.extend({
this.$el.html(html);
-
filetype = that.model.get("filename").split(".")[1];
if(filetype == "js") {
View
2  src/files.js
@@ -32,13 +32,11 @@ tributary.FilesView = Backbone.View.extend({
var filename = this.dataset.filename;
if(that.model) {
var ctx = _.find(tributary.__config__.contexts, function(d) { return d.model.get("filename") === filename; });
- console.log("FOUND", ctx, ctx.model.get("filename"))
that.model.trigger("hide");
ctx.model.trigger("show");
}
});
-
//delete
filelist.select(".delete-file")
.style("z-index", 1000)
View
1  static/tributary.js
@@ -1068,7 +1068,6 @@ var Tributary = function() {
var ctx = _.find(tributary.__config__.contexts, function(d) {
return d.model.get("filename") === filename;
});
- console.log("FOUND", ctx, ctx.model.get("filename"));
that.model.trigger("hide");
ctx.model.trigger("show");
}
View
2  static/tributary.min.js
@@ -1,2 +1,2 @@
//(function(){
-var Tributary=function(){function _assemble(a,b){if(a){console.log("error!",a);return}var c=b.config;tributary.__config__=c,c.contexts=[];var d,e,f,g,h=c.get("endpoint");tributary.endpoint&&(h=tributary.endpoint),h==="delta"?(c.set("display","svg"),c.set("play",!0),c.set("loop",!0),c.set("autoinit",!0)):h==="cypress"?(c.set("display","canvas"),c.set("play",!0),c.set("autoinit",!0)):h==="hourglass"?(c.set("display","svg"),c.set("play",!0),c.set("autoinit",!0)):h==="curiosity"?(c.set("display","webgl"),c.set("play",!0),c.set("autoinit",!0)):h==="bigfish"?(c.set("display","svg"),c.set("play",!0),c.set("autoinit",!1),c.set("restart",!0)):h==="fly"?(c.set("display","canvas"),c.set("play",!0),c.set("autoinit",!1),c.set("restart",!0)):h==="ocean"&&c.set("display","div"),c.get("display")||c.set("display","svg"),c.set("endpoint","");var i=d3.select("#code");tributary.edit=i,b.models.each(function(a){g=a.get("type"),d=tributary.make_context({config:c,model:a,display:display}),d&&(c.contexts.push(d),d.render(),mainfiles.indexOf(a.get("filename"))<0&&d.execute(),d.editor=tributary.make_editor({model:a,parent:i}),a.trigger("hide"))}),c.contexts.forEach(function(a){mainfiles.indexOf(a.model.get("filename"))>=0&&(a.model.trigger("show"),tributary.autoinit=!0,a.execute(),tributary.autoinit=c.get("autoinit"))});var j=new tributary.FilesView({el:"#file-list",model:c});j.render();var k=new tributary.ConfigView({el:"#config",model:c});k.render();var l=new tributary.ControlsView({el:"#controls",model:c});l.render(),$("#config-toggle").on("click",function(){$("#config-content").toggle(),$("#config-toggle").text()=="Config"?$("#config-toggle").text("Close Config"):$("#config-toggle").text("Config")}),$("#library-toggle").on("click",function(){$("#library-content").toggle(),$("#library-toggle").text()=="Add libraries"?$("#library-toggle").text("Close libraries"):$("#library-toggle").text("Add libraries")}),$("#fullscreen").on("click",function(){$("#container").addClass("fullscreen"),$("#exit-fullscreen").show()}),$("#exit-fullscreen").on("click",function(){$("#exit-fullscreen").hide(),$("#container").removeClass("fullscreen")}),setup_header(b),setup_save(b.config)}function setup_header(a){if(a.user){var b=a.user.id;$("#inlet-author").text(a.user.login),$("#gist-title").val(a.gist.description),$("#author-avatar img").attr("src",function(b){return"http://2.gravatar.com/avatar/"+a.user.gravatar_id}),d3.select("title").text("Tributary | "+a.gist.description||"Tributary"),a.user.id!==tributary.userid?($("#fork").css("display","none"),a.config.saveType="fork"):($("#fork").css("display",""),a.config.saveType="save")}else isNaN(tributary.userid)||!a.gist?($("#fork").css("display","none"),a.config.saveType="fork"):a.config.saveType="save";$("#gist-title").on("keyup",function(){a.config.set("description",$("#gist-title").val()),d3.select("title").text($("#gist-title").val())})}function setup_save(a){$("#save").off("click"),$("#save").on("click",function(b){console.log("saving!"),d3.select("#syncing").style("display","block"),tributary.save_gist(a,a.saveType,function(b,c){d3.select("#syncing").style("display","none"),a.saveType==="fork"&&(window.onunload=!1,window.onbeforeunload=!1,window.location=b)})}),$("#fork").off("click"),$("#fork").on("click",function(b){console.log("forking!"),a.saveType="fork",d3.select("#syncing").style("display","block"),tributary.save_gist(a,a.saveType,function(a,b){window.onunload=!1,window.onbeforeunload=!1,window.location=a})}),$("#loginPanel").on("click",function(a){tributary.login_gist(tributary.loggedin,function(a,b){window.onunload=!1,window.onbeforeunload=!1,window.location=a})})}var tributary={};tributary.events=_.clone(Backbone.Events),tributary.data={},window.trib={},window.trib_options={},window.addEventListener("resize",function(a){tributary.events.trigger("resize",a)});var mainfiles=["inlet.js","inlet.coffee","sinwaves.js","squarecircle.js"];tributary.displays=[{name:"svg",description:"creates an <svg> element for you to use"},{name:"canvas",description:"creates a <canvas> element and gives you a Context for the canvas"},{name:"webgl",description:"gives you a Three.js WebGLRenderer scene"},{name:"html",description:"gives you <div id=display>"}],tributary.time_controls=[{name:"play",description:"gives you a play button, and tributary.t. if you provide tributary.run(g,t) it will be executed in a run loop"},{name:"loop",description:"gives you a loop where tributary.t goes from 0 to 1."},{name:"restart",description:"assumes you only want tributary.init(g) to be run when the restart button is clicked"}],tributary.make_context=function(a){var b,c,d,e,f=a.config;if(a.model)c=a.model,g=c.get("filename"),e=c.get("type");else{var g,h;a.filename?g=a.filename:g="inlet.js",a.content?h=a.content:h="";var i=g.split(".");e=i[i.length-1],c=new tributary.CodeModel({name:i[0],filename:g,code:h})}return a.display?d=a.display:d=d3.select("#display"),c.set("type",e),mainfiles.indexOf(g)>=0?b=new tributary.TributaryContext({config:f,model:c,el:d.node()}):e==="json"?(c.set("mode","json"),b=new tributary.JSONContext({config:f,model:c})):e==="csv"?(c.set("mode","text"),b=new tributary.CSVContext({config:f,model:c})):e==="tsv"?(c.set("mode","text"),b=new tributary.TSVContext({config:f,model:c})):e==="js"?b=new tributary.JSContext({config:f,model:c}):e==="coffee"?(c.set("mode","coffeescript"),b=new tributary.CoffeeContext({config:f,model:c})):e==="css"?(c.set("mode","css"),b=new tributary.CSSContext({config:f,model:c})):e==="html"?(c.set("mode","text/html"),b=new tributary.HTMLContext({config:f,model:c,el:d.node()})):e==="svg"&&g!=="inlet.svg"&&(c.set("mode","text/html"),b=new tributary.SVGContext({config:f,model:c,el:d.node()})),b},d3.selection.prototype.moveToFront=function(){return this.each(function(){this.parentNode.appendChild(this)})},tributary.appendSVGFragment=function(a,b){var c="<svg xmlns=http://www.w3.org/2000/svg xmlns:xlink=http://www.w3.org/1999/xlink>",d="</svg>",e=document.createRange();e.selectNode(a);var f=e.createContextualFragment(c+b+d),g=f.childNodes[0].childNodes;for(var h=0,i=g.length;h<i;h++)a.appendChild(g[0])},Handlebars.getTemplate=function(a,b){(Handlebars.templates===undefined||Handlebars.templates[a]===undefined)&&$.ajax({url:"/static/templates/"+a+".handlebars",success:function(c){Handlebars.templates===undefined&&(Handlebars.templates={}),Handlebars.templates[a]=Handlebars.compile(c),b&&b(template)}})},tributary.CodeModel=Backbone.Model.extend({defaults:{code:"",filename:"inlet.js",name:"inlet",type:"js",mode:"javascript"},initialize:function(){this.binder()},binder:function(){this.on("error",this.handle_error)},handle_error:function(a){tributary.trace&&(console.trace(),console.log(a))},handle_coffee:function(){var a=this.get("code");return this.get("mode")==="coffeescript"&&(a=CoffeeScript.compile(a,{bare:!0})),a},local_storage:function(a){a||(a="");var b=this.get("filename")+"/code/"+a;return localStorage[b]},set_local_storage:function(a,b){var c=this.get("filename")+"/code/"+b;localStorage[c]=a}}),tributary.CodeModels=Backbone.Collection.extend({model:tributary.CodeModel}),tributary.Config=Backbone.Model.extend({defaults:{description:"Tributary inlet",endpoint:"tributary",display:"svg","public":!0,require:[],fileconfigs:{},play:!1,loop:!1,restart:!1,autoinit:!0,pause:!0,loop_type:"period",bv:!1,nclones:15,clone_opacity:.4,duration:3e3,ease:"linear",dt:.01},require:function(a){var b=this.get("require"),c=_.pluck(b,"url"),d=function(){return a(null,arguments)};require(c,d)},initialize:function(){this.on("hide",function(){this.contexts.forEach(function(a){a.model.trigger("hide")})},this)}}),tributary.ConfigView=Backbone.View.extend({initialize:function(){},render:function(){function j(){var b={name:h.node().value,url:i.node().value},c=a.model.get("require");c.push(b),a.model.require(function(a,b){}),a.model.set("require",c),l(f.selectAll("li.lib").data(c).enter())}function l(b){var c=b.append("li").classed("lib",!0);c.append("input").attr("type","checkbox").attr("checked",!0).on("change",function(b){var c=a.model.get("require"),d=c.indexOf(b);d>=0?(c.splice(d,1),a.model.set("require",c)):(c.push(b),a.model.set("require",c))}),c.append("span").text(function(a){return a.name})}var a=this,b=d3.select(this.el).select("#config-content select").on("change",function(){var b=this.selectedOptions[0].value;a.model.set("display",b),tributary.events.trigger("execute")}),c=this.model.get("display");b.selectAll("option").each(function(a,d){this.value===c&&(b.node().value=this.value)});var d=d3.select("#timecontrols").selectAll("button");d.datum(function(){return this.dataset}),d.filter(function(b){return a.model.get(b.name)}).classed("active",!0),d.on("click",function(b){var c=!a.model.get(b.name);d3.select(this).classed("active",c),a.model.set(b.name,c)});var e=d3.select(this.el).select("#logerrors").on("click",function(a){var b=d3.select(this);$(this).attr("data-name")==="log-errors"&&(b.classed("active")?(console.log("Error logging disabled"),tributary.hint=!1,tributary.trace=!1,tributary.events.trigger("execute"),b.classed("active",!1)):(console.log("Error logging initiated"),tributary.hint=!0,tributary.trace=!0,tributary.events.trigger("execute"),b.classed("active",!0)))}),f=d3.select(this.el).select("#library-checklist"),g=d3.select(this.el).select("#library-links"),h=g.select("input.library-title"),i=g.select("input.library-url"),k=g.select(".add-library").on("click",j);h.on("keypress",function(){d3.event.charCode===13&&j()}),i.on("keypress",function(){d3.event.charCode===13&&j()});var m=f.selectAll("li.lib").data(this.model.get("require")).enter();l(m)}}),tributary.Context=Backbone.View.extend({initialize:function(){},execute:function(){},render:function(){}}),tributary.TributaryContext=tributary.Context.extend({initialize:function(){this.model.on("change:code",function(){tributary.events.trigger("execute")}),tributary.events.on("execute",this.execute,this),tributary.__config__||(tributary.__config__=this.options.config),this.model.on("change:code",function(){window.onbeforeunload||$(window).on("beforeunload",function(){return"Are you sure you want to leave?"})},this),this.config=this.options.config,this.config.on("change:display",this.set_display,this);var a=this.config;tributary.init=undefined,tributary.run=undefined,tributary.loop=a.get("loop"),tributary.autoinit=a.get("autoinit"),tributary.pause=a.get("pause"),tributary.loop_type=a.get("loop_type"),tributary.bv=a.get("bv"),tributary.nclones=a.get("nclones"),tributary.clone_opacity=a.get("clone_opacity"),tributary.duration=a.get("duration"),tributary.ease=d3.ease(a.get("ease")),tributary.t=0,tributary.dt=a.get("dt"),tributary.reverse=!1,tributary.useThreejsControls=!0,tributary.render=function(){},tributary.execute=function(){if(tributary.run!==undefined){var a=tributary.t;tributary.loop&&(a=tributary.ease(tributary.t)),tributary.run(tributary.g,a,0)}},tributary.timer={then:new Date,duration:tributary.duration,ctime:tributary.t},d3.timer(function(){tributary.render();if(tributary.pause)return!1;var b=new Date,c=b-tributary.timer.then,d;if(tributary.loop){tributary.reverse?d=tributary.timer.ctime*c/tributary.timer.duration*-1:d=(1-tributary.timer.ctime)*c/tributary.timer.duration,tributary.t=tributary.timer.ctime+d;if(tributary.t>=1||tributary.t<=0||tributary.t==="NaN")tributary.loop_type==="period"?(tributary.t=0,tributary.timer.then=new Date,tributary.timer.duration=tributary.duration,tributary.timer.ctime=tributary.t,tributary.reverse=!1):tributary.loop_type==="pingpong"?(tributary.t=!tributary.reverse,tributary.timer.then=new Date,tributary.timer.duration=tributary.duration,tributary.timer.ctime=tributary.t,tributary.reverse=!tributary.reverse):tributary.t!==0&&(tributary.t=1,tributary.pause=!0);tributary.t===!0&&(tributary.t=1),tributary.t===!1&&(tributary.t=0)}else tributary.t+=tributary.dt;tributary.execute(),a.trigger("tick",tributary.t)})},execute:function(){var a=this.model.handle_coffee();if(a.length>0&&this.model.get("type")!=="coffee"){var b=JSHINT(a,{asi:!0,laxcomma:!0,laxbreak:!0,loopfunc:!0,smarttabs:!0,sub:!0});b?this.model.trigger("nojshint"):this.model.trigger("jshint",JSHINT.errors)}try{tributary.initialize=new Function("g","tributary",a)}catch(c){return this.model.trigger("error",c),!1}try{window.trib={},window.trib_options={},trib=window.trib,trib_options=window.trib_options,tributary.autoinit&&(tributary.clear(),tributary.events.trigger("prerender")),this.clones&&$(this.clones.node()).empty(),tributary.bv&&this.make_clones(),tributary.initialize(tributary.g,tributary),tributary.autoinit&&tributary.init!==undefined&&tributary.init(tributary.g,0),tributary.execute()}catch(d){return this.model.trigger("error",d),!1}return this.model.trigger("noerror"),!0},render:function(){this.set_display()},set_display:function(){var a=this;this.$el.empty();var b=this.config.get("display");b==="svg"?this.make_svg():b==="canvas"?this.make_canvas():b==="webgl"?this.make_webgl():b==="div"?(this.g=d3.select(this.el),tributary.g=this.g,tributary.clear=function(){a.$el.empty()}):tributary.clear=function(){a.$el.empty()}},make_svg:function(){this.svg=d3.select(this.el).append("svg").attr({xmlns:"http://www.w3.org/2000/svg",xlink:"http://www.w3.org/1999/xlink","class":"tributary_svg"}),tributary.g=this.svg,tributary.clear=function(){$(tributary.g.node()).empty()}},make_canvas:function(){tributary.clear=function(){tributary.canvas.width=tributary.sw,tributary.canvas.height=tributary.sh,tributary.ctx.clearRect(0,0,tributary.sw,tributary.sh)},tributary.canvas=d3.select(this.el).append("canvas").classed("tributary_canvas",!0).node(),tributary.ctx=tributary.canvas.getContext("2d"),tributary.g=tributary.ctx},make_clones:function(){this.clones=this.svg.selectAll("g.clones").data([0]),this.clones.enter().append("g").attr("class","clones"),tributary.g=this.svg.selectAll("g.delta").data([0]),tributary.g.enter().append("g").attr("class","delta");var a=d3.range(tributary.nclones),b=this.clones.selectAll("g.bvclone").data(a).enter().append("g").attr("class","bvclone").style("opacity",tributary.clone_opacity);b.each(function(a,b){var c=b+1,d=d3.select(this);tributary.init(d,c);var e=tributary.ease(c/(tributary.nclones+1));tributary.run(d,e,c)})},make_webgl:function(){function b(){windowHalfX=tributary.sw/2,windowHalfY=tributary.sh/2,tributary.camera.aspect=tributary.sw/tributary.sh,tributary.camera.updateProjectionMatrix(),tributary.renderer.setSize(tributary.sw,tributary.sh)}container=this.el,tributary.camera=new THREE.PerspectiveCamera(70,tributary.sw/tributary.sh,1,1e3),tributary.camera.position.y=150,tributary.camera.position.z=500,tributary.scene=new THREE.Scene,THREE.Object3D.prototype.clear=function(){var a=this.children,b;for(b=a.length-1;b>=0;b--){var c=a[b];c.clear(),this.remove(c)}},tributary.renderer=new THREE.WebGLRenderer,tributary.renderer.setSize(tributary.sw,tributary.sh),container.appendChild(tributary.renderer.domElement);var a=new THREE.TrackballControls(tributary.camera);a.target.set(0,0,0),a.rotateSpeed=1,a.zoomSpeed=1.2,a.panSpeed=.8,a.noZoom=!1,a.noPan=!1,a.staticMoving=!1,a.dynamicDampingFactor=.15,tributary.controls=a,tributary.render=function(){tributary.useThreejsControls&&tributary.controls.update(),tributary.renderer.render(tributary.scene,tributary.camera)},tributary.render(),tributary.events.on("resize",b,!1),tributary.clear=function(){tributary.scene.clear()}}}),tributary.JSONContext=tributary.Context.extend({initialize:function(){this.model.on("change:code",this.execute,this),this.model.on("change:code",function(){tributary.events.trigger("execute")})},execute:function(){try{var a=JSON.parse(this.model.get("code"));tributary[this.model.get("name")]=a}catch(b){return this.model.trigger("error",b),!1}return this.model.trigger("noerror"),!0},render:function(){}}),tributary.JSContext=tributary.Context.extend({initialize:function(){this.model.on("change:code",this.execute,this),this.model.on("change:code",function(){tributary.events.trigger("execute")})},execute:function(){var js=this.model.get("code");if(js.length>0){var hints=JSHINT(js,{asi:!0,laxcomma:!0,laxbreak:!0,loopfunc:!0,smarttabs:!0,sub:!0});hints?this.model.trigger("nojshint"):this.model.trigger("jshint",JSHINT.errors)}try{eval(js)}catch(e){return this.model.trigger("error",e),!1}return this.model.trigger("noerror"),!0},render:function(){}}),tributary.CoffeeContext=tributary.Context.extend({initialize:function(){this.model.on("change:code",this.execute,this),this.model.on("change:code",function(){tributary.events.trigger("execute")})},execute:function(){var js=this.model.handle_coffee();try{eval(js)}catch(e){return this.model.trigger("error",e),!1}return this.model.trigger("noerror"),!0},render:function(){}}),tributary.CSVContext=tributary.Context.extend({initialize:function(){this.model.on("change:code",this.execute,this),this.model.on("change:code",function(){tributary.events.trigger("execute")})},execute:function(){try{var a=d3.csv.parse(this.model.get("code"));tributary[this.model.get("name")]=a}catch(b){return this.model.trigger("error",b),!1}return this.model.trigger("noerror"),!0},render:function(){}}),tributary.TSVContext=tributary.Context.extend({initialize:function(){this.model.on("change:code",this.execute,this),this.model.on("change:code",function(){tributary.events.trigger("execute")})},execute:function(){try{var a=d3.tsv.parse(this.model.get("code"));tributary[this.model.get("name")]=a}catch(b){return this.model.trigger("error",b),!1}return this.model.trigger("noerror"),!0},render:function(){}}),tributary.CSSContext=tributary.Context.extend({initialize:function(){this.model.on("change:code",this.execute,this),this.model.on("change:code",function(){tributary.events.trigger("execute")}),this.model.on("delete",function(){d3.select(this.el).remove()},this)},execute:function(){try{this.el.textContent=this.model.get("code")}catch(a){return this.model.trigger("error",a),!1}return this.model.trigger("noerror"),!0},render:function(){this.el=d3.select("head").selectAll("style.csscontext").data([this.model],function(a){return a.cid}).enter().append("style").classed("csscontext",!0).attr({type:"text/css"}).node()}}),tributary.HTMLContext=tributary.Context.extend({initialize:function(){this.model.on("change:code",function(){tributary.events.trigger("execute")}),tributary.events.on("prerender",this.execute,this)},execute:function(){try{$(this.el).append(this.model.get("code"))}catch(a){return this.model.trigger("error",a),!1}return this.model.trigger("noerror"),!0},render:function(){}}),tributary.SVGContext=tributary.Context.extend({initialize:function(){this.model.on("change:code",function(){tributary.events.trigger("execute")}),tributary.events.on("prerender",this.execute,this)},execute:function(){try{var a=d3.select(this.el).select("svg").node();tributary.appendSVGFragment(a,this.model.get("code"))}catch(b){return this.model.trigger("error",b),!1}return this.model.trigger("noerror"),!0},render:function(){}}),tributary.make_editor=function(a){var b=a.parent||tributary.edit,c=a.model;a.container?container=a.container:container=b.append("div").attr("id",c.cid);var d;return d=new tributary.Editor({el:container.node(),model:c}),d.render(),d},tributary.Editor=Backbone.View.extend({initialize:function(){this.model.on("show",function(){d3.select(this.el).style("display","")},this),this.model.on("hide",function(){d3.select(this.el).style("display","none")},this),this.model.on("delete",function(){this.$el.remove()},this)},getConfig:function(){var a=tributary.__config__.get("fileconfigs"),b=a[this.model.get("filename")];return b?b:this.defaultConfig()},setConfig:function(a,b){var c=tributary.__config__.get("fileconfigs"),d=c[this.model.get("filename")];d[a]=b;var c=tributary.__config__.set("fileconfigs",c)},defaultConfig:function(){var a=tributary.__config__.get("fileconfigs"),b={"default":!0,vim:!1,emacs:!1,fontSize:12};a[this.model.get("filename")]=b;var a=tributary.__config__.set("fileconfigs",a);return b},render:function(){var a=this,b=d3.select(this.el).classed("editor",!0),c=Handlebars.templates.editor,d=c(this.getConfig());this.$el.html(d),filetype=a.model.get("filename").split(".")[1];if(filetype=="js")var e="lesser-dark";else if(filetype=="svg")var e="vibrant-ink";else if(filetype=="html")var e="ambiance";else if(filetype=="coffee")var e="elegant";else if(filetype=="css")var e="elegant";else var e="lesser-dark";var f={mode:a.model.get("mode"),theme:e,lineNumbers:!0};a.model.get("mode")==="json"&&(f.mode="javascript",f.json=!0),this.cm=CodeMirror(this.el,f),this.cm.on("change",function(){var b=a.cm.getValue();a.model.set("code",b)}),this.cm.setValue(this.model.get("code")),this.inlet=Inlet(this.cm),this.model.on("error",function(){d3.select(a.el).select(".CodeMirror-gutter").classed("error",!0)}),this.model.on("noerror",function(){d3.select(a.el).select(".CodeMirror-gutter").classed("error",!1)});var g=b.select(".toolbar"),h=b.select(".settings").on("click",function(){g.classed("hidden",!g.classed("hidden")),h.classed("active-settings",!g.classed("hidden"))});g.selectAll(".radio").on("change",function(){a.setConfig("default",!1),a.setConfig("vim",!1),a.setConfig("emacs",!1),a.setConfig(this.value,!0),a.cm.setOption("keyMap",this.value)}),g.select(".plusFontSize").on("click",function(){var b=a.getConfig(),c=b.fontSize+1;a.setConfig("fontSize",c);var d=a.cm.getWrapperElement();d3.select(d).select(".CodeMirror-scroll").style({"font-size":c+"px","line-height":c+"px"}),a.cm.refresh()}),g.select(".minusFontSize").on("click",function(){var b=a.getConfig(),c=b.fontSize-1;a.setConfig("fontSize",c);var d=a.cm.getWrapperElement();d3.select(d).select(".CodeMirror-scroll").style({"font-size":c+"px","line-height":c+"px"}),a.cm.refresh()});var i=a.getConfig(),j=i.fontSize,k=a.cm.getWrapperElement();d3.select(k).select(".CodeMirror-scroll").style({"font-size":j+"px","line-height":j+"px"}),a.cm.refresh()}}),tributary.gist=function(a,b){function f(a){c.gist=a,a.user===null||a.user===undefined?c.user={login:"anon",url:"",userid:-1}:c.user=a.user;var d;try{d=a.files["config.json"]}catch(e){d=!1}if(d)try{c.config=new tributary.Config(JSON.parse(d.content))}catch(f){c.config=new tributary.Config}else c.config=new tributary.Config;var g=_.keys(a.files);fileconfigs=c.config.get("fileconfigs")||{},c.models=new tributary.CodeModels;var h,i,j,k=0,l;g.forEach(function(b){h=b.split("."),l=h[h.length-1],b!=="config.json"&&(i=new tributary.CodeModel({filename:b,name:h[0],code:a.files[b].content,type:l}),c.models.add(i)),fileconfigs[b]||(fileconfigs[b]={"default":!0,vim:!1,emacs:!1,fontSize:12})}),c.config.set("fileconfigs",fileconfigs),c.config.require(function(a,d){b(null,c)})}tributary.gistid=a;var c={},d="?cachebust="+Math.random()*0xf12765df4c9b2,e="https://api.github.com/gists/"+a+d;$.ajax({url:e,contentType:"application/json",dataType:"json",success:f,error:function(b){console.log(b),e="/gist/"+a+d,$.ajax({url:e,contentType:"application/json",dataType:"json",success:f,error:function(a){console.log(a)}})}})},tributary.save_gist=function(a,b,c){var d=tributary.gistid||"",e={description:a.get("description"),"public":a.get("public"),files:{}};a.contexts.forEach(function(a){e.files[a.model.get("filename")]={content:a.model.get("code")}}),a.todelete&&a.todelete.forEach(function(a){e.files[a]=null}),e.files["config.json"]={content:JSON.stringify(a.toJSON())};var f;b==="fork"?f="/tributary/fork":f="/tributary/save",d.length>4&&(f+="/"+d);var g=this;$.post(f,{gist:JSON.stringify(e)},function(a){typeof a=="string"&&(a=JSON.parse(a));var b=a.id,d="/inlet/"+b;c(d,b)})},tributary.login_gist=function(a,b){a?url="/github-logout":url="/github-login",url+="/inlet",tributary.gistid&&(url+="/"+tributary.gistid),b(url)},tributary.FilesView=Backbone.View.extend({initialize:function(){},render:function(){var a=this,b=Handlebars.templates.files,c=_.map(tributary.__config__.contexts,function(a){return a.model.toJSON()});c=c.sort(function(a,b){return a.filename<b.filename?-1:1});var d=_.find(c,function(a){return a.filename==="inlet.js"||a.filename==="inlet.coffee"});d&&(c.splice(c.indexOf(d),1),c.unshift(d)),$(this.el).html(b({contexts:c}));var e=d3.select("#file-list").selectAll("li.file");e.on("click",function(b){var c=this.dataset.filename;if(a.model){var d=_.find(tributary.__config__.contexts,function(a){return a.model.get("filename")===c});console.log("FOUND",d,d.model.get("filename")),a.model.trigger("hide"),d.model.trigger("show")}}),e.select(".delete-file").style("z-index",1e3).on("click",function(){var b=this.parentNode.dataset,c=b.filename,d=b.filename.split(".")[0];delete a.model,tributary.__config__.unset(c);var e=_.find(tributary.__config__.contexts,function(a){return a.model.get("filename")===c});e.model.trigger("delete");var f=tributary.__config__.contexts.indexOf(e);tributary.__config__.contexts.splice(f,1),delete e,tributary.__config__.todelete||(tributary.__config__.todelete=[]),tributary.__config__.todelete.push(c),d3.select(a.el).selectAll("li.file").each(function(){this.dataset.filename===c&&$(this).remove()});var g=tributary.__config__.contexts[0].model;g.trigger("show"),d3.event.stopPropagation()});var f=d3.select(this.el).select(".add-file").on("click",function(){console.log("SUP");var b=d3.select(this).select("input").style("display","inline-block");b.node().focus(),b.on("keypress",function(){if(d3.event.charCode===13){var c=tributary.make_context({filename:b.node().value,config:tributary.__config__});if(c){tributary.__config__.contexts.push(c),c.render(),c.execute();var d=tributary.make_editor({model:c.model});a.$el.empty(),a.render(),tributary.__config__.contexts.forEach(function(a){a.model.trigger("hide")}),c.model.trigger("show"),d.cm.focus()}else b.classed("error",!0)}})})}}),tributary.FileView=Backbone.View.extend({render:function(){}}),tributary.ControlsView=Backbone.View.extend({initialize:function(){this.model.on("change:play",this.play_button,this),this.model.on("change:loop",this.time_slider,this),this.model.on("change:restart",this.restart_button,this)},render:function(){var a=d3.select(this.el);a.append("div").attr("id","time_controls"),a.append("div").attr("id","user_controls"),a.append("div").attr("id","time_options"),this.play_button(),this.time_slider(),this.restart_button()},play_button:function(){var a=d3.select(this.el).select("#time_controls");if(this.model.get("play")){var b=a.append("button").classed("play",!0).classed("button_on",!0).text("Play");b.on("click",function(a){tributary.pause?tributary.pause&&(b.classed("playing",!0),b.text("Pause")):(b.classed("playing",!1),b.text("Play"));if(tributary.t<1||!tributary.loop)tributary.pause=!tributary.pause,tributary.pause||(tributary.timer.then=new Date,tributary.timer.duration=(1-tributary.t)*tributary.duration,tributary.timer.ctime=tributary.t)})}else a.select("button.play").remove()},time_slider:function(){tributary.loop=this.model.get("loop");var a=d3.select(this.el).select("#time_controls");if(tributary.loop){var b=a.append("input").attr({type:"range",min:0,max:1,step:.01,value:0,name:"time"}).classed("time_slider",!0);$(b.node()).on("change",function(){tributary.t=parseFloat(this.value),tributary.pause&&tributary.execute()}),this.model.on("tick",function(a){$(b.node()).attr("value",tributary.t)});if(this.model.get("display")==="svg"){var c=a.append("button").classed("bv",!0).classed("button_on",!0).text("BV");c.on("click",function(){tributary.bv=!tributary.bv,tributary.events.trigger("execute")})}}else tributary.bv=!1,a.select("input.time_slider").remove(),a.select("button.bv").remove()},restart_button:function(){var a=this,b=d3.select(this.el).select("#time_controls");if(this.model.get("restart")){tributary.autoinit=!1;var c=b.append("button").classed("restart",!0).classed("button_on",!0).text("Restart");c.on("click",function(a){tributary.clear(),tributary.initialize(tributary.g,tributary),tributary.init(tributary.g),tributary.execute()})}else tributary.autoinit=!0,b.select("button.restart").remove()}}),tributary.batch={},tributary.batch._execute=function(){var a=_.functions(this);_.each(a,function(a){a!=="_execute"&&tributary.batch[a]()})},tributary.ui={};var display,panel_gui,panel,panel_handle,page,header;return tributary.ui.setup=function(){tributary.events.on("resize",function(){$("#display").width()>767?tributary.sw=$("#display").width()-$("#panel").width():tributary.sw=$("#display").width(),$("#container").hasClass("fullscreen")&&(console.log("Fullscreen"),tributary.sw=$("#display").width()),tributary.sh=$("#display").height(),tributary.events.trigger("execute")}),tributary.events.trigger("resize")},tributary.ui.assemble=function(a){tributary.trace=!1,tributary.hint=!1;if(a.length>0)tributary.gist(a,_assemble);else{var b={};b.config=new tributary.Config,b.models=new tributary.CodeModels(new tributary.CodeModel),_assemble(b)}},tributary};
+var Tributary=function(){function _assemble(a,b){if(a){console.log("error!",a);return}var c=b.config;tributary.__config__=c,c.contexts=[];var d,e,f,g,h=c.get("endpoint");tributary.endpoint&&(h=tributary.endpoint),h==="delta"?(c.set("display","svg"),c.set("play",!0),c.set("loop",!0),c.set("autoinit",!0)):h==="cypress"?(c.set("display","canvas"),c.set("play",!0),c.set("autoinit",!0)):h==="hourglass"?(c.set("display","svg"),c.set("play",!0),c.set("autoinit",!0)):h==="curiosity"?(c.set("display","webgl"),c.set("play",!0),c.set("autoinit",!0)):h==="bigfish"?(c.set("display","svg"),c.set("play",!0),c.set("autoinit",!1),c.set("restart",!0)):h==="fly"?(c.set("display","canvas"),c.set("play",!0),c.set("autoinit",!1),c.set("restart",!0)):h==="ocean"&&c.set("display","div"),c.get("display")||c.set("display","svg"),c.set("endpoint","");var i=d3.select("#code");tributary.edit=i,b.models.each(function(a){g=a.get("type"),d=tributary.make_context({config:c,model:a,display:display}),d&&(c.contexts.push(d),d.render(),mainfiles.indexOf(a.get("filename"))<0&&d.execute(),d.editor=tributary.make_editor({model:a,parent:i}),a.trigger("hide"))}),c.contexts.forEach(function(a){mainfiles.indexOf(a.model.get("filename"))>=0&&(a.model.trigger("show"),tributary.autoinit=!0,a.execute(),tributary.autoinit=c.get("autoinit"))});var j=new tributary.FilesView({el:"#file-list",model:c});j.render();var k=new tributary.ConfigView({el:"#config",model:c});k.render();var l=new tributary.ControlsView({el:"#controls",model:c});l.render(),$("#config-toggle").on("click",function(){$("#config-content").toggle(),$("#config-toggle").text()=="Config"?$("#config-toggle").text("Close Config"):$("#config-toggle").text("Config")}),$("#library-toggle").on("click",function(){$("#library-content").toggle(),$("#library-toggle").text()=="Add libraries"?$("#library-toggle").text("Close libraries"):$("#library-toggle").text("Add libraries")}),$("#fullscreen").on("click",function(){$("#container").addClass("fullscreen"),$("#exit-fullscreen").show()}),$("#exit-fullscreen").on("click",function(){$("#exit-fullscreen").hide(),$("#container").removeClass("fullscreen")}),setup_header(b),setup_save(b.config)}function setup_header(a){if(a.user){var b=a.user.id;$("#inlet-author").text(a.user.login),$("#gist-title").val(a.gist.description),$("#author-avatar img").attr("src",function(b){return"http://2.gravatar.com/avatar/"+a.user.gravatar_id}),d3.select("title").text("Tributary | "+a.gist.description||"Tributary"),a.user.id!==tributary.userid?($("#fork").css("display","none"),a.config.saveType="fork"):($("#fork").css("display",""),a.config.saveType="save")}else isNaN(tributary.userid)||!a.gist?($("#fork").css("display","none"),a.config.saveType="fork"):a.config.saveType="save";$("#gist-title").on("keyup",function(){a.config.set("description",$("#gist-title").val()),d3.select("title").text($("#gist-title").val())})}function setup_save(a){$("#save").off("click"),$("#save").on("click",function(b){console.log("saving!"),d3.select("#syncing").style("display","block"),tributary.save_gist(a,a.saveType,function(b,c){d3.select("#syncing").style("display","none"),a.saveType==="fork"&&(window.onunload=!1,window.onbeforeunload=!1,window.location=b)})}),$("#fork").off("click"),$("#fork").on("click",function(b){console.log("forking!"),a.saveType="fork",d3.select("#syncing").style("display","block"),tributary.save_gist(a,a.saveType,function(a,b){window.onunload=!1,window.onbeforeunload=!1,window.location=a})}),$("#loginPanel").on("click",function(a){tributary.login_gist(tributary.loggedin,function(a,b){window.onunload=!1,window.onbeforeunload=!1,window.location=a})})}var tributary={};tributary.events=_.clone(Backbone.Events),tributary.data={},window.trib={},window.trib_options={},window.addEventListener("resize",function(a){tributary.events.trigger("resize",a)});var mainfiles=["inlet.js","inlet.coffee","sinwaves.js","squarecircle.js"];tributary.displays=[{name:"svg",description:"creates an <svg> element for you to use"},{name:"canvas",description:"creates a <canvas> element and gives you a Context for the canvas"},{name:"webgl",description:"gives you a Three.js WebGLRenderer scene"},{name:"html",description:"gives you <div id=display>"}],tributary.time_controls=[{name:"play",description:"gives you a play button, and tributary.t. if you provide tributary.run(g,t) it will be executed in a run loop"},{name:"loop",description:"gives you a loop where tributary.t goes from 0 to 1."},{name:"restart",description:"assumes you only want tributary.init(g) to be run when the restart button is clicked"}],tributary.make_context=function(a){var b,c,d,e,f=a.config;if(a.model)c=a.model,g=c.get("filename"),e=c.get("type");else{var g,h;a.filename?g=a.filename:g="inlet.js",a.content?h=a.content:h="";var i=g.split(".");e=i[i.length-1],c=new tributary.CodeModel({name:i[0],filename:g,code:h})}return a.display?d=a.display:d=d3.select("#display"),c.set("type",e),mainfiles.indexOf(g)>=0?b=new tributary.TributaryContext({config:f,model:c,el:d.node()}):e==="json"?(c.set("mode","json"),b=new tributary.JSONContext({config:f,model:c})):e==="csv"?(c.set("mode","text"),b=new tributary.CSVContext({config:f,model:c})):e==="tsv"?(c.set("mode","text"),b=new tributary.TSVContext({config:f,model:c})):e==="js"?b=new tributary.JSContext({config:f,model:c}):e==="coffee"?(c.set("mode","coffeescript"),b=new tributary.CoffeeContext({config:f,model:c})):e==="css"?(c.set("mode","css"),b=new tributary.CSSContext({config:f,model:c})):e==="html"?(c.set("mode","text/html"),b=new tributary.HTMLContext({config:f,model:c,el:d.node()})):e==="svg"&&g!=="inlet.svg"&&(c.set("mode","text/html"),b=new tributary.SVGContext({config:f,model:c,el:d.node()})),b},d3.selection.prototype.moveToFront=function(){return this.each(function(){this.parentNode.appendChild(this)})},tributary.appendSVGFragment=function(a,b){var c="<svg xmlns=http://www.w3.org/2000/svg xmlns:xlink=http://www.w3.org/1999/xlink>",d="</svg>",e=document.createRange();e.selectNode(a);var f=e.createContextualFragment(c+b+d),g=f.childNodes[0].childNodes;for(var h=0,i=g.length;h<i;h++)a.appendChild(g[0])},Handlebars.getTemplate=function(a,b){(Handlebars.templates===undefined||Handlebars.templates[a]===undefined)&&$.ajax({url:"/static/templates/"+a+".handlebars",success:function(c){Handlebars.templates===undefined&&(Handlebars.templates={}),Handlebars.templates[a]=Handlebars.compile(c),b&&b(template)}})},tributary.CodeModel=Backbone.Model.extend({defaults:{code:"",filename:"inlet.js",name:"inlet",type:"js",mode:"javascript"},initialize:function(){this.binder()},binder:function(){this.on("error",this.handle_error)},handle_error:function(a){tributary.trace&&(console.trace(),console.log(a))},handle_coffee:function(){var a=this.get("code");return this.get("mode")==="coffeescript"&&(a=CoffeeScript.compile(a,{bare:!0})),a},local_storage:function(a){a||(a="");var b=this.get("filename")+"/code/"+a;return localStorage[b]},set_local_storage:function(a,b){var c=this.get("filename")+"/code/"+b;localStorage[c]=a}}),tributary.CodeModels=Backbone.Collection.extend({model:tributary.CodeModel}),tributary.Config=Backbone.Model.extend({defaults:{description:"Tributary inlet",endpoint:"tributary",display:"svg","public":!0,require:[],fileconfigs:{},play:!1,loop:!1,restart:!1,autoinit:!0,pause:!0,loop_type:"period",bv:!1,nclones:15,clone_opacity:.4,duration:3e3,ease:"linear",dt:.01},require:function(a){var b=this.get("require"),c=_.pluck(b,"url"),d=function(){return a(null,arguments)};require(c,d)},initialize:function(){this.on("hide",function(){this.contexts.forEach(function(a){a.model.trigger("hide")})},this)}}),tributary.ConfigView=Backbone.View.extend({initialize:function(){},render:function(){function j(){var b={name:h.node().value,url:i.node().value},c=a.model.get("require");c.push(b),a.model.require(function(a,b){}),a.model.set("require",c),l(f.selectAll("li.lib").data(c).enter())}function l(b){var c=b.append("li").classed("lib",!0);c.append("input").attr("type","checkbox").attr("checked",!0).on("change",function(b){var c=a.model.get("require"),d=c.indexOf(b);d>=0?(c.splice(d,1),a.model.set("require",c)):(c.push(b),a.model.set("require",c))}),c.append("span").text(function(a){return a.name})}var a=this,b=d3.select(this.el).select("#config-content select").on("change",function(){var b=this.selectedOptions[0].value;a.model.set("display",b),tributary.events.trigger("execute")}),c=this.model.get("display");b.selectAll("option").each(function(a,d){this.value===c&&(b.node().value=this.value)});var d=d3.select("#timecontrols").selectAll("button");d.datum(function(){return this.dataset}),d.filter(function(b){return a.model.get(b.name)}).classed("active",!0),d.on("click",function(b){var c=!a.model.get(b.name);d3.select(this).classed("active",c),a.model.set(b.name,c)});var e=d3.select(this.el).select("#logerrors").on("click",function(a){var b=d3.select(this);$(this).attr("data-name")==="log-errors"&&(b.classed("active")?(console.log("Error logging disabled"),tributary.hint=!1,tributary.trace=!1,tributary.events.trigger("execute"),b.classed("active",!1)):(console.log("Error logging initiated"),tributary.hint=!0,tributary.trace=!0,tributary.events.trigger("execute"),b.classed("active",!0)))}),f=d3.select(this.el).select("#library-checklist"),g=d3.select(this.el).select("#library-links"),h=g.select("input.library-title"),i=g.select("input.library-url"),k=g.select(".add-library").on("click",j);h.on("keypress",function(){d3.event.charCode===13&&j()}),i.on("keypress",function(){d3.event.charCode===13&&j()});var m=f.selectAll("li.lib").data(this.model.get("require")).enter();l(m)}}),tributary.Context=Backbone.View.extend({initialize:function(){},execute:function(){},render:function(){}}),tributary.TributaryContext=tributary.Context.extend({initialize:function(){this.model.on("change:code",function(){tributary.events.trigger("execute")}),tributary.events.on("execute",this.execute,this),tributary.__config__||(tributary.__config__=this.options.config),this.model.on("change:code",function(){window.onbeforeunload||$(window).on("beforeunload",function(){return"Are you sure you want to leave?"})},this),this.config=this.options.config,this.config.on("change:display",this.set_display,this);var a=this.config;tributary.init=undefined,tributary.run=undefined,tributary.loop=a.get("loop"),tributary.autoinit=a.get("autoinit"),tributary.pause=a.get("pause"),tributary.loop_type=a.get("loop_type"),tributary.bv=a.get("bv"),tributary.nclones=a.get("nclones"),tributary.clone_opacity=a.get("clone_opacity"),tributary.duration=a.get("duration"),tributary.ease=d3.ease(a.get("ease")),tributary.t=0,tributary.dt=a.get("dt"),tributary.reverse=!1,tributary.useThreejsControls=!0,tributary.render=function(){},tributary.execute=function(){if(tributary.run!==undefined){var a=tributary.t;tributary.loop&&(a=tributary.ease(tributary.t)),tributary.run(tributary.g,a,0)}},tributary.timer={then:new Date,duration:tributary.duration,ctime:tributary.t},d3.timer(function(){tributary.render();if(tributary.pause)return!1;var b=new Date,c=b-tributary.timer.then,d;if(tributary.loop){tributary.reverse?d=tributary.timer.ctime*c/tributary.timer.duration*-1:d=(1-tributary.timer.ctime)*c/tributary.timer.duration,tributary.t=tributary.timer.ctime+d;if(tributary.t>=1||tributary.t<=0||tributary.t==="NaN")tributary.loop_type==="period"?(tributary.t=0,tributary.timer.then=new Date,tributary.timer.duration=tributary.duration,tributary.timer.ctime=tributary.t,tributary.reverse=!1):tributary.loop_type==="pingpong"?(tributary.t=!tributary.reverse,tributary.timer.then=new Date,tributary.timer.duration=tributary.duration,tributary.timer.ctime=tributary.t,tributary.reverse=!tributary.reverse):tributary.t!==0&&(tributary.t=1,tributary.pause=!0);tributary.t===!0&&(tributary.t=1),tributary.t===!1&&(tributary.t=0)}else tributary.t+=tributary.dt;tributary.execute(),a.trigger("tick",tributary.t)})},execute:function(){var a=this.model.handle_coffee();if(a.length>0&&this.model.get("type")!=="coffee"){var b=JSHINT(a,{asi:!0,laxcomma:!0,laxbreak:!0,loopfunc:!0,smarttabs:!0,sub:!0});b?this.model.trigger("nojshint"):this.model.trigger("jshint",JSHINT.errors)}try{tributary.initialize=new Function("g","tributary",a)}catch(c){return this.model.trigger("error",c),!1}try{window.trib={},window.trib_options={},trib=window.trib,trib_options=window.trib_options,tributary.autoinit&&(tributary.clear(),tributary.events.trigger("prerender")),this.clones&&$(this.clones.node()).empty(),tributary.bv&&this.make_clones(),tributary.initialize(tributary.g,tributary),tributary.autoinit&&tributary.init!==undefined&&tributary.init(tributary.g,0),tributary.execute()}catch(d){return this.model.trigger("error",d),!1}return this.model.trigger("noerror"),!0},render:function(){this.set_display()},set_display:function(){var a=this;this.$el.empty();var b=this.config.get("display");b==="svg"?this.make_svg():b==="canvas"?this.make_canvas():b==="webgl"?this.make_webgl():b==="div"?(this.g=d3.select(this.el),tributary.g=this.g,tributary.clear=function(){a.$el.empty()}):tributary.clear=function(){a.$el.empty()}},make_svg:function(){this.svg=d3.select(this.el).append("svg").attr({xmlns:"http://www.w3.org/2000/svg",xlink:"http://www.w3.org/1999/xlink","class":"tributary_svg"}),tributary.g=this.svg,tributary.clear=function(){$(tributary.g.node()).empty()}},make_canvas:function(){tributary.clear=function(){tributary.canvas.width=tributary.sw,tributary.canvas.height=tributary.sh,tributary.ctx.clearRect(0,0,tributary.sw,tributary.sh)},tributary.canvas=d3.select(this.el).append("canvas").classed("tributary_canvas",!0).node(),tributary.ctx=tributary.canvas.getContext("2d"),tributary.g=tributary.ctx},make_clones:function(){this.clones=this.svg.selectAll("g.clones").data([0]),this.clones.enter().append("g").attr("class","clones"),tributary.g=this.svg.selectAll("g.delta").data([0]),tributary.g.enter().append("g").attr("class","delta");var a=d3.range(tributary.nclones),b=this.clones.selectAll("g.bvclone").data(a).enter().append("g").attr("class","bvclone").style("opacity",tributary.clone_opacity);b.each(function(a,b){var c=b+1,d=d3.select(this);tributary.init(d,c);var e=tributary.ease(c/(tributary.nclones+1));tributary.run(d,e,c)})},make_webgl:function(){function b(){windowHalfX=tributary.sw/2,windowHalfY=tributary.sh/2,tributary.camera.aspect=tributary.sw/tributary.sh,tributary.camera.updateProjectionMatrix(),tributary.renderer.setSize(tributary.sw,tributary.sh)}container=this.el,tributary.camera=new THREE.PerspectiveCamera(70,tributary.sw/tributary.sh,1,1e3),tributary.camera.position.y=150,tributary.camera.position.z=500,tributary.scene=new THREE.Scene,THREE.Object3D.prototype.clear=function(){var a=this.children,b;for(b=a.length-1;b>=0;b--){var c=a[b];c.clear(),this.remove(c)}},tributary.renderer=new THREE.WebGLRenderer,tributary.renderer.setSize(tributary.sw,tributary.sh),container.appendChild(tributary.renderer.domElement);var a=new THREE.TrackballControls(tributary.camera);a.target.set(0,0,0),a.rotateSpeed=1,a.zoomSpeed=1.2,a.panSpeed=.8,a.noZoom=!1,a.noPan=!1,a.staticMoving=!1,a.dynamicDampingFactor=.15,tributary.controls=a,tributary.render=function(){tributary.useThreejsControls&&tributary.controls.update(),tributary.renderer.render(tributary.scene,tributary.camera)},tributary.render(),tributary.events.on("resize",b,!1),tributary.clear=function(){tributary.scene.clear()}}}),tributary.JSONContext=tributary.Context.extend({initialize:function(){this.model.on("change:code",this.execute,this),this.model.on("change:code",function(){tributary.events.trigger("execute")})},execute:function(){try{var a=JSON.parse(this.model.get("code"));tributary[this.model.get("name")]=a}catch(b){return this.model.trigger("error",b),!1}return this.model.trigger("noerror"),!0},render:function(){}}),tributary.JSContext=tributary.Context.extend({initialize:function(){this.model.on("change:code",this.execute,this),this.model.on("change:code",function(){tributary.events.trigger("execute")})},execute:function(){var js=this.model.get("code");if(js.length>0){var hints=JSHINT(js,{asi:!0,laxcomma:!0,laxbreak:!0,loopfunc:!0,smarttabs:!0,sub:!0});hints?this.model.trigger("nojshint"):this.model.trigger("jshint",JSHINT.errors)}try{eval(js)}catch(e){return this.model.trigger("error",e),!1}return this.model.trigger("noerror"),!0},render:function(){}}),tributary.CoffeeContext=tributary.Context.extend({initialize:function(){this.model.on("change:code",this.execute,this),this.model.on("change:code",function(){tributary.events.trigger("execute")})},execute:function(){var js=this.model.handle_coffee();try{eval(js)}catch(e){return this.model.trigger("error",e),!1}return this.model.trigger("noerror"),!0},render:function(){}}),tributary.CSVContext=tributary.Context.extend({initialize:function(){this.model.on("change:code",this.execute,this),this.model.on("change:code",function(){tributary.events.trigger("execute")})},execute:function(){try{var a=d3.csv.parse(this.model.get("code"));tributary[this.model.get("name")]=a}catch(b){return this.model.trigger("error",b),!1}return this.model.trigger("noerror"),!0},render:function(){}}),tributary.TSVContext=tributary.Context.extend({initialize:function(){this.model.on("change:code",this.execute,this),this.model.on("change:code",function(){tributary.events.trigger("execute")})},execute:function(){try{var a=d3.tsv.parse(this.model.get("code"));tributary[this.model.get("name")]=a}catch(b){return this.model.trigger("error",b),!1}return this.model.trigger("noerror"),!0},render:function(){}}),tributary.CSSContext=tributary.Context.extend({initialize:function(){this.model.on("change:code",this.execute,this),this.model.on("change:code",function(){tributary.events.trigger("execute")}),this.model.on("delete",function(){d3.select(this.el).remove()},this)},execute:function(){try{this.el.textContent=this.model.get("code")}catch(a){return this.model.trigger("error",a),!1}return this.model.trigger("noerror"),!0},render:function(){this.el=d3.select("head").selectAll("style.csscontext").data([this.model],function(a){return a.cid}).enter().append("style").classed("csscontext",!0).attr({type:"text/css"}).node()}}),tributary.HTMLContext=tributary.Context.extend({initialize:function(){this.model.on("change:code",function(){tributary.events.trigger("execute")}),tributary.events.on("prerender",this.execute,this)},execute:function(){try{$(this.el).append(this.model.get("code"))}catch(a){return this.model.trigger("error",a),!1}return this.model.trigger("noerror"),!0},render:function(){}}),tributary.SVGContext=tributary.Context.extend({initialize:function(){this.model.on("change:code",function(){tributary.events.trigger("execute")}),tributary.events.on("prerender",this.execute,this)},execute:function(){try{var a=d3.select(this.el).select("svg").node();tributary.appendSVGFragment(a,this.model.get("code"))}catch(b){return this.model.trigger("error",b),!1}return this.model.trigger("noerror"),!0},render:function(){}}),tributary.make_editor=function(a){var b=a.parent||tributary.edit,c=a.model;a.container?container=a.container:container=b.append("div").attr("id",c.cid);var d;return d=new tributary.Editor({el:container.node(),model:c}),d.render(),d},tributary.Editor=Backbone.View.extend({initialize:function(){this.model.on("show",function(){d3.select(this.el).style("display","")},this),this.model.on("hide",function(){d3.select(this.el).style("display","none")},this),this.model.on("delete",function(){this.$el.remove()},this)},getConfig:function(){var a=tributary.__config__.get("fileconfigs"),b=a[this.model.get("filename")];return b?b:this.defaultConfig()},setConfig:function(a,b){var c=tributary.__config__.get("fileconfigs"),d=c[this.model.get("filename")];d[a]=b;var c=tributary.__config__.set("fileconfigs",c)},defaultConfig:function(){var a=tributary.__config__.get("fileconfigs"),b={"default":!0,vim:!1,emacs:!1,fontSize:12};a[this.model.get("filename")]=b;var a=tributary.__config__.set("fileconfigs",a);return b},render:function(){var a=this,b=d3.select(this.el).classed("editor",!0),c=Handlebars.templates.editor,d=c(this.getConfig());this.$el.html(d),filetype=a.model.get("filename").split(".")[1];if(filetype=="js")var e="lesser-dark";else if(filetype=="svg")var e="vibrant-ink";else if(filetype=="html")var e="ambiance";else if(filetype=="coffee")var e="elegant";else if(filetype=="css")var e="elegant";else var e="lesser-dark";var f={mode:a.model.get("mode"),theme:e,lineNumbers:!0};a.model.get("mode")==="json"&&(f.mode="javascript",f.json=!0),this.cm=CodeMirror(this.el,f),this.cm.on("change",function(){var b=a.cm.getValue();a.model.set("code",b)}),this.cm.setValue(this.model.get("code")),this.inlet=Inlet(this.cm),this.model.on("error",function(){d3.select(a.el).select(".CodeMirror-gutter").classed("error",!0)}),this.model.on("noerror",function(){d3.select(a.el).select(".CodeMirror-gutter").classed("error",!1)});var g=b.select(".toolbar"),h=b.select(".settings").on("click",function(){g.classed("hidden",!g.classed("hidden")),h.classed("active-settings",!g.classed("hidden"))});g.selectAll(".radio").on("change",function(){a.setConfig("default",!1),a.setConfig("vim",!1),a.setConfig("emacs",!1),a.setConfig(this.value,!0),a.cm.setOption("keyMap",this.value)}),g.select(".plusFontSize").on("click",function(){var b=a.getConfig(),c=b.fontSize+1;a.setConfig("fontSize",c);var d=a.cm.getWrapperElement();d3.select(d).select(".CodeMirror-scroll").style({"font-size":c+"px","line-height":c+"px"}),a.cm.refresh()}),g.select(".minusFontSize").on("click",function(){var b=a.getConfig(),c=b.fontSize-1;a.setConfig("fontSize",c);var d=a.cm.getWrapperElement();d3.select(d).select(".CodeMirror-scroll").style({"font-size":c+"px","line-height":c+"px"}),a.cm.refresh()});var i=a.getConfig(),j=i.fontSize,k=a.cm.getWrapperElement();d3.select(k).select(".CodeMirror-scroll").style({"font-size":j+"px","line-height":j+"px"}),a.cm.refresh()}}),tributary.gist=function(a,b){function f(a){c.gist=a,a.user===null||a.user===undefined?c.user={login:"anon",url:"",userid:-1}:c.user=a.user;var d;try{d=a.files["config.json"]}catch(e){d=!1}if(d)try{c.config=new tributary.Config(JSON.parse(d.content))}catch(f){c.config=new tributary.Config}else c.config=new tributary.Config;var g=_.keys(a.files);fileconfigs=c.config.get("fileconfigs")||{},c.models=new tributary.CodeModels;var h,i,j,k=0,l;g.forEach(function(b){h=b.split("."),l=h[h.length-1],b!=="config.json"&&(i=new tributary.CodeModel({filename:b,name:h[0],code:a.files[b].content,type:l}),c.models.add(i)),fileconfigs[b]||(fileconfigs[b]={"default":!0,vim:!1,emacs:!1,fontSize:12})}),c.config.set("fileconfigs",fileconfigs),c.config.require(function(a,d){b(null,c)})}tributary.gistid=a;var c={},d="?cachebust="+Math.random()*0xf12765df4c9b2,e="https://api.github.com/gists/"+a+d;$.ajax({url:e,contentType:"application/json",dataType:"json",success:f,error:function(b){console.log(b),e="/gist/"+a+d,$.ajax({url:e,contentType:"application/json",dataType:"json",success:f,error:function(a){console.log(a)}})}})},tributary.save_gist=function(a,b,c){var d=tributary.gistid||"",e={description:a.get("description"),"public":a.get("public"),files:{}};a.contexts.forEach(function(a){e.files[a.model.get("filename")]={content:a.model.get("code")}}),a.todelete&&a.todelete.forEach(function(a){e.files[a]=null}),e.files["config.json"]={content:JSON.stringify(a.toJSON())};var f;b==="fork"?f="/tributary/fork":f="/tributary/save",d.length>4&&(f+="/"+d);var g=this;$.post(f,{gist:JSON.stringify(e)},function(a){typeof a=="string"&&(a=JSON.parse(a));var b=a.id,d="/inlet/"+b;c(d,b)})},tributary.login_gist=function(a,b){a?url="/github-logout":url="/github-login",url+="/inlet",tributary.gistid&&(url+="/"+tributary.gistid),b(url)},tributary.FilesView=Backbone.View.extend({initialize:function(){},render:function(){var a=this,b=Handlebars.templates.files,c=_.map(tributary.__config__.contexts,function(a){return a.model.toJSON()});c=c.sort(function(a,b){return a.filename<b.filename?-1:1});var d=_.find(c,function(a){return a.filename==="inlet.js"||a.filename==="inlet.coffee"});d&&(c.splice(c.indexOf(d),1),c.unshift(d)),$(this.el).html(b({contexts:c}));var e=d3.select("#file-list").selectAll("li.file");e.on("click",function(b){var c=this.dataset.filename;if(a.model){var d=_.find(tributary.__config__.contexts,function(a){return a.model.get("filename")===c});a.model.trigger("hide"),d.model.trigger("show")}}),e.select(".delete-file").style("z-index",1e3).on("click",function(){var b=this.parentNode.dataset,c=b.filename,d=b.filename.split(".")[0];delete a.model,tributary.__config__.unset(c);var e=_.find(tributary.__config__.contexts,function(a){return a.model.get("filename")===c});e.model.trigger("delete");var f=tributary.__config__.contexts.indexOf(e);tributary.__config__.contexts.splice(f,1),delete e,tributary.__config__.todelete||(tributary.__config__.todelete=[]),tributary.__config__.todelete.push(c),d3.select(a.el).selectAll("li.file").each(function(){this.dataset.filename===c&&$(this).remove()});var g=tributary.__config__.contexts[0].model;g.trigger("show"),d3.event.stopPropagation()});var f=d3.select(this.el).select(".add-file").on("click",function(){console.log("SUP");var b=d3.select(this).select("input").style("display","inline-block");b.node().focus(),b.on("keypress",function(){if(d3.event.charCode===13){var c=tributary.make_context({filename:b.node().value,config:tributary.__config__});if(c){tributary.__config__.contexts.push(c),c.render(),c.execute();var d=tributary.make_editor({model:c.model});a.$el.empty(),a.render(),tributary.__config__.contexts.forEach(function(a){a.model.trigger("hide")}),c.model.trigger("show"),d.cm.focus()}else b.classed("error",!0)}})})}}),tributary.FileView=Backbone.View.extend({render:function(){}}),tributary.ControlsView=Backbone.View.extend({initialize:function(){this.model.on("change:play",this.play_button,this),this.model.on("change:loop",this.time_slider,this),this.model.on("change:restart",this.restart_button,this)},render:function(){var a=d3.select(this.el);a.append("div").attr("id","time_controls"),a.append("div").attr("id","user_controls"),a.append("div").attr("id","time_options"),this.play_button(),this.time_slider(),this.restart_button()},play_button:function(){var a=d3.select(this.el).select("#time_controls");if(this.model.get("play")){var b=a.append("button").classed("play",!0).classed("button_on",!0).text("Play");b.on("click",function(a){tributary.pause?tributary.pause&&(b.classed("playing",!0),b.text("Pause")):(b.classed("playing",!1),b.text("Play"));if(tributary.t<1||!tributary.loop)tributary.pause=!tributary.pause,tributary.pause||(tributary.timer.then=new Date,tributary.timer.duration=(1-tributary.t)*tributary.duration,tributary.timer.ctime=tributary.t)})}else a.select("button.play").remove()},time_slider:function(){tributary.loop=this.model.get("loop");var a=d3.select(this.el).select("#time_controls");if(tributary.loop){var b=a.append("input").attr({type:"range",min:0,max:1,step:.01,value:0,name:"time"}).classed("time_slider",!0);$(b.node()).on("change",function(){tributary.t=parseFloat(this.value),tributary.pause&&tributary.execute()}),this.model.on("tick",function(a){$(b.node()).attr("value",tributary.t)});if(this.model.get("display")==="svg"){var c=a.append("button").classed("bv",!0).classed("button_on",!0).text("BV");c.on("click",function(){tributary.bv=!tributary.bv,tributary.events.trigger("execute")})}}else tributary.bv=!1,a.select("input.time_slider").remove(),a.select("button.bv").remove()},restart_button:function(){var a=this,b=d3.select(this.el).select("#time_controls");if(this.model.get("restart")){tributary.autoinit=!1;var c=b.append("button").classed("restart",!0).classed("button_on",!0).text("Restart");c.on("click",function(a){tributary.clear(),tributary.initialize(tributary.g,tributary),tributary.init(tributary.g),tributary.execute()})}else tributary.autoinit=!0,b.select("button.restart").remove()}}),tributary.batch={},tributary.batch._execute=function(){var a=_.functions(this);_.each(a,function(a){a!=="_execute"&&tributary.batch[a]()})},tributary.ui={};var display,panel_gui,panel,panel_handle,page,header;return tributary.ui.setup=function(){tributary.events.on("resize",function(){$("#display").width()>767?tributary.sw=$("#display").width()-$("#panel").width():tributary.sw=$("#display").width(),$("#container").hasClass("fullscreen")&&(console.log("Fullscreen"),tributary.sw=$("#display").width()),tributary.sh=$("#display").height(),tributary.events.trigger("execute")}),tributary.events.trigger("resize")},tributary.ui.assemble=function(a){tributary.trace=!1,tributary.hint=!1;if(a.length>0)tributary.gist(a,_assemble);else{var b={};b.config=new tributary.Config,b.models=new tributary.CodeModels(new tributary.CodeModel),_assemble(b)}},tributary};
Please sign in to comment.
Something went wrong with that request. Please try again.