@cosmograph/cosmograph
Advanced tools
Comparing version 1.1.1 to 1.2.0
import { CosmosInputLink, CosmosInputNode, GraphConfigInterface, GraphSimulationSettings, GraphEvents } from '@cosmograph/cosmos'; | ||
export type CosmographConfigInterface<N extends CosmosInputNode, L extends CosmosInputLink> = { | ||
/** | ||
* Do not run the simulation, just render the graph. | ||
* Cosmos uses the x and y values of the nodes’ data to determine their position in the graph. | ||
* If x and y values are not specified, the position of the nodes will be assigned randomly. | ||
* If the value is set to null and the data does not have any links, | ||
* Cosmograph will automatically set this value to `true`. | ||
* Default value: `null` | ||
*/ | ||
disableSimulation?: boolean | null; | ||
/** | ||
* Show labels for the nodes that are currently visible on the screen, | ||
@@ -167,2 +176,2 @@ * and automatically update to reflect the current zoom level. | ||
export declare const defaultCosmographConfig: CosmographConfigInterface<CosmosInputNode, CosmosInputLink>; | ||
export type CosmographInputConfig<N extends CosmosInputNode, L extends CosmosInputLink> = CosmographConfigInterface<N, L> & Omit<GraphConfigInterface<N, L>, 'events' | 'simulation'>; | ||
export type CosmographInputConfig<N extends CosmosInputNode, L extends CosmosInputLink> = CosmographConfigInterface<N, L> & Omit<GraphConfigInterface<N, L>, 'events' | 'simulation' | 'disableSimulation'>; |
@@ -1,2 +0,2 @@ | ||
const o={showDynamicLabels:!0,showTopLabels:!1,showTopLabelsLimit:100,showTopLabelsValueKey:void 0,showLabelsFor:void 0,showHoveredNodeLabel:!0,nodeLabelAccessor:o=>o.id,nodeLabelClassName:void 0,nodeLabelColor:void 0,hoveredNodeLabelClassName:void 0,hoveredNodeLabelColor:void 0,onSetData:void 0,onNodesFiltered:void 0,onLinksFiltered:void 0};export{o as defaultCosmographConfig}; | ||
const o={disableSimulation:null,showDynamicLabels:!0,showTopLabels:!1,showTopLabelsLimit:100,showTopLabelsValueKey:void 0,showLabelsFor:void 0,showHoveredNodeLabel:!0,nodeLabelAccessor:o=>o.id,nodeLabelClassName:void 0,nodeLabelColor:void 0,hoveredNodeLabelClassName:void 0,hoveredNodeLabelColor:void 0,onSetData:void 0,onNodesFiltered:void 0,onLinksFiltered:void 0};export{o as defaultCosmographConfig}; | ||
//# sourceMappingURL=config.js.map |
@@ -8,3 +8,4 @@ import { Graph, CosmosInputNode, CosmosInputLink } from '@cosmograph/cosmos'; | ||
private _previousData; | ||
private _config; | ||
private _cosmographConfig; | ||
private _cosmosConfig; | ||
private _containerNode; | ||
@@ -30,3 +31,4 @@ private _labelsDivElement; | ||
private _selectedNodesFilter; | ||
private _cosmos; | ||
private _disableSimulation; | ||
private _cosmos?; | ||
/** | ||
@@ -36,3 +38,3 @@ * @deprecated Direct use of the cosmos can lead to unexpected results, | ||
* */ | ||
cosmos: Graph<N, L>; | ||
cosmos?: Graph<N, L>; | ||
constructor(containerNode: HTMLDivElement, config?: CosmographInputConfig<N, L>); | ||
@@ -44,7 +46,7 @@ get data(): CosmographData<N, L>; | ||
*/ | ||
get progress(): number; | ||
get progress(): number | undefined; | ||
/** | ||
* A value that gives information about the running simulation status. | ||
*/ | ||
get isSimulationRunning(): boolean; | ||
get isSimulationRunning(): boolean | undefined; | ||
/** | ||
@@ -54,3 +56,3 @@ * The maximum point size. | ||
*/ | ||
get maxPointSize(): number; | ||
get maxPointSize(): number | undefined; | ||
/** | ||
@@ -101,3 +103,3 @@ * Sets the data for the graph. | ||
*/ | ||
getSelectedNodes(): N[] | null; | ||
getSelectedNodes(): N[] | null | undefined; | ||
/** | ||
@@ -118,3 +120,3 @@ * Center the view and zoom in to a node. | ||
*/ | ||
getZoomLevel(): number; | ||
getZoomLevel(): number | undefined; | ||
/** | ||
@@ -129,3 +131,3 @@ * Get current X and Y coordinates of the nodes. | ||
}; | ||
}; | ||
} | undefined; | ||
/** | ||
@@ -135,3 +137,3 @@ * Get current X and Y coordinates of the nodes. | ||
*/ | ||
getNodePositionsMap(): Map<string, [number, number]>; | ||
getNodePositionsMap(): Map<string, [number, number]> | undefined; | ||
/** | ||
@@ -141,3 +143,3 @@ * Get current X and Y coordinates of the nodes. | ||
*/ | ||
getNodePositionsArray(): [number, number][]; | ||
getNodePositionsArray(): [number, number][] | undefined; | ||
/** | ||
@@ -170,3 +172,3 @@ * Center and zoom in/out the view to fit all nodes in the scene. | ||
*/ | ||
spaceToScreenPosition(spacePosition: [number, number]): [number, number]; | ||
spaceToScreenPosition(spacePosition: [number, number]): [number, number] | undefined; | ||
/** | ||
@@ -177,3 +179,3 @@ * Converts the node radius value from the space coordinate system to the screen coordinate system. | ||
*/ | ||
spaceToScreenRadius(spaceRadius: number): number; | ||
spaceToScreenRadius(spaceRadius: number): number | undefined; | ||
/** | ||
@@ -197,3 +199,3 @@ * Get node radius by its index. | ||
*/ | ||
getSampledNodePositionsMap(): Map<string, [number, number]>; | ||
getSampledNodePositionsMap(): Map<string, [number, number]> | undefined; | ||
/** | ||
@@ -228,3 +230,3 @@ * Starts the simulation. | ||
*/ | ||
getNodeDegrees(): number[]; | ||
getNodeDegrees(): number[] | undefined; | ||
private _createCosmosConfig; | ||
@@ -231,0 +233,0 @@ private _updateLabels; |
@@ -1,2 +0,2 @@ | ||
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}; | ||
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 r}from"../../api/supabase/supabase.js";import l 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 r;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._onNodeMouseOver=(...s)=>{var e,o;null===(o=(e=this._cosmographConfig).onNodeMouseOver)||void 0===o||o.call(e,...s);const[t,,i]=s;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(l.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(l.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._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===(r=this._watermarkDivElement)||void 0===r||r.appendChild(h),this._cssLabelsRenderer=new e(this._labelsDivElement),this._hoveredCssLabel=new o(this._labelsDivElement)}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,l;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)||r({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!==(l=Object.keys(null==e?void 0:e[0]).length)&&void 0!==l?l: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.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:r}}=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==r?void 0:r(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 r=[];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,l.cosmographShowDynamicLabels,.7])}))}this._nodesForTopLabels.forEach((s=>{d.set(s,[this._trackedNodeToLabel.get(s),a.get(s.id),l.cosmographShowTopLabels,.9])})),this._nodesForForcedLabels.forEach((s=>{d.set(s,[this._trackedNodeToLabel.get(s),a.get(s.id),l.cosmographShowLabelsFor,1])})),r=[...d.entries()].map((([o,[t,r,l,a]])=>{var d,h,c;const _=this.spaceToScreenPosition([null!==(d=null==r?void 0:r[0])&&void 0!==d?d:0,null!==(h=null==r?void 0:r[1])&&void 0!==h?h:0]),m=this.spaceToScreenRadius(s.config.nodeSizeScale*this.getNodeRadiusById(o.id)),u=!!e,g=null==e?void 0:e.has(o);return{id:o.id,text:null!=t?t:"",x:_[0],y:_[1]-(m+2),weight:u&&!g?.1:a,shouldBeShown:this._nodesForForcedLabels.has(o),style:u&&!g?"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:l}})),this._cssLabelsRenderer.setLabels(r),this._cssLabelsRenderer.draw(!0)}_renderLabelForHovered(s,e){var o,t;if(!this._cosmos)return;const{_cosmographConfig:{showHoveredNodeLabel:i,nodeLabelAccessor:n,hoveredNodeLabelClassName:r,hoveredNodeLabelColor:l}}=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 r?r:null!==(t=null==r?void 0:r(s))&&void 0!==t?t:""),this._hoveredCssLabel.setColor(l&&("string"==typeof l?l:null==l?void 0:l(s)))}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.1.1", | ||
"version": "1.2.0", | ||
"description": "Cosmograph: The fastest web-based graph visualization library", | ||
@@ -11,4 +11,4 @@ "author": "cosmograph-org", | ||
"dependencies": { | ||
"@cosmograph/cosmos": "1.5.0-beta.0", | ||
"@cosmograph/ui": "1.1.1", | ||
"@cosmograph/cosmos": "1.5.1", | ||
"@cosmograph/ui": "1.2.0", | ||
"@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
Sorry, the diff of this file is not supported yet
210302
881
+ Added@cosmograph/cosmos@1.5.1(transitive)
+ Added@cosmograph/ui@1.2.0(transitive)
- Removed@cosmograph/cosmos@1.5.0-beta.0(transitive)
- Removed@cosmograph/ui@1.1.1(transitive)
Updated@cosmograph/cosmos@1.5.1
Updated@cosmograph/ui@1.2.0