@cosmograph/cosmograph
Advanced tools
Comparing version 1.3.1 to 1.4.0-beta.0
@@ -58,4 +58,5 @@ import { Graph, CosmosInputNode, CosmosInputLink } from '@cosmograph/cosmos'; | ||
* @param links - Links to be added to the graph. | ||
* @param runSimulation When set to `false`, the simulation won't be started automatically (`true` by default). | ||
*/ | ||
setData(nodes: N[], links: L[]): void; | ||
setData(nodes: N[], links: L[], runSimulation?: boolean): void; | ||
/** | ||
@@ -62,0 +63,0 @@ * Sets the config for the graph. |
@@ -1,2 +0,2 @@ | ||
import{Graph as s}from"@cosmograph/cosmos";import{LabelRenderer as e,CssLabel as o}from"@interacta/css-labels";import{merge as t}from"@cosmograph/ui";import{color as i}from"d3-color";import{watermark as n}from"./watermark.js";import{addMetrics as l}from"../../api/supabase/supabase.js";import r from"./style.module.css.js";import{defaultCosmographConfig as a}from"./config.js";import{Crossfilter as d}from"./crossfilter.js";class h{constructor(s,i){var l;this._data={nodes:[],links:[]},this._previousData={nodes:[],links:[]},this._cosmographConfig={},this._cosmosConfig={},this._nodesForTopLabels=new Set,this._nodesForForcedLabels=new Set,this._trackedNodeToLabel=new Map,this._isLabelsDestroyed=!1,this._svgParser=new DOMParser,this._nodesCrossfilter=new d(this._applyLinksFilter.bind(this)),this._linksCrossfilter=new d(this._applyNodesFilter.bind(this)),this._nodesFilter=this._nodesCrossfilter.addFilter(!1),this._linksFilter=this._linksCrossfilter.addFilter(!1),this._selectedNodesFilter=this._nodesCrossfilter.addFilter(),this._isDataDifferent=()=>{const s=JSON.stringify(this._data.nodes),e=JSON.stringify(this._previousData.nodes),o=JSON.stringify(this._data.links),t=JSON.stringify(this._previousData.links);return s!==e||o!==t},this._onClick=(...s)=>{var e,o;null===(o=(e=this._cosmographConfig).onClick)||void 0===o||o.call(e,...s)},this._onLabelClick=(s,e)=>{var o,t,i;const n=null===(o=this._cosmos)||void 0===o?void 0:o.graph.getNodeById(e.id);n&&(null===(i=(t=this._cosmographConfig).onLabelClick)||void 0===i||i.call(t,n,s))},this._onHoveredNodeClick=s=>{var e,o;this._hoveredNode&&(null===(o=(e=this._cosmographConfig).onLabelClick)||void 0===o||o.call(e,this._hoveredNode,s))},this._onNodeMouseOver=(...s)=>{var e,o;null===(o=(e=this._cosmographConfig).onNodeMouseOver)||void 0===o||o.call(e,...s);const[t,,i]=s;this._hoveredNode=t,this._renderLabelForHovered(t,i)},this._onNodeMouseOut=(...s)=>{var e,o;null===(o=(e=this._cosmographConfig).onNodeMouseOut)||void 0===o||o.call(e,...s),this._renderLabelForHovered()},this._onMouseMove=(...s)=>{var e,o;null===(o=(e=this._cosmographConfig).onMouseMove)||void 0===o||o.call(e,...s);const[t,,i]=s;this._renderLabelForHovered(t,i)},this._onZoomStart=(...s)=>{var e,o;null===(o=(e=this._cosmographConfig).onZoomStart)||void 0===o||o.call(e,...s)},this._onZoom=(...s)=>{var e,o;null===(o=(e=this._cosmographConfig).onZoom)||void 0===o||o.call(e,...s),this._renderLabelForHovered(),this._renderLabels()},this._onZoomEnd=(...s)=>{var e,o;null===(o=(e=this._cosmographConfig).onZoomEnd)||void 0===o||o.call(e,...s)},this._onStart=(...s)=>{var e,o;null===(o=(e=this._cosmographConfig).onSimulationStart)||void 0===o||o.call(e,...s)},this._onTick=(...s)=>{var e,o;null===(o=(e=this._cosmographConfig).onSimulationTick)||void 0===o||o.call(e,...s),this._renderLabels()},this._onEnd=(...s)=>{var e,o;null===(o=(e=this._cosmographConfig).onSimulationEnd)||void 0===o||o.call(e,...s)},this._onPause=(...s)=>{var e,o;null===(o=(e=this._cosmographConfig).onSimulationPause)||void 0===o||o.call(e,...s)},this._onRestart=(...s)=>{var e,o;null===(o=(e=this._cosmographConfig).onSimulationRestart)||void 0===o||o.call(e,...s)},this._containerNode=s,this._containerNode.classList.add(r.cosmograph),this._cosmographConfig=t(a,null!=i?i:{}),this._cosmosConfig=this._createCosmosConfig(i),this._canvasElement=document.createElement("canvas"),this._labelsDivElement=document.createElement("div"),this._watermarkDivElement=document.createElement("div"),this._watermarkDivElement.classList.add(r.watermark),this._watermarkDivElement.onclick=()=>{var s;return null===(s=window.open("https://cosmograph.app/","_blank"))||void 0===s?void 0:s.focus()},s.appendChild(this._canvasElement),s.appendChild(this._labelsDivElement),s.appendChild(this._watermarkDivElement),this._cssLabelsRenderer=new e(this._labelsDivElement,{dispatchWheelEventElement:this._canvasElement,pointerEvents:"all",onLabelClick:this._onLabelClick.bind(this)}),this._hoveredCssLabel=new o(this._labelsDivElement),this._hoveredCssLabel.setPointerEvents("all"),this._hoveredCssLabel.element.addEventListener("click",this._onHoveredNodeClick.bind(this)),this._linksFilter.setAccessor((s=>[s.source,s.target])),this._nodesFilter.setAccessor((s=>s.id)),this._selectedNodesFilter.setAccessor((s=>s.id)),this._nodesCrossfilter.onFiltered=()=>{var s,e,o,t;let i;this._nodesCrossfilter.isAnyFiltersActive()?(i=this._nodesCrossfilter.getFilteredRecords(),null===(s=this._cosmos)||void 0===s||s.selectNodesByIds(i.map((s=>s.id)))):null===(e=this._cosmos)||void 0===e||e.unselectNodes(),this._updateSelectedNodesSet(i),null===(t=(o=this._cosmographConfig).onNodesFiltered)||void 0===t||t.call(o,i)},this._linksCrossfilter.onFiltered=()=>{var s,e;let o;this._linksCrossfilter.isAnyFiltersActive()&&(o=this._linksCrossfilter.getFilteredRecords()),null===(e=(s=this._cosmographConfig).onLinksFiltered)||void 0===e||e.call(s,o)};const h=this._svgParser.parseFromString(n,"image/svg+xml").firstChild;null===(l=this._watermarkDivElement)||void 0===l||l.appendChild(h)}get data(){return this._data}get progress(){var s;return null===(s=this._cosmos)||void 0===s?void 0:s.progress}get isSimulationRunning(){var s;return null===(s=this._cosmos)||void 0===s?void 0:s.isSimulationRunning}get maxPointSize(){var s;return null===(s=this._cosmos)||void 0===s?void 0:s.maxPointSize}setData(e,o){var t,i,n,r;const{_cosmographConfig:a}=this;this._data={nodes:e,links:o};const d=null===a.disableSimulation?!o.length:a.disableSimulation;this._cosmos||(this._disableSimulation=d,this._cosmosConfig.disableSimulation=this._disableSimulation,this._cosmos=new s(this._canvasElement,this._cosmosConfig),this.cosmos=this._cosmos),this._disableSimulation!==d&&console.warn(`The \`disableSimulation\` was initialized to \`${this._disableSimulation}\` during initialization and will not be modified.`),this._cosmos.setData(e,o),this._nodesCrossfilter.addRecords(e),this._linksCrossfilter.addRecords(o),this._updateLabels(),null===(i=(t=this._cosmographConfig).onSetData)||void 0===i||i.call(t,e,o),this._isDataDifferent()&&(["cosmograph.app"].includes(window.location.hostname)||l({browser:navigator.userAgent,hostname:window.location.hostname,mode:null,is_library_metric:!0,links_count:o.length,links_have_time:null,links_raw_columns:o.length&&null!==(n=Object.keys(null==o?void 0:o[0]).length)&&void 0!==n?n:0,links_raw_lines:null,nodes_count:e.length,nodes_have_time:null,nodes_raw_columns:e.length&&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:o}}setConfig(s){var e,o;if(this._cosmographConfig=t(a,null!=s?s:{}),this._cosmosConfig=this._createCosmosConfig(s),null===(e=this._cosmos)||void 0===e||e.setConfig(this._cosmosConfig),null==s?void 0:s.backgroundColor){const e=null===(o=i(null==s?void 0:s.backgroundColor))||void 0===o?void 0:o.formatHex();if(e){const s=this._checkBrightness(e),o=document.querySelector(":root");s>.65?null==o||o.style.setProperty("--cosmograph-watermark-color","#000000"):null==o||o.style.setProperty("--cosmograph-watermark-color","#ffffff")}}this._updateLabels()}addNodesFilter(){return this._nodesCrossfilter.addFilter()}addLinksFilter(){return this._linksCrossfilter.addFilter()}selectNodesInRange(s){var e;if(!this._cosmos)return;this._cosmos.selectNodesInRange(s);const o=new Set((null!==(e=this.getSelectedNodes())&&void 0!==e?e:[]).map((s=>s.id)));this._selectedNodesFilter.applyFilter((s=>o.has(s)))}selectNodes(s){if(!this._cosmos)return;const e=new Set(s.map((s=>s.id)));this._selectedNodesFilter.applyFilter((s=>e.has(s)))}selectNode(s,e=!1){if(!this._cosmos)return;const o=new Set([s,...e&&this._cosmos.getAdjacentNodes(s.id)||[]].map((s=>s.id)));this._selectedNodesFilter.applyFilter((s=>o.has(s)))}unselectNodes(){this._cosmos&&this._selectedNodesFilter.clear()}getSelectedNodes(){if(this._cosmos)return this._cosmos.getSelectedNodes()}zoomToNode(s){this._cosmos&&this._cosmos.zoomToNodeById(s.id)}setZoomLevel(s,e=0){this._cosmos&&this._cosmos.setZoomLevel(s,e)}getZoomLevel(){if(this._cosmos)return this._cosmos.getZoomLevel()}getNodePositions(){if(this._cosmos)return this._cosmos.getNodePositions()}getNodePositionsMap(){if(this._cosmos)return this._cosmos.getNodePositionsMap()}getNodePositionsArray(){if(this._cosmos)return this._cosmos.getNodePositionsArray()}fitView(s=250){this._cosmos&&this._cosmos.fitView(s)}fitViewByNodeIds(s,e=250){this._cosmos&&this._cosmos.fitViewByNodeIds(s,e)}focusNode(s){this._cosmos&&this._cosmos.setFocusedNodeById(null==s?void 0:s.id)}getAdjacentNodes(s){if(this._cosmos)return this._cosmos.getAdjacentNodes(s)}spaceToScreenPosition(s){if(this._cosmos)return this._cosmos.spaceToScreenPosition(s)}spaceToScreenRadius(s){if(this._cosmos)return this._cosmos.spaceToScreenRadius(s)}getNodeRadiusByIndex(s){if(this._cosmos)return this._cosmos.getNodeRadiusByIndex(s)}getNodeRadiusById(s){if(this._cosmos)return this._cosmos.getNodeRadiusById(s)}getSampledNodePositionsMap(){if(this._cosmos)return this._cosmos.getSampledNodePositionsMap()}start(s=1){this._cosmos&&this._cosmos.start(s)}pause(){this._cosmos&&this._cosmos.pause()}restart(){this._cosmos&&this._cosmos.restart()}step(){this._cosmos&&this._cosmos.step()}remove(){var s;null===(s=this._cosmos)||void 0===s||s.destroy(),this._isLabelsDestroyed||(this._containerNode.innerHTML="",this._isLabelsDestroyed=!0,this._hoveredCssLabel.element.removeEventListener("click",this._onHoveredNodeClick.bind(this)),this._hoveredCssLabel.destroy(),this._cssLabelsRenderer.destroy())}create(){this._cosmos&&this._cosmos.create()}getNodeDegrees(){if(this._cosmos)return this._cosmos.graph.degree}_createCosmosConfig(s){const e={...s,simulation:{...Object.keys(null!=s?s:{}).filter((s=>-1!==s.indexOf("simulation"))).reduce(((e,o)=>{const t=o.replace("simulation","");return e[t.charAt(0).toLowerCase()+t.slice(1)]=null==s?void 0:s[o],e}),{}),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)}};return delete e.disableSimulation,e}_updateLabels(){if(this._isLabelsDestroyed||!this._cosmos)return;const{_cosmos:s,data:{nodes:e},_cosmographConfig:{showTopLabels:o,showTopLabelsLimit:t,showLabelsFor:i,showTopLabelsValueKey:n,nodeLabelAccessor:l}}=this;if(this._nodesForTopLabels.clear(),o&&t){let o;o=n?[...e].sort(((s,e)=>{const o=s[n],t=e[n];return"number"==typeof o&&"number"==typeof t?t-o:0})):Object.entries(s.graph.degree).sort(((s,e)=>e[1]-s[1])).slice(0,t).map((e=>s.graph.getNodeByIndex(+e[0])));for(let s=0;s<t&&!(s>=e.length);s++){const e=o[s];e&&this._nodesForTopLabels.add(e)}}this._nodesForForcedLabels.clear(),null==i||i.forEach(this._nodesForForcedLabels.add,this._nodesForForcedLabels),this._trackedNodeToLabel.clear(),s.trackNodePositionsByIds([...o?this._nodesForTopLabels:[],...this._nodesForForcedLabels].map((s=>{var e;return this._trackedNodeToLabel.set(s,null!==(e=null==l?void 0:l(s))&&void 0!==e?e:s.id),s.id}))),this._renderLabels()}_updateSelectedNodesSet(s){this._isLabelsDestroyed||(s?(this._selectedNodesSet=new Set,null==s||s.forEach(this._selectedNodesSet.add,this._selectedNodesSet)):this._selectedNodesSet=void 0,this._renderLabels())}_renderLabels(){if(this._isLabelsDestroyed||!this._cosmos)return;const{_cosmos:s,_selectedNodesSet:e,_cosmographConfig:{showDynamicLabels:o,nodeLabelAccessor:t,nodeLabelColor:i,nodeLabelClassName:n}}=this;let l=[];const a=s.getTrackedNodePositionsMap(),d=new Map;if(o){const e=this.getSampledNodePositionsMap();null==e||e.forEach(((e,o)=>{var i;const n=s.graph.getNodeById(o);n&&d.set(n,[null!==(i=null==t?void 0:t(n))&&void 0!==i?i:n.id,e,r.cosmographShowDynamicLabels,.7])}))}this._nodesForTopLabels.forEach((s=>{d.set(s,[this._trackedNodeToLabel.get(s),a.get(s.id),r.cosmographShowTopLabels,.9])})),this._nodesForForcedLabels.forEach((s=>{d.set(s,[this._trackedNodeToLabel.get(s),a.get(s.id),r.cosmographShowLabelsFor,1])})),l=[...d.entries()].map((([o,[t,l,r,a]])=>{var d,h,c;const _=this.spaceToScreenPosition([null!==(d=null==l?void 0:l[0])&&void 0!==d?d:0,null!==(h=null==l?void 0:l[1])&&void 0!==h?h:0]),m=this.spaceToScreenRadius(s.config.nodeSizeScale*this.getNodeRadiusById(o.id)),u=!!e,v=null==e?void 0:e.has(o);return{id:o.id,text:null!=t?t:"",x:_[0],y:_[1]-(m+2),weight:u&&!v?.1:a,shouldBeShown:this._nodesForForcedLabels.has(o),style:u&&!v?"opacity: 0.1;":"",color:i&&("string"==typeof i?i:null==i?void 0:i(o)),className:null!==(c="string"==typeof n?n:null==n?void 0:n(o))&&void 0!==c?c:r}})),this._cssLabelsRenderer.setLabels(l),this._cssLabelsRenderer.draw(!0)}_renderLabelForHovered(s,e){var o,t;if(!this._cosmos)return;const{_cosmographConfig:{showHoveredNodeLabel:i,nodeLabelAccessor:n,hoveredNodeLabelClassName:l,hoveredNodeLabelColor:r}}=this;if(!this._isLabelsDestroyed){if(i&&s&&e){const i=this.spaceToScreenPosition(e),a=this.spaceToScreenRadius(this.getNodeRadiusById(s.id));this._hoveredCssLabel.setText(null!==(o=null==n?void 0:n(s))&&void 0!==o?o:s.id),this._hoveredCssLabel.setVisibility(!0),this._hoveredCssLabel.setPosition(i[0],i[1]-(a+2)),this._hoveredCssLabel.setClassName("string"==typeof l?l:null!==(t=null==l?void 0:l(s))&&void 0!==t?t:"");const d=r&&("string"==typeof r?r:null==r?void 0:r(s));d&&this._hoveredCssLabel.setColor(d)}else this._hoveredCssLabel.setVisibility(!1);this._hoveredCssLabel.draw()}}_applyLinksFilter(){if(this._nodesCrossfilter.isAnyFiltersActive(this._nodesFilter)){const s=this._nodesCrossfilter.getFilteredRecords(this._nodesFilter),e=new Set(s.map((s=>s.id)));this._linksFilter.applyFilter((s=>{const o=null==s?void 0:s[0],t=null==s?void 0:s[1];return e.has(o)&&e.has(t)}))}else this._linksFilter.clear()}_applyNodesFilter(){if(this._linksCrossfilter.isAnyFiltersActive(this._linksFilter)){const s=this._linksCrossfilter.getFilteredRecords(this._linksFilter),e=new Set(s.map((s=>[s.source,s.target])).flat());this._nodesFilter.applyFilter((s=>e.has(s)))}else this._nodesFilter.clear()}_checkBrightness(s){const e=(s=>{const e=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(s);return e?{r:parseInt((e[1]||0).toString(),16),g:parseInt((e[2]||0).toString(),16),b:parseInt((e[3]||0).toString(),16)}:{r:0,g:0,b:0}})(s);return(.2126*e.r+.7152*e.g+.0722*e.b)/255}}export{h as Cosmograph}; | ||
import{Graph as s}from"@cosmograph/cosmos";import{LabelRenderer as e,CssLabel as o}from"@interacta/css-labels";import{merge as t}from"@cosmograph/ui";import{color as i}from"d3-color";import{watermark as n}from"./watermark.js";import{addMetrics as l}from"../../api/supabase/supabase.js";import r from"./style.module.css.js";import{defaultCosmographConfig as a}from"./config.js";import{Crossfilter as d}from"./crossfilter.js";class h{constructor(s,i){var l;this._data={nodes:[],links:[]},this._previousData={nodes:[],links:[]},this._cosmographConfig={},this._cosmosConfig={},this._nodesForTopLabels=new Set,this._nodesForForcedLabels=new Set,this._trackedNodeToLabel=new Map,this._isLabelsDestroyed=!1,this._svgParser=new DOMParser,this._nodesCrossfilter=new d(this._applyLinksFilter.bind(this)),this._linksCrossfilter=new d(this._applyNodesFilter.bind(this)),this._nodesFilter=this._nodesCrossfilter.addFilter(!1),this._linksFilter=this._linksCrossfilter.addFilter(!1),this._selectedNodesFilter=this._nodesCrossfilter.addFilter(),this._isDataDifferent=()=>{const s=JSON.stringify(this._data.nodes),e=JSON.stringify(this._previousData.nodes),o=JSON.stringify(this._data.links),t=JSON.stringify(this._previousData.links);return s!==e||o!==t},this._onClick=(...s)=>{var e,o;null===(o=(e=this._cosmographConfig).onClick)||void 0===o||o.call(e,...s)},this._onLabelClick=(s,e)=>{var o,t,i;const n=null===(o=this._cosmos)||void 0===o?void 0:o.graph.getNodeById(e.id);n&&(null===(i=(t=this._cosmographConfig).onLabelClick)||void 0===i||i.call(t,n,s))},this._onHoveredNodeClick=s=>{var e,o;this._hoveredNode&&(null===(o=(e=this._cosmographConfig).onLabelClick)||void 0===o||o.call(e,this._hoveredNode,s))},this._onNodeMouseOver=(...s)=>{var e,o;null===(o=(e=this._cosmographConfig).onNodeMouseOver)||void 0===o||o.call(e,...s);const[t,,i]=s;this._hoveredNode=t,this._renderLabelForHovered(t,i)},this._onNodeMouseOut=(...s)=>{var e,o;null===(o=(e=this._cosmographConfig).onNodeMouseOut)||void 0===o||o.call(e,...s),this._renderLabelForHovered()},this._onMouseMove=(...s)=>{var e,o;null===(o=(e=this._cosmographConfig).onMouseMove)||void 0===o||o.call(e,...s);const[t,,i]=s;this._renderLabelForHovered(t,i)},this._onZoomStart=(...s)=>{var e,o;null===(o=(e=this._cosmographConfig).onZoomStart)||void 0===o||o.call(e,...s)},this._onZoom=(...s)=>{var e,o;null===(o=(e=this._cosmographConfig).onZoom)||void 0===o||o.call(e,...s),this._renderLabelForHovered(),this._renderLabels()},this._onZoomEnd=(...s)=>{var e,o;null===(o=(e=this._cosmographConfig).onZoomEnd)||void 0===o||o.call(e,...s)},this._onStart=(...s)=>{var e,o;null===(o=(e=this._cosmographConfig).onSimulationStart)||void 0===o||o.call(e,...s)},this._onTick=(...s)=>{var e,o;null===(o=(e=this._cosmographConfig).onSimulationTick)||void 0===o||o.call(e,...s),this._renderLabels()},this._onEnd=(...s)=>{var e,o;null===(o=(e=this._cosmographConfig).onSimulationEnd)||void 0===o||o.call(e,...s)},this._onPause=(...s)=>{var e,o;null===(o=(e=this._cosmographConfig).onSimulationPause)||void 0===o||o.call(e,...s)},this._onRestart=(...s)=>{var e,o;null===(o=(e=this._cosmographConfig).onSimulationRestart)||void 0===o||o.call(e,...s)},this._containerNode=s,this._containerNode.classList.add(r.cosmograph),this._cosmographConfig=t(a,null!=i?i:{}),this._cosmosConfig=this._createCosmosConfig(i),this._canvasElement=document.createElement("canvas"),this._labelsDivElement=document.createElement("div"),this._watermarkDivElement=document.createElement("div"),this._watermarkDivElement.classList.add(r.watermark),this._watermarkDivElement.onclick=()=>{var s;return null===(s=window.open("https://cosmograph.app/","_blank"))||void 0===s?void 0:s.focus()},s.appendChild(this._canvasElement),s.appendChild(this._labelsDivElement),s.appendChild(this._watermarkDivElement),this._cssLabelsRenderer=new e(this._labelsDivElement,{dispatchWheelEventElement:this._canvasElement,pointerEvents:"all",onLabelClick:this._onLabelClick.bind(this)}),this._hoveredCssLabel=new o(this._labelsDivElement),this._hoveredCssLabel.setPointerEvents("all"),this._hoveredCssLabel.element.addEventListener("click",this._onHoveredNodeClick.bind(this)),this._linksFilter.setAccessor((s=>[s.source,s.target])),this._nodesFilter.setAccessor((s=>s.id)),this._selectedNodesFilter.setAccessor((s=>s.id)),this._nodesCrossfilter.onFiltered=()=>{var s,e,o,t;let i;this._nodesCrossfilter.isAnyFiltersActive()?(i=this._nodesCrossfilter.getFilteredRecords(),null===(s=this._cosmos)||void 0===s||s.selectNodesByIds(i.map((s=>s.id)))):null===(e=this._cosmos)||void 0===e||e.unselectNodes(),this._updateSelectedNodesSet(i),null===(t=(o=this._cosmographConfig).onNodesFiltered)||void 0===t||t.call(o,i)},this._linksCrossfilter.onFiltered=()=>{var s,e;let o;this._linksCrossfilter.isAnyFiltersActive()&&(o=this._linksCrossfilter.getFilteredRecords()),null===(e=(s=this._cosmographConfig).onLinksFiltered)||void 0===e||e.call(s,o)};const h=this._svgParser.parseFromString(n,"image/svg+xml").firstChild;null===(l=this._watermarkDivElement)||void 0===l||l.appendChild(h)}get data(){return this._data}get progress(){var s;return null===(s=this._cosmos)||void 0===s?void 0:s.progress}get isSimulationRunning(){var s;return null===(s=this._cosmos)||void 0===s?void 0:s.isSimulationRunning}get maxPointSize(){var s;return null===(s=this._cosmos)||void 0===s?void 0:s.maxPointSize}setData(e,o,t=!0){var i,n,r,a;const{_cosmographConfig:d}=this;this._data={nodes:e,links:o};const h=null===d.disableSimulation?!o.length:d.disableSimulation;this._cosmos||(this._disableSimulation=h,this._cosmosConfig.disableSimulation=this._disableSimulation,this._cosmos=new s(this._canvasElement,this._cosmosConfig),this.cosmos=this._cosmos),this._disableSimulation!==h&&console.warn(`The \`disableSimulation\` was initialized to \`${this._disableSimulation}\` during initialization and will not be modified.`),this._cosmos.setData(e,o,t),this._nodesCrossfilter.addRecords(e),this._linksCrossfilter.addRecords(o),this._updateLabels(),null===(n=(i=this._cosmographConfig).onSetData)||void 0===n||n.call(i,e,o),this._isDataDifferent()&&(["cosmograph.app"].includes(window.location.hostname)||l({browser:navigator.userAgent,hostname:window.location.hostname,mode:null,is_library_metric:!0,links_count:o.length,links_have_time:null,links_raw_columns:o.length&&null!==(r=Object.keys(null==o?void 0:o[0]).length)&&void 0!==r?r:0,links_raw_lines:null,nodes_count:e.length,nodes_have_time:null,nodes_raw_columns:e.length&&null!==(a=Object.keys(null==e?void 0:e[0]).length)&&void 0!==a?a:0,nodes_raw_lines:null})),this._previousData={nodes:e,links:o}}setConfig(s){var e,o;if(this._cosmographConfig=t(a,null!=s?s:{}),this._cosmosConfig=this._createCosmosConfig(s),null===(e=this._cosmos)||void 0===e||e.setConfig(this._cosmosConfig),null==s?void 0:s.backgroundColor){const e=null===(o=i(null==s?void 0:s.backgroundColor))||void 0===o?void 0:o.formatHex();if(e){const s=this._checkBrightness(e),o=document.querySelector(":root");s>.65?null==o||o.style.setProperty("--cosmograph-watermark-color","#000000"):null==o||o.style.setProperty("--cosmograph-watermark-color","#ffffff")}}this._updateLabels()}addNodesFilter(){return this._nodesCrossfilter.addFilter()}addLinksFilter(){return this._linksCrossfilter.addFilter()}selectNodesInRange(s){var e;if(!this._cosmos)return;this._cosmos.selectNodesInRange(s);const o=new Set((null!==(e=this.getSelectedNodes())&&void 0!==e?e:[]).map((s=>s.id)));this._selectedNodesFilter.applyFilter((s=>o.has(s)))}selectNodes(s){if(!this._cosmos)return;const e=new Set(s.map((s=>s.id)));this._selectedNodesFilter.applyFilter((s=>e.has(s)))}selectNode(s,e=!1){if(!this._cosmos)return;const o=new Set([s,...e&&this._cosmos.getAdjacentNodes(s.id)||[]].map((s=>s.id)));this._selectedNodesFilter.applyFilter((s=>o.has(s)))}unselectNodes(){this._cosmos&&this._selectedNodesFilter.clear()}getSelectedNodes(){if(this._cosmos)return this._cosmos.getSelectedNodes()}zoomToNode(s){this._cosmos&&this._cosmos.zoomToNodeById(s.id)}setZoomLevel(s,e=0){this._cosmos&&this._cosmos.setZoomLevel(s,e)}getZoomLevel(){if(this._cosmos)return this._cosmos.getZoomLevel()}getNodePositions(){if(this._cosmos)return this._cosmos.getNodePositions()}getNodePositionsMap(){if(this._cosmos)return this._cosmos.getNodePositionsMap()}getNodePositionsArray(){if(this._cosmos)return this._cosmos.getNodePositionsArray()}fitView(s=250){this._cosmos&&this._cosmos.fitView(s)}fitViewByNodeIds(s,e=250){this._cosmos&&this._cosmos.fitViewByNodeIds(s,e)}focusNode(s){this._cosmos&&this._cosmos.setFocusedNodeById(null==s?void 0:s.id)}getAdjacentNodes(s){if(this._cosmos)return this._cosmos.getAdjacentNodes(s)}spaceToScreenPosition(s){if(this._cosmos)return this._cosmos.spaceToScreenPosition(s)}spaceToScreenRadius(s){if(this._cosmos)return this._cosmos.spaceToScreenRadius(s)}getNodeRadiusByIndex(s){if(this._cosmos)return this._cosmos.getNodeRadiusByIndex(s)}getNodeRadiusById(s){if(this._cosmos)return this._cosmos.getNodeRadiusById(s)}getSampledNodePositionsMap(){if(this._cosmos)return this._cosmos.getSampledNodePositionsMap()}start(s=1){this._cosmos&&this._cosmos.start(s)}pause(){this._cosmos&&this._cosmos.pause()}restart(){this._cosmos&&this._cosmos.restart()}step(){this._cosmos&&this._cosmos.step()}remove(){var s;null===(s=this._cosmos)||void 0===s||s.destroy(),this._isLabelsDestroyed||(this._containerNode.innerHTML="",this._isLabelsDestroyed=!0,this._hoveredCssLabel.element.removeEventListener("click",this._onHoveredNodeClick.bind(this)),this._hoveredCssLabel.destroy(),this._cssLabelsRenderer.destroy())}create(){this._cosmos&&this._cosmos.create()}getNodeDegrees(){if(this._cosmos)return this._cosmos.graph.degree}_createCosmosConfig(s){const e={...s,simulation:{...Object.keys(null!=s?s:{}).filter((s=>-1!==s.indexOf("simulation"))).reduce(((e,o)=>{const t=o.replace("simulation","");return e[t.charAt(0).toLowerCase()+t.slice(1)]=null==s?void 0:s[o],e}),{}),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)}};return delete e.disableSimulation,e}_updateLabels(){if(this._isLabelsDestroyed||!this._cosmos)return;const{_cosmos:s,data:{nodes:e},_cosmographConfig:{showTopLabels:o,showTopLabelsLimit:t,showLabelsFor:i,showTopLabelsValueKey:n,nodeLabelAccessor:l}}=this;if(this._nodesForTopLabels.clear(),o&&t){let o;o=n?[...e].sort(((s,e)=>{const o=s[n],t=e[n];return"number"==typeof o&&"number"==typeof t?t-o:0})):Object.entries(s.graph.degree).sort(((s,e)=>e[1]-s[1])).slice(0,t).map((e=>s.graph.getNodeByIndex(+e[0])));for(let s=0;s<t&&!(s>=e.length);s++){const e=o[s];e&&this._nodesForTopLabels.add(e)}}this._nodesForForcedLabels.clear(),null==i||i.forEach(this._nodesForForcedLabels.add,this._nodesForForcedLabels),this._trackedNodeToLabel.clear(),s.trackNodePositionsByIds([...o?this._nodesForTopLabels:[],...this._nodesForForcedLabels].map((s=>{var e;return this._trackedNodeToLabel.set(s,null!==(e=null==l?void 0:l(s))&&void 0!==e?e:s.id),s.id}))),this._renderLabels()}_updateSelectedNodesSet(s){this._isLabelsDestroyed||(s?(this._selectedNodesSet=new Set,null==s||s.forEach(this._selectedNodesSet.add,this._selectedNodesSet)):this._selectedNodesSet=void 0,this._renderLabels())}_renderLabels(){if(this._isLabelsDestroyed||!this._cosmos)return;const{_cosmos:s,_selectedNodesSet:e,_cosmographConfig:{showDynamicLabels:o,nodeLabelAccessor:t,nodeLabelColor:i,nodeLabelClassName:n}}=this;let l=[];const a=s.getTrackedNodePositionsMap(),d=new Map;if(o){const e=this.getSampledNodePositionsMap();null==e||e.forEach(((e,o)=>{var i;const n=s.graph.getNodeById(o);n&&d.set(n,[null!==(i=null==t?void 0:t(n))&&void 0!==i?i:n.id,e,r.cosmographShowDynamicLabels,.7])}))}this._nodesForTopLabels.forEach((s=>{d.set(s,[this._trackedNodeToLabel.get(s),a.get(s.id),r.cosmographShowTopLabels,.9])})),this._nodesForForcedLabels.forEach((s=>{d.set(s,[this._trackedNodeToLabel.get(s),a.get(s.id),r.cosmographShowLabelsFor,1])})),l=[...d.entries()].map((([o,[t,l,r,a]])=>{var d,h,c;const _=this.spaceToScreenPosition([null!==(d=null==l?void 0:l[0])&&void 0!==d?d:0,null!==(h=null==l?void 0:l[1])&&void 0!==h?h:0]),m=this.spaceToScreenRadius(s.config.nodeSizeScale*this.getNodeRadiusById(o.id)),u=!!e,v=null==e?void 0:e.has(o);return{id:o.id,text:null!=t?t:"",x:_[0],y:_[1]-(m+2),weight:u&&!v?.1:a,shouldBeShown:this._nodesForForcedLabels.has(o),style:u&&!v?"opacity: 0.1;":"",color:i&&("string"==typeof i?i:null==i?void 0:i(o)),className:null!==(c="string"==typeof n?n:null==n?void 0:n(o))&&void 0!==c?c:r}})),this._cssLabelsRenderer.setLabels(l),this._cssLabelsRenderer.draw(!0)}_renderLabelForHovered(s,e){var o,t;if(!this._cosmos)return;const{_cosmographConfig:{showHoveredNodeLabel:i,nodeLabelAccessor:n,hoveredNodeLabelClassName:l,hoveredNodeLabelColor:r}}=this;if(!this._isLabelsDestroyed){if(i&&s&&e){const i=this.spaceToScreenPosition(e),a=this.spaceToScreenRadius(this.getNodeRadiusById(s.id));this._hoveredCssLabel.setText(null!==(o=null==n?void 0:n(s))&&void 0!==o?o:s.id),this._hoveredCssLabel.setVisibility(!0),this._hoveredCssLabel.setPosition(i[0],i[1]-(a+2)),this._hoveredCssLabel.setClassName("string"==typeof l?l:null!==(t=null==l?void 0:l(s))&&void 0!==t?t:"");const d=r&&("string"==typeof r?r:null==r?void 0:r(s));d&&this._hoveredCssLabel.setColor(d)}else this._hoveredCssLabel.setVisibility(!1);this._hoveredCssLabel.draw()}}_applyLinksFilter(){if(this._nodesCrossfilter.isAnyFiltersActive(this._nodesFilter)){const s=this._nodesCrossfilter.getFilteredRecords(this._nodesFilter),e=new Set(s.map((s=>s.id)));this._linksFilter.applyFilter((s=>{const o=null==s?void 0:s[0],t=null==s?void 0:s[1];return e.has(o)&&e.has(t)}))}else this._linksFilter.clear()}_applyNodesFilter(){if(this._linksCrossfilter.isAnyFiltersActive(this._linksFilter)){const s=this._linksCrossfilter.getFilteredRecords(this._linksFilter),e=new Set(s.map((s=>[s.source,s.target])).flat());this._nodesFilter.applyFilter((s=>e.has(s)))}else this._nodesFilter.clear()}_checkBrightness(s){const e=(s=>{const e=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(s);return e?{r:parseInt((e[1]||0).toString(),16),g:parseInt((e[2]||0).toString(),16),b:parseInt((e[3]||0).toString(),16)}:{r:0,g:0,b:0}})(s);return(.2126*e.r+.7152*e.g+.0722*e.b)/255}}export{h as Cosmograph}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@cosmograph/cosmograph", | ||
"version": "1.3.1", | ||
"version": "1.4.0-beta.0", | ||
"description": "Cosmograph: The fastest web-based graph visualization library", | ||
@@ -11,4 +11,4 @@ "author": "cosmograph-org", | ||
"dependencies": { | ||
"@cosmograph/cosmos": "1.5.1", | ||
"@cosmograph/ui": "1.3.1", | ||
"@cosmograph/cosmos": "1.6.0", | ||
"@cosmograph/ui": "1.4.0-beta.0", | ||
"@interacta/css-labels": "^0.1.1", | ||
@@ -15,0 +15,0 @@ "@supabase/supabase-js": "^2.38.4", |
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
213910
895
2
+ Added@cosmograph/cosmos@1.6.0(transitive)
+ Added@cosmograph/ui@1.4.0-beta.0(transitive)
- Removed@cosmograph/cosmos@1.5.1(transitive)
- Removed@cosmograph/ui@1.3.1(transitive)
Updated@cosmograph/cosmos@1.6.0
Updated@cosmograph/ui@1.4.0-beta.0