/*\
title: $:/plugins/ihm/widgets/tidgraph.js
type: application/javascript
module-type: widget

Tidgraph widget to render HTML5/SVG graph of tiddlers

\*/
(function(){var e=require("$:/core/modules/widgets/widget.js").widget,c=function(b,f){this.initialise(b,f)},d=require("$:/plugins/ihm/tidgraph/utils.js");c.prototype=new e;c.prototype.render=function(b,f){this.tidtree&&this.delTempTiddlers();this.parentDomNode=b;this.nextSiblingDomNode=f;this.computeAttributes();this.execute();-1===["tagging","linking"].indexOf(this.mode)&&(this.mode=$tw.wiki.getTiddlerText("$:/config/tidgraph/modes/"+this.mode)||this.mode);this.tidtree=[];this.tidtree.mode=this.mode;
this.tidtree.maxdepth=this.maxdepth;this.tidtree.startat=this.startat;this.tidtree.nodetitle=this.nodetitle;this.tidtree.tooltip=this.tooltip;this.tidtree.filter=this.filter;this.tidtree.nocollapse=this.nocollapse;this.tidtree.document=this.document;this.tidtree.nodetemplate=this.nodetemplate;this.tidtree.layout=this.layout;this.templatesInUse=$tw.utils.parseStringArray(this.nodetemplate);this.tidtree.id=(new Date).valueOf();if($tw.wiki.getTiddler(this.startTid)){this.div=this.document.createElement("div");
this.div.className="tgr-container tgr";this.tablediv=this.document.createElement("div");this.tablediv.className="ihm-tgr-tablediv";this.table=void 0;this.div.appendChild(this.tablediv);this.svgdiv=this.document.createElement("div");this.svgdiv.className="tgr-svg-int";this.div.appendChild(this.svgdiv);this.parentDomNode.insertBefore(this.div,this.nextSiblingDomNode);this.domNodes.push(this.div);this.tidtree.root=d.makeTidTree(this.startTid,this.tidtree,{widget:this});this.paint();var a=this,c=function(){a.svgdiv.innerHTML=
d.buildSVG(a.tablediv,a.tidtree);a.oldresize&&a.oldresize()},e=function(){a.svgdiv.innerHTML=d.buildSVG(a.tablediv,a.tidtree)};this.div.onscroll=function(){a.scroll_to||clearTimeout(a.scroll_to);a.scroll_to=setTimeout(e,100)};this.onresize_updated||(window.onresize&&void 0==this.oldresize&&(this.oldresize=window.onresize),window.onresize=function(){a.resize_to||clearTimeout(a.resize_to);a.resize_to=setTimeout(c,100)},this.onresize_updated=!0)}};c.prototype.delTempTiddlers=function(){var b=$tw.wiki.filterTiddlers("[prefix[$:/temp/tidgraph/"+
this.tidtree.id+"]]");$tw.utils.each(b,function(b){$tw.wiki.deleteTiddler(b)})};c.prototype.paint=function(){this.sidebar=$tw.wiki.getTiddlerText("$:/state/sidebar");var b=d.buildTable(this.startTid,this.tidtree);this.table?this.tablediv.replaceChild(b,this.table):this.tablediv.appendChild(b);this.svgdiv.innerHTML=d.buildSVG(this.tablediv,this.tidtree);this.table=b};c.prototype.execute=function(){this.startTid=this.getAttribute("start");this.mode=this.getAttribute("mode","tagging");this.maxdepth=
parseInt(this.getAttribute("maxdepth","10"));this.startat=this.getAttribute("startat","0");this.nodetitle=this.getAttribute("nodetitle");this.tooltip=this.getAttribute("tooltip","summary");this.filter=this.getAttribute("filter","[!is[system]]");this.nocollapse=this.hasAttribute("nocollapse");this.nodetemplate=this.getAttribute("nodetemplate","");this.layout=this.getAttribute("layout","E");-1==["E","S"].indexOf(this.layout)&&(this.layout="E")};c.prototype.refresh=function(b){var c=!1,a;this.computeAttributes();
this.execute();for(a in b)if((b=document.getElementById(this.tidtree.id+"-"+encodeURIComponent(a))||d.isDescendant(a,this.startTid,this.tidtree)||-1!==this.templatesInUse.indexOf(a))||(b=(b=$tw.wiki.getTiddler(a))&&b.hasTag("$:/tags/Stylesheet")?!0:!1),b||-1!==a.indexOf("$:/config/tidgraph/modes")){c=!0;break}$tw.wiki.getTiddlerText("$:/state/sidebar")!==this.sidebar&&(c=!0);return c?(this.refreshSelf(),!0):!1};exports.tidgraph=c})();
