-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjas.editor.min.js
45 lines (45 loc) · 22.7 KB
/
jas.editor.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
(function(w){function z(a,c){if(null===a||"object"!==typeof a)return a;var d=a.constructor(),b;for(b in a)a.hasOwnProperty(b)&&(d[b]=c?z(a[b],!0):a[b]);return d}function C(a){for(var c in a)if(a.hasOwnProperty(c))switch(typeof a[c]){case "number":a[c]|=0;break;case "object":C(a[c])}}function p(a,c,d,b){var e=a[c];if("function"!==typeof e||"function"!==typeof d)throw Error("the parameters must be functions");a[c]=function(){b=b||this;var a=e.apply(this,arguments);d.apply(b,arguments);return a};return p}
function G(a){return a&&a.r?a.r:16}function H(a){return a&&a.r?a.r:13}function I(a){var c=[0,0],d=[0,0],b=[0,0],e=function(){return[c[0],c[1]]};e.start=function(){b[0]=d3.event.pageX;b[1]=d3.event.pageY};e.mouse=function(){return d3.mouse(a[0][0])};e.to_mouse=function(){d[0]=d3.event.pageX-b[0];d[1]=d3.event.pageY-b[1];b[0]=d3.event.pageX;b[1]=d3.event.pageY;c[0]+=d[0];c[1]+=d[1];a.attr("transform","translate("+c[0]+","+c[1]+")")};return e}function J(a){return this.target===a.source&&this.source===
a.target}function K(a){a.source===a.target?a.type=2:0<this._graph.edges.filter(J,a).length?a.type=1:a.type=0}function x(a,c){function d(){"function"===typeof b.plane_handler&&b.plane_handler.apply(this,arguments)}var b=this,e=d3.select(a||"body"),f=e.append("svg").attr("width",500).attr("height",300).classed("unselectable",!0).on("contextmenu",function(){d3.event.preventDefault()});this.selection_rectangle=function(){return x.prototype.selection_rectangle.context(f)};this.select=function(){return x.prototype.select.context(b,
k)};this.edge_handler=this.node_handler=void 0;f.on("mousedown",d).on("mouseover",function(){A.handle(d)}).on("mouseup",d).on("mousemove",d).on("dblclick",d).on("dragstart",function(){d3.event.preventDefault()});var l=f.append("svg:defs");l.append("svg:marker").attr("id","marker-arrow").attr("orient","auto").attr("markerWidth",6).attr("markerHeight",6).attr("refX",6).attr("refY",3).append("svg:path").attr("d","M0,0 L6,3 L0,6");l.append("style").html("g.nodes circle {fill: dodgerblue;stroke: #555;stroke-width: 0.09em;fill-opacity: 0.5;}path.edge {fill: none;stroke: #333;stroke-width: 0.09em;}path.catch {fill: none;} .nodes text, .edges text {font-size: small;font-family: Verdana, sans-serif;pointer-events: none;text-anchor: middle;dominant-baseline: central;}");
var k=f.append("g");this.transform=function(){b.node.attr("transform",m.get_node_transformation);b.edge.each(b.transform_edge)};var g=d3.layout.force().charge(-800).linkDistance(150).chargeDistance(450).size([500,300]).on("tick",this.transform);this.spring=function(){var a=!1,b=function(b){arguments.length&&(b?a?g.resume():(g.start(),a=!0):(g.stop(),a=!1));return a};b.on=function(){a&&g.resume()};b.off=function(){a&&g.stop()};return b}();this.node=k.append("g").attr("class","nodes").selectAll("g");
this.edge=k.append("g").attr("class","edges").selectAll("g");this.pan=I(k);this.svg=f;this.container=e;this.force=g;this.graph(c)}function v(){return d3.event.ctrlKey}function M(a,c){function d(){b.update()}var b=c;p(a.node,"add",d);p(a.node,"remove",d);p(a.node,"text",b.node_text.bind(b));p(a.node,"shift",b.transform);p(a.node,"move",b.transform);p(a.node,"mark",b.mark_node.bind(b));p(a.node,"unmark",b.mark_node.bind(b));p(a.node,"initial",b.initial.bind(b));p(a.node,"stress",b.stress_node.bind(b));
p(a.edge,"add",d);p(a.edge,"remove",d);p(a.edge,"text",b.edge_text.bind(b));p(a.edge,"move",d);p(a.edge,"stress",b.stress_edge.bind(b));return a}w=w||window;w.jas=w.jas||{};w=w.jas;var n={length:function(a){return Math.sqrt(a[0]*a[0]+a[1]*a[1])},normalize:function(a,c){var d=this.length(a),d=1/d;c[0]=a[0]*d;c[1]=a[1]*d;return c},orthogonal:function(a,c){c[0]=a[1];c[1]=-a[0];return c},scale:function(a,c,d){d[0]=a[0]*c;d[1]=a[1]*c;return d},add:function(a,c,d){d[0]=a[0]+c[0];d[1]=a[1]+c[1];return d},
subtract:function(a,c,d){d[0]=a[0]-c[0];d[1]=a[1]-c[1];return d},copy:function(a,c){c[0]=a[0];c[1]=a[1];return c}},A=function(){var a;return{handle:function(c){a=c},handler:function(){a&&"function"===typeof a&&a.apply(this,arguments)}}}();d3.select(window).on("keydown",A.handler).on("keyup",A.handler);var m={};m.make_edge=function(){var a=[0,0],c=[0,0],d=function(){var a=Math.PI/3,c=Math.PI/12;return{DX1:16*Math.cos(a),DY1:16*Math.sin(a),DX2:64*Math.cos(a),DY2:64*Math.sin(a),DX3:64*Math.cos(c),DY3:64*
Math.sin(c),DX4:16*Math.cos(c),DY4:16*Math.sin(c),NX:Math.cos(a-Math.PI/24),NY:Math.sin(a-Math.PI/24)}}();return{r1:0,r2:0,stright:function(b,d){n.subtract(d,b,a);n.normalize(a,c);n.scale(c,this.r1,a);n.add(b,a,b);n.scale(c,this.r2,a);n.subtract(d,a,d)},drag:function(b,d,f){n.subtract(d,b,a);n.normalize(a,c);n.scale(c,this.r2,a);n.add(b,a,b);f&&n.subtract(d,a,d)},curve:function(b,d,f){n.subtract(d,b,a);n.normalize(a,c);f[0]=.5*(b[0]+d[0])+c[1]*this.r1*2;f[1]=.5*(b[1]+d[1])-c[0]*this.r2*2;n.copy(f,
a);this.stright(b,a);n.copy(f,a);this.stright(d,a)},loop:function(b,c,f,l){n.copy(b,a);b[0]=a[0]+d.DX1;b[1]=a[1]-d.DY1;f[0]=a[0]+d.DX2;f[1]=a[1]-d.DY2;l[0]=a[0]+d.DX3;l[1]=a[1]-d.DY3;c[0]=a[0]+d.DX4;c[1]=a[1]-d.DY4}}}();m.get_edge_transformation=function(){var a=[0,0],c=[0,0],d=[0,0],b=[0,0];return function(e){a[0]=e.source.x;a[1]=e.source.y;c[0]=e.target.x;c[1]=e.target.y;m.make_edge.r1=void 0!==e.source.r?e.source.r:16;m.make_edge.r2=void 0!==e.target.r?e.target.r:16;e.tx=e.source.x+e.target.x>>>
1;e.ty=e.source.y+e.target.y>>>1;switch(e.type){case 1:m.make_edge.curve(a,c,d);e.tx=d[0]+c[0]>>>1;e.ty=d[1]+c[1]>>>1;break;case 2:m.make_edge.loop(a,c,d,b);e.tx=d[0]+b[0]>>>1;e.ty=d[1]+b[1]>>>1;break;default:m.make_edge.stright(a,c)}e.x1=a[0];e.y1=a[1];e.x2=c[0];e.y2=c[1];switch(e.type){case 1:return"M"+a[0]+","+a[1]+"Q"+d[0]+","+d[1]+","+c[0]+","+c[1];case 2:return"M"+a[0]+","+a[1]+"C"+d[0]+","+d[1]+","+b[0]+","+b[1]+","+c[0]+","+c[1];default:return"M"+a[0]+","+a[1]+"L"+c[0]+","+c[1]}}}();m.get_node_transformation=
function(a){return a&&void 0!==a.x&&void 0!==a.y?"translate("+a.x+","+a.y+")":""};m.mark_node=function(a){a.filter(function(a){return!!a.marked&&d3.select(this).select("circle.marked").empty()}).append("circle").attr("r",H).classed("marked",!0);a.filter(function(a){return!a.marked}).selectAll("circle.marked").remove()};m.initial=function(a,c){2>arguments.length||c?a.append("path").attr("class","edge").attr("marker-end","url(#marker-arrow)").attr("d",function(){return"M-41.6,0L-16,0"}):a.select("path.edge").remove()};
m.add_node=function(a,c){var d=a.append("g").attr("transform",m.get_node_transformation).on("mousedown",c).on("mouseup",c).on("mouseover",c).on("mouseout",c).on("dblclick",c);d.append("circle").attr("r",G);d.call(m.mark_node);d.append("text").attr("alignment-baseline","center").text(function(a){return a.text||""});m.initial(d.filter(function(a){return!!a.initial}))};m.add_edge=function(a,c){var d=a.append("g").on("mousedown",c).on("mouseup",c).on("mouseover",c).on("mouseout",c).on("dblclick",c);d.append("path").attr("class",
"edge").attr("marker-end","url(#marker-arrow)");d.append("path").attr("class","catch");d.append("text").attr("alignment-baseline","center").text(function(a){return a.text||""});return d};var D=function(){function a(){"function"===typeof g&&g.apply(this,arguments);f.remove()}function c(){"function"===typeof k&&k.apply(this,arguments);f.remove()}function d(){switch(d3.event.keyCode){case 13:c.apply(this,arguments);break;case 27:a.apply(this,arguments);break;default:d3.event.stopPropagation(),e()}return null}
function b(){f.each(function(){this.style.height="auto";this.style.height=this.scrollHeight+"px"})}function e(){window.setTimeout(b,0)}var f=null,l=null,k=null,g=null;return function(a,L,y,t,m,q){f&&f.remove();l=a;y=y||0;t=t||0;k=m;g=q;a=Number(getComputedStyle(document.body,null).fontSize.match(/(\d*(\.\d*)?)px/)[1]);isNaN(a)||(t-=a/2);f=l.append("textarea").attr("id","c88d9c30-5871-11e4-8ed6-0800200c9a66").attr("rows",1).style("position","absolute").style("height","1em").style("left",y+"px").style("top",
t+"px").attr("placeholder","Type here...");f.on("blur",c).on("change",b).on("keydown",d).on("cut",e).on("drop",e).on("paste",e);f.each(function(){this.value=L;this.focus();this.select()});b()}}();window.textarea=D;(function(){function a(a,b){a instanceof Array?a.forEach(b):b(a)}function c(a){void 0===a.uid&&(a.uid=f());return a.uid}function d(a,b){return b instanceof Array?a.filter(function(a){return 0<=b.indexOf(a)}):a.filter(function(a){return a===b})}function b(a){var b=!1;a.forEach(function(a,
c){void 0===a.x&&(a.x=c,b=!0);void 0===a.y&&(a.y=c,b=!0)});return b}function e(a,b){a.forEach(function(a){delete a[b]})}var f=function(){var a=0;return function(){return a++}}();this.graph=function(a){if(0<arguments.length){this._graph=null;this._graph=a||{nodes:[],edges:[]};e(this._graph.nodes,"uid");e(this._graph.edges,"uid");var c=this;this._graph.edges.forEach(function(a){"number"===typeof a.source&&(a.source=c._graph.nodes[a.source]);"number"===typeof a.target&&(a.target=c._graph.nodes[a.target])});
b(this._graph.nodes)&&this.spring(!0);this.update()}return this._graph};this.size=function(a,b){arguments.length&&(this.svg.attr("width",a).attr("height",b),this.force.size([a,b]))};this.update=function(){var a=this.spring();a&&this.spring(!1);this.node=this.node.data(this.graph().nodes,c);this.node.enter().call(m.add_node,this.node_handler);this.node.exit().remove();this.edge=this.edge.data(this.graph().edges,c);this.edge.enter().call(m.add_edge,this.edge_handler);this.edge.exit().remove();this.force.nodes(this._graph.nodes).links(this._graph.edges);
a&&this.spring(!0);var b=this;this.edge.each(function(){K.apply(b,arguments)});this.transform()};this.node_text=function(a,b){d(this.node,a).select("text").text(b)};this.mark_node=function(a){d(this.node,a).call(m.mark_node)};this.edge_text=function(a,b){d(this.edge,a).select("text").text(b)};this.edge_by_data=function(a){return d(this.edge,a)};this.select_node=function(b,c){var e=this;c=void 0===c?!0:!!c;a(b,function(a){d(e.node,a).select("circle").classed("selected",c)})};this.select_edge=function(b,
c){var e=this;c=void 0===c?!0:!!c;a(b,function(a){d(e.edge,a).select("path.edge").classed("selected",c)})};this.selected_nodes=function(){var a=[];this.node.select(".selected").each(function(b){a.push(b)});return a};this.selected_edges=function(){var a=[];this.edge.select(".selected").each(function(b){a.push(b)});return a};this.unselect_all=function(){this.svg.selectAll(".selected").classed("selected",!1)};this.initial=function(a){this.node.selectAll("path.edge").remove();m.initial(d(this.node,a))};
this.transform_edge=function(a){var b=m.get_edge_transformation(a),c=d3.select(this);c.selectAll("path").attr("d",b);c.select("text").attr("x",a.tx).attr("y",a.ty)};this.stress_node=function(b){var c=this.node;c.select(".stressed").classed("stressed",!1);a(b,function(a){d(c,a).select("circle").classed("stressed",!0)})};this.stress_edge=function(b){var c=this.edge;c.select(".stressed").classed("stressed",!1);a(b,function(a){d(c,a).select("path.edge").classed("stressed",!0)})}}).call(x.prototype);x.prototype.selection_rectangle=
function(){var a,c,d,b,e,f,l={},k,g,h=function(){var e=[a,c,d,b];a>d&&(e[0]=d,e[2]=a);c>b&&(e[1]=b,e[3]=c);return e};h.show=function(b){a=b[0];c=b[1];k=g.append("rect").attr({x:a,y:c,"class":"selection"})};h.update=function(h){d=h[0];b=h[1];e=d-a;f=b-c;l.x=a;l.y=c;0>e&&(e=-e,l.x=d);0>f&&(f=-f,l.y=b);l.width=e;l.height=f;k.attr(l)};h.hide=function(){k.remove()};h.context=function(a){g=a;return this};return h}();x.prototype.select=function(){function a(a,b,c){return a>c[0]&&a<c[2]&&b>c[1]&&b<c[3]}var c;
return{context:function(a,b){c=a;return this},by_rectangle:function(d){var b=c.pan();d[0]-=b[0];d[2]-=b[0];d[1]-=b[1];d[3]-=b[1];c.node.each(function(b){a(b.x,b.y,d)&&c.select_node(b)});c.edge.each(function(b){a(b.x1,b.y1,d)&&a(b.x2,b.y2,d)&&c.select_edge(b)})}}}();var u=function(){function a(){}var c=function(a,c){a&&(this.redo=a);c&&(this.undo=c)};c.prototype.redo=a;c.prototype.undo=a;var d=function(b){this.graph=b;this.stack=[];this.macro=[];this.index=0;this.update=a};(function(){this.start=function(){this.index<
this.stack.length&&(this.stack.length=this.index);this.macro=[];this.stack.push(this.macro);this.index=this.stack.length;return this};this.undo=function(){if(0<this.index){for(var a=this.stack[--this.index],c=a.length;0<c--;)a[c].undo();this.update()}};this.redo=function(){if(this.index<this.stack.length){var a=this.stack[this.index++],c,d=a.length;for(c=0;c<d;c++)a[c].redo();this.update()}};this.create=function(a,d){this[a]&&console?console.error("Command",a,"already exists"):a&&"function"===typeof d&&
(this[a]=function(){for(var a=arguments,b=a.length;b--;)a[b]instanceof Array&&(a[b]=a[b].slice(0));a=new c;a.graph=this.graph;d.apply(a,arguments);this.macro.push(a);a.redo();this.update();return this})};this.clear_history=function(){this.stack.length=0;this.macro.length=0}}).call(d.prototype);return d}();u.prototype.create("add_node",function(a){var c=this.graph;this.redo=function(){c.node.add(a)};this.undo=function(){c.node.remove(a)}});u.prototype.create("del_node",function(a){var c=this.graph;
this.redo=function(){c.node.remove(a)};this.undo=function(){c.node.add(a)}});u.prototype.create("add_edge",function(a){var c=this.graph;this.redo=function(){c.edge.add(a)};this.undo=function(){c.edge.remove(a)}});u.prototype.create("del_edge",function(a){var c=this.graph;this.redo=function(){c.edge.remove(a)};this.undo=function(){c.edge.add(a)}});u.prototype.create("node_text",function(a,c){var d=this.graph,b=a.text;this.redo=function(){d.node.text(a,c)};this.undo=function(){d.node.text(a,b)}});u.prototype.create("edge_text",
function(a,c){var d=this.graph,b=a.text;this.redo=function(){d.edge.text(a,c)};this.undo=function(){d.edge.text(a,b)}});u.prototype.create("move_node",function(a,c,d){var b=this.graph;this.redo=function(){b.node.move(a,d)};this.undo=function(){b.node.move(a,c)}});u.prototype.create("mark_node",function(a){var c=this.graph;this.redo=function(){c.node.mark(a)};this.undo=function(){c.node.unmark(a)}});u.prototype.create("unmark_node",function(a){var c=this.graph;this.redo=function(){c.node.unmark(a)};
this.undo=function(){c.node.mark(a)}});u.prototype.create("initial",function(a,c){var d=this.graph;this.redo=function(){d.node.initial(c)};this.undo=function(){d.node.initial(a)}});u.prototype.create("move_edge",function(a,c,d){var b=this.graph;this.redo=function(){b.edge.move(a,d[0],d[1])};this.undo=function(){b.edge.move(a,c[0],c[1])}});u.prototype.create("spring",function(a){var c=this.graph,d=[],b=c.object().nodes;b.forEach(function(a){d.push(a.x,a.y)});this.redo=function(){a.spring(!0)};this.undo=
function(){a.spring(!1);c.node.move(b,d)}});var r,E=function(){var a,c,d,b={init:function(){a=d3.mouse(this);d=b.ready},ready:function(e){switch(d3.event.type){case "mousemove":v()||e.unselect_all();c=e.selection_rectangle();c.show(a);d=b.update;break;case "mouseup":v()||e.unselect_all();d=b.init;break;default:d=b.init}},update:function(a){switch(d3.event.type){case "mousemove":c.update(d3.mouse(this));break;case "mouseup":a.select().by_rectangle(c()),c.hide(),d=b.init}}};d=b.init;return function f(){d.apply(this,
arguments);f.done=d===b.init;return f}}(),F=function(){var a,c,d=[],b,e=[],f,l={init:function(b){a=b.pan.mouse();f=l.ready},ready:function(a){switch(d3.event.type){case "mousemove":d.length=0;c=a.selected_nodes();c.forEach(function(a){a.fixed=!0;d.push(a.x,a.y)});f=l.update;break;case "mouseup":f=l.init}},update:function(k){switch(d3.event.type){case "mousemove":b=a;a=k.pan.mouse();b[0]=a[0]-b[0];b[1]=a[1]-b[1];r.graph.node.shift(c,b);k.spring.on();b[0]=a[0];b[1]=a[1];break;case "mouseup":e.length=
0;c.forEach(function(a){delete a.fixed;e.push(a.x,a.y)});if(k.spring())k.spring.on();else r.start().move_node(c,d,e);f=l.init}}};f=l.init;return function g(){f.apply(this,arguments);g.done=f===l.init;return g}}(),B=function(){var a,c,d,b,e,f,l,k,g,h={init:function(b,d,f){c=f;switch(d){case "node":g=h.wait_for_new_edge;break;case "edge":d=[];var l=[];a=b.pan.mouse();n.subtract(a,[f.x1,f.y1],l);n.subtract(a,[f.x2,f.y2],d);e=n.length(d)<n.length(l);g=h.wait_for_edge_dragging}},wait_for_new_edge:function(l){switch(d3.event.type){case "mouseup":g=
h.init;break;case "mouseout":a=l.pan.mouse(),d={x:a[0],y:a[1],r:1},b={source:c,target:d},r.start().add_edge(b),e=!0,f=l.edge_by_data(b).selectAll("path"),l.spring.off(),g=h.drag_edge}},wait_for_edge_dragging:function(c,k,t){switch(k){case "edge":switch(d3.event.type){case "mouseout":a=c.pan.mouse();d={x:a[0],y:a[1],r:1};b=t;l=[b.source,b.target];e?t.target=d:t.source=d;r.start().move_edge(b,l,[b.source,b.target]);f=c.edge_by_data(b).selectAll("path");c.unselect_all();c.select_edge(b);c.spring.off();
g=h.drag_edge;break;default:g=h.init}}},drag_edge:function(c,k,t){switch(d3.event.type){case "mousemove":a=c.pan.mouse();d.x=a[0];d.y=a[1];f.attr("d",m.get_edge_transformation(b));break;case "mouseup":delete d.r;r.add_node(d);c.unselect_all();c.select_edge(b);c.select_node(e?b.target:b.source);c.spring.on();g=h.init;break;case "mouseover":switch(k){case "node":l=[b.source,b.target],e?b.target=t:b.source=t,r.move_edge(b,l,[b.source,b.target]),c.spring.off(),g=h.drop_edge_or_exit}}},drop_edge_or_exit:function(a,
c){switch(c){case "node":switch(d3.event.type){case "mouseup":k=a.graph().edges.filter(function(a){return a.source===b.source&&a.target===b.target});1<k.length&&r.del_edge(b);v()||a.unselect_all();1>=k.length&&a.select_edge(b);a.spring.on();g=h.init;break;case "mouseout":l=[b.source,b.target],e?b.target=d:b.source=d,r.move_edge(b,l,[b.source,b.target]),a.spring.off(),g=h.drag_edge}}}};g=h.init;return function y(){g.apply(this,arguments);y.done=g===h.init;return y}}(),N=function(){function a(a,c,d,
e,h){a.text("");D(b.container,c||"",d,e,function(){h(this.value||"")},function(){a.text(c)})}function c(a){b=this.view;r=this.commands;f=a}function d(){if(b){if(e!==b){if(h!==q.init)return;e=b}m=h;h.apply(this,arguments);f=b=null;m!==h&&console.log("transition:",m._name+" -> "+h._name)}}var b,e,f,l,k,g,h,m,n,t,p,q={init:function(c){if("keydown"===d3.event.type)switch(d3.event.keyCode){case 46:k=b.selected_nodes();g=b.selected_edges();g=g.concat(r.graph.edge.adjacent(k).filter(function(a){return 0>
g.indexOf(a)}));r.start().del_edge(g).del_node(k);h=q.wait_for_keyup;break;case 70:b.spring()?b.spring(!1):r.start().spring(b);break;case 73:r.start().initial(b._graph.nodes.filter(function(a){return!!a.initial}),b.selected_nodes());break;case 77:k=b.selected_nodes();v()?r.start().unmark_node(k):r.start().mark_node(k);break;case 89:v()&&(r.redo(),b.spring.on());h=q.wait_for_keyup;break;case 90:v()&&(r.undo(),b.spring.on()),h=q.wait_for_keyup}else switch(f){case "plane":switch(d3.event.type){case "dblclick":v()||
b.unselect_all();l=b.pan.mouse();var d={x:l[0],y:l[1]};r.start().add_node(d);b.select_node(d);break;case "mousedown":d3.event.shiftKey?(b.pan.start(),h=q.drag_graph):(E.call(this,b),h=q.selection)}break;case "node":switch(d3.event.type){case "mousedown":d3.event.shiftKey?b.select_node(c):v()?b.select_node(c,0>b.selected_nodes().indexOf(c)):(b.unselect_all(),b.select_node(c));d3.event.shiftKey?(F.call(this,b),h=q.drag_node):(B.call(this,b,f,c),h=q.drag_edge);break;case "dblclick":n=b.pan(),t=c.x+n[0],
p=c.y+n[1],a(d3.select(this).select("text"),c.text,t,p,function(a){r.start().node_text(c,a)}),d3.event.stopPropagation()}break;case "edge":switch(d3.event.type){case "mousedown":g=b.selected_edges();d3.event.shiftKey?(b.select_edge(c),g=b.selected_edges()):v()?b.select_edge(c,0>g.indexOf(c)):(b.unselect_all(),b.select_edge(c));B.call(this,b,f,c);h=q.drag_edge;break;case "dblclick":n=b.pan(),t=c.tx+n[0],p=c.ty+n[1],a(d3.select(this).select("text"),c.text,t,p,function(a){r.start().edge_text(c,a)}),
d3.event.stopPropagation()}}},drag_node:function(){F.call(this,b).done&&(h=q.init)},drag_edge:function(a){B.call(this,b,f,a).done&&(h=q.init)},drag_graph:function(){switch(d3.event.type){case "mousemove":d3.event.shiftKey||(h=q.init);b.pan.to_mouse();break;case "mouseup":h=q.init}},selection:function(){E.call(this,b).done&&(h=q.init)},wait_for_keyup:function(){"keyup"===d3.event.type&&(h=q.init)}};h=q.init;for(var u in q)q.hasOwnProperty(u)&&(q[u]._name=u);return function(a,b){this.view=a;this.commands=
b;this.event=d;this.context=c;var e=this;this.view.node_handler=function(){c.call(e,"node");d.apply(this,arguments)};this.view.edge_handler=function(){c.call(e,"edge");d.apply(this,arguments)};this.view.plane_handler=function(){c.call(e,"plane");d.apply(this,arguments)}}}(),O=function(){function a(a,b,c){c=c||this;a instanceof Array?a.forEach(b,c):b.call(c,a)}var c={};(function(){function b(a){this.push(a)}function c(a){a=this.indexOf(a);0<=a&&this.splice(a,1)}function d(a){a.stressed=!0}function k(a){delete a.stressed}
this.add=function(c){a(c,b,this.data);return this};this.remove=function(b){a(b,c,this.data);return this};this.text=function(a,b){a.text=b;return this};this.stress=function(b){a(this.data,k);a(b,d)}}).call(c);var d=Object.create(c);(function(){function b(a){a.x+=this[0];a.y+=this[1];a.px=a.x;a.py=a.y}function c(a){a.marked=!0}function d(a){delete a.marked}function k(a){a.initial=!0}function g(a){delete a.initial}this.shift=function(c,d){a(c,b,d)};this.move=function(b,c){if(c instanceof Array){var d=
0;a(b,function(a){a.x=c[d++]||a.x;a.y=c[d++]||a.y;a.px=a.x;a.py=a.y})}};this.mark=function(b){a(b,c)};this.unmark=function(b){a(b,d)};this.initial=function(b){a(this.data,g);a(b,k)}}).call(d);var b=Object.create(c);(function(){function a(b,c,d){var e;c instanceof Array?(e=[],c.forEach(function(a){for(var c=b.filter(function(b){return d(b,a)&&0>e.indexOf(b)});c.length;)e.push(c.pop())})):e=b.filter(function(a){return d(a,c)});return e}this.adjacent=function(b){return a(this.data,b,function(a,b){return a.source===
b||a.target===b})};this.incoming=function(b){return a(this.data,b,function(a,b){return a.target===b})};this.outgoing=function(b){return a(this.data,b,function(a,b){return a.source===b})};this.move=function(a,b,c){a.source=b;a.target=c}}).call(b);c=function(a){this.node=Object.create(d);this.edge=Object.create(b);this.node.data=[];this.edge.data=[];this.set_json(a)};c.prototype.object=function(){return{nodes:this.node.data,edges:this.edge.data}};c.prototype.set_json=function(b){this.node.data.length=
0;this.edge.data.length=0;if("object"===typeof b){a(b.nodes,function(a){"object"===typeof a&&0>this.indexOf(a)&&this.push(a)},this.node.data);var c=this,d,k,g=this.node.data.length;a(b.edges,function(a){"object"===typeof a&&0>this.indexOf(a)&&(d=Number(a.source),k=Number(a.target),0<=d&&d<g&&0<=k&&k<g&&(a.source=c.node.data[d],a.target=c.node.data[k],this.push(a)))},this.edge.data)}};c.prototype.get_json=function(){var a=this.object();a.edges=a.edges.map(function(b){var c=z(b);c.source=a.nodes.indexOf(b.source);
c.target=a.nodes.indexOf(b.target);return c});a=z(a,!0);C(a);return a};return c}();w.Editor=function(a){function c(){this.commands.clear_history();this.view.graph(this.graph.object())}this.graph=new O;this.view=new x(a);M(this.graph,this.view);this.commands=new u(this.graph);this.controller=new N(this.view,this.commands);c.call(this);p(this.graph,"set_json",c.bind(this))};w.after=p})(window);