!function(a,b){"function"==typeofdefine&&define.amd?define(["underscore","backbone"],function(c,d){returnb(a,c,d)}):a.Cello=b(a,_,Backbone)}(this,function(a,b,c){functiond(a,b){returnMath.floor(Math.random()*(b-a+1))+a}vare={desc:"",version:.2,license:"!! TODO !!",DEBUG:!1};e.log=function(){console.log("INFO",arguments)},e.debug=function(){e.DEBUG&&console.log("DEBUG",arguments)},e.assert=function(a,c){if(!a){vard="Assertion failed";throwb.isArray(c)&&(d=c.join("\n")),c&&(d=c),newError(d)}},e.get=function(a,c,d){default_getter=function(){returne.assert(b(a).has("attributes")),e.assert(b(a.attributes).has(c)),a.attributes[c]},a.__defineGetter__(c,d||default_getter)},e.set=function(a,c,d){varf=function(d){e.assert(b(a).has("attributes"));varf=d;b(a).has("attributes")&&(b(a.attributes).has(c)&&(f=a.attributes[c]),a.attributes[c]=d,f!=d&&(a.trigger("change",a),a.trigger("change:"+c,a,d)))};a.__defineSetter__(c,d||f)},e.getset=function(a,b,c,d){e.get(a,b,c),e.set(a,b,d)},e.FlagableCollection=function(a){a.model.active_flags||[];b.each(a.model.active_flags,function(b){e.FlagMethod(a,b)}),a.by_flag=function(b){returna.filter(function(a){returna.has_flag(b)})},a._check_models_param=function(a){returna=b.isUndefined(a)?this.models:a,a=b.isNull(a)?[]:a,a=b.isArray(a)?a:[a]},a.set_flag=function(c,d){d=a._check_models_param(d);vare=a.by_flag(c),f=b.sortBy(d,f);b.isEqual(e,d)===!1&&a.add_flag(c,d,!0)},a.add_flag=function(c,d,e,f){vare=void0!==e&&e,g=a.by_flag(c);if(d=a._check_models_param(d),(0!=g.length||0!=d.length)&&b.isObject(d)){varh=b.union(d,e?[]:g),i=b.difference(g,h);b.difference(h,g);a.remove_flag(c,i,f),b.each(d,function(a){a.add_flag(c,f)})}},a.remove_flag=function(c,d,e){d=a._check_models_param(d),b.each(d,function(a){a.remove_flag(c,e)})}},e.Flagable=function(a){a.get("flags")||a.set("flags",[]),e.get(a,"flags"),a.add_flag=function(a,c){this.has_flag(a)||(this.set("flags",b.union(this.flags,[a]),{silent:!0}),c&&c.silent||(this.trigger("addflag",a,this),this.trigger("addflag:"+a,this),this.collection.trigger("addflag:"+a,this,c)))},a.remove_flag=function(a,c){this.has_flag(a)&&(this.set("flags",b.without(this.flags,a),{silent:!0}),c&&c.silent||(this.trigger("rmflag",a,this),this.trigger("rmflag:"+a,this),this.collection.trigger("rmflag:"+a,this)))},a.has_flag=function(a){returnthis.flags||console.log(this),this.flags.indexOf(a)>=0}},e.FlagMethod=function(a,b){varc="add_"+b,d="set_"+b;e.assert(void0===a[c]),e.assert(void0===a[d]),a[d]=function(c){a.set_flag(b,c,!0)},a[c]=function(c,d){a.add_flag(b,c,d)}},e.SortableCollection=function(a,d,f,g){e.assert(b.isString(f)),e.assert(b.isObject(d)),a.sortables=newc.Collection([],{model:e.Sortable}),e.FlagableCollection(a.sortables),b(d).each(function(b){a.sortables.add(newe.Sortable(b))}),a.listenTo(a.sortables,"change:selected change:reversed",function(b){a.comparator=b.get_comparator(),a.sort()}),console.log(a.sortables);varh=a.sortables.findWhere({field:f});returne.assert(h,"invalid default_key ("+f+")"),h.select(),a.sort_reverse&&h.reverse(),a.comparator=h.get_comparator(),a},e.Sortable=c.Model.extend({defaults:{field:"",type:"",label:null},comparators:{alpha:function(a){varb=function(b,c){returnb.get(a).localeCompare(c.get(a))};returnb},numeric:function(a){varb=function(b,c){returnb.get(a)-c.get(a)==0?0:b.get(a)-c.get(a)>0?1:-1};returnb}},initialize:function(a,c){e.Flagable(this),e.get(this,"field"),e.get(this,"type"),e.get(this,"selected",function(){returnthis.has_flag("selected")}),e.get(this,"reversed",function(){returnthis.has_flag("reversed")}),this.listenTo(this,"addflag:selected rmflag:selected",function(){this.collection.trigger("change:selected",this),this.collection.trigger("change")}),this.listenTo(this,"addflag:reversed rmflag:reversed",function(){this.collection.trigger("change:reversed",this),this.collection.trigger("change")}),b.has(a,"label")&&a.label||this.set("label",a.field);this.get_comparator();returnthis},get_comparator:function(){vara=this.type,c=null;if(b.isFunction(a))c=a(this.field);else{if(!b.has(this.comparators,a))throwError("comparator not found ! (type: '"+a+"')");c=this.comparators[a](this.field)}if(this.reversed){vard=c;c=function(a,b){returnd(b,a)}}returnc},select:function(){this.selected||(b(this.collection.by_flag("selected")).each(function(a){a.remove_flag("selected"),a.reversed&&a.remove_flag("reversed")}),this.add_flag("selected"))},reverse:function(){this.reversed||this.add_flag("reversed")},toggle_reverse:function(){this.reversed?this.remove_flag("reversed"):this.add_flag("reversed")}},{active_flags:["selected","reversed"]}),e.DocList=c.Collection.extend({model:e.Doc,initialize:function(a,c){b(this).bindAll("_set_sort_key","_set_sort_reverse","_set_sortables","_get_sort_key","_get_sort_reverse","_get_sortables"),c=c||{},e.get(this,"selected",function(){returnthis.has_flag("selected")});vard=c.sort_key||"title",f=c.sort_reverse||!1,g=c.sortables||[];this.model&&(e.FlagableCollection(this),e.SortableCollection(this,g,d,f))},_set_sort_key:function(a){varb=this.sort_key;this._sort_key=a,b!=this.sort_key&&(this.trigger("change"),this.trigger("change:sort_key"))},_get_sort_key:function(){returnthis._sort_key},_set_sort_reverse:function(a){varb=this.sort_reverse;this._sort_reverse=a,b!=this.sort_reverse&&(this.trigger("change"),this.trigger("change:sort_reverse"))},_get_sort_reverse:function(){returnthis._sort_reverse},_set_sortables:function(a){varb=this.sortables;this._sortables=a,b!=this.sortables&&(this.trigger("change"),this.trigger("change:sort_reverse"))},_get_sortables:function(){returnthis._sortables},select:function(a){a.select(),this.trigger("change:selected")},clear_selection:function(){this.set_selected(null),options&&options.silent||this.trigger("change:selected"),this.trigger("change:selected")},unselect:function(a){a.remove_flag("selected"),this.trigger("change:selected")}}),e.Doc=c.Model.extend({defaults:{docnum:null,selected:!1,clusters:null},idAttribute:"docnum",initialize:function(a,b){e.get(this,"docnum"),e.get(this,"selected",function(){returnthis.has_flag("selected")}),e.getset(this,"clusters"),this.clusters={},e.Flagable(this),e.assert(null!==this.docnum,"Document should have a docnum")},select:function(){this.add_flag("selected")},toggle_select:function(){this.selected?this.remove_flag("selected"):this.add_flag("selected")}},{active_flags:["selected"]}),e.QueryModel=c.Model.extend({defaults:{cellist:null,query:"",loaded:!1},loaded_query:null,initialize:function(a,c){b.bindAll(this,"set_query","play_completed","query_updated"),e.get(this,"cellist"),e.get(this,"loaded"),e.get(this,"query"),e.set(this,"query",this.set_query),this.listenTo(this.cellist,"play:complete",this.play_completed),this.on("change:query",this.query_updated)},set_query:function(a){a=a.trim(),console.log("set_query",a),this.set("query",a)},query_updated:function(){this.query!==this.loaded_query?this.set("loaded",!1):this.set("loaded",!0)},play_completed:function(a){a.results.query!=this.query&&(this.query=a.results.query),this.loaded_query=this.query,this.set("loaded",!0)},validate:function(){return!0},play:function(){this.cellist.play()},export_for_engine:function(){returnthis.query}}),e.Option=c.Model.extend({defaults:{value:void0,name:null,otype:{}},idAttribute:"name",initialize:function(a,c){vard=this;b.bindAll(this,"validate"),e.get(this,"name"),e.get(this,"otype"),e.get(this,"value"),e.set(this,"value",function(a){varb=d.validate(a);d.value!=b&&d.set("value",b)}),e.assert(null!==this.name,"Option should have a name"),e.assert(null!==a.otype,"(Option: "+this.name+") otype should not be 'null'")},is_default:function(){returnb.isEqual(this.value,this.otype.default)},parse:function(a){returnthis.otype&&("Boolean"===this.otype.type&&(a=[1,!0,"true","True","TRUE","1","yes"].indexOf(a)>=0),"float"===this.otype.vtype&&(a=parseFloat(a)),"int"===this.otype.vtype&&(a=parseInt(a),b.isNaN(a)&&(a=""))),a},_validate_one:function(a){a=this.parse(a);varc=this.otype.choices;if(c&&b.indexOf(c,a)<0)thrownewError("invalid option value");returna},is_multi:function(){returnthis.otype.multi},validate:function(a){varc=this;if(this.is_multi()){vard=[];b.each(a,function(a){d.push(c._validate_one(a))}),a=d}elsea=this._validate_one(a);returna}}),e.Options=c.Collection.extend({model:e.Option}),e.Component=c.Model.extend({idAttribute:"name",defaults:{name:null,selected:!1,doc:"",options:newe.Options},initialize:function(){e.get(this,"name"),e.get(this,"options"),e.get(this,"selected"),this.listenTo(this.options,"reset",this.optionsChanged),this.listenTo(this.options,"change",this.optionsChanged),e.assert(null!==this.name,"Component should have a name")},get_option:function(a){returnthis.options.where({name:a})[0]},set_option:function(a,b){varc=this.get_option(a);c.value=b},parse:function(a,b){returna.options=newe.Options(a.options,{parse:!0}),a.default&&(a.selected=!0),a},optionsChanged:function(a){this.trigger("change",this,a),this.trigger("change:options",this,a)},changed_options:function(){vara=[];returnb.each(this.options.models,function(b){b.is_default()||a.push(b)}),a},as_dict:function(a){void0!==a&&null!=a||(a=!1);varc={name:this.name},d=a?this.changed_options():this.options.models;returnd.length>0&&(c.options={},b.each(d,function(a){c.options[a.name]=a.value})),c},set_state:function(a){varc=this;b.each(a,function(a,b){c.set_option(b,a)})}}),e.Components=c.Collection.extend({model:e.Component}),e.Block=c.Model.extend({defaults:{name:"",components:newe.Components,required:!0,multiple:!1,args:null,returns:null},initialize:function(a){e.get(this,"components"),e.get(this,"selected",this._get_selected),e.get(this,"name"),e.get(this,"required"),e.get(this,"multiple"),e.get(this,"args"),e.get(this,"returns"),e.assert(null!==this.name,"Block should have a name"),e.assert(b.isNull(this.args)||b.isArray(this.args),"'args' should be null or an Array"),null===this.returns&&this.set("returns",this.name),this.listenTo(this.components,"reset",this.componentsChanged),this.listenTo(this.components,"change",this.componentsChanged),this.selection_default=b.map(this.selected,function(a){returna.name})},componentsChanged:function(a){this.trigger("change",this,a),this.trigger("change:components",this,a)},parse:function(a,b){returna.components=newe.Components(a.components,{parse:!0}),a},reset:function(){this.components.reset()},get_component:function(a){returnb.find(this.components.models,function(b){returnb.name==a})},_get_selected:function(){returnthis.components.where({selected:!0})},select:function(a){a.selected?this.required||(a.set("selected",!1),this.trigger("change"),this.trigger("change:selected")):(this.multiple||b.each(this.selected,function(a){a.set("selected",!1)}),a.set("selected",!0),this.trigger("change"),this.trigger("change:selected"))},unselect:function(a){a.selected&&(!this.required||this.multiple&&this.selected.length>1)&&(a.set("selected",!1),this.trigger("change"),this.trigger("change:selected"))},clear_selection:function(){vara=this;b.each(this.selected,function(b){a.unselect(b)})},validate:function(){},get_state:function(a){void0!==a&&null!=a||(a=!1);varc=[],d=this.selected,e=b.isEqual(b.map(d,function(a){returna.name}),this.selection_default);for(varfind){varg=d[f],h=g.as_dict(a);a&&e&&!b.has(h,"options")||c.push(g.as_dict(a))}returnc},set_state:function(a){varc=this;b.each(a,function(a){varb=a.name,d=a.options,e=c.get_component(b);e.set_state(d),c.select(e)})}}),e.Blocks=c.Collection.extend({model:e.Block}),e.Engine=c.Model.extend({defaults:{blocks:newe.Blocks,args:null,returns:null,needed_inputs:[]},initialize:function(a,b){varc=a.url;this.input_models={},this.url=c,this.play_url=c,e.get(this,"blocks"),e.get(this,"args"),e.get(this,"returns"),e.get(this,"needed_inputs"),this.listenTo(this.blocks,"change reset",this.blockChanged)},get_block:function(a){returnb.find(this.blocks.models,function(b){returnb.get("name")==a})},blockChanged:function(a){this._update_needed_inputs(),this.trigger("change",this,a),this.trigger("change:blocks",this,a)},_update_needed_inputs:function(){vara=[],b=[],c=this.blocks.models;for(vardinc){vare=c[d];if(e.selected.length>0){for(varfine.args){varg=e.args[f];b.indexOf(g)<0&&a.indexOf(g)&&a.push(g)}b.push(e.returns)}}this.set({needed_inputs:a},{silent:!0})},parse:function(a,b){returnconsole.log("Engine parse",a,b),this.data=a,a.blocks=newe.Blocks(a.blocks,{parse:!0}),a},reset:function(a){a=this.parse(a),this.set(a)},get_state:function(a){void0!==a&&null!=a||(a=!1);varb={},c=this.blocks.models;for(vardinc){vare=c[d],f=e.get_state(a);f.length>0&&(b[e.name]=f)}returnb},set_state:function(a){varc=this;b.each(a,function(a,b){vard=c.get_block(b);d.set_state(a)})},get_state_str:function(a){varb=this.get_state(a),c=$.param(b);returnc},set_state_str:function(a){varb=e.utils.deparam(a);this.set_state(b)},register_input:function(a,b){this.input_models[a]=b},play:function(a){vard=this,f=this.get_state(),g={};b.each(this.input_models,function(a,b,c){g[b]=a.export_for_engine()});varg=b.extend(g,a),h=b.extend({},g,{options:f});e.log("play",h),d.trigger("play:loading",g,f);varh=JSON.stringify(h);c.ajax({url:d.play_url,method:"post",contentType:"application/json",data:h,success:function(b,c,e){b.meta&&b.meta.errors&&b.meta.errors.length>0?d.trigger("play:error",b,e):(console.log("play:success",b,a,f),d.trigger("play:success",b,a,f),d.trigger("play:complete",b,a,f))},error:function(a,b,c){d.trigger("play:error",{},a),d.trigger("play:complete",{},a)}})}});varf=c.Model.extend({IN:1,OUT:2,ALL:4,defaults:{gid:null,directed:!1,bipartite:!1},idAttribute:"gid",initialize:function(a,b){vard=this;if(this.edge_list={},this.nodetype_model=a.nodetype_model||h,this.nodetypes=newp([],{model:this.nodetype_model}),this.edgetype_model=a.edgetype_model||j,this.edgetypes=newp([],{model:this.edgetype_model}),this.properties||(this.properties=newc.Model),this.meta||(this.meta=newc.Model),e.get(this,"label",function(){returnthis.properties.get("name")}),this.urlRoot=a.urlRoot,this.urlRoot){varf=function(a){d.nodetypes.url=d.url()+"/nodetypes",d.nodetypes.reset(),d.nodetypes.fetch({remove:!1}),d.edgetypes.url=d.url()+"/edgetypes",d.edgetypes.reset(),d.edgetypes.fetch({remove:!1})};this.on("change:gid",f),this.nodetypes.on("add",function(a){a.urlRoot=d.url()+"/nodetype"}),this.edgetypes.on("add",function(a){a.urlRoot=d.url()+"/edgetype"})}this.vertex_model=a.vertex_model||l,this.vs=newe.Vertices([],{graph:this,model:this.vertex_model}),this.vs.reset([],{collection:this.vs});varg=function(a){a&&(a.collection=d.vs,void0===a.id&&(a.id=d.vs.size()),a.idind.edge_list||(d.edge_list[a.id]=[]))},i=function(a){varb=d.es.filter(function(b){returnb.get("source")==a.id||b.get("target")==a.id});d.es.remove(b),deleted.edge_list[a.id]};this.vs.on("add",g),this.vs.on("remove",i),this.edge_model=a.edge_model||m,this.es=newe.Edges([],{graph:this,model:this.edge_model}),this.es.reset([],{collection:this.es});vark=function(a){a.collection=d.es,d.edge_list[a.get("source")].push(a),d.edge_list[a.get("target")].push(a)},n=function(a){d.edge_list[a.get("source")].splice(d.edge_list[a.get("source")].indexOf(a),1),d.edge_list[a.get("target")].splice(d.edge_list[a.get("target")].indexOf(a),1)};this.es.on("add",k),this.es.on("remove",n),e.FlagableCollection(this.vs),e.FlagableCollection(this.es),a.data&&this.reset(a.data)},url:function(){returnthis.urlRoot+this.id},parse:function(a,b){this.reset(a[this.id],b)},reset:function(a,c){e.debug("parse graph",a),a.nodetypes&&this.nodetypes.set({nodetypes:a.nodetypes},{parse:!0}),a.edgetypes&&this.edgetypes.set({edgetypes:a.edgetypes},{parse:!0}),a.properties&&this.properties.set(a.properties,{parse:!0}),a.meta&&this.meta.set(a.meta,{parse:!0}),c=c?b.clone(c):{},a.vs&&a.es&&(this.edge_list={},this.es.reset([],c),this.vs.reset([],c),c={parse:!0},this.vs.set(a.vs,c),this.es.set(a.es,c)),this.trigger("reset")},merge:function(a,b){e.debug("merge graph",a),a.nodetypes&&this.nodetypes.set({nodetypes:a.nodetypes},{remove:!1,parse:!0}),a.edgetypes&&this.edgetypes.set({edgetypes:a.edgetypes},{remove:!1,parse:!0}),a.meta&&this.meta.set(a.meta,{parse:!0}),a.properties&&this.properties.set(a.properties,{parse:!0}),this.vs.add(a.vs,{parse:!0}),this.es.add(a.es,{parse:!0}),this.trigger("merge")},get_edge_type:function(a){varb=this.edgetypes.get(a);if(b)returnb},get_node_type:function(a){varb=this.nodetypes.get(a);if(b)returnb;if(a){varb=newthis.nodetype_model({name:a,uuid:a});returnthis.nodetypes.add(b),b}},summary:function(){return{attrs:this.attributes,vcount:this.vcount(),ecount:this.ecount(),density:this.density(),v_attrs:this.attributes.v_attrs,e_attrs:this.attributes.e_attrs}},str:function(){vara=b.template("v:<%=vcount%>, e:<%=ecount%>,density:<%=density%>,\nv attrs:<%=v_attrs%>, \ne attrs:<%=e_attrs%>, ");returna(this.summary())},add_vertex:function(a){this.vs.add(a)},vcount:function(){returnthis.vs.length},add_edge:function(a){this.es.add(a)},is_loop:function(a){varc=function(a){returna.source===a.target};returnb.map(a,c)},ecount:function(){returnthis.es.length},incident:function(a,c,d){vare=this,f=[],g=a.id,h=void0===c?this.ALL:c,i=void0===d||d;returnh==e.ALL?f=b.filter(e.edge_list[g],function(a){return!!i||!a.is_loop()}):h==e.IN?f=b.filter(e.edge_list[g],function(a){return!(a.source.id!=g||!i&&a.is_loop())}):h==e.OUT&&(f=b.filter(e.edge_list[g],function(a){return!(a.target.id!=g||!i&&a.is_loop())})),f},degree:function(a,b,c){returnthis.incident(a,b,c).length},neighbors:function(a,c,d){vare=this.incident(a,c,d),f=b(e).map(function(b){returnb.source!=a?b.source:b.target});returnf},strength:function(a,c,d){vare=this.incident(a,c,d),f=function(a,b){returna+b.weight};returnb.reduce(e,f,0)},select:function(a){varc={degree:1,strength:1},d=function(d){for(vareina){varf,g=a[e],h=e.split(":"),i=h[0],j=2==h.length?h[1]:"eq";if("_"==i.substring(0,1)?(method=i.slice(1),methodinc&&(f=d[method]())):f=d.get(i),"eq"==j){if(b.isEqual(f,g)===!1)return!1}elseif("ne"==j){if(f==g)return!1}elseif("lt"==j){if(f<g==!1)return!1}elseif("gt"==j){if(f>g==!1)return!1}elseif("le"==j){if(f<=g==!1)return!1}elseif("ge"==j){if(f>=g==!1)return!1}elseif("in"==j){if(b.indexOf(g,f)===-1)return!1}elseif("notin"==j&&b.indexOf(g,f)!==-1)return!1}return!0};returnb.filter(this.vs.models,d)},random_vertex:function(){vara=this.es.at(d(0,this.es.size()-1));returnMath.random()>.5?a.source:a.target},density:function(){return2*this.es.length/(this.vs.length*(this.vs.length-1))},adjacency:function(){vara=[],c=0,d=function(){return0};for(c=this.vcount(),i=0;i<c;i++)a.push(b.range(c).map(d));for(c=this.ecount(),i=0;i<c;i++){vare=this.es[i];a[e.source][e.target]=e.weight}this.adjacency=a}}),g=c.Model.extend({idAttribute:"uuid",defaults:{name:"",description:"",properties:newe.Options,material:{}},get_property:function(a){returnthis.properties.where({name:a})[0]},add_property:function(a,b){},delete_property:function(a,b){},parse:function(a,b){varc=[];for(kina.properties)c.push({name:k,otype:a.properties[k]});return{properties:newe.Options(c,{parse:!0}),name:a.name,description:a.description||"",uuid:a.uuid}},toString:function(){returnthis.get("name")},toJSON:function(a){varc=b.pick(this.attributes,"name","description","uuid"),d=this.get("properties").models,e={};for(varfind){varg=d[f];""!=g.get("name")&&(e[g.get("name")]=g.get("otype"))}returnc.properties=e,c}}),h=g.extend({initialize:function(a,b){e.get(this,"name"),e.get(this,"properties"),e.get(this,"label",function(){vara=this.get("name");returnvoid0===a?"":a});vard=this;this.on("sync",function(a,b,d){c.trigger("nodetype:save",this,b,d)}),this.listenTo(this.attributes.properties,"change",function(){d.trigger("change:properties",d.attributes.properties)})}}),j=g.extend({initialize:function(a,b){e.get(this,"name"),e.get(this,"properties"),e.get(this,"label",function(){vara=this.get("name");returnvoid0===a?"":a}),this.on("sync",function(a,b,d){c.trigger("edgetype:save",this,b,d)})}}),l=c.Model.extend({idAttribute:"uuid",defaults:{uuid:"",nodetype:"",label:"",color:[0,0,0],coords:[0,0,0],clusters:null},initialize:function(a,d){varf=this;e.getset(this,"color"),e.getset(this,"clusters"),this.clusters={},e.get(this,"graph",function(){returnnull!=f.collection?f.collection.graph:null}),e.get(this,"nodetype",function(){returnf.graph?f.graph.get_node_type(f.get("nodetype")):null}),e.get(this,"label",function(){vara=this.get("label");returnvoid0===a?"":a}),e.Flagable(this),b.bindAll(this,"degree","format_label","neighbors","strength"),e.get(this,"formatted_label",this.format_label),this.on("sync",function(a,b,d){c.trigger("node:save",f,b,d)})},getHexColor:function(){return0},format_label:function(a){varb=this.label;returna&&(b=b.substring(0,a)),[{form:b,css:".normal-font"}]},degree:function(a,b){returnthis.graph.degree(this,a,b)},strength:function(a,b){returnthis.graph.strength(this,a,b)},incident:function(a,b){returnthis.graph.incident(this,a,b)},neighbors:function(a,b){returnthis.graph.neighbors(this,a,b)}},{active_flags:[]}),m=c.Model.extend({idAttribute:"uuid",defaults:{label:"",edgetype:null,source:null,target:null},initialize:function(a,b){vard=this;a||(a={}),e.get(this,"graph",function(){returnnull!=d.collection?d.collection.graph:null}),e.get(this,"edgetype",function(){returnd.graph?d.graph.get_edge_type(d.get("edgetype")):null}),e.get(this,"source",function(){returnd.graph?d.graph.vs.get(d.get("source")):null}),e.get(this,"target",function(){returnd.graph?d.graph.vs.get(d.get("target")):null}),e.get(this,"label",function(){returnd.get("label")}),e.get(this,"sym",this.sym),a.w&&(this.weight=a.w),e.Flagable(this),this.on("sync",function(a,b,d){c.trigger("edge:save",a,b,d)})},str:function(){vara=function(a,b){returnb+": "+a};return"("+this.get("s")+","+this.get("t")+") "+this.source.label+"-->"+this.target.label+","+b.map(this.attributes,a).join(", ")},tuple:function(){},sym:function(){returnb(this.collection.models).findWhere({source:this.target,target:this.source})},is_loop:function(){returnthis.source.id==this.target.id}},{active_flags:[]}),n=c.Collection.extend({model:l,initialize:function(a,b){_this=this,b&&(this.graph=b.graph)},copy_attr:function(a,c,d){b.map(this.graph.vs.select({}),function(b){b.set(c,b.get(a),d)})},select:function(a){returnthis.graph.select(a)}}),o=c.Collection.extend({model:m,initialize:function(a,b){this.graph=b.graph},between:function(a,b,c){if(a&&b)returnthis.models.filter(function(d){returnc?d.source==a&d.target==b:(d.source==a|d.source==b)&(d.target==a|d.target==b)})}}),p=c.Collection.extend({model:g,parse:function(a){return"nodetypes"ina?a.nodetypes:"edgetypes"ina?a.edgetypes:void0}});e.Graph=f,e.Type=g,e.Vertices=n,e.Vertex=l,e.Edges=o,e.Edge=m,e.EdgeType=j,e.NodeType=h,e.ClusterLabel=c.Model.extend({idAttribute:"id",defaults:{label:"",score:1,role:"*",size:12,clusters:null},initialize:function(){e.get(this,"label"),e.get(this,"role"),e.get(this,"score"),e.getset(this,"clusters"),this.clusters={},b.bindAll(this,"_format_label"),e.get(this,"formatted_label",this._format_label),e.Flagable(this)},_format_label:function(){return[{form:this.get("label"),css:"normal"}]}},{active_flags:[]}),e.Cluster=c.Model.extend({defaults:{members:{},labels:[],misc:!1,selected:!1,color:[200,200,200]},initialize:function(a,c){vard=this;b.bindAll(d,"_compute_membership","_compute_colors"),e.get(this,"members"),e.getset(this,"labels"),e.get(this,"misc"),e.getset(this,"color"),e.get(this,"selected",function(){returnd.has_flag("selected")}),this.listenTo(this,"addflag:selected rmflag:selected",function(){d.collection.trigger("change:selected")}),e.Flagable(this)},is_misc:function(){returnthis.misc},select:function(a){a?this.collection.set_selected([this]):this.add_flag("selected")},toggle_select:function(a){varb=this.collection.selected.length;this.selected?a&&b>=2?this.collection.set_selected([this]):this.remove_flag("selected"):this.select(a)},some_selected:function(){returnthis.selected||this.collection.by_flag("selected")},_compute_membership:function(){vara=this,c=this.collection.clustering.cid;b(a.members).each(function(b){b.each(function(b){vard={cluster:a};b.clusters[c]?b.clusters[c].push(d):b.clusters[c]=[d],b.trigger("change:clusters"),b.trigger("change:clusters:"+c)})})},_compute_colors_old:function(){vara=this.collection.length,b=this.collection.clustering.get("color_value"),c=this.collection.clustering.get("color_saturation"),d=this.collection.indexOf(this),f=[99,99,99];this.misc===!1&&(f=e.utils.hsvToRgb(d/a*360|0,c,b)),this.color=f},_compute_colors:function(a){if(this.misc===!0)returnvoid(this.color=[99,99,99]);varc=(this.collection.length,this.collection.clustering.get("color_value")),d=this.collection.clustering.get("color_saturation"),f=(this.collection.indexOf(this),[0,0,0]),g=f,h=0,i={};this.members.vs.each(function(a){varb=a.get("cl_color");s_last_node_cl_color=b.toString(),i[s_last_node_cl_color]?i[s_last_node_cl_color]++:i[s_last_node_cl_color]=1,i[s_last_node_cl_color]>h&&(h=i[s_last_node_cl_color],g=b)}),cluster_color=g;for(varj=0;b.isEqual(cluster_color,f)|a.indexOf(cluster_color.toString())!=-1;)cluster_color=e.utils.hsvToRgb(1*j*222.23%360|0,d,c),j++;a.push(cluster_color.toString()),this.color=cluster_color}},{active_flags:["selected"]}),e.ClustersList=c.Collection.extend({model:e.Cluster,initialize:function(a,b){_this=this,e.get(this,"selected",function(){returnthis.by_flag("selected")}),e.assert(b.clustering,"options.clustering is needed"),this.clustering=b.clustering,this.on("add remove reset",function(){vara=[];this.each(function(b){b._compute_membership(),b._compute_colors(a)})}),this.listenTo(this.clustering,"change:color_saturation change:color_value",function(){vara=[];this.each(function(b){b._compute_colors(a)})})},some_selected:function(){returnthis.by_flag("selected").length>0},select:function(a,b){a.select(b),this.trigger("change:selected",a)},clear_selection:function(a){this.set_selected(null),a&&a.silent||this.trigger("change:selected")},unselect:function(a){a.remove_flag("selected"),this.trigger("change:selected")},has_misc:function(){vara=function(a){returna.is_misc()};returnb.some(this.models,a)},cluster:function(a){returnthis.at(a)}}),e.Clustering=c.Model.extend({defaults:{clusters:null,members:{},color_value:80,color_saturation:40},ClusterLabelModel:e.ClusterLabel,ClusterModel:e.Cluster,ClustersCollection:e.ClustersList,initialize:function(a,b){a=a||{},e.getset(this,"members"),e.getset(this,"clusters"),e.getset(this,"color_value"),e.getset(this,"color_saturation"),this.ClusterLabelModel=a.ClusterLabelModel||this.ClusterLabelModel,this.ClusterModel=a.ClusterModel||this.ClusterModel,this.ClustersCollection=a.ClustersCollection||this.ClustersCollection;varc={clustering:this,model:this.ClusterModel},d=newthis.ClustersCollection([],c);this.set("clusters",d),e.FlagableCollection(this.clusters)},reset:function(a,c){vard=this,e=b(a).clone();c&&c.members&&b.extend(this.members,c.members);varf=this.members;b.map(e.clusters,function(a){a.misc=!1}),e.misc>-1&&(e.clusters[e.misc].misc=!0),cluster_models=[],b.each(e.clusters,function(a){cluster_members={},b.each(f,function(c,d){source_clone=c.source.clone(),source_filtered=source_clone.filter(function(d){returnb(a[c.id_field]).contains(d.id)}),source_clone.reset(source_filtered,{silent:!0}),cluster_members[d]=source_clone}),cluster_models.push(newd.ClusterModel({members:cluster_members,misc:a.misc}))}),this.clusters.reset(cluster_models),this.trigger("reset")},set_labels:function(a,b){this.clusters.each(function(b,c){b.labels=a.labels[c]})}}),e.utils={},e.utils.asEvents=function(a){varb;return{on:function(c,d){if(b)thrownewError("this is one off wrapper");a.addEventListener(c,d,!1),b=[c,d]},off:function(){a.removeEventListener.apply(a,b)}}};varq=function(a){returna="0"+a.toString(16),a.substring(a.length-2)};returne.utils.css_color=function(a){varc="#000000";returna&&(c="#"+b.map(a,q).join("")),c},e.utils.css_gradient=function(a,b){return"-webkit-linear-gradient("+e.utils.css_color(a)+","+e.utils.css_color(b)+")"},e.utils.color_darker=function(a){varb=e.utils.rgbToHsv(a[0],a[1],a[2]);returne.utils.hsvToRgb(b[0],b[1],60)},e.utils.hsvToRgb=function(a,b,c){b/=100,c/=100;vard=Math.floor(a/60%6),e=a/60-d,f=c*(1-b),g=c*(1-e*b),h=c*(1-(1-e)*b),i=[];switch(d){case0:i=[c,h,f];break;case1:i=[g,c,f];break;case2:i=[f,c,h];break;case3:i=[f,g,c];break;case4:i=[h,f,c];break;case5:i=[c,f,g]}varj=Math.min(255,256*i[0]|0),k=Math.min(255,256*i[1]|0),l=Math.min(255,256*i[2]|0);return[j,k,l]},e.utils.rgbToHsv=function(a,b,c){vard,e,f=a/255,g=b/255,h=c/255,i=Math.min(Math.min(f,g),h),j=Math.max(Math.max(f,g),h),k=j;returnj==i?e=0:j==f?e=60*((g-h)/(j-i))%360:j==g?e=60*((h-f)/(j-i))+120:j==h&&(e=60*((f-g)/(j-i))+240),e<0&&(e+=360),d=0===j?0:1-i/j,[0|e,100*d|0,100*k|0]},e.utils.addCSSRule=function(a,b,c){for(vard,e,f=0;f<document.styleSheets.length;f++){d=document.styleSheets[f],e=d.cssRules||d.rules;for(varg=a.toLowerCase(),h=0,i=e.length;h<i;h++)if(e[h].selectorText&&e[h].selectorText.toLowerCase()==g){if(null!==c)returnvoid(e[h].style[b]=c);d.deleteRule?d.deleteRule(h):d.removeRule?d.removeRule(h):e[h].style.cssText=""}}d=document.styleSheets[0]||{},d.insertRule?(e=d.cssRules||d.rules,d.insertRule(a+"{ "+b+":"+c+"; }",e.length)):d.addRule&&d.addRule(a,b+":"+c+";",0)},e.utils.deparam=function(a,b){varc={},d={true:!0,false:!1,null:null};return$.each(a.replace(/\+/g," ").split("&"),function(a,e){varf,g=e.split("="),h=decodeURIComponent(g[0]),i=c,j=0,k=h.split("]["),l=k.length-1;if(/\[/.test(k[0])&&/\]$/.test(k[l])?(k[l]=k[l].replace(/\]$/,""),k=k.shift().split("[").concat(k),l=k.length-1):l=0,2===g.length)if(f=decodeURIComponent(g[1]),b&&(f=f&&!isNaN(f)?+f:"undefined"===f?void0:void0!==d[f]?d[f]:f),l)for(;j<=l;j++)h=""===k[j]?i.length:k[j],i=i[h]=j<l?i[h]||(k[j+1]&&isNaN(k[j+1])?{}:[]):f;else$.isArray(c[h])?c[h].push(f):void0!==c[h]?c[h]=[c[h],f]:c[h]=f;elseh&&(c[h]=b?void0:"")}),c},e.utils.piwikTrackCurrentUrl=function(){b.isUndefined(window._paq)||"function"!=typeofwindow._paq.push||(window._paq.push(["setCustomUrl",window.location.href]),window._paq.push(["trackPageView"]))},e});
!function(a,b){"function"==typeofdefine&&define.amd?define(["underscore","backbone","cello","tween","threejs","pdgconst"],function(c,d,e,f,g,h){returnb(a,c,d,e,f,g,h)}):a.Gviz=b(a,_,Backbone,Cello,TWEEN,THREE,Const)}(this,function(a,c,d,e,f,h,j){h.TrackballControls=function(a,b){functionc(a){n.enabled!==!1&&(window.removeEventListener("keydown",c),s=r,r===o.NONE&&(a.keyCode!==n.keys[o.ROTATE]||n.noRotate?a.keyCode!==n.keys[o.ZOOM]||n.noZoom?a.keyCode!==n.keys[o.PAN]||n.noPan||(r=o.PAN):r=o.ZOOM:r=o.ROTATE))}functiond(a){n.enabled!==!1&&(r=s,window.addEventListener("keydown",c,!1))}functione(a){n.enabled!==!1&&(_MOUSEDOWN=!0,a.preventDefault(),a.stopPropagation(),r===o.NONE&&(r=a.button),r!==o.ROTATE||n.noRotate?r!==o.ZOOM||n.noZoom?r!==o.PAN||n.noPan||(C.copy(H(a.pageX,a.pageY)),D.copy(C)):(y.copy(H(a.pageX,a.pageY)),z.copy(y)):(v.copy(I(a.pageX,a.pageY)),u.copy(v)),document.addEventListener("mousemove",f,!1),document.addEventListener("mouseup",g,!1),n.dispatchEvent(F))}functionf(a){n.enabled!==!1&&(a.preventDefault(),a.stopPropagation(),r!==o.ROTATE||n.noRotate?r!==o.ZOOM||n.noZoom?r!==o.PAN||n.noPan||D.copy(H(a.pageX,a.pageY)):z.copy(H(a.pageX,a.pageY)):(u.copy(v),v.copy(I(a.pageX,a.pageY))))}functiong(a){n.enabled!==!1&&(_MOUSEDOWN=!1,a.preventDefault(),a.stopPropagation(),r=o.NONE,document.removeEventListener("mousemove",f),document.removeEventListener("mouseup",g),n.dispatchEvent(G))}functioni(a){if(n.enabled!==!1){a.preventDefault(),a.stopPropagation();varb=0;a.wheelDelta?b=a.wheelDelta/40:a.detail&&(b=-a.detail/3),y.y+=.01*b,n.dispatchEvent(F),n.dispatchEvent(G)}}functionj(a){if(n.enabled!==!1){switch(a.touches.length){case1:r=o.TOUCH_ROTATE,v.copy(I(a.touches[0].pageX,a.touches[0].pageY)),u.copy(v);break;case2:r=o.TOUCH_ZOOM_PAN;varb=a.touches[0].pageX-a.touches[1].pageX,c=a.touches[0].pageY-a.touches[1].pageY;B=A=Math.sqrt(b*b+c*c);vard=(a.touches[0].pageX+a.touches[1].pageX)/2,e=(a.touches[0].pageY+a.touches[1].pageY)/2;C.copy(H(d,e)),D.copy(C);break;default:r=o.NONE}n.dispatchEvent(F)}}functionk(a){if(n.enabled!==!1)switch(a.preventDefault(),a.stopPropagation(),a.touches.length){case1:u.copy(v),v.copy(I(a.touches[0].pageX,a.touches[0].pageY));break;case2:varb=a.touches[0].pageX-a.touches[1].pageX,c=a.touches[0].pageY-a.touches[1].pageY;B=Math.sqrt(b*b+c*c);vard=(a.touches[0].pageX+a.touches[1].pageX)/2,e=(a.touches[0].pageY+a.touches[1].pageY)/2;D.copy(H(d,e));break;default:r=o.NONE}}functionl(a){if(n.enabled!==!1){switch(a.touches.length){case1:u.copy(v),v.copy(I(a.touches[0].pageX,a.touches[0].pageY));break;case2:A=B=0;varb=(a.touches[0].pageX+a.touches[1].pageX)/2,c=(a.touches[0].pageY+a.touches[1].pageY)/2;D.copy(H(b,c)),C.copy(D)}r=o.NONE,n.dispatchEvent(G)}}functionm(a){a.preventDefault()}varn=this,o={NONE:-1,ROTATE:0,ZOOM:1,PAN:2,TOUCH_ROTATE:3,TOUCH_ZOOM_PAN:4};this.object=a,this.domElement=void0!==b?b:document,this.enabled=!0,this.screen={left:0,top:0,width:0,height:0},this.rotateSpeed=1,this.zoomSpeed=1.2,this.panSpeed=.3,this.noRotate=!1,this.noZoom=!1,this.noPan=!1,this.staticMoving=!1,this.dynamicDampingFactor=.2,this.minDistance=0,this.maxDistance=5e3,this.keys=[65,83,68],this.AUTO_ROTATE=!1,this.autoRotateSpeed=.005,this.target=newh.Vector3;varp=1e-6,q=newh.Vector3,r=o.NONE,s=o.NONE,t=newh.Vector3,u=newh.Vector2,v=newh.Vector2,w=newh.Vector3,x=0,y=newh.Vector2,z=newh.Vector2,A=0,B=0,C=newh.Vector2,D=newh.Vector2;_MOUSEDOWN=!1,this.target0=this.target.clone(),this.position0=this.object.position.clone(),this.up0=this.object.up.clone();varE={type:"change"},F={type:"start"},G={type:"end"};this.handleResize=function(){if(this.domElement===document)this.screen.left=0,this.screen.top=0,this.screen.width=window.innerWidth,this.screen.height=window.innerHeight;else{vara=this.domElement.getBoundingClientRect(),b=this.domElement.ownerDocument.documentElement;this.screen.left=a.left+window.pageXOffset-b.clientLeft,this.screen.top=a.top+window.pageYOffset-b.clientTop,this.screen.width=a.width,this.screen.height=a.height}},this.handleEvent=function(a){"function"==typeofthis[a.type]&&this[a.type](a)};varH=function(){vara=newh.Vector2;returnfunction(b,c){returna.set((b-n.screen.left)/n.screen.width,(c-n.screen.top)/n.screen.height),a}}(),I=function(){vara=newh.Vector2;returnfunction(b,c){returna.set((b-.5*n.screen.width-n.screen.left)/(.5*n.screen.width),(n.screen.height+2*(n.screen.top-c))/n.screen.width),a}}();this.rotateCamera=function(){vara,b=newh.Vector3,c=newh.Quaternion,d=newh.Vector3,e=newh.Vector3,f=newh.Vector3,g=newh.Vector3;returnfunction(){this.AUTO_ROTATE&&!_MOUSEDOWN&&(v.x=u.x+this.autoRotateSpeed),g.set(v.x-u.x,v.y-u.y,0),a=g.length(),a?(t.copy(n.object.position).sub(n.target),d.copy(t).normalize(),e.copy(n.object.up).normalize(),f.crossVectors(e,d).normalize(),e.setLength(v.y-u.y),f.setLength(v.x-u.x),g.copy(e.add(f)),b.crossVectors(g,t).normalize(),a*=n.rotateSpeed,c.setFromAxisAngle(b,a),t.applyQuaternion(c),n.object.up.applyQuaternion(c),w.copy(b),x=a):!n.staticMoving&&x&&(x*=Math.sqrt(1-n.dynamicDampingFactor),t.copy(n.object.position).sub(n.target),c.setFromAxisAngle(w,x),t.applyQuaternion(c),n.object.up.applyQuaternion(c)),u.copy(v)}}(),this.zoomCamera=function(){vara;r===o.TOUCH_ZOOM_PAN?(a=A/B,A=B,t.multiplyScalar(a)):(a=1+(z.y-y.y)*n.zoomSpeed,1!==a&&a>0&&(t.multiplyScalar(a),n.staticMoving?y.copy(z):y.y+=(z.y-y.y)*this.dynamicDampingFactor))},this.panCamera=function(){vara=newh.Vector2,b=newh.Vector3,c=newh.Vector3;returnfunction(){a.copy(D).sub(C),a.lengthSq()&&(a.multiplyScalar(t.length()*n.panSpeed),c.copy(t).cross(n.object.up).setLength(a.x),c.add(b.copy(n.object.up).setLength(a.y)),n.object.position.add(c),n.target.add(c),n.staticMoving?C.copy(D):C.add(a.subVectors(D,C).multiplyScalar(n.dynamicDampingFactor)))}}(),this.checkDistances=function(){n.noZoom&&n.noPan||(t.lengthSq()>n.maxDistance*n.maxDistance&&(n.object.position.addVectors(n.target,t.setLength(n.maxDistance)),y.copy(z)),t.lengthSq()<n.minDistance*n.minDistance&&(n.object.position.addVectors(n.target,t.setLength(n.minDistance)),y.copy(z)))},this.update=function(){t.subVectors(n.object.position,n.target),n.noRotate||n.rotateCamera(),n.noZoom||n.zoomCamera(),n.noPan||n.panCamera(),n.object.position.addVectors(n.target,t),n.checkDistances(),n.object.lookAt(n.target),q.distanceToSquared(n.object.position)>p&&(n.dispatchEvent(E),q.copy(n.object.position))},this.reset=function(){r=o.NONE,s=o.NONE,n.target.copy(n.target0),n.object.position.copy(n.position0),n.object.up.copy(n.up0),t.subVectors(n.object.position,n.target),n.object.lookAt(n.target),n.dispatchEvent(E),q.copy(n.object.position)},this.dispose=function(){this.domElement.removeEventListener("contextmenu",m,!1),this.domElement.removeEventListener("mousedown",e,!1),this.domElement.removeEventListener("mousewheel",i,!1),this.domElement.removeEventListener("DOMMouseScroll",i,!1),this.domElement.removeEventListener("touchstart",j,!1),this.domElement.removeEventListener("touchend",l,!1),this.domElement.removeEventListener("touchmove",k,!1),document.removeEventListener("mousemove",f,!1),document.removeEventListener("mouseup",g,!1),document.removeEventListener("mouseout",g,!1),window.removeEventListener("keydown",c,!1),window.removeEventListener("keyup",d,!1)},this.domElement.addEventListener("contextmenu",m,!1),this.domElement.addEventListener("mousedown",e,!1),this.domElement.addEventListener("mousewheel",i,!1),this.domElement.addEventListener("DOMMouseScroll",i,!1),this.domElement.addEventListener("touchstart",j,!1),this.domElement.addEventListener("touchend",l,!1),this.domElement.addEventListener("touchmove",k,!1),window.addEventListener("keydown",c,!1),window.addEventListener("keyup",d,!1),this.handleResize(),this.update()},h.TrackballControls.prototype=Object.create(h.EventDispatcher.prototype),h.TrackballControls.prototype.constructor=h.TrackballControls;varh=window.THREE,f=window.TWEEN,l=e.utils.hsvToRgb,m=e.utils.rgbToHsv,n=function(a,b,c){c|=1;vard=-1,e=0,f=a.split(" ");f.length;for(varginf){if(g=parseInt(g),e+=f[g].length,d=g,e+g>b&&d>=c)break;d+=1}return[f.slice(0,d).join(" "),f.slice(d).join(" ")]},o=function(a,b){varc=parseInt(/([0-9]*)px/.exec(a)[1]);returnc+=parseInt(b),a.replace(/[0-9]+(.*)/,c+"$1")},p=function(a,b,d){if(c.isArray(d)&&3==d.length)style="rgb("+d.join(",")+")";elseif(c.isArray(d)&&2==d.length){style=a.createLinearGradient(-.5,-.5,.5,.5);for(vareind)style.addColorStop(e,d[e])}elseif("gradient:"==d.substring(0,9)){varf=newh.Color(d.substring(9)),g=m(f.r,f.g,f.b),i=l(g[0],g[1],60),j="rgb("+i.join(",")+")";style=a.createLinearGradient(-.5,-.5,.5,.5),style.addColorStop(0,j),style.addColorStop(1,f.getStyle())}elsestyle=d;a[b]=style},q=function(a,b){varc=[],d=[],e={},f="",g=[{form:a.label,css:".normal-font"}];if(a.format_label&&(g=a.format_label(b.textLength)),void0===g)return[];g.length&&(e=g[0],f+=e.form);for(varh=b.line_max_length;g.length||f.length;){vari=n(f,h,1),j=i[0],k=i[1];k||(k=""),!j.length&&k.length&&(j=k,k=""),h-=j.length,h<=0&&(0==c.length?d.length>0&&c.push(d):d.length>0&&c.push(d),d=[],h=b.line_max_length),j&&j.length&&d.push({form:j,css:e.css}),k.length&&j.length?(c.push(d),f=k,h=b.line_max_length,d=[]):k.length<=h?(k.length&&(d.push({form:k,css:e.css}),k="",h-=k.length),0===h&&(c.push(d),d=[],h=line_max_length),g.length&&g.shift(),g.length?(e=g[0],f=e.form):f=""):f=k}returnd.length&&c.push(d),c},r={Layout:{}};r.hexcolor=function(a){varb=c.map(a,function(a){returna/255});returnnewh.Color(b[0],b[1],b[2]).getHex()},r.csscolor=function(a){varb=c.map(a,function(a){returna/255});returnnewh.Color(b[0],b[1],b[2]).getStyle()},r.DEFAULTS={show_nodes:!0,show_edges:!0,show_text:!0,show_images:!0,background_color:11184810,user_font_size:3,user_vtx_size:1,initial_size:10,initial_z:1400,raycaster_precision:2,adaptive_zoom:!1,use_material_transitions:!0,force_position_no_delay:!1,node_material_transition_delay:100,edge_material_transition_delay:200,auto_rotate:!1,debug:!1},r.ThreeViz=d.View.extend({initialize:function(a){varb=this;attrs=c.extend({},r.DEFAULTS,a),attrs.el||(attrs.el="#vz_threejs_main"+Math.round(1e4*Math.random())),this.show_nodes=attrs.show_nodes,this.show_edges=attrs.show_edges,this.show_images=attrs.show_images,this.show_text=attrs.show_text,this.DISPLAY_EDGE_LABEL=attrs.DISPLAY_EDGE_LABEL||!0,this.DISPLAY_ARROW_INIT=attrs.DISPLAY_ARROW_INIT||!1,this.DISPLAY_ARROW_END=attrs.DISPLAY_ARROW_END||!1,this.AUTO_FOCUS=attrs.AUTO_FOCUS,this.ENABLE_FOG=attrs.ENABLE_FOG,this.auto_rotate=attrs.auto_rotate||!1,this.initial_size=attrs.initial_size,this.initial_z=attrs.initial_z,this.user_vtx_size=attrs.user_vtx_size,this.user_font_size=attrs.user_font_size,this.background_color=attrs.background_color,this.render_node=attrs.render_node||r.ThreeVizHelpers.render_node,this.wnode_scale=attrs.wnode_scale||r.ThreeVizHelpers.wnode_scale,this.raycaster_precision=attrs.raycaster_precision,this.force_position_no_delay=attrs.force_position_no_delay,this.edge_materials={},this.node_materials={},this.use_material_transitions=attrs.use_material_transitions,this.node_material_transition_delay=attrs.node_material_transition_delay,this.edge_material_transition_delay=attrs.edge_material_transition_delay;vard=function(a,d){c.each(a,function(a){vare=c.keys(a)[0];b.add_material(d,e,a[e])})};returnd(r.ThreeVizHelpers.edge_materials,"edge"),d(r.ThreeVizHelpers.node_materials,"node"),attrs.materials&&(attrs.materials.node&&d(attrs.materials.node,"node"),attrs.materials.edge&&d(attrs.materials.edge,"edge")),this.adaptive_zoom=attrs.adaptive_zoom,this.debug=attrs.debug,this._width=attrs.width||-1,this._height=attrs.height||-1,e.get(this,"width",function(){vara=b.$el.width();returna<=0&&(a=$(window).width()),b._width>0?b._width:a}),e.get(this,"height",function(){vara=b.$el.height();returna<=0&&(a=$(window).height()),b._height>0?b._height:a}),this.clear_color=newh.Color(attrs.background_color),this._inited=!1,this.wnodes=[],this.wedges=[],this.wnidx={},this.weidx={},this.WINDOWVISIBLE=!0,this.MOUSEDOWN=!1,this.MOUSEHASMOVED=!1,this.ANIMATE=!1,this.intersected=null,this.program_factory=function(a){varc=b.render_node;returnfunction(d){c(b,a,d)}},this},enable:function(){vara,b,d,f,g=this;newh.Vector2;a=newh.PerspectiveCamera(40,this.width/this.height,10,1e4),a.position.x=0,a.position.y=0,a.position.z=this.initial_z,d=newh.Scene,d.autoUpdate=!0,b=newh.TrackballControls(a,this.el),b.rotateSpeed=5,b.zoomSpeed=4,b.panSpeed=3,b.noZoom=!1,b.noPan=!1,b.staticMoving=!0,b.dynamicDampingFactor=.3,b.minDistance=50,b.autoRotateSpeed=.002,b.AUTO_ROTATE=this.auto_rotate,f=newr.GraphRenderer({antialias:!0}),f.sortObjects=!0,f.setSize(this.width,this.height),f.DISPLAY_EDGE=this.show_edges,f.DISPLAY_EDGE_LABEL=!0,f.DISPLAY_ARROW_INIT=!0,f.DISPLAY_ARROW_END=!0,f.ENABLE_FOG=!0,this.camera=a,this.controls=b,this.scene=d,this.renderer=f,this.changeFocusSpeed=1e3,this.changeCoordSpeed=800,this.fogDistance=800,c.bindAll(this,"animate","render","resize_rendering"),c.bindAll(this,"onMouseMove","onMouseUp","onMouseDown","onMouseOut","onDblClick"),this.listenTo(e.utils.asEvents(window),"focus",function(a){g.WINDOWVISIBLE=!0}),this.listenTo(e.utils.asEvents(window),"blur",function(a){g.WINDOWVISIBLE=!1}),this.listenTo(this.model,"change",function(){g.request_animation()}),this.listenTo(this.model.vs,"remove",function(a){g.stopListening(a,"change:coords")}),f.domElement.addEventListener("mousemove",this.onMouseMove,!1),f.domElement.addEventListener("mousedown",this.onMouseDown,!1),f.domElement.addEventListener("mouseout",this.onMouseOut,!1),f.domElement.addEventListener("mouseup",this.onMouseUp,!1),f.domElement.addEventListener("dblclick",this.onDblClick,!1);vari=function(a){g.request_animation(1e3)};f.domElement.addEventListener("mousewheel",i,!1),f.domElement.addEventListener("DOMMouseScroll",i,!1),f.domElement.addEventListener("touchstart",function(a){g.MOUSEDOWN=!0,g.request_animation()},!1),f.domElement.addEventListener("touchend",function(a){g.MOUSEDOWN=!1},!1);varj=f.domElement.className.split(" ").indexOf("pdg-renderer");returnj<0&&(this.renderer.domElement.className+=" pdg-renderer"),this.el.appendChild(f.domElement),(this._width<0||this._height<0)&&this.listenTo(e.utils.asEvents(window),"resize",this.resize_rendering),this.set_clear_color(this.clear_color.getStyle()),this.renderer=f,this._inited=!0,this},set_clear_color:function(a){varb=newh.Color(a);this.background_style=b.getStyle(),this.renderer.setClearColor(b.getHex()),$(this.renderer.domElement).css("background-color",b.getStyle()),this.clear_color=b},resize_rendering:function(){if(this._inited){vara=this.width,b=this.height;this.controls.handleResize(),this.camera.aspect=a/b,this.camera.updateProjectionMatrix(),this.renderer.setSize(a,b),this.request_animation()}},clean:function(){vara,b,d=this.scene.children,e=this.scene;for(b=d.length-1;b>=0;b--)a=d[b],c.has(a,"_type")&&e.remove(a);this.wnodes=[],this.wedges=[],this.wnidx={},this.weidx={}},append_node:function(a){varb=this,c=newh.Sprite;b.wnidx[a.id]=c,c.position=newh.Vector3(0,0,0),c.scale.x=c.scale.y=b.wnode_scale(a),c._type="vertex",c._node=a,c._edges=[],c.program_material=b.get_material(b.node_materials,a),c.material=newh.SpriteCanvasMaterial({program:b.program_factory(c)}),b.listenTo(a,"change:coords",function(){b.setPosition(c.position,a.get("coords"),this.changeCoordSpeed,f.Easing.Elastic.OutIn)}),b.listenTo(a,"change:color",function(){c.material_needs_update=!0,b.request_animation()}),b.listenTo(a,"rmflag",function(){c.material_needs_update=!0,b.request_animation()}),b.listenTo(a,"addflag",function(){c.material_needs_update=!0,b.request_animation()}),b.wnodes.push(c),b.scene.add(c)},remove_node:function(a){varb=this.wnidx[a.id];this.scene.remove(b),deletethis.wnidx[a.id],this.request_animation()},remove_edge:function(a){varb=this.weidx[a.id];this.scene.remove(b),deletethis.weidx[a.id],console.log("gviz remove edge",a),this.request_animation()},append_edge:function(a){if(!(a.idinthis.weidx)){varb=this,c=b.wnidx[a.source.id],d=b.wnidx[a.target.id];if(void0===c||void0===d)returnvoidconsole.log("edge without source or target");vare=newh.Geometry;e.vertices.push(c.position.clone()),e.vertices.push(d.position.clone());varg=f.Easing.Circular.In,i=newh.LineBasicMaterial({}),j=newh.Line(e,i);j._type="edge",j._edge=a,b.set_line_material(j),this.weidx[a.id]=j,b.scene.add(j);vark=function(){e.computeBoundingSphere(),b.set_line_material(j)};b.listenTo(a.source,"change:coords",function(){a.collection&&b.setPosition(e.vertices[0],a.source.get("coords"),this.changeCoordSpeed,g,k)}),b.listenTo(a.target,"change:coords",function(){a.collection&&b.setPosition(e.vertices[1],a.target.get("coords"),this.changeCoordSpeed,g,k)}),b.listenTo(a,"rmflag",function(a,c){b.set_line_material(j),b.request_animation()}),b.listenTo(a,"addflag",function(a,c,d){b.set_line_material(j),b.request_animation()})}},add_material:function(a,b,c){returnthis.set_material(a,b,c)},set_material:function(a,b,d){varf=["node","edge"];e.assert(c.indexOf(f,a)>-1,["Wrong material type",f]),e.log("GViz: Adding material",a,b),binthis[a+"_materials"]?c.extend(this[a+"_materials"][b],d):this[a+"_materials"][b]=d},set_materials:function(a,b){_this=this;vard=["node","edge"];e.assert(c.indexOf(d,a)>-1,["Wrong material type",d]),c.each(b,function(b){vard=c.keys(b)[0];_this.set_material(a,d,b[d])})},get_material:function(a,b){vard=b.flags||{},e=c.filter(c.keys(a),function(a){return"."==a.substring(0,1)}),f=c.extend({},a.default),g=!0;e=c.sortBy(e,function(a){returna.split(".").length}),c.each(e,function(b){for(css_classes=c(b.split(".")).rest(1),g=!0,i=0;i<css_classes.length;i++)if(!c(d).contains(css_classes[i])){g=!1;break}g&&(f=c.extend(f,a[b]))});for(kinf){varh=f[k];if(c.isString(h)&&"get:"==h.substring(0,4)){varj=h.substring(4);h=b.get(j)}elseif(c.isString(h)&&"prop:"==h.substring(0,5)){varj=h.substring(5);h=b.properties.get(j)}elseif(c.isFunction(h))try{h=h(b)}catch(a){h=0}f[k]=h}returnb.nodetype&&(f.text_lines=q(b,f)),null==f.shape&&(f.shape="circle"),f.id=b.id,f},set_node_material:function(a){varb=this.wnidx[a.id],c=this.get_material(this.node_materials,a),d={opacity:c.opacity,scale:c.scale,fontScale:c.fontScale};if(this.use_material_transitions&&this.node_material_transition_delay>0)c.opacity=b.program_material.opacity,c.scale=b.program_material.scale,c.fontScale=b.program_material.fontScale,tween=newf.Tween(c).to(d,this.node_material_transition_delay).start();elsefor(kind)c[k]=d[k];b.program_material=c,b.material_needs_update=!1},set_line_material:function(a){varb=a._edge;if(null!=b){vard,e=this.get_material(this.edge_materials,b),g=null;c.isArray(e.color)&&2==e.color.length?(d=[newh.Color(e.color[0]),newh.Color(e.color[1])],g=h.VertexColors):d=newh.Color(e.color),a.material.linecap=e.linecap,a.material.linejoin=e.linejoin,a.material.lineType=e.lineType,a.material.dashSize=e.dashSize,a.material.gapSize=e.gapSize,a.material.vertexColors=g,a.geometry.colors=d,a.material.color=d,a.material.label_visible=e.label_visible,a.material.font=e.font,a.material.fontFillStyle=e.fontFillStyle,a.material.textAlign=e.textAlign,a.material.orientation_visible=e.orientation_visible;vari={opacity:e.opacity,linewidth:e.lineWidth};if(this.use_material_transitions&&this.edge_material_transition_delay>0)tween=newf.Tween(a.material).to(i,this.edge_material_transition_delay).start();elsefor(kini)a.material[k]=i[k]}},setPosition:function(a,b,d,e,g){this.force_position_no_delay&&(d=0);varg=g||null,e=e||f.Easing.Circular.In,h={};if(c.isArray(b)?(3==b.length|b.push(0),h.x=1e3*b[0],h.y=1e3*b[1],h.z=1e3*b[2]):h=b,d)tween=newf.Tween(a).to(h,d).easing(e).onComplete(g).start();elsefor(kinh)a[k]=h[k]},increase_vertex_size:function(){this.user_vtx_size=Math.min(25,1.5*this.user_vtx_size),this.request_animation(100)},decrease_vertex_size:function(){this.user_vtx_size=Math.max(.1,this.user_vtx_size/1.5),this.request_animation(100)},increase_font_size:function(){this.user_font_size=Math.min(25,this.user_font_size+1),this.request_animation(100)},decrease_font_size:function(){this.user_font_size=Math.max(-5,this.user_font_size-1),this.request_animation(100)},collapse:function(a,b,c){if(this.scene.children.length>0){a|=0,c|=0;for(varb=b||f.Easing.Circular.In,d={x:0,y:0,z:0},e=0;e<this.wnodes.length;e++){varg=this.wnodes[e];this.setPosition(g.position,d,a,b,c)}for(vare=0;e<this.wedges.length;e++){varh=this.wedges[e];this.setPosition(h.geometry.vertices[0],d,a,b,c),this.setPosition(h.geometry.vertices[1],d,a,b,c)}this.request_animation()}},setFocus:function(a){null==a&&(a=newh.Vector3(0,0,0)),tween=newf.Tween(this.controls.target).to(a,this.changeFocusSpeed).start()},request_animation:function(a){if(a){this.ANIMATE=!0,this._animate_timeout_id&&(clearTimeout(this._animate_timeout_id),this._animate_timeout_id=null);varb=this;this._animate_timeout_id=setTimeout(function(){b.ANIMATE=!1},a)}this._timeout_id&&(clearTimeout(this._timeout_id),this._timeout_id=null,requestAnimationFrame(this.animate))},animate:function(){this.render();vara=f.getAll().length>0;if((this.ANIMATE||a||this.MOUSEDOWN||this.controls.AUTO_ROTATE)&&this.WINDOWVISIBLE)requestAnimationFrame(this.animate);else{varb=this;this._timeout_id=setTimeout(function(){requestAnimationFrame(b.animate)},5e3)}returnthis},render:function(){this.controls.update(),f.update();vara=this.renderer.domElement,b=a.getContext("2d");returnb.globalAlpha=1,b.fillStyle=this.background_style,b.fillRect(0,0,a.width,a.height),this.renderer.DISPLAY_EDGE=this.show_edges,this.renderer.DISPLAY_EDGE_LABEL=this.show_edges&&this.DISPLAY_EDGE_LABEL,this.renderer.DISPLAY_ARROW_INIT=this.show_edges&&this.DISPLAY_ARROW_INIT,this.renderer.DISPLAY_ARROW_END=this.show_edges&&this.DISPLAY_ARROW_END,this.renderer.ENABLE_FOG=this.ENABLE_FOG,this.renderer.render(this.scene,this.camera),this.renderClustersLabels(b),this.debug&&this.print_debug(),this},renderClustersLabels:function(a){if(this.clustering){varb=this;for(varcinthis.clustering.clusters.models){vard=this.clustering.clusters.models[c],e=d.members.vs.models,f=0,g={x:0,y:0,minX:1e5,maxX:0,minY:1e5,maxY:0};e.forEach(function(a,c){vard=b.wnidx[a.id];if(d&&!(d.screenX<0)){vare=d.screenX,h=d.screenY;f++,g.y+=h,g.x+=e,g.minX=Math.min(e,g.minX),g.maxX=Math.max(e,g.maxX)}});varh="Cluster "+c;if(d.labels||d.labels.length){vari=d.labels.map(function(a){returna.label});h=i.join(", ")}if(h.length){a.font=Math.min(25,14+f)+"px Arial",a.lineWidth=3;varj=a.measureText(h).width,k=a.measureText("M").width;g.y=g.y/f,1==f?g.x=g.x-j/2:g.x=g.minX+(g.maxX-g.minX-j)/2,a.beginPath(),a.rect(g.x-8,g.y-5-k,j+16,k+16),a.fillStyle="rgba(200,200,200, 0.5)",a.fill();varl="rgb("+d.color.join(",")+")";a.fillStyle=l,a.strokeStyle="#333",a.strokeText(h,g.x,g.y),a.fillText(h,g.x,g.y)}}}},print_debug:function(){vara=$(".gviz-debug",this.$el),b=$("<div></div>").append(["camera.x:"+this.camera.position.x+"<br/>","camera.y:"+this.camera.position.y+"<br/>","camera.z:"+this.camera.position.z+"<br/>","user_vtx_size:"+this.user_vtx_size+"<br/>","<br/>"]),c=this.intersected;if(c){vard=this.wnidx[c.id],e=c;b.append("<h3>"+c._type+"</h3>"),d?b.append("obj.id:"+e.get("id")+"<br/>").append("obj.x:"+d.position.x+"<br/>").append("obj.y:"+d.position.y+"<br/>").append("obj.z:"+d.position.z+"<br/>").append("<br/>").append("neighbors:"+e.get("neighbors")+"<br/>").append("<br/>").append("flags:"+e.get("flags")+"<br/>").append("<br/>").append("distance:"+e._distance+"<br/>").append("ratio:"+e._ratio+"<br/>").append("scale:"+this.wnode_scale(e)+"<br/>").append("wscale:"+d.scale.x+"<br/>").append("material scale:"+d.program_material.scale+"<br/>").append("font scale:"+d.program_material.fontScale+"<br/>").append("<br/>"):b.append("flags:"+c.get("flags")+"<br/>")}a.html(b)},getMouseOnCanvas:function(a,b){return{x:a.clientX-b.left,y:a.clientY-b.top}},onMouseMove:function(a){a.preventDefault(),this.MOUSEHASMOVED=!0;if(this.MOUSEDOWN===!1){varb=this.el.getBoundingClientRect(),c=this.getMouseOnCanvas(a,b),d={x:c.x/$("canvas",this.$el).width()*2-1,y:2*-(c.y/$("canvas",this.$el).height())+1},e=newh.Raycaster;e.linePrecision=this.raycaster_precision,e.setFromCamera(d,this.camera);varf=null,g=e.intersectObjects(this.scene.children);if(g.length>0){for(variing){varj=g[i].object;if(j.material&&0!=j.material.opacity&&j.visible){vark=j._type;if("vertex"==k){f=j._node,this.trigger("vertex:mouseover",f,a);break}if("edge"==k){f=j._edge,this.trigger("edge:mouseover",f,a);break}}}null==f&&this.trigger("intersectOff",this.intersected,a)}elsethis.trigger("intersectOff",this.intersected,a);this.intersected=f}},onMouseDown:function(a){a.preventDefault(),this.MOUSEDOWN=!0,this.MOUSEHASMOVED=!1,this.request_animation()},onMouseUp:function(a){a.preventDefault();varb=null;this.MOUSEHASMOVED===!1&&(this.intersectedinstanceofe.Edge?b="edge":this.intersectedinstanceofe.Vertex&&(b="vertex"),b&&this.trigger(b+":click",this.intersected,a),this.trigger("click",this.intersected,a)),this.MOUSEDOWN=!1},onMouseOut:function(a){a.preventDefault(),this.MOUSEDOWN=!1},onDblClick:function(a){d.trigger("dblclick",this.intersected,a);varb=null;this.intersectedinstanceofe.Edge?b="edge":this.intersectedinstanceofe.Vertex&&(b="vertex"),b?this.trigger(b+":dblclick",this.intersected,a):this.controls.AUTO_ROTATE=!this.controls.AUTO_ROTATE}}),r.ThreeVizHelpers={PI2:2*Math.PI,SPLIT_LABEL_RE:/^(.{4,15})(.*)/m,to_color:function(a){if(c.isArray(a))returnnewh.Color(a[0],a[1],a[2])},meanColor:function(){vara=g=b=0;for(varcinarguments){vard=arguments[c];a+=d.r,g+=d.g,b+=d.b}returnmean=newh.Color,mean.r=a/arguments.length,mean.g=g/arguments.length,mean.b=b/arguments.length,mean},wnode_scale:function(a){varb=a.get("SIZE");returnthis.user_vtx_size*b},render_node:function(a,b,d){vare=a,f=b._node;b.material_needs_update&&a.set_node_material(f);varg=b.program_material;if(g.opacity&&g.visible){if(d.globalAlpha=g.opacity,a.ENABLE_FOG&&null==f.flags[1]){varh=b.position.clone();h.add(a.camera.position),a.camera.worldToLocal(h);vari=1;i*=h.z>=-1?1:Math.exp(h.z/e.fogDistance),d.globalAlpha=g.opacity*i}varj=a.wnode_scale(f);if(a.adaptive_zoom){vark=a.camera.position.distanceTo(b.position),l=0==k?1:k/1e3,m=j/10,n=1*j;j=m+(n-m)*l,f._scale=j}if(b.scale.x!=j&&(b.scale.x=j,b.scale.y=j),d.scale(1,-1),d.save(),a.show_nodes){varq=/^(rect:)([0-9\/.]+),([0-9\/.]+)/,s=null,t=g.scale,u=t,v=t;if(d.scale(t,t),f._scale*=t,"circle"==g.shape)d.beginPath(),d.arc(0,0,1,0,r.ThreeVizHelpers.PI2,!0),d.closePath();elseif("square"==g.shape)d.beginPath(),d.moveTo(-1,-1),d.lineTo(-1,1),d.lineTo(1,1),d.lineTo(1,-1),d.lineTo(-1,-1),d.closePath();elseif("losange"==g.shape||"diamond"==g.shape)d.beginPath(),d.moveTo(0,-1),d.lineTo(-1,0),d.lineTo(0,1),d.lineTo(1,0),d.closePath();elseif("triangle"==g.shape||"triangle-top"==g.shape)d.beginPath(),d.moveTo(0,-1),d.lineTo(-1,1),d.lineTo(1,1),d.closePath();elseif("triangle-bottom"==g.shape)d.beginPath(),d.moveTo(0,1),d.lineTo(-1,-1),d.lineTo(1,-1),d.closePath();elseif(null!=(s=q.exec(g.shape))){varw=u=s[2],x=v=s[3];d.beginPath(),d.moveTo(-w,-x),d.lineTo(-w,x),d.lineTo(w,x),d.lineTo(w,-x),d.lineTo(-w,-x),d.closePath()}if(g.fillStyle&&(p(d,"fillStyle",g.fillStyle),d.fill()),a.show_images&&g.image){vary=document.getElementById("img"+g.id);y&&y.width&&(d.clip(),d.drawImage(y,-u,-v,2*u,2*v))}g.lineWidth>0&&g.strokeStyle&&(d.lineWidth=g.lineWidth,p(d,"strokeStyle",g.strokeStyle),d.stroke())}if(d.restore(),a.show_text){d.save();varz=g.text_lines;for(varAinz){d.save();varB=0,C=0,D=0,E=0|g.textPaddingX,F=0|g.textPaddingY,G=0,H=1;c.each(z[A],function(b){varf=e.node_materials[b.css].font;f=o(f,a.user_font_size),d.font=f,H=c.max([H,parseInt(/([0-9]*)px/.exec(f)[1])]),D+=d.measureText(b.form).width}),C="center"==g.textVerticalAlign?1:"bottom"==g.textVerticalAlign?0:.5,"left"==g.textAlign?(d.translate(1*g.scale,0),B=0+G):"right"==g.textAlign?(d.translate(-1*g.scale,0),B=-D+G):(d.translate(0,1),B=D/-2+G),d.scale(g.fontScale,g.fontScale);varI=z[0][0],J=e.node_materials[I.css],K=0|J.paddingRelX,L=(0|J.paddingRelY,o(J.font,a.user_font_size)),H=parseInt(/([0-9]*)px/.exec(L)[1]);d.font=L;varM=d.measureText("M").width;C=C-(z.length-1)*M/2+A*M,c.each(z[A],function(a,b){varc=B+E+K,e=C-F;J.fontFillStyle&&(p(d,"fillStyle",J.fontFillStyle),d.fillText(a.form,c,e)),J.fontStrokeStyle&&J.fontStrokeWidth&&(p(d,"strokeStyle",J.fontStrokeStyle),d.lineWidth=J.fontStrokeWidth,d.strokeText(a.form,c,e));varf=d.measureText(a.form).width;B+=f}),d.restore()}d.restore()}}},edge_materials:[{default:{lineWidth:2,linecap:"butt",linejoin:"bevel",lineType:"plain",dashSize:2,gapSize:5,opacity:.61,color:function(a){return[r.hexcolor(a.source.get("color")),r.hexcolor(a.target.get("color"))]},label_visible:!1,font:"normal 12px Arial",fontFillStyle:"#4C4D00",textAlign:"center",orientation_visible:!1}}],node_materials:[{default:{visible:!0,scale:1,z:1,opacity:1,line_max_length:15,shape:"circle",image:"prop:image",fillStyle:function(a){return"gradient:"+r.csscolor(a.get("color"))},strokeStyle:function(a){return"gradient:"+r.csscolor(a.get("color"))},lineWidth:.1,textLength:20,textAlign:"center",textVerticalAlign:"center",fontScale:.1,font:"normal 10px Arial",fontFillStyle:"#333",fontStrokeStyle:"#333",fontStrokeWidth:.1,paddingRelY:0,paddingRelX:2}},{".normal-font":{font:"normal 10px Arial",fontFillStyle:"#333",fontStrokeStyle:"#333",fontStrokeWidth:.1,paddingRelY:0,paddingRelX:2}}]};vars=r;returns.SimpleViz=function(a,b){b.model=a;vare=news.ThreeViz(b);returne.on("click",function(a,b){null==a&&(d.trigger(j.unselect_nodes),d.trigger(j.unselect_edges),e.AUTO_FOCUS&&e.setFocus())}),e.on("vertex:click",function(b,c){if(b&&b.id&&b.has_flag&&0==b.has_flag("disabled")){vare=a.vs.by_flag("selected");1==e.length&&c.ctrlKey&&d.trigger(j.ui_create_edge,{source:e[0],target:b}),d.trigger(j.select_node,b)}}),e.on("vertex:mouseover",function(a,b){a&&a.id&&a.has_flag&&0==a.has_flag("disabled")&&d.trigger("vertex:mouseover",a,b)}),e.on("vertex:dblclick",function(a,b){a&&a.id&&a.has_flag&&0==a.has_flag("disabled")&&d.trigger("engine:expand_prox",{nodes:[a.id],weights:[1]})}),e.on("edge:mouseover",function(a,b){a&&a.id&&a.has_flag&&0==a.has_flag("disabled")&&d.trigger("edge:mouseover",a,b)}),e.on("edge:click",function(a,b){console.log("edge:click",a,b),a&&a.id&&a.has_flag&&0==a.has_flag("disabled")&&d.trigger(j.select_edge,a,b)}),e.on("dblclick",function(a,b){console.log("dblclick",a,b)}),e.on("intersectOff",function(b,c){b&&b.id&&b.has_flag&&0==b.has_flag("disabled")&&(a.es.remove_flag("intersected"),a.vs.remove_flag("intersected"),b.edgetype&&d.trigger("edge:mouseout",b,c),b.nodetype&&d.trigger("vertex:mouseout",b,c),e.request_animation())}),d.listenTo(d,"vertex:mouseout",function(a,b){a&&a.id&&a.remove_flag("intersected")}),d.listenTo(d,"vertex:mouseover",function(b,c){b&&b.id&&(a.vs.set_intersected(null!==b?b:[]),a.es.set_intersected(b.incident(4,!1)),b.has_flag("selected")&&(this.vertex_menu=b),e.request_animation())}),d.listenTo(d,"engine:request_animation",function(){e.request_animation()}),d.listenTo(d,"edge:mouseover",function(b,c){b&&b.id&&(a.vs.set_intersected([]),a.es.set_intersected(null!==b?b:[]))}),d.listenTo(d,"edge:mouseout",function(a,b){a&&a.id&&a.remove_flag("intersected")}),e.listenTo(a.vs,"reset",function(){console.log("padagraph-gviz","vs reset"),e.collapse(500),e.clean(),e.camera.position.x=0,e.camera.position.y=0,e.camera.position.z=e.initial_z,e.camera.lookAt(newh.Vector3(0,0,0))}),e.listenTo(a.es,"add",function(a){e.append_edge(a),e.listenTo(a,"addflag:selected",function(){a.add_flag("es-bolder",{silent:!0}),a.add_flag("es-mo-adjacent")}),e.listenTo(a,"rmflag:selected",function(){a.remove_flag("es-bolder",{silent:!0}),a.remove_flag("es-mo-adjacent")}),e.listenTo(a,"addflag:intersected",function(){a.add_flag("es-bolder")}),e.listenTo(a,"rmflag:intersected",function(){
a.remove_flag("es-bolder")})}),e.listenTo(a.es,"remove",function(a,b){a.remove_flag("intersected",{silent:!0}),a.remove_flag("selected",{silent:!0}),a.remove_flag("disabled"),e.remove_edge(a)}.bind(this)),e.listenTo(a.vs,"remove",function(a){a.remove_flag("intersected",{silent:!0}),a.remove_flag("selected",{silent:!0}),a.remove_flag("disabled"),e.remove_node(a)}.bind(this)),e.listenTo(a.vs,"add",function(b){_size=function(a){returna.get("properties").has("size")?parseFloat(a.get("properties").get("size")):1};vard=c.map(a.vs.models,_size).sort();d=d[d.length/2|1],c.each(a.vs.models,function(a){a.set("SIZE",9*(_size(a)/d))}),e.append_node(b),e.listenTo(b,"addflag:intersected",function(){vard=b.neighbors();d.push(b),a.vs.add_flag("mo-faded",c(a.vs.models).difference(d)),a.vs.add_flag("mo-adjacent",c(d).without(b));varf=a.incident(b);a.es.add_flag("es-mo-adjacent",f,!1),a.es.add_flag("es-mo-faded",c.difference(a.es.models,f),!1),e.request_animation()}),e.listenTo(b,"rmflag:intersected",function(){a.vs.remove_flag("mo-faded",a.vs.models),a.vs.remove_flag("mo-adjacent"),a.es.remove_flag("es-mo-adjacent",a.es.models),a.es.remove_flag("es-mo-faded"),a.es.remove_flag("es-bolder"),e.request_animation()}),e.listenTo(b,"addflag:selected",function(d){d.collection.remove_flag("selected",c(a.vs.models).without(d));varf=b.neighbors();d.collection.add_flag("sel-faded",c(a.vs.models).difference(f)),d.collection.add_flag("sel-adjacent",c(f).without(d));varg=a.incident(d);a.es.add_flag("es-bolder",g,{silent:!0}),a.es.add_flag("es-sel-adjacent",g,{silent:!0}),a.es.add_flag("es-sel-faded",c(a.es.models).difference(g)),e.request_animation()}),a.listenTo(b,"rmflag:selected",function(b){a.vs.remove_flag("mo-faded"),a.vs.remove_flag("sel-faded"),a.vs.remove_flag("sel-adjacent"),a.es.remove_flag("es-bolder"),a.es.remove_flag("es-sel-adjacent"),a.es.remove_flag("es-sel-faded"),a.es.remove_flag("es-mo-faded")})}.bind(this)),e},h.RenderableObject=function(){this.id=0,this.object=null,this.z=0,this.renderOrder=0},h.RenderableFace=function(){this.id=0,this.v1=newh.RenderableVertex,this.v2=newh.RenderableVertex,this.v3=newh.RenderableVertex,this.normalModel=newh.Vector3,this.vertexNormalsModel=[newh.Vector3,newh.Vector3,newh.Vector3],this.vertexNormalsLength=0,this.color=newh.Color,this.material=null,this.uvs=[newh.Vector2,newh.Vector2,newh.Vector2],this.z=0,this.renderOrder=0},h.RenderableVertex=function(){this.position=newh.Vector3,this.positionWorld=newh.Vector3,this.positionScreen=newh.Vector4,this.visible=!0},h.RenderableVertex.prototype.copy=function(a){this.positionWorld.copy(a.positionWorld),this.positionScreen.copy(a.positionScreen)},h.RenderableLine=function(){this.id=0,this.v1=newh.RenderableVertex,this.v2=newh.RenderableVertex,this.vertexColors=[newh.Color,newh.Color],this.material=null,this.z=0,this.renderOrder=0},h.RenderableSprite=function(){this.id=0,this.object=null,this.x=0,this.y=0,this.z=0,this.rotation=0,this.scale=newh.Vector2,this.material=null,this.renderOrder=0},h.Projector=function(){functiona(){if(j===u){vara=newh.RenderableObject;returnt.push(a),u++,j++,a}returnt[j++]}functionb(){if(l===w){vara=newh.RenderableVertex;returnv.push(a),w++,l++,a}returnv[l++]}functionc(){if(n===y){vara=newh.RenderableFace;returnx.push(a),y++,n++,a}returnx[n++]}functiond(){if(p===A){vara=newh.RenderableLine;returnz.push(a),A++,p++,a}returnz[p++]}functione(){if(r===C){vara=newh.RenderableSprite;returnB.push(a),C++,r++,a}returnB[r++]}functionf(a,b){returna.renderOrder!==b.renderOrder?a.renderOrder-b.renderOrder:a.z!==b.z?b.z-a.z:a.id!==b.id?a.id-b.id:0}functiong(a,b){varc=0,d=1,e=a.z+a.w,f=b.z+b.w,g=-a.z+a.w,h=-b.z+b.w;returne>=0&&f>=0&&g>=0&&h>=0||!(e<0&&f<0||g<0&&h<0)&&(e<0?c=Math.max(c,e/(e-f)):f<0&&(d=Math.min(d,e/(e-f))),g<0?c=Math.max(c,g/(g-h)):h<0&&(d=Math.min(d,g/(g-h))),!(d<c)&&(a.lerp(b,c),b.lerp(a,1-d),!0))}vari,j,k,l,m,n,o,p,q,r,s,t=[],u=0,v=[],w=0,x=[],y=0,z=[],A=0,B=[],C=0,D={objects:[],lights:[],elements:[]},E=newh.Vector3,F=newh.Vector4,G=newh.Box3(newh.Vector3(-1,-1,-1),newh.Vector3(1,1,1)),H=newh.Box3,I=newArray(3),J=(newArray(4),newh.Matrix4),K=newh.Matrix4,L=newh.Matrix4,M=newh.Matrix3,N=newh.Frustum,O=newh.Vector4,P=newh.Vector4;this.projectVector=function(a,b){console.warn("THREE.Projector: .projectVector() is now vector.project()."),a.project(b)},this.unprojectVector=function(a,b){console.warn("THREE.Projector: .unprojectVector() is now vector.unproject()."),a.unproject(b)},this.pickingRay=function(a,b){console.error("THREE.Projector: .pickingRay() is now raycaster.setFromCamera().")};varQ=function(){vara=[],e=[],f=null,g=null,i=newh.Matrix3,j=function(b){f=b,g=f.material,i.getNormalMatrix(f.matrixWorld),a.length=0,e.length=0},l=function(a){varb=a.position,c=a.positionWorld,d=a.positionScreen;c.copy(b).applyMatrix4(s),d.copy(c).applyMatrix4(K);vare=1/d.w;d.x*=e,d.y*=e,d.z*=e,a.visible=d.x>=-1&&d.x<=1&&d.y>=-1&&d.y<=1&&d.z>=-1&&d.z<=1},n=function(a,c,d){k=b(),k.position.set(a,c,d),l(k)},p=function(b,c,d){a.push(b,c,d)},q=function(a,b){e.push(a,b)},r=function(a,b,c){returna.visible===!0||b.visible===!0||c.visible===!0||(I[0]=a.positionScreen,I[1]=b.positionScreen,I[2]=c.positionScreen,G.isIntersectionBox(H.setFromPoints(I)))},t=function(a,b,c){return(c.positionScreen.x-a.positionScreen.x)*(b.positionScreen.y-a.positionScreen.y)-(c.positionScreen.y-a.positionScreen.y)*(b.positionScreen.x-a.positionScreen.x)<0},u=function(a,b){varc=v[a],e=v[b];o=d(),o.id=f.id,o.v1.copy(c),o.v2.copy(e),o.z=(c.positionScreen.z+e.positionScreen.z)/2,o.renderOrder=f.renderOrder,o.material=f.material,D.elements.push(o)},w=function(b,d,j){vark=v[b],l=v[d],n=v[j];if(r(k,l,n)!==!1&&(g.side===h.DoubleSide||t(k,l,n)===!0)){m=c(),m.id=f.id,m.v1.copy(k),m.v2.copy(l),m.v3.copy(n),m.z=(k.positionScreen.z+l.positionScreen.z+n.positionScreen.z)/3,m.renderOrder=f.renderOrder,m.normalModel.fromArray(a,3*b),m.normalModel.applyMatrix3(i).normalize();for(varo=0;o<3;o++){varp=m.vertexNormalsModel[o];p.fromArray(a,3*arguments[o]),p.applyMatrix3(i).normalize();varq=m.uvs[o];q.fromArray(e,2*arguments[o])}m.vertexNormalsLength=3,m.material=f.material,D.elements.push(m)}};return{setObject:j,projectVertex:l,checkTriangleVisibility:r,checkBackfaceCulling:t,pushVertex:n,pushNormal:p,pushUv:q,pushLine:u,pushTriangle:w}},R=newQ;this.projectScene=function(k,t,u,w){n=0,p=0,r=0,D.elements.length=0,k.autoUpdate===!0&&k.updateMatrixWorld(),null===t.parent&&t.updateMatrixWorld(),J.copy(t.matrixWorldInverse.getInverse(t.matrixWorld)),K.multiplyMatrices(t.projectionMatrix,J),N.setFromMatrix(K),j=0,D.objects.length=0,D.lights.length=0,k.traverseVisible(function(b){if(binstanceofh.Light)D.lights.push(b);elseif(binstanceofh.Mesh||binstanceofh.Line||binstanceofh.Sprite){varc=b.material;if(c.visible===!1)return;b.frustumCulled!==!1&&N.intersectsObject(b)!==!0||(i=a(),i.id=b.id,i.object=b,E.setFromMatrixPosition(b.matrixWorld),E.applyProjection(K),i.z=E.z,i.renderOrder=b.renderOrder,D.objects.push(i))}}),u===!0&&D.objects.sort(f);for(varx=0,y=D.objects.length;x<y;x++){varz=D.objects[x].object,A=z.geometry;if(R.setObject(z),s=z.matrixWorld,l=0,zinstanceofh.Mesh){if(Ainstanceofh.BufferGeometry){varB=A.attributes,C=A.groups;if(void0===B.position)continue;for(varG=B.position.array,H=0,I=G.length;H<I;H+=3)R.pushVertex(G[H],G[H+1],G[H+2]);if(void0!==B.normal)for(varQ=B.normal.array,H=0,I=Q.length;H<I;H+=3)R.pushNormal(Q[H],Q[H+1],Q[H+2]);if(void0!==B.uv)for(varS=B.uv.array,H=0,I=S.length;H<I;H+=2)R.pushUv(S[H],S[H+1]);if(null!==A.index){varT=A.index.array;if(C.length>0)for(varx=0;x<C.length;x++)for(varU=C[x],H=U.start,I=U.start+U.count;H<I;H+=3)R.pushTriangle(T[H],T[H+1],T[H+2]);elsefor(varH=0,I=T.length;H<I;H+=3)R.pushTriangle(T[H],T[H+1],T[H+2])}elsefor(varH=0,I=G.length/3;H<I;H+=3)R.pushTriangle(H,H+1,H+2)}elseif(Ainstanceofh.Geometry){varV=A.vertices,W=A.faces,X=A.faceVertexUvs[0];M.getNormalMatrix(s);for(varY=z.material,Z=Yinstanceofh.MeshFaceMaterial,$=Z===!0?z.material:null,_=0,aa=V.length;_<aa;_++){varba=V[_];if(E.copy(ba),Y.morphTargets===!0)for(varca=A.morphTargets,da=z.morphTargetInfluences,ea=0,fa=ca.length;ea<fa;ea++){varga=da[ea];if(0!==ga){varha=ca[ea],ia=ha.vertices[_];E.x+=(ia.x-ba.x)*ga,E.y+=(ia.y-ba.y)*ga,E.z+=(ia.z-ba.z)*ga}}R.pushVertex(E.x,E.y,E.z)}for(varja=0,ka=W.length;ja<ka;ja++){varla=W[ja];if(Y=Z===!0?$.materials[la.materialIndex]:z.material,void0!==Y){varma=Y.side,na=v[la.a],oa=v[la.b],pa=v[la.c];if(R.checkTriangleVisibility(na,oa,pa)!==!1){varqa=R.checkBackfaceCulling(na,oa,pa);if(ma!==h.DoubleSide){if(ma===h.FrontSide&&qa===!1)continue;if(ma===h.BackSide&&qa===!0)continue}m=c(),m.id=z.id,m.v1.copy(na),m.v2.copy(oa),m.v3.copy(pa),m.normalModel.copy(la.normal),qa!==!1||ma!==h.BackSide&&ma!==h.DoubleSide||m.normalModel.negate(),m.normalModel.applyMatrix3(M).normalize();for(varra=la.vertexNormals,sa=0,ta=Math.min(ra.length,3);sa<ta;sa++){varua=m.vertexNormalsModel[sa];ua.copy(ra[sa]),qa!==!1||ma!==h.BackSide&&ma!==h.DoubleSide||ua.negate(),ua.applyMatrix3(M).normalize()}m.vertexNormalsLength=ra.length;varva=X[ja];if(void0!==va)for(varwa=0;wa<3;wa++)m.uvs[wa].copy(va[wa]);m.color=la.color,m.material=Y,m.z=(na.positionScreen.z+oa.positionScreen.z+pa.positionScreen.z)/3,m.renderOrder=z.renderOrder,D.elements.push(m)}}}}}elseif(zinstanceofh.Line){if(Ainstanceofh.BufferGeometry){varB=A.attributes;if(void0!==B.position){for(varG=B.position.array,H=0,I=G.length;H<I;H+=3)R.pushVertex(G[H],G[H+1],G[H+2]);if(null!==A.index)for(varT=A.index.array,H=0,I=T.length;H<I;H+=2)R.pushLine(T[H],T[H+1]);elsefor(varxa=zinstanceofh.LineSegments?2:1,H=0,I=G.length/3-1;H<I;H+=xa)R.pushLine(H,H+1)}}elseif(Ainstanceofh.Geometry){L.multiplyMatrices(K,s);varV=z.geometry.vertices;if(0===V.length)continue;na=b(),na.positionScreen.copy(V[0]).applyMatrix4(L);for(varxa=zinstanceofh.LineSegments?2:1,_=1,aa=V.length;_<aa;_++)na=b(),na.positionScreen.copy(V[_]).applyMatrix4(L),(_+1)%xa>0||(oa=v[l-2],O.copy(na.positionScreen),P.copy(oa.positionScreen),g(O,P)===!0&&(O.multiplyScalar(1/O.w),P.multiplyScalar(1/P.w),o=d(),o.id=z.id,o.v1.positionScreen.copy(O),o.v2.positionScreen.copy(P),o.z=Math.max(O.z,P.z),o.renderOrder=z.renderOrder,o.material=z.material,o.object=z,z.material.vertexColors===h.VertexColors&&(o.vertexColors[0].copy(z.geometry.colors[_]),o.vertexColors[1].copy(z.geometry.colors[_-1])),D.elements.push(o)))}}elseif(zinstanceofh.Sprite){F.set(s.elements[12],s.elements[13],s.elements[14],1),F.applyMatrix4(K);varya=1/F.w;F.z*=ya,F.z>=-1&&F.z<=1&&(q=e(),q.id=z.id,q.x=F.x*ya,q.y=F.y*ya,q.z=F.z,q.renderOrder=z.renderOrder,q.object=z,q.rotation=z.rotation,q.scale.x=z.scale.x*Math.abs(q.x-(F.x+t.projectionMatrix.elements[0])/(F.w+t.projectionMatrix.elements[12])),q.scale.y=z.scale.y*Math.abs(q.y-(F.y+t.projectionMatrix.elements[5])/(F.w+t.projectionMatrix.elements[13])),q.material=z.material,D.elements.push(q))}}returnw===!0&&D.elements.sort(f),D}},h.SpriteCanvasMaterial=function(a){h.Material.call(this),this.type="SpriteCanvasMaterial",this.color=newh.Color(16777215),this.program=function(a,b){},this.setValues(a)},h.SpriteCanvasMaterial.prototype=Object.create(h.Material.prototype),h.SpriteCanvasMaterial.prototype.constructor=h.SpriteCanvasMaterial,h.SpriteCanvasMaterial.prototype.clone=function(){vara=newh.SpriteCanvasMaterial;returna.copy(this),a.color.copy(this.color),a.program=this.program,a},r.GraphRenderer=function(a){functionb(a,b,c){i(c.opacity),j(c.blending);vard=b.scale.x*H,g=b.scale.y*I,k=.5*Math.sqrt(d*d+g*g);if(W.min.set(a.x-k,a.y-k),W.max.set(a.x+k,a.y+k),cinstanceofh.SpriteMaterial||cinstanceofh.ParticleSystemMaterial){varl=c.map;if(null!==l){l.hasEventListener("update",e)===!1&&(void0!==l.image&&l.image.width>0&&f(l),l.addEventListener("update",e));varm=T[l.id];o(void0!==m?m:"rgba( 0, 0, 0, 1 )");varp=l.image,q=p.width*l.offset.x,r=p.height*l.offset.y,s=p.width*l.repeat.x,t=p.height*l.repeat.y,u=d/s,v=g/t;J.save(),J.translate(a.x,a.y),0!==c.rotation&&J.rotate(c.rotation),J.translate(-d/2,-g/2),J.scale(u,v),J.translate(-q,-r),J.fillRect(q,r,s,t),J.restore()}elseo(c.color.getStyle()),J.save(),J.translate(a.x,a.y),0!==c.rotation&&J.rotate(c.rotation),J.scale(d,-g),J.fillRect(-.5,-.5,1,1),J.restore()}elsecinstanceofh.SpriteCanvasMaterial&&(n(c.color.getStyle()),o(c.color.getStyle()),J.save(),J.translate(a.x,a.y),0!==c.rotation&&J.rotate(c.rotation),J.scale(d,g),c.program(J),J.restore())}functionc(a,b,c,e){if(i(e.opacity),j(e.blending),k(e.linewidth),l(e.linecap),m(e.linejoin),0!=C.DISPLAY_EDGE&&0!=e.opacity){varf=c.object._edge.source,g=c.object._edge.target;if(f&&g){varo=b.positionScreen.x-a.positionScreen.x,p=b.positionScreen.y-a.positionScreen.y;if(0!=o||0!=p){varq=a.positionScreen.x,r=b.positionScreen.x,s=a.positionScreen.y,t=b.positionScreen.y,u=q<r,v=Math.sqrt(Math.pow(o,2)+Math.pow(p,2)),w=Math.atan((t-s)/(r-q));q==r?t-s>0?w+=Math.PI/2:t<s&&(w-=Math.PI/2):q>r&&(w+=Math.PI),J.save(),J.translate(a.positionScreen.x,a.positionScreen.y+5),J.rotate(w),J.scale(1,-1);e.opacity;if(e.vertexColors!==h.VertexColors)J.strokeStyle=e.color.getStyle();else{varx=c.vertexColors[0].getStyle(),y=c.vertexColors[1].getStyle();if(x===y)J.strokeStyle=x;else{try{varz=J.createLinearGradient(0,0,v,0);z.addColorStop(0,x),z.addColorStop(1,y)}catch(a){z=x}J.strokeStyle=z}}"dashed"==e.lineType?J.setLineDash([e.dashSize,e.gapSize]):J.setLineDash([]),J.beginPath(),J.moveTo(0,0),J.lineTo(v,0),J.closePath(),J.stroke(),W.expandByScalar(2*e.linewidth),J.setLineDash([]);varA="";J.translate(v/2,0),C.DISPLAY_EDGE_LABEL&&e.label_visible&&(J.save(),A=c.object._edge.label,A||(A=u?g.label+" <--- "+f.label:f.label+" ---> "+g.label),u||J.scale(-1,-1),J.textAlign=e.textAlign,J.font=e.font,J.fillStyle=e.fontFillStyle,J.fillText(A,0,-2),J.restore());varB=3;if(C.DISPLAY_ARROW_END&&e.orientation_visible){varD=1.6*(g._scale/g._distance*1e3+B);J.save(),J.translate(-v/2+D,0),J.scale(-B,-B),n(y),d(0,.5,0,-.5,1,0),J.stroke(),J.restore()}if(C.DISPLAY_ARROW_INIT&&e.orientation_visible){varD=1.6*(f._scale/f._distance*1e3+B)+5;J.save(),J.translate(v/2-D,0),J.scale(-B,-B),n(x),d(0,.5,0,-.5,1,0),J.stroke(),J.restore()}J.restore()}}}}functiond(a,b,c,d,e,f){J.beginPath(),J.moveTo(a,b),J.lineTo(c,d),J.lineTo(e,f),J.closePath()}functione(a){f(a.target)}functionf(a){varb=a.wrapS===h.RepeatWrapping,c=a.wrapT===h.RepeatWrapping,d=a.image,e=document.createElement("canvas");e.width=d.width,e.height=d.height;varf=e.getContext("2d");f.setTransform(1,0,0,-1,0,d.height),f.drawImage(d,0,0),T[a.id]=J.createPattern(e,b===!0&&c===!0?"repeat":b===!0&&c===!1?"repeat-x":b===!1&&c===!0?"repeat-y":"no-repeat")}functiong(a,b,c){vard,e=b.x-a.x,f=b.y-a.y,g=e*e+f*f;0!==g&&(d=c/Math.sqrt(g),e*=d,f*=d,b.x+=e,b.y+=f,a.x-=e,a.y-=f)}functioni(a){M!==a&&(J.globalAlpha=a,M=a)}functionj(a){N!==a&&(a===h.NormalBlending?J.globalCompositeOperation="source-over":a===h.AdditiveBlending?J.globalCompositeOperation="lighter":a===h.SubtractiveBlending&&(J.globalCompositeOperation="darker"),N=a)}functionk(a){Q!==a&&(J.lineWidth=a,Q=a)}functionl(a){R!==a&&(J.lineCap=a,R=a)}functionm(a){S!==a&&(J.lineJoin=a,S=a)}functionn(a){O!==a&&(J.strokeStyle=a,O=a)}functiono(a){P!==a&&(J.fillStyle=a,P=a)}console.log("gviz.CanvasRenderer based on THREE ",h.REVISION);h.Math.smoothstep;a=a||{};varp,q,r,s,t,u,v,w,x,y,z,A,B,C=this,D=newh.Projector,E=void0!==a.canvas?a.canvas:document.createElement("canvas"),F=E.width,G=E.height,H=Math.floor(F/2),I=Math.floor(G/2),J=E.getContext("2d",{alpha:a.alpha===!0}),K=newh.Color(0),L=0,M=1,N=0,O=null,P=null,Q=null,R=null,S=null,T=(newh.RenderableVertex,newh.RenderableVertex,newh.Color,newh.Color,newh.Color,newh.Color,newh.Color,newh.Color,newh.Color,newh.Color,{}),U=newh.Box2,V=newh.Box2,W=newh.Box2,X=(newh.Color,newh.Color,newh.Color,newh.Vector3,newh.Vector3,newh.Matrix3),Y=16;w=document.createElement("canvas"),w.width=w.height=2,x=w.getContext("2d"),x.fillStyle="rgba(0,0,0,1)",x.fillRect(0,0,2,2),y=x.getImageData(0,0,2,2),z=y.data,A=document.createElement("canvas"),A.width=A.height=Y,B=A.getContext("2d"),B.translate(-Y/2,-Y/2),B.scale(Y,Y),Y--,this.DISPLAY_EDGE=!0,this.DISPLAY_EDGE_LABEL=!0,this.DISPLAY_ARROW_INIT=!0,this.DISPLAY_ARROW_END=!0,this.ENABLE_FOG=!0,void0===J.setLineDash&&(void0!==J.mozDash?J.setLineDash=function(a){J.mozDash=null!==a[0]?a:null}:J.setLineDash=function(){}),this.domElement=E,this.devicePixelRatio=void0!==a.devicePixelRatio?a.devicePixelRatio:void0!==self.devicePixelRatio?self.devicePixelRatio:1,this.autoClear=!0,this.sortObjects=!0,this.sortElements=!0,this.info={render:{vertices:0,faces:0}},this.supportsVertexTextures=function(){},this.setFaceCulling=function(){},this.setSize=function(a,b,c){F=a*this.devicePixelRatio,G=b*this.devicePixelRatio,H=Math.floor(F/2),I=Math.floor(G/2),E.width=F,E.height=G,1!==this.devicePixelRatio&&c!==!1&&(E.style.width=a+"px",E.style.height=b+"px"),U.min.set(-H,-I),U.max.set(H,I),V.min.set(-H,-I),V.max.set(H,I),M=1,N=0,O=null,P=null,Q=null,R=null,S=null},this.setClearColor=function(a,b){K.set(a),L=void0!==b?b:1,V.min.set(-H,-I),V.max.set(H,I)},this.setClearColorHex=function(a,b){console.warn("DEPRECATED: .setClearColorHex() is being removed. Use .setClearColor() instead."),this.setClearColor(a,b)},this.getMaxAnisotropy=function(){return0},this.clear=function(){J.setTransform(1,0,0,-1,H,I),V.isEmpty()===!1&&(V.intersect(U),V.expandByScalar(2),L<1&&J.clearRect(0|V.min.x,0|V.min.y,V.max.x-V.min.x|0,V.max.y-V.min.y|0),L>0&&(j(h.NormalBlending),i(1),o("rgba("+Math.floor(255*K.r)+","+Math.floor(255*K.g)+","+Math.floor(255*K.b)+","+L+")"),J.fillRect(0|V.min.x,0|V.min.y,V.max.x-V.min.x|0,V.max.y-V.min.y|0)),V.makeEmpty())},this.clearColor=function(){},this.clearDepth=function(){},this.clearStencil=function(){},this.render=function(a,d){if(dinstanceofh.Camera==!1)returnvoidconsole.error("THREE.CanvasRenderer.render: camera is not an instance of THREE.Camera.");this.autoClear===!0&&this.clear(),J.setTransform(1,0,0,-1,H,I),C.info.render.vertices=0,C.info.render.faces=0,p=D.projectScene(a,d,this.sortObjects,this.sortElements),q=p.elements,r=p.lights,s=d,X.getNormalMatrix(d.matrixWorldInverse);for(vare=0,f=q.length;e<f;e++){vari=q[e],j=i.material;if(void0!==j&&j.visible!==!1){if(W.makeEmpty(),iinstanceofh.RenderableSprite){t=i,t.x*=H,t.y*=I,i.object.x=t.x,i.object.y=t.y;vark=newh.Vector3;k.setFromMatrixPosition(i.object.matrixWorld),k.project(d),k.x=k.x*H+H,k.y=-(k.y*I)+I,i.object.screenX=k.x,i.object.screenY=k.y,b(t,i,j)}elseif(iinstanceofh.RenderableLine)t=i.v1,u=i.v2,t.positionScreen.x*=H,t.positionScreen.y*=I,u.positionScreen.x*=H,u.positionScreen.y*=I,W.setFromPoints([t.positionScreen,u.positionScreen]),U.intersectsBox(W)===!0&&c(t,u,i,j);elseif(iinstanceofh.RenderableFace){if(t=i.v1,u=i.v2,v=i.v3,t.positionScreen.z<-1||t.positionScreen.z>1)continue;if(u.positionScreen.z<-1||u.positionScreen.z>1)continue;if(v.positionScreen.z<-1||v.positionScreen.z>1)continue;t.positionScreen.x*=H,t.positionScreen.y*=I,u.positionScreen.x*=H,u.positionScreen.y*=I,v.positionScreen.x*=H,v.positionScreen.y*=I,j.overdraw>0&&(g(t.positionScreen,u.positionScreen,j.overdraw),g(u.positionScreen,v.positionScreen,j.overdraw),g(v.positionScreen,t.positionScreen,j.overdraw)),W.setFromPoints([t.positionScreen,u.positionScreen,v.positionScreen]),U.intersectsBox(W)===!0&&renderFace3(t,u,v,0,1,2,i,j)}V.union(W)}}J.setTransform(1,0,0,1,0,0)}},r.Layout.ForceDirected={run:function(a,b){varc,d,e,f,g,i,j,k,l,m,n,o,p,q,r,s;for(j=a,b=b||{},c=b.hasOwnProperty("iterations")?b.iterations:1e4,d=b.hasOwnProperty("forceStrength")?b.forceStrength:10,e=.01,f=2,g=50,n=newh.Vector3,a.vs.each(function(a){a.position=newh.Vector3(Math.random(),Math.random(),Math.random()),a.force=newh.Vector3(Math.random(),Math.random(),Math.random())}),i=function(){e-=.01/c;varb=a.vs.elements,i=a.vs.elements;for(l=0;l<b.length;l+=1)for(m=0;m<b.length;m+=1)l!==m&&(p=b[l],q=b[m],n.subVectors(q.position,p.position),o=n.length(),o<.1&&(n.set(Math.random(),Math.random(),Math.random()).multiplyScalar(.1).addScalar(.1),o=n.length()),o<g&&(n.multiplyScalar(d*d/(o*o)),p.force.sub(n.clone().multiplyScalar(q.scale.x)),q.force.add(n.clone().multiplyScalar(p.scale.x))));for(l=0;l<i.length;l+=1)p=b[i[l].source],q=b[i[l].target],n.subVectors(q.position,p.position),o=n.length(),o<.1&&(n.set(h.Math.randFloat(.1,.2),h.Math.randFloat(.1,.2),h.Math.randFloat(.1,.2)),o=n.length()),o=Math.min(o,g),n.multiplyScalar((o*o-d*d)/(o*d)),p.force.add(n.clone().multiplyScalar(q.scale.x)),q.force.sub(n.clone().multiplyScalar(p.scale.x));for(l=0;l<b.length;l+=1)p=b[l],p.force.multiplyScalar(e),p.force.setX(h.Math.clamp(p.force.x,-f,f)),p.force.setY(h.Math.clamp(p.force.y,-f,f)),p.force.setZ(h.Math.clamp(p.force.z,-f,f)),p.position.add(p.force),p.force.set(0,0,0);for(l=0;l<i.length;l+=1)r=i[l],p=b[r.source],q=b[r.target],o=q.position.distanceTo(p.position),r.position.addVectors(p.position,q.position).divideScalar(2),r.lookAt(q.position),r.scale.z=o,j.directed&&(s=j.arrows[l],s.position.copy(r.position),s.lookAt(q.position))},k=0;k<c;k+=1)setTimeout(i,0)}},s});