Skip to content

Instantly share code, notes, and snippets.

@dannyko
Last active September 17, 2015 09:16
Show Gist options
  • Save dannyko/ca8cc0fc1df5d7282cb5 to your computer and use it in GitHub Desktop.
Save dannyko/ca8cc0fc1df5d7282cb5 to your computer and use it in GitHub Desktop.
vizflow demo

vizflow demo - three circles

vizflow.js is an application-agnostic interactive visualization engine written using EcmaScript.6 (ES6) with no other external dependencies.

It provides a lightweight interactive visualization engine with smaller footprints than other visualization libraries like D3js.

This vizflow demo contained in index.html shows an interactive stochastic dynamics simulation with 3 frictionless, non-interacting particles in a rectangular domain with inelastic boundaries.

Also viewable as block for remote demoing.

The particles are rendered as colored circles.

Clicking on any of the circles will randomly change their 2D position by sampling from a uniform distribution.

"format register";!function(e){function t(e){for(var t=[],r=0,n=e.length;n>r;r++)-1==d.call(t,e[r])&&t.push(e[r]);return t}function r(e,r,n,i){if("string"!=typeof e)throw"System.register provided no module name";var u;u="boolean"==typeof n?{declarative:!1,deps:r,execute:i,executingRequire:n}:{declarative:!0,deps:r,declare:n},u.name=e,l[e]||(l[e]=u),u.deps=t(u.deps),u.normalizedDeps=u.deps}function n(e,t){if(t[e.groupIndex]=t[e.groupIndex]||[],-1==d.call(t[e.groupIndex],e)){t[e.groupIndex].push(e);for(var r=0,i=e.normalizedDeps.length;i>r;r++){var u=e.normalizedDeps[r],o=l[u];if(o&&!o.evaluated){var s=e.groupIndex+(o.declarative!=e.declarative);if(void 0===o.groupIndex||o.groupIndex<s){if(void 0!==o.groupIndex&&(t[o.groupIndex].splice(d.call(t[o.groupIndex],o),1),0==t[o.groupIndex].length))throw new TypeError("Mixed dependency cycle detected");o.groupIndex=s}n(o,t)}}}}function i(e){var t=l[e];t.groupIndex=0;var r=[];n(t,r);for(var i=!!t.declarative==r.length%2,u=r.length-1;u>=0;u--){for(var s=r[u],c=0;c<s.length;c++){var f=s[c];i?o(f):a(f)}i=!i}}function u(e){return p[e]||(p[e]={name:e,dependencies:[],exports:{},importers:[]})}function o(t){if(!t.module){var r=t.module=u(t.name),n=t.module.exports,i=t.declare.call(e,function(e,t){r.locked=!0,n[e]=t;for(var i=0,u=r.importers.length;u>i;i++){var o=r.importers[i];if(!o.locked){var s=d.call(o.dependencies,r);o.setters[s](n)}}return r.locked=!1,t});if(r.setters=i.setters,r.execute=i.execute,!r.setters||!r.execute)throw new TypeError("Invalid System.register form for "+t.name);for(var s=0,a=t.normalizedDeps.length;a>s;s++){var c,m=t.normalizedDeps[s],v=l[m],g=p[m];g?c=g.exports:v&&!v.declarative?c={"default":v.module.exports,__useDefault:!0}:v?(o(v),g=v.module,c=g.exports):c=f(m),g&&g.importers?(g.importers.push(r),r.dependencies.push(g)):r.dependencies.push(null),r.setters[s]&&r.setters[s](c)}}}function s(e){var t,r=l[e];if(r)r.declarative?c(e,[]):r.evaluated||a(r),t=r.module.exports;else if(t=f(e),!t)throw new Error("Unable to load dependency "+e+".");return(!r||r.declarative)&&t&&t.__useDefault?t["default"]:t}function a(t){if(!t.module){var r={},n=t.module={exports:r,id:t.name};if(!t.executingRequire)for(var i=0,u=t.normalizedDeps.length;u>i;i++){var o=t.normalizedDeps[i],c=l[o];c&&a(c)}t.evaluated=!0;var f=t.execute.call(e,function(e){for(var r=0,n=t.deps.length;n>r;r++)if(t.deps[r]==e)return s(t.normalizedDeps[r]);throw new TypeError("Module "+e+" not declared as a dependency.")},r,n);f&&(n.exports=f)}}function c(t,r){var n=l[t];if(!n.evaluated&&n.declarative){r.push(t);for(var i=0,u=n.normalizedDeps.length;u>i;i++){var o=n.normalizedDeps[i];-1==d.call(r,o)&&(l[o]?c(o,r):f(o))}n.evaluated||(n.evaluated=!0,n.module.execute.call(e))}}function f(e){if(m[e])return m[e];var t=l[e];if(!t)throw"Module "+e+" not present.";i(e),c(e,[]),l[e]=void 0;var r=t.declarative?t.module.exports:{"default":t.module.exports,__useDefault:!0};return m[e]=r}var l={},d=Array.prototype.indexOf||function(e){for(var t=0,r=this.length;r>t;t++)if(this[t]===e)return t;return-1},p={},m={};return function(t,n){var i;"undefined"!=typeof i&&i.register?(n(i),i["import"](t)):(n(i={register:r,get:f,set:function(e,t){m[e]=t},newModule:function(e){return e},global:e}),i.set("@empty",i.newModule({})),f(t))}}("undefined"!=typeof window?window:global)("src/vizflow",function(e){e.register("src/step",[],function(e){function t(){$Z.sim=$Z.pipe($Z.task)}function r(){$Z.iter++,window.requestAnimationFrame(t)}return e("default",r),{setters:[],execute:function(){"use strict"}}}),e.register("src/item",[],function(e){function t(){for(var e=arguments.length,t=Array(e),r=0;e>r;r++)t[r]=arguments[r];return 0==t.length?$Z._item:($Z._item=t[0],$Z)}return e("default",t),{setters:[],execute:function(){"use strict"}}}),e.register("src/pipe",[],function(e){function t(e){for(var t=Promise.resolve(),r=0;r<e.length;r++)t=t.then(e[r]);return t}return e("default",t),{setters:[],execute:function(){"use strict"}}}),e.register("src/done",[],function(e){function t(){return 0==$Z._item.length||$Z.iter>$Z.maxIter?!0:!1}return e("default",t),{setters:[],execute:function(){"use strict"}}}),e.register("src/exit",[],function(e){function t(){return!1}return e("default",t),{setters:[],execute:function(){"use strict"}}}),e.register("src/run",[],function(e){function t(){$Z.sim=$Z.pipe($Z.task)}return e("default",t),{setters:[],execute:function(){"use strict"}}}),e.register("src/update",[],function(e){function t(){var e=this,t=[],r=[];if(void 0!==e.transition){for(var n=0;n<e.transition.length;n++){var i=e.transition[n],u=0;void 0===i.startTime?i.startTime=Date.now():u=Date.now()-i.startTime;var o=i.duration-u;if(0==u)i.startValue=e[i.varName];else if(o>0){var s=1-o/i.duration;e[i.varName]=i.interpFunc(s)}else e[i.varName]=i.endValue,t.push(n),void 0!==i.child&&r.push(i.child)}for(var a=t.length-1;a>=0;a--)e.transition.splice(t[a],1);for(var c=0;c<r.length;c++)e.transition.push(r[c])}}return e("default",t),{setters:[],execute:function(){"use strict"}}}),e.register("src/transition",[],function(e){var t;return{setters:[],execute:function(){"use strict";t={linear_interp:function(e){return(1-e)*this.startValue+e*this.endValue},color_interp:function(e){var t=this.startValue,r=this.endValue;t=t.slice(1),r=r.slice(1),3===t.length&&(t=t.replace(/([0-9a-f])/gi,"$1$1")),3===r.length&&(r=r.replace(/([0-9a-f])/gi,"$1$1"));for(var n="#",i=0;3>i;i++){var u=parseInt(t.slice(2*i,2*(i+1)),16),o=parseInt(r.slice(2*i,2*(i+1)),16),s=Math.round((1-e)*u+e*o);s=s.toString(16).toUpperCase(),1===s.length&&(s+=s),n+=s}return n},linear_transition_func:function(e,t){return function(r){return{varName:e,duration:t,endValue:r,interpFunc:$Z.transition.linear_interp}}},color_transition_func:function(e,t){return function(r){return{varName:e,duration:t,endValue:r,interpFunc:$Z.transition.color_interp}}}},e("default",t)}}}),e.register("src/acquire_input",[],function(e){function t(){var e=this;return new Promise(function(t){t(e.name)})}return e("default",t),{setters:[],execute:function(){"use strict"}}}),e.register("src/update_items",[],function(e){function t(){return Promise.all($Z.item().map(function(e){return e.update?e.update():$Z.update.call(e)}))}return e("default",t),{setters:[],execute:function(){"use strict"}}}),e.register("src/detect_actions",[],function(e){function t(){var e=this;return new Promise(function(t){t(e.name)})}return e("default",t),{setters:[],execute:function(){"use strict"}}}),e.register("src/perform_actions",[],function(e){function t(){return Promise.resolve()}return e("default",t),{setters:[],execute:function(){"use strict"}}}),e.register("src/render_image",[],function(e){function t(){return Promise.all($Z.item().map(function(e){return e.render()}))}return e("default",t),{setters:[],execute:function(){"use strict"}}}),e.register("src/step_or_exit",[],function(e){function t(){return $Z.done()?($Z.exit(),Promise.resolve(!0)):($Z.step(),Promise.resolve(!1))}return e("default",t),{setters:[],execute:function(){"use strict"}}}),e.register("src/vizflow",["src/step","src/item","src/pipe","src/done","src/exit","src/run","src/update","src/transition","src/acquire_input","src/update_items","src/detect_actions","src/perform_actions","src/render_image","src/step_or_exit"],function(e){var t,r,n,i,u,o,s,a,c,f,l,d,p,m,v,g,x,h,_;return{setters:[function(e){t=e["default"]},function(e){r=e["default"]},function(e){n=e["default"]},function(e){i=e["default"]},function(e){u=e["default"]},function(e){o=e["default"]},function(e){s=e["default"]},function(e){a=e["default"]},function(e){c=e["default"]},function(e){f=e["default"]},function(e){l=e["default"]},function(e){d=e["default"]},function(e){p=e["default"]},function(e){m=e["default"]}],execute:function(){"use strict";v=[],g=0,x=!1,h=1/0,_=[c,f,l,d,p,m],window.$Z={verbose:x,iter:g,maxIter:h,transition:a,_item:v,item:r,update:s,pipe:n,step:t,done:i,exit:u,task:_,run:o},e("default",{})}}})});
//# sourceMappingURL=build.js.map
{"version":3,"file":"build.js","sources":["src/step.js","src/item.js","src/pipe.js","src/done.js","src/exit.js","src/run.js","src/update.js","src/transition.js","src/acquire_input.js","src/update_items.js","src/detect_actions.js","src/perform_actions.js","src/render_image.js","src/step_or_exit.js","src/vizflow.js"],"names":["run","$Z","sim","pipe","task","step","iter","window","requestAnimationFrame","item","args","Array","_len","_key","arguments","length","_item","prom","Promise","resolve","i","then","done","maxIter","exit","update","el","this","removeList","children","undefined","transition","kt","trans","elapsedTime","startTime","Date","now","remainingTime","duration","startValue","varName","normalizedTime","interpFunc","endValue","push","child","kr","splice","kc","linear_interp","t","color_interp","color1","color2","slice","replace","color","split1","parseInt","split2","split","Math","round","toString","toUpperCase","linear_transition_func","color_transition_func","acquire_input","_this","name","update_items","all","map","d","call","detect_actions","perform_actions","render_image","render","step_or_exit","verbose","_srcStep","_srcItem","_srcPipe","_srcDone","_srcExit","_srcRun","_srcUpdate","_srcTransition","_srcAcquire_input","_srcUpdate_items","_srcDetect_actions","_srcPerform_actions","_srcRender_image","_srcStep_or_exit"],"mappings":"ozGAAA,QAASA,KAERC,GAAGC,IAAMD,GAAGE,KAAKF,GAAGG,MAGN,QAASC,KACvBJ,GAAGK,OACFC,OAAOC,sBAAsBR,sBAFPK,wFCLT,QAASI,gCAAQC,EAAIC,MAAAC,GAAAC,EAAA,EAAAD,EAAAC,EAAAA,IAAJH,EAAIG,GAAAC,UAAAD,EAClC,OAAkB,IAAfH,EAAKK,OACCd,GAAGe,OAEXf,GAAGe,MAAQN,EAAK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M;AACN,YAAI,EAAJ,IAAI;AACJ,YAAI,EAAJ,IAAI;AACJ,YAAI,EAAJ,IAAI;AACJ,YAAI,EAAJ,IAAI;AACJ,YAAI,EAAJ,IAAI;AACJ,WAAG,EAAH,GAAG;AAAA,OACH,CAAE;;yBAEY,EAAE"}
<!doctype html5>
<html>
<head>
<style>
body { margin: 0; }
</style>
</head>
<body>
<script type="text/javascript" src="build.js"></script>
<script type="text/javascript" src="three_circles.js"></script>
<script>
three_circles() ;
</script>
</body>
</html>
// three colored circles with SVG rendering, a simple demo of vizflow's transition features
function three_circles() {
var width = 40 ;
var height = 20 ;
var svgns = "http://www.w3.org/2000/svg" ;
var svg = document.createElementNS(svgns, 'svg') ;
svg.setAttribute( 'viewBox', '0 0 ' + 2 * width + ' ' + 2 * height) ;
document.body.appendChild(svg) ;
var g = document.createElementNS(svgns, 'g') ;
g.setAttribute('transform', 'translate(' + width + ',' + height + ')' ) ;
svg.appendChild(g) ;
function render() {
this.viz.setAttribute( 'cx', this.x ) ;
this.viz.setAttribute( 'cy', this.y ) ;
this.viz.setAttribute( 'fill', this.color ) ;
this.viz.setAttribute( 'r', this.radius ) ;
}
function random_color() {
var r = Math.round( 255 * Math.random() ).toString( 16 ) ;
var g = Math.round( 255 * Math.random() ).toString( 16 ) ;
var b = Math.round( 255 * Math.random() ).toString( 16 ) ;
// make sure they are the right length
if ( r.length === 1 ) r += r ;
if ( g.length === 1 ) g += g ;
if ( b.length === 1 ) b += b ;
return '#' + r + g + b ;
}
var dur = 500 ; // transition duration in milliseconds
var x_transition = $Z.transition.linear_transition_func ( 'x', dur ) ; // function accepting an x end-value and returning a transition object
var y_transition = $Z.transition.linear_transition_func ( 'y', dur ) ; // function accepting a y end-value and returning a transition object
var r_transition = $Z.transition.linear_transition_func ( 'radius', dur ) ; // function accepting a y end-value and returning a transition object
var c_transition = $Z.transition.color_transition_func ( 'color', dur ) ; // function accepting a color end-value and returning a transition object
var red = '#993333' ;
var green = '#339933' ;
var blue = '#333399' ;
var data = [ // array of object literals defining the three circles
{ x: -10, y: 0, radius: 2, color: red, color0: red },
{ x: 10, y: 0, radius: 2, color: green, color0: green },
{ x: 0, y: -10, radius: 2, color: blue, color0: blue }
] ;
data.forEach(function (d) {
d.render = render ; // function that tells the visulization engine how to render the items for each frame of the visualization
d.viz = document.createElementNS(svgns, 'circle') ;
d.viz['__d__'] = d ; // bind the data to the viz element for efficient access
d.viz.onclick = click ;
d.viz.setAttribute( 'cx', d.x ) ;
d.viz.setAttribute( 'cy', d.y ) ;
d.viz.setAttribute( 'r', d.radius ) ;
d.viz.setAttribute( 'fill', d.color ) ;
g.appendChild(d.viz) ;
}) ;
function click() {
var tx = x_transition ( width * (Math.random() - 0.5) ) ; // x transition object
var ty = y_transition ( height * (Math.random() - 0.5) ) ; // y transition object
var tr = r_transition ( 1 + (4 * Math.random()) ) ; // radius transition object
var tc = c_transition ( random_color() ) ; // transient color transition object
var tc2 = c_transition ( this.__d__.color0 ) ; // final color transition object (return back to starting color)
tc.child = tc2 ; // ** example of the vizflow transition-chaining syntax
this.__d__.transition = [tx, ty, tr, tc] ; // set the transitions for this item, also cancels all existing transitions for this item (side-effect)
}
$Z.item(data) ; // load the user data into the visualization engine to initialize the time equals zero (t = 0) state
$Z.run() ; // run the interactive visualization (infinite loop by default)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment