UNPKG

popoto

Version:

Graph based search interface for Neo4j database.

2 lines 91.2 kB
// Copyright (c) 2018 NHOGS Interactive. ((e,t)=>{"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("d3")):"function"==typeof define&&define.amd?define(["exports","d3"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).popoto=e.popoto||{},e.d3)})(this,function(e,t){function n(n){var r;return n&&n.__esModule?n:(r=Object.create(null),n&&Object.keys(n).forEach(function(e){var t;"default"!==e&&(t=Object.getOwnPropertyDescriptor(n,e),Object.defineProperty(r,e,t.get?t:{enumerable:!0,get:function(){return n[e]}}))}),r.default=n,Object.freeze(r))}var s=n(t),t="4.0.8",v={idGen:0,generateId:function(){return v.idGen++},nodes:[],links:[],getRootNode:function(){return v.nodes[0]}},u={},m=(u.LogLevels=Object.freeze({DEBUG:0,INFO:1,WARN:2,ERROR:3,NONE:4}),u.LEVEL=u.LogLevels.NONE,u.TRACE=!1,u.log=function(e,t){if(console&&e>=u.LEVEL)switch(u.TRACE&&(t=t+"\n"+(new Error).stack),e){case u.LogLevels.DEBUG:case u.LogLevels.INFO:console.log(t);break;case u.LogLevels.WARN:console.warn(t);break;case u.LogLevels.ERROR:console.error(t)}},u.debug=function(e){u.log(u.LogLevels.DEBUG,e)},u.info=function(e){u.log(u.LogLevels.INFO,e)},u.warn=function(e){u.log(u.LogLevels.WARN,e)},u.error=function(e){u.log(u.LogLevels.ERROR,e)},{}),d=(m.MAX_RESULTS_COUNT=100,m.VALUE_QUERY_LIMIT=100,m.USE_PARENT_RELATION=!1,m.USE_RELATION_DIRECTION=!0,m.RETURN_LABELS=!1,m.COLLECT_RELATIONS_WITH_VALUES=!1,m.prefilter="",m.prefilterParameters={},m.applyPrefilters=function(t){return t.statement=m.prefilter+t.statement,Object.keys(m.prefilterParameters).forEach(function(e){t.parameters[e]=m.prefilterParameters[e]}),t},m.NEO4J_INTERNAL_ID=Object.freeze({queryInternalName:"NEO4JID"}),m.filterRelation=function(e){return!0},m.generateTaxonomyCountQuery=function(e){var t=L.node.getConstraintAttribute(e),n=[];return L.node.getPredefinedConstraints(e).forEach(function(e){n.push(e.replace(new RegExp("\\$identifier","g"),"n"))}),t===m.NEO4J_INTERNAL_ID?"MATCH (n:`"+e+"`)"+(0<n.length?" WHERE "+n.join(" AND "):"")+" RETURN count(DISTINCT ID(n)) as count":"MATCH (n:`"+e+"`)"+(0<n.length?" WHERE "+n.join(" AND "):"")+" RETURN count(DISTINCT n."+t+") as count"},m.generateNegativeQueryElements=function(){var f=[],h={};return v.nodes.filter(function(e){return!0===e.isNegative}).forEach(function(e){if(void 0!==L.node.getGenerateNegativeNodeValueConstraints(e)){var t,n=L.node.getGenerateNegativeNodeValueConstraints(e)(e);for(t in f=f.concat(n.whereElements),n.parameters)n.parameters.hasOwnProperty(t)&&(h[t]=n.parameters[t])}else{var r=m.getLinksToRoot(e,v.links),a=r.length-1,o="(NOT exists(";for(o+="("+v.getRootNode().internalLabel+")";0<=a;){var l=r[a],i=l.target;if(!0===i.isParentRelReverse&&!0===m.USE_RELATION_DIRECTION?o+="<-":o+="-",o=o+("[:`"+l.label+"`]")+(!0!==i.isParentRelReverse&&!0===m.USE_RELATION_DIRECTION?"->":"-"),i===e&&void 0!==i.value&&0<i.value.length){var s=L.node.getConstraintAttribute(i.label),u=i.internalLabel+"_"+s;if(1<i.value.length){for(var d=0;d<i.value.length;d++)h[u+"_"+d]=i.value[d].attributes[s];o+="(:`"+i.label+"`{"+s+":$x$})"}else h[u]=i.value[0].attributes[s],o+="(:`"+i.label+"`{"+s+":$"+u+"})"}else o+="(:`"+i.label+"`)";a--}if(o+="))",void 0!==e.value&&1<e.value.length)for(var p=L.node.getConstraintAttribute(e.label),c=e.internalLabel+"_"+p,g=0;g<i.value.length;g++)f.push(o.replace("$x$","$"+c+"_"+g));else f.push(o)}}),{whereElements:f,parameters:h}},m.generateQueryElements=function(t,d,e,p,c){var g=[],f=[],h=[],v=[],E={};if(L.node.getPredefinedConstraints(t.label).forEach(function(e){f.push(e.replace(new RegExp("\\$identifier","g"),t.internalLabel))}),g.push("("+t.internalLabel+":`"+t.label+"`)"),p||t.immutable){var n,r=m.generateNodeValueConstraints(t,c),f=f.concat(r.whereElements);for(n in r.parameters)r.parameters.hasOwnProperty(n)&&(E[n]=r.parameters[n])}var y=0;return e.forEach(function(e){var t=e.source,n=e.target,r="",a="",a=m.USE_RELATION_DIRECTION?!0===n.isParentRelReverse?(r="<-","-"):(r="-","->"):r="-",o="r"+y++;h.push(o);L.node.getPredefinedConstraints(n.label).forEach(function(e){f.push(e.replace(new RegExp("\\$identifier","g"),n.internalLabel))}),m.COLLECT_RELATIONS_WITH_VALUES&&n===d&&v.push("COLLECT("+o+") AS incomingRels");var l="",i=(c&&void 0!==L.node.getGenerateNodeValueConstraints(t)||(l=":`"+t.label+"`"),"");if(c&&void 0!==L.node.getGenerateNodeValueConstraints(n)||(i=":`"+n.label+"`"),g.push("("+t.internalLabel+l+")"+r+"["+o+":`"+e.label+"`]"+a+"("+n.internalLabel+i+")"),n!==d&&(p||n.immutable)){var s,u=m.generateNodeValueConstraints(n,c);for(s in f=f.concat(u.whereElements),u.parameters)u.parameters.hasOwnProperty(s)&&(E[s]=u.parameters[s])}}),{matchElements:g,whereElements:f,relationElements:h,returnElements:v,parameters:E}},m.generateNodeValueConstraints=function(e,t){var n,r,a;return t&&void 0!==L.node.getGenerateNodeValueConstraints(e)?L.node.getGenerateNodeValueConstraints(e)(e):(n={},t=[],void 0!==e.value&&0<e.value.length&&(r=L.node.getConstraintAttribute(e.label),a=r===m.NEO4J_INTERNAL_ID?e.internalLabel+"_internalID":e.internalLabel+"_"+r,1<e.value.length?(n[a]=[],e.value.forEach(function(e){e=r===m.NEO4J_INTERNAL_ID?e.internalID:e.attributes[r];n[a].push(e)}),t.push(r===m.NEO4J_INTERNAL_ID?"ID("+e.internalLabel+") IN $"+a:e.internalLabel+"."+r+" IN $"+a)):(n[a]=r===m.NEO4J_INTERNAL_ID?e.value[0].internalID:e.value[0].attributes[r],t.push(r===m.NEO4J_INTERNAL_ID?"ID("+e.internalLabel+") = $"+a:e.internalLabel+"."+r+" = $"+a))),{parameters:n,whereElements:t})},m.getRelevantLinks=function(a,t,e){var o=e.slice(),l=[],e=o.filter(function(e){return e.target===t||void 0!==e.target.value&&0<e.target.value.length&&!0==!e.target.isNegative});return e.forEach(function(e){o.splice(o.indexOf(e),1)}),e.forEach(function(e){for(var t=e.source,n=!0;n;){var r=null;o.forEach(function(e){e.target===t&&(r=e)}),null===r?n=!1:r.source===a?(l.push(r),o.splice(o.indexOf(r),1),n=!1):(l.push(r),o.splice(o.indexOf(r),1),t=r.source)}}),e.concat(l)},m.getLinksToRoot=function(e,t){for(var n=[],r=e;r!==v.getRootNode();){for(var a,o=0;o<t.length;o++){var l=t[o];if(l.target===r){a=l;break}}a&&(n.push(a),r=a.source)}return n},m.generateResultQuery=function(e){var t,n=v.getRootNode(),r=m.generateNegativeQueryElements(),a=m.generateQueryElements(n,n,m.getRelevantLinks(n,n,v.links),!0,!0),o=a.matchElements,l=a.whereElements.concat(r.whereElements),i=a.relationElements,s=[],u=[],d=a.parameters;for(t in r.parameters)r.parameters.hasOwnProperty(t)&&(d[t]=r.parameters[t]);var p,c,g=L.node.getResultOrderByAttribute(n.label),e=(null!=g&&(a=[],c=L.node.isResultOrderAscending(n.label),p=[],Array.isArray(c)?p=c.map(function(e){return e?"ASC":"DESC"}):p.push(c?"ASC":"DESC"),Array.isArray(g)?a=g.map(function(e){var t=g.indexOf(e);return t<p.length?e+" "+p[t]:e+" "+p[p.length-1]}):a.push(g+" "+p[0]),u.push("ORDER BY "+a.join(", "))),u.push("LIMIT "+m.MAX_RESULTS_COUNT),e?(s.push(n.internalLabel),i.forEach(function(e){s.push(e)})):(c=L.node.getReturnAttributes(n.label),s=c.map(function(e){return e===m.NEO4J_INTERNAL_ID?"ID("+n.internalLabel+") AS "+m.NEO4J_INTERNAL_ID.queryInternalName:n.internalLabel+"."+e+" AS "+e}),!0===m.RETURN_LABELS&&(a="labels("+n.internalLabel+")",c.indexOf("labels")<0&&(a+=" AS labels"),s.push(a))),"MATCH "+o.join(", ")+(0<l.length?" WHERE "+l.join(" AND "):"")+" RETURN DISTINCT "+s.join(", ")+" "+u.join(" ")),i=L.node.filterResultQuery(n.label,{statement:e,matchElements:o,whereElements:l,withElements:[],returnElements:s,endElements:u,parameters:d});return m.applyPrefilters(i)},m.generateNodeCountQuery=function(e){var t,n=m.generateNegativeQueryElements(),r=m.generateQueryElements(v.getRootNode(),e,m.getRelevantLinks(v.getRootNode(),e,v.links),!0,!0),a=r.matchElements,o=r.whereElements.concat(n.whereElements),l=[],i=r.parameters;for(t in n.parameters)n.parameters.hasOwnProperty(t)&&(i[t]=n.parameters[t]);r=L.node.getConstraintAttribute(e.label),l.push(r===m.NEO4J_INTERNAL_ID?"count(DISTINCT ID("+e.internalLabel+")) as count":"count(DISTINCT "+e.internalLabel+"."+r+") as count"),r="MATCH "+a.join(", ")+(0<o.length?" WHERE "+o.join(" AND "):"")+" RETURN "+l.join(", "),e=L.node.filterNodeCountQuery(e,{statement:r,matchElements:a,whereElements:o,returnElements:l,endElements:[],parameters:i});return m.applyPrefilters(e)},m.generateNodeValueQuery=function(e){var t,n=m.generateNegativeQueryElements(),r=v.getRootNode(),a=m.generateQueryElements(r,e,m.getRelevantLinks(r,e,v.links),!0,!1),o=a.matchElements,l=a.whereElements.concat(n.whereElements),i=[],s=[],u=a.parameters;for(t in n.parameters)n.parameters.hasOwnProperty(t)&&(u[t]=n.parameters[t]);var d=L.node.getValueOrderByAttribute(e.label),p=(d&&(g=L.node.isValueOrderAscending(e.label)?"ASC":"DESC",s.push("ORDER BY "+d+" "+g)),s.push("LIMIT "+m.VALUE_QUERY_LIMIT),L.node.getReturnAttributes(e.label));L.node.getConstraintAttribute(e.label);for(var c=0;c<p.length;c++)p[c]===m.NEO4J_INTERNAL_ID?i.push("ID("+e.internalLabel+") AS "+m.NEO4J_INTERNAL_ID.queryInternalName):i.push(e.internalLabel+"."+p[c]+" AS "+p[c]);var d=L.node.getConstraintAttribute(r.label),g=(i.push(d===m.NEO4J_INTERNAL_ID?"count(DISTINCT ID("+r.internalLabel+")) AS count":"count(DISTINCT "+r.internalLabel+"."+d+") AS count"),m.COLLECT_RELATIONS_WITH_VALUES&&a.returnElements.forEach(function(e){i.push(e)}),"MATCH "+o.join(", ")+(0<l.length?" WHERE "+l.join(" AND "):"")+" RETURN "+i.join(", ")+" "+s.join(" ")),r=L.node.filterNodeValueQuery(e,{statement:g,matchElements:o,whereElements:l,returnElements:i,endElements:s,parameters:u});return m.applyPrefilters(r)},m.generateNodeRelationQuery=function(e){var t=m.getLinksToRoot(e,v.links),t=m.generateQueryElements(v.getRootNode(),e,t,!1,!1),n=t.matchElements,r=t.whereElements,a=[],o=[],t=t.parameters,l=(n.push("("+e.internalLabel+":`"+e.label+"`)-[r]"+(m.USE_RELATION_DIRECTION?"->":"-")+"(x)"),a.push("type(r) AS label"),a.push(m.USE_PARENT_RELATION?"head(labels(x)) AS target":"last(labels(x)) AS target"),a.push("count(r) AS count"),o.push("ORDER BY count(r) DESC"),"MATCH "+n.join(", ")+(0<r.length?" WHERE "+r.join(" AND "):"")+" RETURN "+a.join(", ")+" "+o.join(" ")),e=L.node.filterNodeRelationQuery(e,{statement:l,matchElements:n,whereElements:r,returnElements:a,endElements:o,parameters:t});return m.applyPrefilters(e)},{}),p=(d.createSession=function(){if(void 0!==d.DRIVER)return d.DRIVER.session({defaultAccessMode:"READ"});throw new Error("popoto.runner.DRIVER must be defined")},d.run=function(e){u.info("STATEMENTS:"+JSON.stringify(e));var t=d.createSession();return t.readTransaction(function(t){return Promise.all(e.statements.map(function(e){return t.run({text:e.statement,parameters:e.parameters})}))}).finally(function(){t.close()})},d.toObject=function(e){return e.map(function(e){return e.records.map(function(e){return e.toObject()})})},{});function c(){i();var e=v.getRootNode();e&&void 0!==e.label&&(I.isActive&&I.updateQuery(),x.isActive&&x.updateQuery(),p.isActive||0<p.resultListeners.length||0<p.resultCountListeners.length||0<p.graphResultListeners.length)&&p.updateResults()}function i(){b.isActive&&(b.link.updateLinks(),b.node.updateNodes(),b.force.nodes(v.nodes),b.force.force("link").links(v.links),b.force.alpha(1).restart())}p.containerId="popoto-results",p.hasChanged=!0,p.resultCountListeners=[],p.resultListeners=[],p.graphResultListeners=[],p.RESULTS_PAGE_SIZE=10,p.TOTAL_COUNT=!1,p.onTotalResultCount=function(e){p.resultCountListeners.push(e)},p.onResultReceived=function(e){p.resultListeners.push(e)},p.onGraphResultReceived=function(e){p.graphResultListeners.push(e)},p.parseGraphResultData=function(e){var t,n,r={},a={},o=(e.results[1].data.forEach(function(e){e.graph.nodes.forEach(function(e){r.hasOwnProperty(e.id)||(r[e.id]=e)}),e.graph.relationships.forEach(function(e){a.hasOwnProperty(e.id)||(a[e.id]=e)})}),[]),l=[];for(t in r)r.hasOwnProperty(t)&&o.push(r[t]);for(n in a)a.hasOwnProperty(n)&&l.push(a[n]);return{nodes:o,edges:l}},p.updateResults=function(){var a,e,t,n;p.hasChanged&&(a={},e=0,t=m.generateResultQuery(),t={statements:[{statement:(p.lastGeneratedQuery=t).statement,parameters:t.parameters}]},a.results=e++,0<p.graphResultListeners.length&&(n=m.generateResultQuery(!0),p.lastGeneratedQuery=n,t.statements.push({statement:n.statement,parameters:n.parameters}),a.graph=e++),!0===p.TOTAL_COUNT&&0<p.resultCountListeners.length&&(n=m.generateNodeCountQuery(v.getRootNode()),t.statements.push({statement:n.statement,parameters:n.parameters}),a.total=e++),u.info("Results ==>"),d.run(t).then(function(e){u.info("<== Results");var t,n,e=d.toObject(e),r=e[a.results].map(function(e,t){return{resultIndex:t,label:v.getRootNode().label,attributes:e}});p.lastResults=r,a.hasOwnProperty("total")&&(t=e[a.total][0].count,p.resultCountListeners.forEach(function(e){e(t)})),p.resultListeners.forEach(function(e){e(r)}),0<p.graphResultListeners.length&&(n=p.parseGraphResultData(response),p.graphResultListeners.forEach(function(e){e(n)})),p.isActive&&(s.select("#"+p.containerId).selectAll(".ppt-result").data([]).exit().remove(),s.select("#"+p.containerId).selectAll(".ppt-result").data(r.slice(0,p.RESULTS_PAGE_SIZE),function(e){return e.resultIndex}).enter().append("div").attr("class","ppt-result").attr("id",function(e){return"popoto-result-"+e.resultIndex}).each(function(e){L.node.getDisplayResults(e.label)(s.select(this))})),p.hasChanged=!1}).catch(function(e){u.error(e),p.resultListeners.forEach(function(e){e([])})}))},p.updateResultsCount=function(){0<p.resultCountListeners.length&&p.resultCountListeners.forEach(function(e){e(v.getRootNode().count)})};var l={containerId:"popoto-taxonomy",createTaxonomyPanel:function(){var e=s.select("#"+l.containerId).append("ul").attr("class","ppt-taxo-ul"),t=l.generateTaxonomiesData(),e=e.selectAll(".taxo").data(t).enter().append("li").attr("id",function(e){return e.id}).attr("class","ppt-taxo-li").attr("value",function(e){return e.label}),n=(e.append("span").attr("class",function(e){return"ppt-icon "+L.taxonomy.getCSSClass(e.label,"span-icon")}).html("&nbsp;"),e.append("span").attr("class","ppt-label").text(function(e){return L.taxonomy.getTextValue(e.label)}),e.append("span").attr("class","ppt-count"),e.on("click",l.onClick),l.addTaxonomyChildren(e),[]);t.forEach(function(e){n.push(e),e.children&&l.flattenChildren(e,n)}),b.DISABLE_COUNT||l.updateCount(n)},flattenChildren:function(e,t){e.children.forEach(function(e){t.push(e),e.children&&t.concat(l.flattenChildren(e,t))})},updateCount:function(e){var r,t=[];e.forEach(function(e){t.push({statement:m.generateTaxonomyCountQuery(e.label)})}),r=e,u.info("Count taxonomies ==>"),d.run({statements:t}).then(function(e){u.info("<== Count taxonomies");for(var t=0;t<r.length;t++){var n=e[t].records[0].get("count").toString();s.select("#"+r[t].id).select(".ppt-count").text(" ("+n+")")}},function(e){u.error(e),s.select("#popoto-taxonomy").selectAll(".ppt-count").text(" (0)")}).catch(function(e){u.error(e),s.select("#popoto-taxonomy").selectAll(".ppt-count").text(" (0)")})},addTaxonomyChildren:function(e){e.each(function(e){var t=s.select(this),n=e.children;e.children&&((e=t.append("ul").attr("class","ppt-taxo-sub-ul").selectAll("li").data(n).enter().append("li").attr("id",function(e){return e.id}).attr("class","ppt-taxo-sub-li").attr("value",function(e){return e.label})).append("span").attr("class",function(e){return"ppt-icon "+L.taxonomy.getCSSClass(e.label,"span-icon")}).html("&nbsp;"),e.append("span").attr("class","ppt-label").text(function(e){return L.taxonomy.getTextValue(e.label)}),e.append("span").attr("class","ppt-count"),e.on("click",l.onClick),l.addTaxonomyChildren(e))})},onClick:function(e){e.stopPropagation();e=this.attributes.value.value;v.nodes.length=0,v.links.length=0,b.node.internalLabels={},c(),b.mainLabel=e,void 0!==L.node.getSchema(e)?b.addSchema(L.node.getSchema(e)):b.addRootNode(e),b.hasGraphChanged=!0,p.hasChanged=!0,b.ignoreCount=!1,c(),r.center()},generateTaxonomiesData:function(){var e,t=0,n=[];for(e in L.node.Provider)L.node.Provider.hasOwnProperty(e)&&L.node.getProperty(e,"isSearchable")&&!L.node.Provider[e].parent&&n.push({label:e,id:"popoto-lbl-"+t++});return n.forEach(function(e){L.node.getProvider(e.label).hasOwnProperty("children")&&(t=l.addChildrenData(e,t))}),n},addChildrenData:function(r,a){return r.children=[],L.node.getProvider(r.label).children.forEach(function(e){var t=L.node.getProvider(e),n={label:e,id:"popoto-lbl-"+a++};t.hasOwnProperty("children")&&(a=l.addChildrenData(n,a)),L.node.getProperty(e,"isSearchable")&&r.children.push(n)}),a}},r={CENTER_GRAPH:!0,RESET_GRAPH:!0,SAVE_GRAPH:!(p.generatePreQuery=function(){var t={ids:[]};return p.lastResults.forEach(function(e){t.ids.push(e.attributes.id)}),{query:"MATCH (d) WHERE d.id IN $ids WITH d",param:t}}),TOGGLE_TAXONOMY:!1,TOGGLE_FULL_SCREEN:!0,TOGGLE_VIEW_RELATION:!0,TOGGLE_FIT_TEXT:!0,reset:function(){v.nodes.length=0,v.links.length=0,b.node.internalLabels={},"string"==typeof b.mainLabel||b.mainLabel instanceof String?void 0!==L.node.getSchema(b.mainLabel)?b.addSchema(L.node.getSchema(b.mainLabel)):b.addRootNode(b.mainLabel):b.loadSchema(b.mainLabel),b.hasGraphChanged=!0,p.hasChanged=!0,c(),r.center()},center:function(){b.svgTag.transition().call(b.zoom.transform,s.zoomIdentity)},toggleTaxonomy:function(){var e=s.select("#"+l.containerId);e.filter(".disabled").empty()?e.classed("disabled",!0):e.classed("disabled",!1),b.centerRootNode()},toggleFitText:function(){b.USE_FIT_TEXT=!b.USE_FIT_TEXT,b.node.updateNodes()},toggleViewRelation:function(){b.DISABLE_RELATION=!b.DISABLE_RELATION,s.selectAll(".ppt-g-node-background").classed("hide",b.DISABLE_RELATION),b.tick()},toggleFullScreen:function(){var e=document.getElementById(b.containerId);document.fullscreenElement||document.mozFullScreenElement||document.webkitFullscreenElement||document.msFullscreenElement?document.exitFullscreen?document.exitFullscreen():document.msExitFullscreen?document.msExitFullscreen():document.mozCancelFullScreen?document.mozCancelFullScreen():document.webkitExitFullscreen&&document.webkitExitFullscreen():e.requestFullscreen?e.requestFullscreen():e.msRequestFullscreen?e.msRequestFullscreen():e.mozRequestFullScreen?e.mozRequestFullScreen():e.webkitRequestFullscreen&&e.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT)}},a={TOOL_TAXONOMY:"Show/hide taxonomy panel",TOOL_RELATION:"Show/hide relation",TOOL_CENTER:"Center view",TOOL_FULL_SCREEN:"Full screen",TOOL_RESET:"Reset graph",TOOL_SAVE:"Save graph",TOOL_FIT_TEXT:"Fit text in nodes",render:function(e){e=e.append("div").attr("class","ppt-toolbar");r.TOGGLE_VIEW_RELATION&&e.append("span").attr("id","popoto-toggle-relation").attr("class","ppt-icon ppt-menu relation").attr("title",e.TOOL_RELATION).on("click",function(){r.toggleViewRelation()}),r.RESET_GRAPH&&e.append("span").attr("id","popoto-reset-menu").attr("class","ppt-icon ppt-menu reset").attr("title",e.TOOL_RESET).on("click",function(){b.notifyListeners(b.Events.GRAPH_RESET,[]),r.reset()}),r.TOGGLE_TAXONOMY&&e.append("span").attr("id","popoto-taxonomy-menu").attr("class","ppt-icon ppt-menu taxonomy").attr("title",e.TOOL_TAXONOMY).on("click",r.toggleTaxonomy),r.CENTER_GRAPH&&e.append("span").attr("id","popoto-center-menu").attr("class","ppt-icon ppt-menu center").attr("title",e.TOOL_CENTER).on("click",r.center),r.TOGGLE_FULL_SCREEN&&e.append("span").attr("id","popoto-fullscreen-menu").attr("class","ppt-icon ppt-menu fullscreen").attr("title",e.TOOL_FULL_SCREEN).on("click",r.toggleFullScreen),r.SAVE_GRAPH&&e.append("span").attr("id","popoto-save-menu").attr("class","ppt-icon ppt-menu save").attr("title",e.TOOL_SAVE).on("click",function(){b.notifyListeners(b.Events.GRAPH_SAVE,[b.getSchema()])}),r.TOGGLE_FIT_TEXT&&e.append("span").attr("id","popoto-fit-text-menu").attr("class","ppt-icon ppt-menu fit-text").attr("title",e.TOOL_FIT_TEXT).on("click",r.toggleFitText)}},o={};function g(e){return"function"==typeof e?e:function(){return e}}o.LinkTypes=Object.freeze({RELATION:0,VALUE:1,SEGMENT:2}),o.TEXT_DY=-4,o.SHOW_MARKER=!1,o.gID="popoto-glinks",o.updateLinks=function(){var e=o.updateData();o.removeElements(e.exit()),o.addNewElements(e.enter()),o.updateElements()},o.updateData=function(){return b.svg.select("#"+o.gID).selectAll(".ppt-glink").data(v.links,function(e){return e.id})},o.removeElements=function(e){e.remove()},o.addNewElements=function(e){e=e.append("g").attr("class","ppt-glink").on("click",o.clickLink).on("mouseover",o.mouseOverLink).on("mouseout",o.mouseOutLink);e.append("path").attr("class","ppt-link"),e.append("text").attr("text-anchor","middle").attr("dy",o.TEXT_DY).append("textPath").attr("class","ppt-textPath").attr("startOffset","50%")},o.updateElements=function(){var e=b.svg.select("#"+o.gID).selectAll(".ppt-glink");e.attr("id",function(e){return"ppt-glink_"+e.id}),e.selectAll(".ppt-link").attr("id",function(e){return"ppt-path_"+e.id}).attr("stroke",function(e){return L.link.getColor(e,"path","stroke")}).attr("class",function(e){return"ppt-link "+L.link.getCSSClass(e,"path")}),e.selectAll("text").attr("id",function(e){return"ppt-text_"+e.id}).attr("class",function(e){return L.link.getCSSClass(e,"text")}).attr("fill",function(e){return L.link.getColor(e,"text","fill")}).selectAll(".ppt-textPath").attr("id",function(e){return"ppt-textpath_"+e.id}).attr("class",function(e){return"ppt-textpath "+L.link.getCSSClass(e,"text-path")}).attr("xlink:href",function(e){return"#ppt-path_"+e.id}).text(function(e){return L.link.getTextValue(e)})},o.mouseOverLink=function(){s.select(this).select("path").attr("class",function(e){return"ppt-link "+L.link.getCSSClass(e,"path--hover")}),s.select(this).select("text").attr("class",function(e){return L.link.getCSSClass(e,"text--hover")});var t=s.select(this).data()[0];I.isActive&&(I.queryConstraintSpanElements.filter(function(e){return e.ref===t}).classed("hover",!0),I.querySpanElements.filter(function(e){return e.ref===t}).classed("hover",!0)),x.isActive&&x.querySpanElements.filter(function(e){return e.link===t}).classed("hover",!0)},o.mouseOutLink=function(){s.select(this).select("path").attr("class",function(e){return"ppt-link "+L.link.getCSSClass(e,"path")}),s.select(this).select("text").attr("class",function(e){return L.link.getCSSClass(e,"text")});var t=s.select(this).data()[0];I.isActive&&(I.queryConstraintSpanElements.filter(function(e){return e.ref===t}).classed("hover",!1),I.querySpanElements.filter(function(e){return e.ref===t}).classed("hover",!1)),x.isActive&&x.querySpanElements.filter(function(e){return e.link===t}).classed("hover",!1)},o.clickLink=function(){var e=s.select(this).data()[0];e.type!==o.LinkTypes.VALUE&&(b.node.collapseAllNode(),e=b.node.removeNode(e.target),b.hasGraphChanged=!0,p.hasChanged=e,c())};var f=document.createElement("canvas").getContext("2d"),h=12;function E(e){return f.measureText(e).width}function y(e){if(null==e)return[];for(var t,n,e=String(e),e=((n=(n=e).split(/\s+/g))[n.length-1]||n.pop(),n[0]||n.shift(),Math.sqrt(E(e.trim())*h)),r=n,a=e,o=1/0,l=[],i=0,s=r.length;i<s;++i){var u=(t?t.text+" ":"")+r[i],d=E(u);(o+d)/2<a?(t.width=o=d,t.text=u):(o=E(r[i]),l.push(t={width:o,text:r[i]}))}return l}function A(e,t,n,r){var a,o,l=g(n),i=g(t),n=r&&g(r),t=(a=n,e.each(function(e){var t=s.select(this).selectAll(".fitted-text").data([{}]);t.enter().append("text").merge(t).attr("class","fitted-text"+(void 0!==a?" "+a(e):"")).attr("style","text-anchor: middle; font: 10px sans-serif")}),e.select(".fitted-text"));o=i,t.each(function(e){var n=y(o(e)),e=s.select(this).selectAll("tspan").data(n);e.exit().remove(),e.enter().append("tspan").merge(e).attr("x",0).attr("y",function(e,t){return(t-n.length/2+.8)*h}).text(function(e){return e.text})}),t.attr("transform",function(e){var t=(e=>{for(var t=0,n=0,r=e.length;n<r;++n)var a=e[n].width/2,o=(Math.abs(n-r/2+.5)+.5)*h,t=Math.max(t,Math.sqrt(a*a+o*o));return t})(y(i(e))),n=1;return"translate(0,0) scale("+(n=0!==t&&t?l(e)/t:n)+")"})}var N={getNodeBoundingBox:function(e){return e.getBBox()},render:function(e){var t=e.append("rect").attr("fill",function(e){return L.node.getColor(e,"back-text","fill")}).attr("class",function(e){return L.node.getCSSClass(e,"back-text")});A(e,function(e){return L.node.getTextValue(e)},function(e){return L.node.getSize(e)},function(e){return L.node.getCSSClass(e,"text")}),t.attr("x",function(e){return N.getNodeBoundingBox(s.select(this.parentNode).select("text").node()).x-3}).attr("y",function(e){return N.getNodeBoundingBox(s.select(this.parentNode).select("text").node()).y}).attr("rx","5").attr("ry","5").attr("width",function(e){return N.getNodeBoundingBox(s.select(this.parentNode).select("text").node()).width+6}).attr("height",function(e){return N.getNodeBoundingBox(s.select(this.parentNode).select("text").node()).height}).attr("transform",function(e){return s.select(this.parentNode).select("text").attr("transform")})}},R={TEXT_Y:8,getNodeBoundingBox:function(e){return e.getBBox()},render:function(e){var t=e.append("rect").attr("fill",function(e){return L.node.getColor(e,"back-text","fill")}).attr("class",function(e){return L.node.getCSSClass(e,"back-text")});e.append("text").attr("x",0).attr("y",R.TEXT_Y).attr("text-anchor","middle").attr("class",function(e){return L.node.getCSSClass(e,"text")}).on("mouseover",function(e){s.select(this.parentNode).attr("clip-path",null)}).on("mouseout",function(e){s.select(this.parentNode).attr("clip-path",function(e){return"url(#node-view"+e.id+")"})}).text(function(e){return L.node.getTextValue(e)}),t.attr("x",function(e){return R.getNodeBoundingBox(s.select(this.parentNode).select("text").node()).x-3}).attr("y",function(e){return R.getNodeBoundingBox(s.select(this.parentNode).select("text").node()).y}).attr("rx","5").attr("ry","5").attr("width",function(e){return R.getNodeBoundingBox(s.select(this.parentNode).select("text").node()).width+6}).attr("height",function(e){return R.getNodeBoundingBox(s.select(this.parentNode).select("text").node()).height})}},T={gID:"popoto-gnodes",DONUTS_MARGIN:0,DONUT_WIDTH:20,NODE_MAX_CHARS:11,NODE_TITLE_MAX_CHARS:100,PAGE_SIZE:10,CountBox:{x:16,y:33,w:52,h:19},chooseWaiting:!1,getDonutInnerRadius:function(e){return L.node.getSize(e)+T.DONUTS_MARGIN},getDonutOuterRadius:function(e){return L.node.getSize(e)+T.DONUTS_MARGIN+T.DONUT_WIDTH}},O=(T.pie=s.pie().sort(null).value(function(e){return 1}),T.NodeTypes=Object.freeze({ROOT:0,CHOOSE:1,VALUE:2,GROUP:3}),T.internalLabels={},T.generateInternalLabel=function(e){e=e?e.toLowerCase().replace(/ /g,""):"n";return e in T.internalLabels?(T.internalLabels[e]=T.internalLabels[e]+1,e+T.internalLabels[e]):(T.internalLabels[e]=0,e)},T.updateNodes=function(){var e=T.updateData();T.removeElements(e.exit()),T.addNewElements(e.enter()),T.updateElements()},T.updateData=function(){var e=b.svg.select("#"+T.gID).selectAll(".ppt-gnode").data(v.nodes,function(e){return e.id});return b.hasGraphChanged&&(T.updateAutoLoadValues(),b.DISABLE_COUNT||b.ignoreCount||T.updateCount()),b.hasGraphChanged=!1,e},T.updateCount=function(){var t=[],r=v.nodes.filter(function(e){return!(e.type===T.NodeTypes.VALUE||e.type===T.NodeTypes.GROUP||e.hasOwnProperty("isNegative")&&e.isNegative)});r.forEach(function(e){e=m.generateNodeCountQuery(e);t.push({statement:e.statement,parameters:e.parameters})}),u.info("Count nodes ==>"),d.run({statements:t}).then(function(e){u.info("<== Count nodes");for(var t=d.toObject(e),n=0;n<r.length;n++)r[n].count=t[n][0].count;0<p.resultCountListeners.length&&p.updateResultsCount(),T.updateElements(),b.link.updateElements()}).catch(function(e){u.error(e),r.forEach(function(e){e.count=0}),T.updateElements(),b.link.updateElements()})},T.updateAutoLoadValues=function(){for(var e=[],o=T.getAutoLoadValueNodes(),t=0;t<o.length;t++){var n=o[t],n=m.generateNodeValueQuery(n);e.push({statement:n.statement,parameters:n.parameters})}0<e.length&&(u.info("AutoLoadValue ==>"),d.run({statements:e}).then(function(e){u.info("<== AutoLoadValue");for(var t=d.toObject(e),n=0;n<o.length;n++){var r=o[n],a=L.node.getConstraintAttribute(r.label);r.data=t[n].filter(function(t){var n=!0;return r.hasOwnProperty("value")&&0<r.value.length&&r.value.forEach(function(e){e.attributes[a]===t[a]&&(n=!1)}),n}),r.page=1}b.notifyListeners(b.Events.GRAPH_NODE_DATA_LOADED,[o])}).catch(function(e){u.error(e)}))},T.removeElements=function(e){e.filter(function(e){return!e.parent}).remove(),e.filter(function(e){return e.parent}).transition().duration(300).attr("transform",function(e){return"translate("+e.parent.x+","+e.parent.y+")"}).remove()},T.addNewElements=function(e){e=e.append("g").attr("class","ppt-gnode");e.on("click",T.nodeClick).on("mouseover",T.mouseOverNode).on("mouseout",T.mouseOutNode),e.filter(function(e){return e.type!==T.NodeTypes.VALUE}).on("contextmenu",T.clearSelection),e.filter(function(e){return e.type===T.NodeTypes.VALUE}).on("contextmenu",function(e){e.preventDefault()}),e.append("defs").append("clipPath").attr("id",function(e){return"node-view"+e.id}).append("circle").attr("cx",0).attr("cy",0),T.addBackgroundElements(e),T.addMiddlegroundElements(e),T.addForegroundElements(e)},T.addBackgroundElements=function(e){e=e.append("g").attr("class","ppt-g-node-background").classed("hide",b.DISABLE_RELATION);e.append("g").attr("class","ppt-donut-labels"),e.append("g").attr("class","ppt-donut-segments")},T.addMiddlegroundElements=function(e){e.append("g").attr("class","ppt-g-node-middleground")},T.addForegroundElements=function(e){var e=e.append("g").attr("class","ppt-g-node-foreground"),t=e.filter(function(e){return e.type===T.NodeTypes.ROOT||e.type===T.NodeTypes.CHOOSE}).append("g").attr("class","ppt-node-foreground-g-arrows"),n=t.append("g"),n=(n.append("circle").attr("class","ppt-larrow").attr("cx","-43").attr("cy","-23").attr("r","17"),n.append("path").attr("class","ppt-arrow").attr("d","m -44.905361,-23 6.742,-6.742 c 0.81,-0.809 0.81,-2.135 0,-2.944 l -0.737,-0.737 c -0.81,-0.811 -2.135,-0.811 -2.945,0 l -8.835,8.835 c -0.435,0.434 -0.628,1.017 -0.597,1.589 -0.031,0.571 0.162,1.154 0.597,1.588 l 8.835,8.834 c 0.81,0.811 2.135,0.811 2.945,0 l 0.737,-0.737 c 0.81,-0.808 0.81,-2.134 0,-2.943 l -6.742,-6.743 z"),n.on("click",function(e,t){e.stopPropagation(),1<t.page&&(t.page--,T.collapseNode(t),T.expandNode(t))}),t.append("g"));n.append("circle").attr("class","ppt-rarrow").attr("cx","43").attr("cy","-23").attr("r","17"),n.append("path").attr("class","ppt-arrow").attr("d","m 51.027875,-24.5875 -8.835,-8.835 c -0.811,-0.811 -2.137,-0.811 -2.945,0 l -0.738,0.737 c -0.81,0.81 -0.81,2.136 0,2.944 l 6.742,6.742 -6.742,6.742 c -0.81,0.81 -0.81,2.136 0,2.943 l 0.737,0.737 c 0.81,0.811 2.136,0.811 2.945,0 l 8.835,-8.836 c 0.435,-0.434 0.628,-1.017 0.597,-1.588 0.032,-0.569 -0.161,-1.152 -0.596,-1.586 z"),n.on("click",function(e,t){e.stopPropagation(),t.page*T.PAGE_SIZE<t.count&&(t.page++,T.collapseNode(t),T.expandNode(t))}),b.DISABLE_COUNT||((t=e.filter(function(e){return e.type!==T.NodeTypes.GROUP})).append("rect").attr("x",T.CountBox.x).attr("y",T.CountBox.y).attr("width",T.CountBox.w).attr("height",T.CountBox.h).attr("class","ppt-count-box"),t.append("text").attr("x",42).attr("y",48).attr("text-anchor","middle").attr("class","ppt-count-text")),e.filter(function(e){return e.type===T.NodeTypes.CHOOSE}).append("g").attr("class","ppt-g-node-ban").append("path").attr("d","M89.1 19.2C88 17.7 86.6 16.2 85.2 14.8 83.8 13.4 82.3 12 80.8 10.9 72 3.9 61.3 0 50 0 36.7 0 24.2 5.4 14.8 14.8 5.4 24.2 0 36.7 0 50c0 11.4 3.9 22.1 10.9 30.8 1.2 1.5 2.5 3 3.9 4.4 1.4 1.4 2.9 2.7 4.4 3.9C27.9 96.1 38.6 100 50 100 63.3 100 75.8 94.6 85.2 85.2 94.6 75.8 100 63.3 100 50 100 38.7 96.1 28 89.1 19.2ZM11.9 50c0-10.2 4-19.7 11.1-27C30.3 15.9 39.8 11.9 50 11.9c8.2 0 16 2.6 22.4 7.3L19.3 72.4C14.5 66 11.9 58.2 11.9 50Zm65 27c-7.2 7.1-16.8 11.1-27 11.1-8.2 0-16-2.6-22.4-7.4L80.8 27.6C85.5 34 88.1 41.8 88.1 50c0 10.2-4 19.7-11.1 27z")},T.updateElements=function(){var e=b.svg.select("#"+T.gID).selectAll(".ppt-gnode");e.attr("id",function(e){return"popoto-gnode_"+e.id}),b.USE_VORONOI_LAYOUT&&e.attr("clip-path",function(e){return"url(#voroclip-"+e.id+")"}),e.select("defs").select("clipPath").attr("id",function(e){return"node-view"+e.id}).selectAll("circle").attr("r",function(e){return L.node.getSize(e)}),e.filter(function(e){return e.type!==T.NodeTypes.ROOT}).call(s.drag().on("start",function(e,t){e.active||b.force.alphaTarget(.3).restart();t.fx=t.x,t.fy=t.y}).on("drag",function(e,t){t.fx=e.x,t.fy=e.y}).on("end",function(e,t){e.active||b.force.alphaTarget(0);!1===t.fixed&&(t.fx=null,t.fy=null)})),T.updateBackgroundElements(),T.updateMiddlegroundElements(),T.updateForegroundElements()},T.updateBackgroundElements=function(){var e=b.svg.select("#"+T.gID).selectAll(".ppt-gnode").selectAll(".ppt-g-node-background"),t=(e.select(".ppt-donut-labels").selectAll("*").remove(),e.select(".ppt-donut-segments").selectAll("*").remove(),e.select(".ppt-donut-segments").selectAll(".ppt-segment-container").data(function(e){var t=[];return t=e.hasOwnProperty("relationships")?e.relationships:t},function(e){return e.id}).enter().append("g").attr("class",".ppt-segment-container").on("click",T.segmentClick).on("mouseover",function(e){s.select(this).select(".ppt-text-arc").classed("hover",!0)}).on("mouseout",function(e){s.select(this).select(".ppt-text-arc").classed("hover",!1)}));t.append("title").attr("class","ppt-svg-title").text(function(e){return e.label+" "+e.target}),e.select(".ppt-donut-labels").selectAll(".ppt-segment-container").data(function(e){var t=[];return t=e.hasOwnProperty("relationships")?e.relationships:t},function(e){return e.id}).enter().append("g").attr("class",".ppt-segment-container").on("click",T.segmentClick).on("mouseover",function(e){s.select(this).select(".ppt-text-arc").classed("hover",!0)}).on("mouseout",function(e){s.select(this).select(".ppt-text-arc").classed("hover",!1)}).append("path").attr("class","ppt-hidden-arc").attr("id",function(e,t){return"arc_"+s.select(this.parentNode.parentNode).datum().id+"_"+t}).attr("d",function(e){var t=s.select(this.parentNode.parentNode).datum(),e={startAngle:e.directionAngle-(Math.PI-.1),endAngle:e.directionAngle+(Math.PI-.1)},t=s.arc().innerRadius(T.getDonutInnerRadius(t)).outerRadius(T.getDonutOuterRadius(t))(e),e=/(^.+?)L/.exec(t);return(e&&1<e.length?e:/(^.+?)M/.exec(t))[1].replace(/,/g," ")}).style("fill","none").style("stroke","none"),t.append("text").attr("text-anchor","middle").attr("class",function(e){var t=s.select(this.parentNode.parentNode).datum();return t.hasOwnProperty("count")&&0===t.count?"ppt-text-arc disabled":"ppt-text-arc"}).attr("fill",function(e){var t=s.select(this.parentNode.parentNode).datum();return L.link.getColor({label:e.label,type:b.link.LinkTypes.SEGMENT,source:t,target:{label:e.target}},"segment","fill")}).attr("dy",b.link.TEXT_DY).append("textPath").attr("startOffset","50%").attr("xlink:href",function(e,t){return"#arc_"+s.select(this.parentNode.parentNode.parentNode).datum().id+"_"+t}).text(function(e){var t=s.select(this.parentNode.parentNode.parentNode).datum();return L.link.getTextValue({source:t,target:{label:e.target},label:e.label,type:b.link.LinkTypes.SEGMENT})}),t.append("path").attr("class",function(e){var t=s.select(this.parentNode.parentNode).datum();return t.hasOwnProperty("count")&&0===t.count?"ppt-segment disabled":"ppt-segment"}).attr("d",function(e){var t=s.select(this.parentNode.parentNode).datum();return s.arc().innerRadius(T.getDonutInnerRadius(t)).outerRadius(T.getDonutOuterRadius(t))(e)}).attr("fill",function(e){var t=s.select(this.parentNode.parentNode).datum();return L.link.getColor({label:e.label,type:b.link.LinkTypes.RELATION,source:t,target:{label:e.target}},"path","fill")}).attr("stroke",function(e){var t=s.select(this.parentNode.parentNode).datum();return L.link.getColor({label:e.label,type:b.link.LinkTypes.RELATION,source:t,target:{label:e.target}},"path","stroke")})},T.updateMiddlegroundElements=function(){var e=b.svg.select("#"+T.gID).selectAll(".ppt-gnode").selectAll(".ppt-g-node-middleground");e.attr("clip-path",function(e){return"url(#node-view"+e.id+")"}),e.selectAll("*").remove(),T.updateMiddlegroundElementsTooltip(e),T.updateMiddlegroundElementsText(e.filter(function(e){return L.node.getNodeDisplayType(e)===L.node.DisplayTypes.TEXT})),T.updateMiddlegroundElementsImage(e.filter(function(e){return L.node.getNodeDisplayType(e)===L.node.DisplayTypes.IMAGE})),T.updateMiddlegroundElementsSymbol(e.filter(function(e){return L.node.getNodeDisplayType(e)===L.node.DisplayTypes.SYMBOL})),T.updateMiddlegroundElementsSVG(e.filter(function(e){return L.node.getNodeDisplayType(e)===L.node.DisplayTypes.SVG})),T.updateMiddlegroundElementsDisplayedText(e.filter(function(e){return L.node.isTextDisplayed(e)}))},T.updateMiddlegroundElementsTooltip=function(e){e.append("title").attr("class",function(e){return L.node.getCSSClass(e,"title")}).text(function(e){return L.node.getTextValue(e,T.NODE_TITLE_MAX_CHARS)})},T.updateMiddlegroundElementsText=function(e){e.append("circle").attr("r",function(e){return L.node.getSize(e)}).attr("class",function(e){return L.node.getCSSClass(e,"circle")}).attr("fill",function(e){return L.node.getColor(e,"circle","fill")}).attr("stroke",function(e){return L.node.getColor(e,"circle","stroke")})},T.updateMiddlegroundElementsImage=function(e){e.append("circle").attr("r",function(e){return L.node.getSize(e)}).attr("class",function(e){return L.node.getCSSClass(e,"image-background-circle")}),e.append("image").attr("class",function(e){return L.node.getCSSClass(e,"image")}).attr("width",function(e){return L.node.getImageWidth(e)}).attr("height",function(e){return L.node.getImageHeight(e)}).attr("transform",function(e){return"translate("+-L.node.getImageWidth(e)/2+","+-L.node.getImageHeight(e)/2+")"}).attr("xlink:href",function(e){return L.node.getImagePath(e)})},T.updateMiddlegroundElementsSymbol=function(e){e.append("circle").attr("r",function(e){return L.node.getSize(e)}).attr("class",function(e){return L.node.getCSSClass(e,"symbol-background-circle")}).attr("fill",function(e){return L.node.getColor(e,"circle","fill")}).attr("stroke",function(e){return L.node.getColor(e,"circle","stroke")}),e.append("use").attr("class",function(e){return L.node.getCSSClass(e,"symbol")}).attr("width",function(e){return L.node.getImageWidth(e)}).attr("height",function(e){return L.node.getImageHeight(e)}).attr("transform",function(e){return"translate("+-L.node.getImageWidth(e)/2+","+-L.node.getImageHeight(e)/2+")"}).attr("xlink:href",function(e){return L.node.getImagePath(e)}).attr("fill",function(e){return L.node.getColor(e,"circle","fill")}).attr("stroke",function(e){return L.node.getColor(e,"circle","stroke")})},T.updateMiddlegroundElementsSVG=function(e){var e=e.append("g"),t=(e.append("circle").attr("r",function(e){return L.node.getSize(e)}).attr("class","ppt-svg-node-background"),e.selectAll("path").data(function(e){return L.node.getSVGPaths(e)}));t.exit().remove(),t.enter().append("path"),e.selectAll("path").attr("class",function(e){var t=s.select(this.parentNode).datum();return L.node.getCSSClass(t,"path")}).each(function(e,t){for(var n in e)e.hasOwnProperty(n)&&s.select(this).attr(n,e[n])})},T.updateMiddlegroundElementsDisplayedText=function(e){e=e.filter(function(e){return L.node.isTextDisplayed(e)});(b.USE_FIT_TEXT?N:R).render(e)},T.updateForegroundElements=function(){var e=b.svg.select("#"+T.gID).selectAll(".ppt-gnode").selectAll(".ppt-g-node-foreground").selectAll(".ppt-node-foreground-g-arrows"),e=(e.classed("active",function(e){return e.valueExpanded&&e.data&&e.data.length>T.PAGE_SIZE}),e.selectAll(".ppt-larrow").classed("enabled",function(e){return 1<e.page}),e.selectAll(".ppt-rarrow").classed("enabled",function(e){var t;return!!e.data&&(t=e.data.length,e.page*T.PAGE_SIZE<t)}),b.svg.select("#"+T.gID).selectAll(".ppt-gnode").selectAll(".ppt-g-node-foreground"));e.selectAll(".ppt-count-box").filter(function(e){return e.type!==T.NodeTypes.CHOOSE}).classed("root",!0),e.selectAll(".ppt-count-box").filter(function(e){return e.type===T.NodeTypes.CHOOSE}).classed("value",!0),e.selectAll(".ppt-count-box").classed("disabled",function(e){return 0===e.count}),b.DISABLE_COUNT||e.selectAll(".ppt-count-text").text(function(e){return null!==e.count?e.count:"..."}).classed("disabled",function(e){return 0===e.count}),b.svg.select("#"+T.gID).selectAll(".ppt-gnode").selectAll(".ppt-g-node-foreground").filter(function(e){return!0===e.isNegative}).selectAll(".ppt-g-node-ban").attr("transform",function(e){return"translate("+-L.node.getSize(e)+","+-L.node.getSize(e)+") scale("+2*L.node.getSize(e)/100+")"}).attr("stroke-width",function(e){return 2/(2*L.node.getSize(e)/100)+"px"}),b.svg.select("#"+T.gID).selectAll(".ppt-gnode").selectAll(".ppt-g-node-foreground").selectAll(".ppt-g-node-ban").classed("active",function(e){return!0===e.isNegative})},T.segmentClick=function(e,t){e.preventDefault();e=s.select(this.parentNode.parentNode).datum();b.ignoreCount=!0,b.addRelationshipData(e,t,function(t){b.notifyListeners(b.Events.GRAPH_NODE_RELATION_ADD,[v.links.filter(function(e){return e.target===t})]),b.ignoreCount=!1,b.hasGraphChanged=!0,c()})},T.mouseOverNode=function(e){e.preventDefault();var t=s.select(this).data()[0];I.isActive&&(I.queryConstraintSpanElements.filter(function(e){return e.ref===t}).classed("hover",!0),I.querySpanElements.filter(function(e){return e.ref===t}).classed("hover",!0)),x.isActive&&x.querySpanElements.filter(function(e){return e.node===t}).classed("hover",!0)},T.mouseOutNode=function(e){e.preventDefault();var t=s.select(this).data()[0];I.isActive&&(I.queryConstraintSpanElements.filter(function(e){return e.ref===t}).classed("hover",!1),I.querySpanElements.filter(function(e){return e.ref===t}).classed("hover",!1)),x.isActive&&x.querySpanElements.filter(function(e){return e.node===t}).classed("hover",!1)},T.nodeClick=function(e){if(!e.defaultPrevented){var t=s.select(this).data()[0];if(u.debug("nodeClick ("+t.label+")"),t.type===T.NodeTypes.VALUE)T.valueNodeClick(t);else if(t.type===T.NodeTypes.CHOOSE||t.type===T.NodeTypes.ROOT)if(e.ctrlKey){if(t.type===T.NodeTypes.CHOOSE){if(t.isNegative=!t.hasOwnProperty("isNegative")||!t.isNegative,T.collapseAllNode(),!(t.hasOwnProperty("value")&&0<t.value.length)&&t.isNegative){for(var n=v.links.length-1;0<=n;n--)v.links[n].source===t&&T.removeNode(v.links[n].target);t.count=0}p.hasChanged=!0,b.hasGraphChanged=!0,c()}}else t.valueExpanded?T.collapseNode(t):T.chooseNodeClick(t)}},T.collapseNode=function(t){if(t.valueExpanded){u.debug("collapseNode ("+t.label+")"),b.notifyListeners(b.Events.GRAPH_NODE_VALUE_COLLAPSE,[t]);var e=v.links.filter(function(e){return e.source===t&&e.type===b.link.LinkTypes.VALUE});e.forEach(function(e){v.nodes.splice(v.nodes.indexOf(e.target),1)});for(var n=v.links.length-1;0<=n;n--)0<=e.indexOf(v.links[n])&&v.links.splice(n,1);t.type!==T.NodeTypes.ROOT&&(t.fixed=!1,t.fx=null,t.fy=null),t.parent&&t.parent.type!==T.NodeTypes.ROOT&&(t.parent.fixed=!1,t.parent.fx=null,t.parent.fy=null),t.valueExpanded=!1,c()}else u.debug("collapseNode called on an unexpanded node")},T.collapseAllNode=function(){v.nodes.forEach(function(e){e.type!==T.NodeTypes.CHOOSE&&e.type!==T.NodeTypes.ROOT||!e.valueExpanded||T.collapseNode(e)})},T.valueNodeClick=function(e){u.debug("valueNodeClick ("+e.label+")"),b.notifyListeners(b.Events.GRAPH_NODE_ADD_VALUE,[e]),void 0===e.parent.value&&(e.parent.value=[]),e.parent.value.push(e),p.hasChanged=!0,b.hasGraphChanged=!0,T.collapseNode(e.parent)},T.chooseNodeClick=function(a){var e;u.debug("chooseNodeClick ("+a.label+") with waiting state set to "+T.chooseWaiting),T.chooseWaiting||a.immutable||0===a.count||(T.collapseAllNode(),T.chooseWaiting=!0,void 0!==a.data&&a.isAutoLoadValue?(a.page=1,T.expandNode(a),T.chooseWaiting=!1):(u.info("Values ("+a.label+") ==>"),e=m.generateNodeValueQuery(a),d.run({statements:[{statement:e.statement,parameters:e.parameters}]}).then(function(e){u.info("<== Values ("+a.label+")");var e=d.toObject(e),r=L.node.getConstraintAttribute(a.label);a.data=e[0].filter(function(t){var n=!0;return a.hasOwnProperty("value")&&0<a.value.length&&a.value.forEach(function(e){e.attributes[r]===t[r]&&(n=!1)}),n}),a.page=1,T.expandNode(a),T.chooseWaiting=!1}).catch(function(e){T.chooseWaiting=!1,u.error(e)})))},T.addExpandedValue=function(e,t){for(var n=!1,r=v.nodes.length-1;0<=r;r--)if(v.nodes[r].valueExpanded){for(var a=v.nodes[r].data.length-1;0<=a;a--)v.nodes[r].data[a][e]===t&&(n=!0,v.nodes[r].hasOwnProperty("value")||(v.nodes[r].value=[]),v.nodes[r].value.push({attributes:v.nodes[r].data[a]}),v.nodes[r].data.splice(a,1));T.collapseNode(v.nodes[r]),T.expandNode(v.nodes[r])}n&&(p.hasChanged=!0,b.hasGraphChanged=!0,c())},T.getContainingValue=function(n){var r=[],e=v.links,t=v.nodes;return 0<t.length&&(void 0!==(t=t[0]).value&&0<t.value.length&&(void 0!==n&&n!==t.label||r.push(t)),e.forEach(function(e){var t=e.target;e.type===b.link.LinkTypes.RELATION&&void 0!==t.value&&0<t.value.length&&(void 0!==n&&n!==t.label||r.push(t))})),r},T.addValueForLabel=function(e,t){for(var n,r,a=!1,o=v.nodes.length-1;0<=o;o--)v.nodes[o].type===T.NodeTypes.CHOOSE&&v.nodes[o].label===e&&(v.nodes[o].hasOwnProperty("value")||(v.nodes[o].value=[]),n=!1,r=L.node.getConstraintAttribute(e),v.nodes[o].value.forEach(function(e){e.attributes.hasOwnProperty(r)&&e.attributes[r]===t.attributes[r]&&(n=!0)}),n||(v.nodes[o].value.push(t),a=!0));return a},T.addValue=function(e,t){for(var n=!1,r=0;r<v.nodes.length;r++){var a,o=v.nodes[r];0<=e.indexOf(o.id)&&(o.hasOwnProperty("value")||(o.value=[]),a=L.node.getReturnAttributes(o.label)[0],o.data.forEach(function(e){e.hasOwnProperty(a)&&e[a]===t&&(n=!0,o.value.push({attributes:e}))}))}n&&(p.hasChanged=!0,b.hasGraphChanged=!0,c())},T.removeValue=function(e,t){var n=!1;T.collapseNode(e);for(var r=e.value.length-1;0<=r;r--)e.value[r]===t&&(e.value.splice(r,1),n=!0);return n},T.removeValues=function(e){var t=!1;return T.collapseNode(e),t=void 0!==e.value&&0<e.value.length?!(e.value.length=0):t},T.getValue=function(e,t){for(var n=0;n<v.nodes.length;n++){var r=v.nodes[n];if(r.id===e)for(var a=L.node.getConstraintAttribute(r.label),o=r.value.length-1;0<=o;o--)if(r.value[o].attributes[a]===t)return r.value[o]}},T.removeExpandedValue=function(e,t){for(var n=!1,r=v.nodes.length-1;0<=r;r--)if(v.nodes[r].valueExpanded){for(var a=[],o=v.nodes[r].value.length-1;0<=o;o--)v.nodes[r].value[o].attributes[e]===t&&(n=!0,a=a.concat(v.nodes[r].value.splice(o,1)));for(var l=0;l<a.length;l++)v.nodes[r].data.push(a[l].attributes);T.collapseNode(v.nodes[r]),T.expandNode(v.nodes[r])}n&&(p.hasChanged=!0,b.hasGraphChanged=!0,c())},T.getAutoLoadValueNodes=function(){return v.nodes.filter(function(e){return e.hasOwnProperty("isAutoLoadValue")&&!0===e.isAutoLoadValue&&!(!0===e.isNegative)})},T.addRelatedValues=function(i,e,s){var a,e=T.filterExistingValues(i,e);e.length<=0||(a=[],e.forEach(function(e){var t=L.node.getConstraintAttribute(e.label),n="MATCH ",t=(n+=t===m.NEO4J_INTERNAL_ID?"(v:`"+e.label+"`) WHERE (ID(v) = $p)":"(v:`"+e.label+"`) WHERE (v."+t+" = $p)",L.node.getReturnAttributes(e.label)),r="";n+=' RETURN DISTINCT "'+e.rel+'" AS rel, "'+e.label+'" AS label, {'+t.reduce(function(e,t){return e+=r+t+":v."+t,r=", ",e},"")+"} AS value LIMIT 1",a.push({statement:n,parameters:{p:e.id},resultDataContents:["row"]})}),u.info("addRelatedValues ==>"),d.run({statements:a}).then(function(e){u.info("<== addRelatedValues");var o=d.toObject(e),l=0;o.forEach(function(e){var t,n,r,a;0<e.length&&(t=e[0].label,r=e[0].value,n=e[0].rel,e={id:v.generateId(),parent:i,attributes:r,type:T.NodeTypes.VALUE,label:t},b.ignoreCount=!0,r=i.relationships.filter(function(e){return e.label===n&&e.target===t}),a={label:n,target:t},0<r.length&&(a=r[0]),b.addRelationshipData(i,a,function(){++l===o.length&&(b.ignoreCount=!1,b.hasGraphChanged=!0,p.hasChanged=!0,c())},[e],s))})}).catch(function(e){u.error(e)}))},T.addRelatedBranch=function(e,t,n,r){var a,o;0<t.length?(a=t[0],t=t.slice(1),0<(o=e.relationships.filter(function(e){return e.label===a.type&&e.target===a.target})).length&&b.addRelationshipData(e,o[0],function(e){T.addRelatedBranch(e,t,n,r)})):T.addRelatedValues(e,n,r)},T.filterExistingValues=function(e,t){var a=[],o=v.nodes.filter(function(e){return e.parent===e&&e.hasOwnProperty("value")&&0<e.value.length});return t.forEach(function(t){var n=!1,r=L.node.getConstraintAttribute(t.label);o.forEach(function(e){e.label===t.label&&e.value.forEach(function(e){e.attributes[r]===t.id&&(n=!0)})}),n||a.push(t)}),a},T.expandNode=function(r){b.notifyListeners(b.Events.GRAPH_NODE_VALUE_EXPAND,[r]);var e=r.page*T.PAGE_SIZE,a=r.data.slice(e-T.PAGE_SIZE,e),o=b.computeParentAngle(r),l=1;a.forEach(function(e){var t=r.parent?360/(a.length+1)*l:360/a.length*l,n=r.x+100*Math.cos(t*(Math.PI/180)-o),t=r.y+100*Math.sin(t*(Math.PI/180)-o),n={id:v.generateId(),parent:r,attributes:e,type:T.NodeTypes.VALUE,label:r.label,count:e.count,x:n,y:t,internalID:e[m.NEO4J_INTERNAL_ID.queryInternalName]};v.nodes.push(n),v.links.push({id:"l"+v.generateId(),source:r,target:n,type:b.link.LinkTypes.VALUE}),l++}),r.fixed=!0,r.fx=r.x,r.fy=r.y,r.parent&&r.parent.type!==T.NodeTypes.ROOT&&(r.parent.fixed=!0,r.parent.fx=r.parent.x,r.parent.fy=r.parent.y),r.valueExpanded=!0,c()},T.loadRelationshipData=function(t,n,r){var e=L.node.getSchema(t.label);void 0!==e?e.hasOwnProperty("rel")&&0<e.rel.length?n(T.pie.startAngle(r-Math.PI).endAngle(r+Math.PI)(e.rel).map(function(e){var t={id:e.data.label+e.data.target.label,label:e.data.label,target:e.data.target.label,count:0,startAngle:e.startAngle,endAngle:e.endAngle,directionAngle:(e.startAngle+e.endAngle)/2};return!0===e.data.isReverse&&(t.isReverse=!0),t})):n([]):(e=m.generateNodeRelationQuery(t),u.info("Relations ("+t.label+") ==>"),d.run({statements:[{statement:e.statement,parameters:e.parameters}]}).then(function(e){u.info("<== Relations ("+t.label+")");e=d.toObject(e)[0].filter(function(e){return m.filterRelation(e)}),e=T.pie.startAngle(r-Math.PI).endAngle(r+Math.PI)(e).map(function(e){return{id:e.data.label+e.data