@cosmograph/cosmograph
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -1,2 +0,2 @@ | ||
import{Graph as e}from"@cosmograph/cosmos";import{LabelRenderer as s,CssLabel as o}from"@interacta/css-labels";import{merge as t}from"@cosmograph/ui";import{color as i}from"d3-color";import{watermark as r}from"./watermark.js";import{addMetrics as n}from"../../api/supabase/supabase.js";import l from"./style.module.css.js";import{defaultCosmographConfig as d}from"./config.js";import{Crossfilter as a}from"./crossfilter.js";class h{constructor(i,n){var h;this._data={nodes:[],links:[]},this._previousData={nodes:[],links:[]},this._config={},this._nodesForTopLabels=new Set,this._nodesForForcedLabels=new Set,this._trackedNodeToLabel=new Map,this._isLabelsDestroyed=!1,this._svgParser=new DOMParser,this._nodesCrossfilter=new a(this._applyLinksFilter.bind(this)),this._linksCrossfilter=new a(this._applyNodesFilter.bind(this)),this._nodesFilter=this._nodesCrossfilter.addFilter(!1),this._linksFilter=this._linksCrossfilter.addFilter(!1),this._selectedNodesFilter=this._nodesCrossfilter.addFilter(),this._isDataDifferent=()=>{const e=JSON.stringify(this._data.nodes),s=JSON.stringify(this._previousData.nodes),o=JSON.stringify(this._data.links),t=JSON.stringify(this._previousData.links);return e!==s||o!==t},this._onClick=(...e)=>{var s,o;null===(o=(s=this._config).onClick)||void 0===o||o.call(s,...e)},this._onNodeMouseOver=(...e)=>{var s,o;null===(o=(s=this._config).onNodeMouseOver)||void 0===o||o.call(s,...e);const[t,,i]=e;this._renderLabelForHovered(t,i)},this._onNodeMouseOut=(...e)=>{var s,o;null===(o=(s=this._config).onNodeMouseOut)||void 0===o||o.call(s,...e),this._renderLabelForHovered()},this._onMouseMove=(...e)=>{var s,o;null===(o=(s=this._config).onMouseMove)||void 0===o||o.call(s,...e);const[t,,i]=e;this._renderLabelForHovered(t,i)},this._onZoomStart=(...e)=>{var s,o;null===(o=(s=this._config).onZoomStart)||void 0===o||o.call(s,...e)},this._onZoom=(...e)=>{var s,o;null===(o=(s=this._config).onZoom)||void 0===o||o.call(s,...e),this._renderLabelForHovered(),this._renderLabels()},this._onZoomEnd=(...e)=>{var s,o;null===(o=(s=this._config).onZoomEnd)||void 0===o||o.call(s,...e)},this._onStart=(...e)=>{var s,o;null===(o=(s=this._config).onSimulationStart)||void 0===o||o.call(s,...e)},this._onTick=(...e)=>{var s,o;null===(o=(s=this._config).onSimulationTick)||void 0===o||o.call(s,...e),this._renderLabels()},this._onEnd=(...e)=>{var s,o;null===(o=(s=this._config).onSimulationEnd)||void 0===o||o.call(s,...e)},this._onPause=(...e)=>{var s,o;null===(o=(s=this._config).onSimulationPause)||void 0===o||o.call(s,...e)},this._onRestart=(...e)=>{var s,o;null===(o=(s=this._config).onSimulationRestart)||void 0===o||o.call(s,...e)},this._containerNode=i,this._containerNode.classList.add(l.cosmograph),this._config=t(d,null!=n?n:{}),this._canvasElement=document.createElement("canvas"),this._labelsDivElement=document.createElement("div"),this._watermarkDivElement=document.createElement("div"),this._watermarkDivElement.classList.add(l.watermark),this._watermarkDivElement.onclick=()=>{var e;return null===(e=window.open("https://cosmograph.app/","_blank"))||void 0===e?void 0:e.focus()},i.appendChild(this._canvasElement),i.appendChild(this._labelsDivElement),i.appendChild(this._watermarkDivElement),this._cosmos=new e(this._canvasElement,this._createCosmosConfig(n)),this.cosmos=this._cosmos,this._linksFilter.setAccessor((e=>[e.source,e.target])),this._nodesFilter.setAccessor((e=>e.id)),this._selectedNodesFilter.setAccessor((e=>e.id)),this._nodesCrossfilter.onFiltered=()=>{var e,s;let o;this._nodesCrossfilter.isAnyFiltersActive()?(o=this._nodesCrossfilter.getFilteredRecords(),this._cosmos.selectNodesByIds(o.map((e=>e.id)))):this._cosmos.unselectNodes(),this._updateSelectedNodesSet(o),null===(s=(e=this._config).onNodesFiltered)||void 0===s||s.call(e,o)},this._linksCrossfilter.onFiltered=()=>{var e,s;let o;this._linksCrossfilter.isAnyFiltersActive()&&(o=this._linksCrossfilter.getFilteredRecords()),null===(s=(e=this._config).onLinksFiltered)||void 0===s||s.call(e,o)};const c=this._svgParser.parseFromString(r,"image/svg+xml").firstChild;null===(h=this._watermarkDivElement)||void 0===h||h.appendChild(c),this._cssLabelsRenderer=new s(this._labelsDivElement),this._hoveredCssLabel=new o(this._labelsDivElement)}get data(){return this._data}get progress(){return this._cosmos.progress}get isSimulationRunning(){return this._cosmos.isSimulationRunning}get maxPointSize(){return this._cosmos.maxPointSize}setData(e,s){var o,t,i,r;this._data={nodes:e,links:s},this._cosmos.setData(e,s),this._nodesCrossfilter.addRecords(e),this._linksCrossfilter.addRecords(s),this._updateLabels(),null===(t=(o=this._config).onSetData)||void 0===t||t.call(o,e,s),this._isDataDifferent()&&(["cosmograph.app"].includes(window.location.hostname)||n({browser:navigator.userAgent,hostname:window.location.hostname,mode:null,is_library_metric:!0,links_count:s.length,links_have_time:null,links_raw_columns:null!==(i=Object.keys(null==s?void 0:s[0]).length)&&void 0!==i?i:0,links_raw_lines:null,nodes_count:e.length,nodes_have_time:null,nodes_raw_columns:null!==(r=Object.keys(null==e?void 0:e[0]).length)&&void 0!==r?r:0,nodes_raw_lines:null})),this._previousData={nodes:e,links:s}}setConfig(e){var s;if(this._config=t(d,null!=e?e:{}),this._cosmos.setConfig(this._createCosmosConfig(e)),null==e?void 0:e.backgroundColor){const o=null===(s=i(null==e?void 0:e.backgroundColor))||void 0===s?void 0:s.formatHex();if(o){const e=this._checkBrightness(o),s=document.querySelector(":root");e>.65?null==s||s.style.setProperty("--cosmograph-watermark-color","#000000"):null==s||s.style.setProperty("--cosmograph-watermark-color","#ffffff")}}this._updateLabels()}addNodesFilter(){return this._nodesCrossfilter.addFilter()}addLinksFilter(){return this._linksCrossfilter.addFilter()}selectNodesInRange(e){var s;this._cosmos.selectNodesInRange(e);const o=new Set((null!==(s=this.getSelectedNodes())&&void 0!==s?s:[]).map((e=>e.id)));this._selectedNodesFilter.applyFilter((e=>o.has(e)))}selectNodes(e){const s=new Set(e.map((e=>e.id)));this._selectedNodesFilter.applyFilter((e=>s.has(e)))}selectNode(e,s=!1){const o=new Set([e,...s&&this._cosmos.getAdjacentNodes(e.id)||[]].map((e=>e.id)));this._selectedNodesFilter.applyFilter((e=>o.has(e)))}unselectNodes(){this._selectedNodesFilter.clear()}getSelectedNodes(){return this._cosmos.getSelectedNodes()}zoomToNode(e){this._cosmos.zoomToNodeById(e.id)}setZoomLevel(e,s=0){this._cosmos.setZoomLevel(e,s)}getZoomLevel(){return this._cosmos.getZoomLevel()}getNodePositions(){return this._cosmos.getNodePositions()}getNodePositionsMap(){return this._cosmos.getNodePositionsMap()}getNodePositionsArray(){return this._cosmos.getNodePositionsArray()}fitView(e=250){this._cosmos.fitView(e)}fitViewByNodeIds(e,s=250){this._cosmos.fitViewByNodeIds(e,s)}focusNode(e){this._cosmos.setFocusedNodeById(null==e?void 0:e.id)}getAdjacentNodes(e){return this._cosmos.getAdjacentNodes(e)}spaceToScreenPosition(e){return this._cosmos.spaceToScreenPosition(e)}spaceToScreenRadius(e){return this._cosmos.spaceToScreenRadius(e)}getNodeRadiusByIndex(e){return this._cosmos.getNodeRadiusByIndex(e)}getNodeRadiusById(e){return this._cosmos.getNodeRadiusById(e)}getSampledNodePositionsMap(){return this._cosmos.getSampledNodePositionsMap()}start(e=1){this._cosmos.start(e)}pause(){this._cosmos.pause()}restart(){this._cosmos.restart()}step(){this._cosmos.step()}remove(){this._cosmos.destroy(),this._isLabelsDestroyed||(this._containerNode.innerHTML="",this._isLabelsDestroyed=!0,this._hoveredCssLabel.destroy(),this._cssLabelsRenderer.destroy())}create(){this._cosmos.create()}getNodeDegrees(){return this._cosmos.graph.degree}_createCosmosConfig(e){return{...e,simulation:{...Object.keys(null!=e?e:{}).filter((e=>-1!==e.indexOf("simulation"))).reduce(((s,o)=>{const t=o.replace("simulation","");return s[t.charAt(0).toLowerCase()+t.slice(1)]=null==e?void 0:e[o],s}),{}),onStart:this._onStart.bind(this),onTick:this._onTick.bind(this),onEnd:this._onEnd.bind(this),onPause:this._onPause.bind(this),onRestart:this._onRestart.bind(this)},events:{onClick:this._onClick.bind(this),onNodeMouseOver:this._onNodeMouseOver.bind(this),onNodeMouseOut:this._onNodeMouseOut.bind(this),onMouseMove:this._onMouseMove.bind(this),onZoomStart:this._onZoomStart.bind(this),onZoom:this._onZoom.bind(this),onZoomEnd:this._onZoomEnd.bind(this)}}}_updateLabels(){if(this._isLabelsDestroyed)return;const{data:{nodes:e},_config:{showTopLabels:s,showTopLabelsLimit:o,showLabelsFor:t,showTopLabelsValueKey:i,nodeLabelAccessor:r}}=this;if(this._nodesForTopLabels.clear(),s&&o){let s;s=i?[...e].sort(((e,s)=>{const o=e[i],t=s[i];return"number"==typeof o&&"number"==typeof t?t-o:0})):Object.entries(this._cosmos.graph.degree).sort(((e,s)=>s[1]-e[1])).slice(0,o).map((e=>this._cosmos.graph.getNodeByIndex(+e[0])));for(let t=0;t<o&&!(t>=e.length);t++){const e=s[t];e&&this._nodesForTopLabels.add(e)}}this._nodesForForcedLabels.clear(),null==t||t.forEach(this._nodesForForcedLabels.add,this._nodesForForcedLabels),this._trackedNodeToLabel.clear(),this._cosmos.trackNodePositionsByIds([...s?this._nodesForTopLabels:[],...this._nodesForForcedLabels].map((e=>{var s;return this._trackedNodeToLabel.set(e,null!==(s=null==r?void 0:r(e))&&void 0!==s?s:e.id),e.id}))),this._renderLabels()}_updateSelectedNodesSet(e){this._isLabelsDestroyed||(e?(this._selectedNodesSet=new Set,null==e||e.forEach(this._selectedNodesSet.add,this._selectedNodesSet)):this._selectedNodesSet=void 0,this._renderLabels())}_renderLabels(){if(this._isLabelsDestroyed)return;const{_selectedNodesSet:e,_config:{showDynamicLabels:s,nodeLabelAccessor:o,nodeLabelColor:t,nodeLabelClassName:i}}=this;let r=[];const n=this._cosmos.getTrackedNodePositionsMap(),d=new Map;if(s){this.getSampledNodePositionsMap().forEach(((e,s)=>{var t;const i=this._cosmos.graph.getNodeById(s);i&&d.set(i,[null!==(t=null==o?void 0:o(i))&&void 0!==t?t:i.id,e,l.cosmographShowDynamicLabels,.7])}))}this._nodesForTopLabels.forEach((e=>{d.set(e,[this._trackedNodeToLabel.get(e),n.get(e.id),l.cosmographShowTopLabels,.9])})),this._nodesForForcedLabels.forEach((e=>{d.set(e,[this._trackedNodeToLabel.get(e),n.get(e.id),l.cosmographShowLabelsFor,1])})),r=[...d.entries()].map((([s,[o,r,n,l]])=>{var d,a,h;const c=this.spaceToScreenPosition([null!==(d=null==r?void 0:r[0])&&void 0!==d?d:0,null!==(a=null==r?void 0:r[1])&&void 0!==a?a:0]),_=this.spaceToScreenRadius(this._cosmos.config.nodeSizeScale*this.getNodeRadiusById(s.id)),u=!!e,m=null==e?void 0:e.has(s);return{id:s.id,text:null!=o?o:"",x:c[0],y:c[1]-(_+2),weight:u&&!m?.1:l,shouldBeShown:this._nodesForForcedLabels.has(s),style:u&&!m?"opacity: 0.1;":"",color:t&&("string"==typeof t?t:null==t?void 0:t(s)),className:null!==(h="string"==typeof i?i:null==i?void 0:i(s))&&void 0!==h?h:n}})),this._cssLabelsRenderer.setLabels(r),this._cssLabelsRenderer.draw(!0)}_renderLabelForHovered(e,s){var o,t;const{_config:{showHoveredNodeLabel:i,nodeLabelAccessor:r,hoveredNodeLabelClassName:n,hoveredNodeLabelColor:l}}=this;if(!this._isLabelsDestroyed){if(i&&e&&s){const i=this.spaceToScreenPosition(s),d=this.spaceToScreenRadius(this.getNodeRadiusById(e.id));this._hoveredCssLabel.setText(null!==(o=null==r?void 0:r(e))&&void 0!==o?o:e.id),this._hoveredCssLabel.setVisibility(!0),this._hoveredCssLabel.setPosition(i[0],i[1]-(d+2)),this._hoveredCssLabel.setClassName("string"==typeof n?n:null!==(t=null==n?void 0:n(e))&&void 0!==t?t:""),this._hoveredCssLabel.setColor(l&&("string"==typeof l?l:null==l?void 0:l(e)))}else this._hoveredCssLabel.setVisibility(!1);this._hoveredCssLabel.draw()}}_applyLinksFilter(){if(this._nodesCrossfilter.isAnyFiltersActive(this._nodesFilter)){const e=this._nodesCrossfilter.getFilteredRecords(this._nodesFilter),s=new Set(e.map((e=>e.id)));this._linksFilter.applyFilter((e=>{const o=null==e?void 0:e[0],t=null==e?void 0:e[1];return s.has(o)&&s.has(t)}))}else this._linksFilter.clear()}_applyNodesFilter(){if(this._linksCrossfilter.isAnyFiltersActive(this._linksFilter)){const e=this._linksCrossfilter.getFilteredRecords(this._linksFilter),s=new Set(e.map((e=>[e.source,e.target])).flat());this._nodesFilter.applyFilter((e=>s.has(e)))}else this._nodesFilter.clear()}_checkBrightness(e){const s=(e=>{const s=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);return s?{r:parseInt((s[1]||0).toString(),16),g:parseInt((s[2]||0).toString(),16),b:parseInt((s[3]||0).toString(),16)}:{r:0,g:0,b:0}})(e);return(.2126*s.r+.7152*s.g+.0722*s.b)/255}}export{h as Cosmograph}; | ||
import{Graph as e}from"@cosmograph/cosmos";import{LabelRenderer as s,CssLabel as t}from"@interacta/css-labels";import{merge as o}from"@cosmograph/ui";import{color as i}from"d3-color";import{watermark as n}from"./watermark.js";import{addMetrics as r}from"../../api/supabase/supabase.js";import l from"./style.module.css.js";import{defaultCosmographConfig as d}from"./config.js";import{Crossfilter as a}from"./crossfilter.js";class h{constructor(i,r){var h;this._data={nodes:[],links:[]},this._previousData={nodes:[],links:[]},this._config={},this._nodesForTopLabels=new Set,this._nodesForForcedLabels=new Set,this._trackedNodeToLabel=new Map,this._isLabelsDestroyed=!1,this._svgParser=new DOMParser,this._nodesCrossfilter=new a(this._applyLinksFilter.bind(this)),this._linksCrossfilter=new a(this._applyNodesFilter.bind(this)),this._nodesFilter=this._nodesCrossfilter.addFilter(!1),this._linksFilter=this._linksCrossfilter.addFilter(!1),this._selectedNodesFilter=this._nodesCrossfilter.addFilter(),this._isDataDifferent=()=>{const e=JSON.stringify(this._data.nodes),s=JSON.stringify(this._previousData.nodes),t=JSON.stringify(this._data.links),o=JSON.stringify(this._previousData.links);return e!==s||t!==o},this._onClick=(...e)=>{var s,t;null===(t=(s=this._config).onClick)||void 0===t||t.call(s,...e)},this._onNodeMouseOver=(...e)=>{var s,t;null===(t=(s=this._config).onNodeMouseOver)||void 0===t||t.call(s,...e);const[o,,i]=e;this._renderLabelForHovered(o,i)},this._onNodeMouseOut=(...e)=>{var s,t;null===(t=(s=this._config).onNodeMouseOut)||void 0===t||t.call(s,...e),this._renderLabelForHovered()},this._onMouseMove=(...e)=>{var s,t;null===(t=(s=this._config).onMouseMove)||void 0===t||t.call(s,...e);const[o,,i]=e;this._renderLabelForHovered(o,i)},this._onZoomStart=(...e)=>{var s,t;null===(t=(s=this._config).onZoomStart)||void 0===t||t.call(s,...e)},this._onZoom=(...e)=>{var s,t;null===(t=(s=this._config).onZoom)||void 0===t||t.call(s,...e),this._renderLabelForHovered(),this._renderLabels()},this._onZoomEnd=(...e)=>{var s,t;null===(t=(s=this._config).onZoomEnd)||void 0===t||t.call(s,...e)},this._onStart=(...e)=>{var s,t;null===(t=(s=this._config).onSimulationStart)||void 0===t||t.call(s,...e)},this._onTick=(...e)=>{var s,t;null===(t=(s=this._config).onSimulationTick)||void 0===t||t.call(s,...e),this._renderLabels()},this._onEnd=(...e)=>{var s,t;null===(t=(s=this._config).onSimulationEnd)||void 0===t||t.call(s,...e)},this._onPause=(...e)=>{var s,t;null===(t=(s=this._config).onSimulationPause)||void 0===t||t.call(s,...e)},this._onRestart=(...e)=>{var s,t;null===(t=(s=this._config).onSimulationRestart)||void 0===t||t.call(s,...e)},this._containerNode=i,this._containerNode.classList.add(l.cosmograph),this._config=o(d,null!=r?r:{}),this._canvasElement=document.createElement("canvas"),this._labelsDivElement=document.createElement("div"),this._watermarkDivElement=document.createElement("div"),this._watermarkDivElement.classList.add(l.watermark),this._watermarkDivElement.onclick=()=>{var e;return null===(e=window.open("https://cosmograph.app/","_blank"))||void 0===e?void 0:e.focus()},i.appendChild(this._canvasElement),i.appendChild(this._labelsDivElement),i.appendChild(this._watermarkDivElement),this._cosmos=new e(this._canvasElement,this._createCosmosConfig(r)),this.cosmos=this._cosmos,this._linksFilter.setAccessor((e=>[e.source,e.target])),this._nodesFilter.setAccessor((e=>e.id)),this._selectedNodesFilter.setAccessor((e=>e.id)),this._nodesCrossfilter.onFiltered=()=>{var e,s;let t;this._nodesCrossfilter.isAnyFiltersActive()?(t=this._nodesCrossfilter.getFilteredRecords(),this._cosmos.selectNodesByIds(t.map((e=>e.id)))):this._cosmos.unselectNodes(),this._updateSelectedNodesSet(t),null===(s=(e=this._config).onNodesFiltered)||void 0===s||s.call(e,t)},this._linksCrossfilter.onFiltered=()=>{var e,s;let t;this._linksCrossfilter.isAnyFiltersActive()&&(t=this._linksCrossfilter.getFilteredRecords()),null===(s=(e=this._config).onLinksFiltered)||void 0===s||s.call(e,t)};const c=this._svgParser.parseFromString(n,"image/svg+xml").firstChild;null===(h=this._watermarkDivElement)||void 0===h||h.appendChild(c),this._cssLabelsRenderer=new s(this._labelsDivElement),this._hoveredCssLabel=new t(this._labelsDivElement)}get data(){return this._data}get progress(){return this._cosmos.progress}get isSimulationRunning(){return this._cosmos.isSimulationRunning}get maxPointSize(){return this._cosmos.maxPointSize}setData(e,s){var t,o,i,n;this._data={nodes:e,links:s},this._cosmos.setData(e,s),this._nodesCrossfilter.addRecords(e),this._linksCrossfilter.addRecords(s),this._updateLabels(),null===(o=(t=this._config).onSetData)||void 0===o||o.call(t,e,s),this._isDataDifferent()&&(["cosmograph.app"].includes(window.location.hostname)||r({browser:navigator.userAgent,hostname:window.location.hostname,mode:null,is_library_metric:!0,links_count:s.length,links_have_time:null,links_raw_columns:s.length&&null!==(i=Object.keys(null==s?void 0:s[0]).length)&&void 0!==i?i:0,links_raw_lines:null,nodes_count:e.length,nodes_have_time:null,nodes_raw_columns:e.length&&null!==(n=Object.keys(null==e?void 0:e[0]).length)&&void 0!==n?n:0,nodes_raw_lines:null})),this._previousData={nodes:e,links:s}}setConfig(e){var s;if(this._config=o(d,null!=e?e:{}),this._cosmos.setConfig(this._createCosmosConfig(e)),null==e?void 0:e.backgroundColor){const t=null===(s=i(null==e?void 0:e.backgroundColor))||void 0===s?void 0:s.formatHex();if(t){const e=this._checkBrightness(t),s=document.querySelector(":root");e>.65?null==s||s.style.setProperty("--cosmograph-watermark-color","#000000"):null==s||s.style.setProperty("--cosmograph-watermark-color","#ffffff")}}this._updateLabels()}addNodesFilter(){return this._nodesCrossfilter.addFilter()}addLinksFilter(){return this._linksCrossfilter.addFilter()}selectNodesInRange(e){var s;this._cosmos.selectNodesInRange(e);const t=new Set((null!==(s=this.getSelectedNodes())&&void 0!==s?s:[]).map((e=>e.id)));this._selectedNodesFilter.applyFilter((e=>t.has(e)))}selectNodes(e){const s=new Set(e.map((e=>e.id)));this._selectedNodesFilter.applyFilter((e=>s.has(e)))}selectNode(e,s=!1){const t=new Set([e,...s&&this._cosmos.getAdjacentNodes(e.id)||[]].map((e=>e.id)));this._selectedNodesFilter.applyFilter((e=>t.has(e)))}unselectNodes(){this._selectedNodesFilter.clear()}getSelectedNodes(){return this._cosmos.getSelectedNodes()}zoomToNode(e){this._cosmos.zoomToNodeById(e.id)}setZoomLevel(e,s=0){this._cosmos.setZoomLevel(e,s)}getZoomLevel(){return this._cosmos.getZoomLevel()}getNodePositions(){return this._cosmos.getNodePositions()}getNodePositionsMap(){return this._cosmos.getNodePositionsMap()}getNodePositionsArray(){return this._cosmos.getNodePositionsArray()}fitView(e=250){this._cosmos.fitView(e)}fitViewByNodeIds(e,s=250){this._cosmos.fitViewByNodeIds(e,s)}focusNode(e){this._cosmos.setFocusedNodeById(null==e?void 0:e.id)}getAdjacentNodes(e){return this._cosmos.getAdjacentNodes(e)}spaceToScreenPosition(e){return this._cosmos.spaceToScreenPosition(e)}spaceToScreenRadius(e){return this._cosmos.spaceToScreenRadius(e)}getNodeRadiusByIndex(e){return this._cosmos.getNodeRadiusByIndex(e)}getNodeRadiusById(e){return this._cosmos.getNodeRadiusById(e)}getSampledNodePositionsMap(){return this._cosmos.getSampledNodePositionsMap()}start(e=1){this._cosmos.start(e)}pause(){this._cosmos.pause()}restart(){this._cosmos.restart()}step(){this._cosmos.step()}remove(){this._cosmos.destroy(),this._isLabelsDestroyed||(this._containerNode.innerHTML="",this._isLabelsDestroyed=!0,this._hoveredCssLabel.destroy(),this._cssLabelsRenderer.destroy())}create(){this._cosmos.create()}getNodeDegrees(){return this._cosmos.graph.degree}_createCosmosConfig(e){return{...e,simulation:{...Object.keys(null!=e?e:{}).filter((e=>-1!==e.indexOf("simulation"))).reduce(((s,t)=>{const o=t.replace("simulation","");return s[o.charAt(0).toLowerCase()+o.slice(1)]=null==e?void 0:e[t],s}),{}),onStart:this._onStart.bind(this),onTick:this._onTick.bind(this),onEnd:this._onEnd.bind(this),onPause:this._onPause.bind(this),onRestart:this._onRestart.bind(this)},events:{onClick:this._onClick.bind(this),onNodeMouseOver:this._onNodeMouseOver.bind(this),onNodeMouseOut:this._onNodeMouseOut.bind(this),onMouseMove:this._onMouseMove.bind(this),onZoomStart:this._onZoomStart.bind(this),onZoom:this._onZoom.bind(this),onZoomEnd:this._onZoomEnd.bind(this)}}}_updateLabels(){if(this._isLabelsDestroyed)return;const{data:{nodes:e},_config:{showTopLabels:s,showTopLabelsLimit:t,showLabelsFor:o,showTopLabelsValueKey:i,nodeLabelAccessor:n}}=this;if(this._nodesForTopLabels.clear(),s&&t){let s;s=i?[...e].sort(((e,s)=>{const t=e[i],o=s[i];return"number"==typeof t&&"number"==typeof o?o-t:0})):Object.entries(this._cosmos.graph.degree).sort(((e,s)=>s[1]-e[1])).slice(0,t).map((e=>this._cosmos.graph.getNodeByIndex(+e[0])));for(let o=0;o<t&&!(o>=e.length);o++){const e=s[o];e&&this._nodesForTopLabels.add(e)}}this._nodesForForcedLabels.clear(),null==o||o.forEach(this._nodesForForcedLabels.add,this._nodesForForcedLabels),this._trackedNodeToLabel.clear(),this._cosmos.trackNodePositionsByIds([...s?this._nodesForTopLabels:[],...this._nodesForForcedLabels].map((e=>{var s;return this._trackedNodeToLabel.set(e,null!==(s=null==n?void 0:n(e))&&void 0!==s?s:e.id),e.id}))),this._renderLabels()}_updateSelectedNodesSet(e){this._isLabelsDestroyed||(e?(this._selectedNodesSet=new Set,null==e||e.forEach(this._selectedNodesSet.add,this._selectedNodesSet)):this._selectedNodesSet=void 0,this._renderLabels())}_renderLabels(){if(this._isLabelsDestroyed)return;const{_selectedNodesSet:e,_config:{showDynamicLabels:s,nodeLabelAccessor:t,nodeLabelColor:o,nodeLabelClassName:i}}=this;let n=[];const r=this._cosmos.getTrackedNodePositionsMap(),d=new Map;if(s){this.getSampledNodePositionsMap().forEach(((e,s)=>{var o;const i=this._cosmos.graph.getNodeById(s);i&&d.set(i,[null!==(o=null==t?void 0:t(i))&&void 0!==o?o:i.id,e,l.cosmographShowDynamicLabels,.7])}))}this._nodesForTopLabels.forEach((e=>{d.set(e,[this._trackedNodeToLabel.get(e),r.get(e.id),l.cosmographShowTopLabels,.9])})),this._nodesForForcedLabels.forEach((e=>{d.set(e,[this._trackedNodeToLabel.get(e),r.get(e.id),l.cosmographShowLabelsFor,1])})),n=[...d.entries()].map((([s,[t,n,r,l]])=>{var d,a,h;const c=this.spaceToScreenPosition([null!==(d=null==n?void 0:n[0])&&void 0!==d?d:0,null!==(a=null==n?void 0:n[1])&&void 0!==a?a:0]),_=this.spaceToScreenRadius(this._cosmos.config.nodeSizeScale*this.getNodeRadiusById(s.id)),u=!!e,m=null==e?void 0:e.has(s);return{id:s.id,text:null!=t?t:"",x:c[0],y:c[1]-(_+2),weight:u&&!m?.1:l,shouldBeShown:this._nodesForForcedLabels.has(s),style:u&&!m?"opacity: 0.1;":"",color:o&&("string"==typeof o?o:null==o?void 0:o(s)),className:null!==(h="string"==typeof i?i:null==i?void 0:i(s))&&void 0!==h?h:r}})),this._cssLabelsRenderer.setLabels(n),this._cssLabelsRenderer.draw(!0)}_renderLabelForHovered(e,s){var t,o;const{_config:{showHoveredNodeLabel:i,nodeLabelAccessor:n,hoveredNodeLabelClassName:r,hoveredNodeLabelColor:l}}=this;if(!this._isLabelsDestroyed){if(i&&e&&s){const i=this.spaceToScreenPosition(s),d=this.spaceToScreenRadius(this.getNodeRadiusById(e.id));this._hoveredCssLabel.setText(null!==(t=null==n?void 0:n(e))&&void 0!==t?t:e.id),this._hoveredCssLabel.setVisibility(!0),this._hoveredCssLabel.setPosition(i[0],i[1]-(d+2)),this._hoveredCssLabel.setClassName("string"==typeof r?r:null!==(o=null==r?void 0:r(e))&&void 0!==o?o:""),this._hoveredCssLabel.setColor(l&&("string"==typeof l?l:null==l?void 0:l(e)))}else this._hoveredCssLabel.setVisibility(!1);this._hoveredCssLabel.draw()}}_applyLinksFilter(){if(this._nodesCrossfilter.isAnyFiltersActive(this._nodesFilter)){const e=this._nodesCrossfilter.getFilteredRecords(this._nodesFilter),s=new Set(e.map((e=>e.id)));this._linksFilter.applyFilter((e=>{const t=null==e?void 0:e[0],o=null==e?void 0:e[1];return s.has(t)&&s.has(o)}))}else this._linksFilter.clear()}_applyNodesFilter(){if(this._linksCrossfilter.isAnyFiltersActive(this._linksFilter)){const e=this._linksCrossfilter.getFilteredRecords(this._linksFilter),s=new Set(e.map((e=>[e.source,e.target])).flat());this._nodesFilter.applyFilter((e=>s.has(e)))}else this._nodesFilter.clear()}_checkBrightness(e){const s=(e=>{const s=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);return s?{r:parseInt((s[1]||0).toString(),16),g:parseInt((s[2]||0).toString(),16),b:parseInt((s[3]||0).toString(),16)}:{r:0,g:0,b:0}})(e);return(.2126*s.r+.7152*s.g+.0722*s.b)/255}}export{h as Cosmograph}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@cosmograph/cosmograph", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "Cosmograph: The fastest web-based graph visualization library", | ||
@@ -12,3 +12,3 @@ "author": "cosmograph-org", | ||
"@cosmograph/cosmos": "1.5.0-beta.0", | ||
"@cosmograph/ui": "1.1.0", | ||
"@cosmograph/ui": "1.1.1", | ||
"@interacta/css-labels": "^0.0.11", | ||
@@ -15,0 +15,0 @@ "@supabase/supabase-js": "^2.38.4", |
Sorry, the diff of this file is not supported yet
204032
865
+ Added@cosmograph/ui@1.1.1(transitive)
- Removed@cosmograph/ui@1.1.0(transitive)
Updated@cosmograph/ui@1.1.1