Interface: ICosmograph
Public Cosmograph API interface.
Properties
stats
readonly
stats:CosmographStats
Statistical information about current points and links in the graph.
Returns
An object containing the count of points and links and summaries of points and links data.
Summaries include:
- Column names and types
- Aggregates for each column (count, min, max, approx_unique, avg, std, q25, q50, q75)
- Percentage of NULL values
focusedPointIndex
readonly
focusedPointIndex:undefined
|number
Gets the index of the currently focused point.
Returns
The index of the focused point, or undefined
if no point is focused.
clusterMapping
readonly
clusterMapping:Map
<string
, {index
:number
;count
:number
; }>
Gets the mapping of cluster values to their auto-generated indices and counts of items in each cluster.
Remarks
If pointClusterByFn is provided, keys of map will be values of pointClusterBy after applying pointClusterByFn.
crossfilter
readonly
crossfilter:object
Gets the crossfilter sets for links, points, and their intersection.
Name | Type |
---|---|
links | Set <number > |
points | Set <number > |
intersection | Set <number > |
Returns
An object containing the crossfiltered indices Sets.
activePointColorStrategy
readonly
activePointColorStrategy:"map"
|"palette"
|"interpolatePalette"
|"degree"
|"direct"
Provides the active point color strategy for the Cosmograph instance.
Returns
The active point color strategy.
activePointSizeStrategy
readonly
activePointSizeStrategy:"auto"
|"degree"
|"direct"
Provides the active point size strategy for the Cosmograph instance.
Returns
The active point size strategy.
linksTableName
readonly
linksTableName:string
Provides the name of the links table used by the Cosmograph instance.
Returns
The name of the links table.
pointsTableName
readonly
pointsTableName:string
Provides the name of the points table used by the Cosmograph instance.
Returns
The name of the points table.
progress
readonly
progress:undefined
|number
A value that gives information about the running simulation progress.
Returns
The current progress of the simulation, where 0 represents the start of the simulation and 1 represents the end, or undefined
if not available.
isSimulationRunning
readonly
isSimulationRunning:undefined
|boolean
Gets a boolean indicating whether the simulation is currently running.
Returns
true
if the simulation is running, false
if it is not running, or undefined
if the information is not available.
isSimulationAvailable
readonly
isSimulationAvailable:boolean
Gets a boolean indicating if a simulation can run for the current graph configuration and data.
Remarks
Determined on graph init/rebuild. Based on enableSimulation
config (if set), or defaults to true
if links exist or points lack layout (pointXBy/pointYBy).
The value updates upon graph initialization or rebuild (e.g., after setConfig
or data loading).
Returns
true
if a simulation can run, false
otherwise.
pointDegrees
readonly
pointDegrees:undefined
|number
[]
Gets the point degrees for the current graph.
Returns
The point degrees as an array of their degree values in the order they were sent to Cosmograph, or undefined
if not available.
maxPointSize
readonly
maxPointSize:number
Gets the maximum point size. This value is the maximum size of the gl.POINTS
primitive that WebGL can render on the userās hardware.
Returns
The maximum point size, or 0 if not available.
dataUploaded()
dataUploaded: () =>
Promise
<void
>
Waits for the data upload promise to resolve, if it exists. This method is used to ensure that any necessary data has been uploaded before proceeding with other operations.
Returns
Promise
<void
>
A promise that resolves when the data is ready.
rescaleXFn
readonly
rescaleXFn:undefined
| (x
) =>number
Gets the callback function for rescaling the x-axis.
Returns
The callback function for rescaling the x-axis, or undefined
if not set.
rescaleYFn
readonly
rescaleYFn:undefined
| (y
) =>number
Gets the callback function for rescaling the y-axis.
Returns
The callback function for rescaling the y-axis, or undefined
if not set.
Methods
setConfig()
setConfig(
config?
):void
Sets the config for the Cosmograph.
Parameters
Parameter | Type | Description |
---|---|---|
config? | CosmographConfig | Config to be applied to the Cosmograph. |
Returns
void
getConfig()
getConfig():
Promise
<CosmographConfig
>
Retrieves the current configuration of the Cosmograph.
Returns
Promise
<CosmographConfig
>
A promise that resolves with the current Cosmograph configuration.
getActivePointColorFn()
getActivePointColorFn():
Promise
<undefined
|ColorAccessorFn
>
Gets the current coloring function.
Returns
Promise
<undefined
| ColorAccessorFn
>
The point coloring function, or undefined
if not available.
getActivePointSizeFn()
getActivePointSizeFn():
Promise
<undefined
|SizeAccessorFn
>
Gets the current point sizing function.
Returns
Promise
<undefined
| SizeAccessorFn
>
The point sizing function, or undefined
if not available.
getActiveLinkColorFn()
getActiveLinkColorFn():
Promise
<undefined
|ColorAccessorFn
>
Gets the current link coloring function.
Returns
Promise
<undefined
| ColorAccessorFn
>
The link coloring function, or undefined
if not available.
getActiveLinkWidthFn()
getActiveLinkWidthFn():
Promise
<undefined
|SizeAccessorFn
>
Gets the current link width function.
Returns
Promise
<undefined
| SizeAccessorFn
>
The link width function, or undefined
if not available.
captureScreenshot()
captureScreenshot(
fileName?
):void
Captures a screenshot of the current graph view.
Parameters
Parameter | Type | Description |
---|---|---|
fileName? | string | Optional name for the downloaded file (default: ācosmograph-screenshot.pngā). |
Returns
void
activateRectSelection()
activateRectSelection():
void
Activates the rectangular selection element.
Returns
void
deactivateRectSelection()
deactivateRectSelection():
void
Deactivates the rectangular selection element.
Returns
void
activatePolygonalSelection()
activatePolygonalSelection():
void
Activates the polygonal selection element.
Returns
void
deactivatePolygonalSelection()
deactivatePolygonalSelection():
void
Deactivates the polygonal selection element.
Returns
void
selectPointsInRect()
selectPointsInRect(
selection
):void
Selects points inside a rectangular area.
Parameters
Parameter | Type | Description |
---|---|---|
selection | null | [[number , number ], [number , number ]] | Array of two corners of the rectangle [[left, top], [right, bottom]] . |
Returns
void
selectPointsInPolygon()
selectPointsInPolygon(
polygonalPoints
,addToSelection?
):void
Selects points inside a polygonal polygon.
Parameters
Parameter | Type | Description |
---|---|---|
polygonalPoints | [number , number ][] | Array of points defining the polygonal polygon. |
addToSelection? | boolean | Optional parameter determining whether to add the points to the current selection. |
Returns
void
selectPoints()
selectPoints(
pointIndices
):void
Selects points.
Parameters
Parameter | Type | Description |
---|---|---|
pointIndices | null | number [] | Array of point indices to be selected. |
Returns
void
selectPoint()
selectPoint(
pointIndexBy?
,addToSelection?
,selectConnectedPoints?
):void
Selects a point and, optionally, its connected points.
Parameters
Parameter | Type | Description |
---|---|---|
pointIndexBy? | number | Selected point index. |
addToSelection? | boolean | Optional parameter determining whether to add the point to the current selection. |
selectConnectedPoints? | boolean | Optional parameter determining whether to also select the connected points. |
Returns
void
unselectPoint()
unselectPoint(
pointIndexBy?
,unselectConnectedPoints?
):void
Unselects a point and, optionally, its connected points.
Parameters
Parameter | Type | Description |
---|---|---|
pointIndexBy? | number | Selected point index. |
unselectConnectedPoints? | boolean | Optional parameter determining whether to also unselect the connected points. |
Returns
void
unselectPointsByIndicies()
unselectPointsByIndicies(
indicesToRemove
):void
Unselects points by indices.
Parameters
Parameter | Type | Description |
---|---|---|
indicesToRemove | number [] | Array of point indices to be unselected. |
Returns
void
unselectAllPoints()
unselectAllPoints():
void
Unselects all points.
Returns
void
getSelectedPointIndices()
getSelectedPointIndices():
undefined
|null
|number
[]
Get indices for currently selected points.
Returns
undefined
| null
| number
[]
Array of selected point indices.
start()
start(
alpha?
):void
Starts the simulation.
Parameters
Parameter | Type | Description |
---|---|---|
alpha? | number | Value between 0 and 1. The higher the value, the more energy the simulation gets. |
Returns
void
pause()
pause():
void
Pauses the simulation.
Returns
void
restart()
restart():
void
Restarts the simulation.
Returns
void
step()
step():
void
Renders only one frame of the simulation (stops the simulation if it was running).
Returns
void
destroy()
destroy():
Promise
<void
>
Destroys the Cosmograph instance and cleans up associated resources.
Returns
Promise
<void
>
A promise that resolves when the destroy operation is complete.
reset()
reset(
total?
):Promise
<void
>
Resets the Cosmograph instance to its initial state.
Parameters
Parameter | Type | Description |
---|---|---|
total? | boolean | If true, resets configuration and displays the message div. |
Returns
Promise
<void
>
A promise that resolves when the reset operation is complete.
setZoomLevel()
setZoomLevel(
value
,duration?
):void
Zooms the view in or out to the specified zoom level.
Parameters
Parameter | Type | Description |
---|---|---|
value | number | Zoom level. |
duration? | number | Duration of the zoom transition. |
Returns
void
getZoomLevel()
getZoomLevel():
undefined
|number
Gets the zoom level of the view.
Returns
undefined
| number
Zoom level value.
zoomToPoint()
zoomToPoint(
index
,duration?
,scale?
,canZoomOut?
):void
Centers the view and zooms in to a point by its index.
Parameters
Parameter | Type | Description |
---|---|---|
index | number | Point index to be zoomed in. |
duration? | number | Optional duration in milliseconds. |
scale? | number | Optional zoom level. |
canZoomOut? | boolean | Optional parameter determining whether the view can zoom out. |
Returns
void
getPointPositions()
getPointPositions():
undefined
|number
[]
Gets the current X and Y coordinates of the points.
Returns
undefined
| number
[]
Array of point positions.
getPointPositionByIndex()
getPointPositionByIndex(
index
):undefined
| [number
,number
]
Gets the current X and Y coordinates of a point by its index.
Parameters
Parameter | Type | Description |
---|---|---|
index | number | Point index. |
Returns
undefined
| [number
, number
]
Array with X and Y coordinates of the point, or undefined
if the point index is invalid.
getClusterPositions()
getClusterPositions():
undefined
|number
[]
Gets the current X and Y coordinates of the clusters.
Returns
undefined
| number
[]
Array of point cluster positions.
getPointColors()
getPointColors():
undefined
|Float32Array
<ArrayBufferLike
>
Gets the current colors for each point.
Returns
undefined
| Float32Array
<ArrayBufferLike
>
A Float32Array containing RGBA color values for each point, or undefined
if not available.
getPointSizes()
getPointSizes():
undefined
|Float32Array
<ArrayBufferLike
>
Gets the current sizes for each point.
Returns
undefined
| Float32Array
<ArrayBufferLike
>
A Float32Array containing size values for each point, or undefined
if not available.
getLinkColors()
getLinkColors():
undefined
|Float32Array
<ArrayBufferLike
>
Gets the current colors for each link.
Returns
undefined
| Float32Array
<ArrayBufferLike
>
A Float32Array containing RGBA color values for each link, or undefined
if not available.
getLinkWidths()
getLinkWidths():
undefined
|Float32Array
<ArrayBufferLike
>
Gets the current widths for each link.
Returns
undefined
| Float32Array
<ArrayBufferLike
>
A Float32Array containing width values for each link, or undefined
if not available.
getSampledPoints()
getSampledPoints():
undefined
| {indices
:number
[];positions
:number
[]; }
Retrieves sampled point data as arrays with indices and positions.
Returns
undefined
| { indices
: number
[]; positions
: number
[]; }
An object containing separate arrays for point indices and their corresponding positions, or undefined
if not available.
The indices
array contains point indices, and the positions
array contains flattened coordinates [x0, y0, x1, y1, ...]
.
getTrackedPointPositionsArray()
getTrackedPointPositionsArray():
undefined
|number
[]
Gets an array of point positions that are currently tracked by the renderer. Use trackPointPositionsByIndices to specify which points to track.
Returns
undefined
| number
[]
A flattened array of point positions [x0, y0, x1, y1, ...]
for tracked points, or undefined
if not available.
See
- trackPointPositionsByIndices to set which points to track
- getTrackedPointPositionsMap for a more convenient Map-based format
getTrackedPointPositionsMap()
getTrackedPointPositionsMap():
undefined
|Map
<number
, [number
,number
]>
Gets a Map of point positions that are currently tracked by the renderer. Use trackPointPositionsByIndices to specify which points to track.
Returns
undefined
| Map
<number
, [number
, number
]>
A Map where keys are point indices and values are their corresponding X, Y coordinates, or undefined
if not available.
See
- trackPointPositionsByIndices to set which points to track
- getTrackedPointPositionsArray for a flattened array format
trackPointPositionsByIndices()
trackPointPositionsByIndices(
indices
):void
Tracks point positions by indices on each simulation tick. Once tracking is enabled, use getTrackedPointPositionsArray or getTrackedPointPositionsMap to retrieve the current positions.
Parameters
Parameter | Type | Description |
---|---|---|
indices | number [] | Array of point indices. |
Returns
void
See
- getTrackedPointPositionsArray to get tracked positions as a flattened array
- getTrackedPointPositionsMap to get tracked positions as a Map
fitView()
fitView(
duration?
,padding?
):void
Centers and zooms the view to fit all points in the scene.
Parameters
Parameter | Type | Description |
---|---|---|
duration? | number | Duration of the animation (default: 250ms). |
padding? | number | Padding around the viewport (0 to 1 as 100% of the viewport, default 0.1. |
Returns
void
fitViewByIndices()
fitViewByIndices(
indices
,duration?
,padding?
):void
Centers and zooms the viewport to fit points based on their indices.
Parameters
Parameter | Type | Description |
---|---|---|
indices | number [] | Array of point indices. |
duration? | number | Duration of the animation (default: 250ms). |
padding? | number | Padding around the viewport (0 to 1 as 100% of the viewport, default 0.1. |
Returns
void
fitViewByCoordinates()
fitViewByCoordinates(
coordinates
,duration?
,padding?
):void
Fits the given coordinates into the viewport.
Parameters
Parameter | Type | Description |
---|---|---|
coordinates | number [] | Array of coordinates in the format [x0, y0, x1, y1, ā¦]. |
duration? | number | Duration of the animation (default: 250ms). |
padding? | number | Padding around the viewport (0 to 1 as 100% of the viewport, default 0.1). |
Returns
void
setFocusedPoint()
setFocusedPoint(
index?
):void
Sets focus on a point by index. Draws a ring around the focused point.
Parameters
Parameter | Type | Description |
---|---|---|
index? | number | Index of the point to be focused. |
Returns
void
Remarks
If focusedPointIndex
is set, it will have priority over this method.
getConnectedPointIndices()
getConnectedPointIndices(
index
):undefined
|number
[]
Gets the indices of the points that are connected to the point with the given index.
Parameters
Parameter | Type | Description |
---|---|---|
index | number | The index of the point to get the connected points for. |
Returns
undefined
| number
[]
An array of indices of the connected points, or undefined
if the point index is invalid or there are no connected points.
spaceToScreenPosition()
spaceToScreenPosition(
spacePosition
):undefined
| [number
,number
]
Converts the X and Y point coordinates from the space coordinate system to the screen coordinate system.
Parameters
Parameter | Type | Description |
---|---|---|
spacePosition | [number , number ] | Array of x and y coordinates in the space coordinate system. |
Returns
undefined
| [number
, number
]
Array of x and y coordinates in the screen coordinate system.
screenToSpacePosition()
screenToSpacePosition(
screenPosition
):undefined
| [number
,number
]
Converts the X and Y point coordinates from the screen coordinate system to the space coordinate system.
Parameters
Parameter | Type | Description |
---|---|---|
screenPosition | [number , number ] | Array of x and y coordinates in the screen coordinate system. |
Returns
undefined
| [number
, number
]
Array of x and y coordinates in the space coordinate system.
spaceToScreenRadius()
spaceToScreenRadius(
spaceRadius
):undefined
|number
Converts the point radius value from the space coordinate system to the screen coordinate system.
Parameters
Parameter | Type | Description |
---|---|---|
spaceRadius | number | Radius of the point in the space coordinate system. |
Returns
undefined
| number
Radius of the point in the screen coordinate system.
getPointRadiusByIndex()
getPointRadiusByIndex(
index
):undefined
|number
Get point space radius by its index.
Parameters
Parameter | Type | Description |
---|---|---|
index | number | Index of the point. |
Returns
undefined
| number
Radius of the point in the space coordinate system.
getPointScreenRadiusByIndex()
getPointScreenRadiusByIndex(
index
):undefined
|number
Get point screen radius by its index.
Parameters
Parameter | Type | Description |
---|---|---|
index | number | Index of the point. |
Returns
undefined
| number
Radius of the point in the screen coordinate system.
getSampledPointPositionsMap()
getSampledPointPositionsMap():
undefined
|Map
<number
, [number
,number
]>
For the points that are currently visible on the screen, get a sample of point ids with their coordinates.
The resulting number of points will depend on the pointSamplingDistance
configuration property,
and the sampled points will be evenly distributed.
Returns
undefined
| Map
<number
, [number
, number
]>
A Map where keys are the ids of the points and values are their corresponding X and Y coordinates.
getPointIndicesByIds()
getPointIndicesByIds(
ids
):Promise
<undefined
|number
[]>
Returns an array of point indices in the order they were sent to getPointIndicesByIds
.
Parameters
Parameter | Type | Description |
---|---|---|
ids | string [] | Array of point ids. |
Returns
Promise
<undefined
| number
[]>
A Promise resolving to an array of point indices.
getPointIdsByIndices()
getPointIdsByIndices(
indices
):Promise
<undefined
|string
[]>
Returns an array of point ids in the order they were sent to getPointIdsByIndices
.
Parameters
Parameter | Type | Description |
---|---|---|
indices | number [] | Array of point indices. |
Returns
Promise
<undefined
| string
[]>
A Promise resolving to an array of point ids.
getPointsByIndices()
getPointsByIndices(
indices
):Promise
<undefined
|CosmographData
>
Returns points entries as a CosmographData
table by their indices.
Parameters
Parameter | Type | Description |
---|---|---|
indices | number [] | Array of point indices. |
Returns
Promise
<undefined
| CosmographData
>
A Promise resolving to a CosmographData
table of points.
getPointIndicesByExactValues()
getPointIndicesByExactValues(
column
,values
):Promise
<undefined
|number
[]>
Returns an array of point indices that match the provided values in a column.
Parameters
Parameter | Type | Description |
---|---|---|
column | string | The column to filter by. |
values | (string | number )[] | The values to match in the specified column. |
Returns
Promise
<undefined
| number
[]>
A Promise resolving to an array of point indices, or undefined
if the operation fails.
getPointIndicesByNumericValue()
getPointIndicesByNumericValue(
column
,value
,isMax
):Promise
<undefined
|number
[]>
Returns an array of point indices that match the provided numeric value in the specified column.
Parameters
Parameter | Type | Description |
---|---|---|
column | string | The column in the points table to filter by. |
value | string | number | The numeric value to match in the specified column. |
isMax | boolean | Indicates whether to return the indices for the maximum or minimum value. |
Returns
Promise
<undefined
| number
[]>
A Promise resolving to an array of point indices, or undefined
if the operation fails.
getPointIndicesByLinksExactValues()
getPointIndicesByLinksExactValues(
column
,values
):Promise
<undefined
|number
[]>
Returns an array of point indices that match the provided link column values.
Parameters
Parameter | Type | Description |
---|---|---|
column | string | The column in the links table to filter by. |
values | (string | number )[] | The values to match in the specified column. |
Returns
Promise
<undefined
| number
[]>
A Promise resolving to an array of point indices.
getPointIndicesByLinksNumericValue()
getPointIndicesByLinksNumericValue(
column
,value
,isMax
):Promise
<undefined
|number
[]>
Returns an array of point indices that match the provided link column numeric value.
Parameters
Parameter | Type | Description |
---|---|---|
column | string | The column in the links table to filter by. |
value | string | number | The numeric value to match in the specified column. |
isMax | boolean | Indicates whether to return the indices for the maximum or minimum value. |
Returns
Promise
<undefined
| number
[]>
A Promise resolving to an array of point indices.
getLinksByPointIds()
getLinksByPointIds(
ids
):Promise
<undefined
|CosmographData
>
Returns links entries as a CosmographData
table where the source or target point id is in the provided array.
Parameters
Parameter | Type | Description |
---|---|---|
ids | string [] | Array of point ids. |
Returns
Promise
<undefined
| CosmographData
>
A Promise resolving to a CosmographData
table of links.
getLinksByPointIndices()
getLinksByPointIndices(
indices
):Promise
<undefined
|CosmographData
>
Returns links entries as a CosmographData
table where the source or target point index is in the provided array.
Parameters
Parameter | Type | Description |
---|---|---|
indices | number [] | Array of point indices. |
Returns
Promise
<undefined
| CosmographData
>
A Promise resolving to a CosmographData
table of links.
getPointsData()
getPointsData():
Promise
<undefined
|CosmographData
>
Returns all points entries as a CosmographData
table.
Returns
Promise
<undefined
| CosmographData
>
A Promise resolving to a CosmographData
table of points.
getLinksData()
getLinksData():
Promise
<undefined
|CosmographData
>
Returns all links entries as a CosmographData
table.
Returns
Promise
<undefined
| CosmographData
>
A Promise resolving to a CosmographData
table of links.
convertCosmographDataToObject()
convertCosmographDataToObject(
data
):Record
<string
,unknown
>[]
Converts a CosmographData
table to an array of objects.
Parameters
Parameter | Type | Description |
---|---|---|
data | CosmographData | CosmographData table. |
Returns
Record
<string
, unknown
>[]
An array of objects.
flattenPositions()
flattenPositions(
positions
):undefined
|number
[]
Converts an array of tuple positions to a single flattened array containing all coordinates sequentially.
Parameters
Parameter | Type | Description |
---|---|---|
positions | [number , number ][] | An array of tuple positions. |
Returns
undefined
| number
[]
A flattened array of coordinates.
pair()
pair(
pointPositions
):undefined
| [number
,number
][]
Converts a flat array of point positions to tuple pairs representing coordinates.
Parameters
Parameter | Type | Description |
---|---|---|
pointPositions | number [] | A flattened array of coordinates. |
Returns
undefined
| [number
, number
][]
An array of tuple positions.
addPoints()
addPoints(
points
):Promise
<void
>
Adds points to the Cosmograph instance.
Parameters
Parameter | Type | Description |
---|---|---|
points | CosmographPointInput [] | The points data to add. |
Returns
Promise
<void
>
A promise that resolves when the points have been added.
Remarks
Minimal to provide is point a id. Other fields are optional, should respect already existing fields in the points data, if not provided, will be filled with default values.
addLinks()
addLinks(
links
):Promise
<void
>
Adds links to the Cosmograph instance.
Parameters
Parameter | Type | Description |
---|---|---|
links | CosmographLinkInput [] | The links data to add. |
Returns
Promise
<void
>
A promise that resolves when the links have been added.
Remarks
Minimal to provide is a source point and target point id. Other fields are optional, should respect already existing fields in the links data, if not provided, will be filled with default values.
removePointsByIndices()
removePointsByIndices(
indices
,removeAttachedLinks?
):Promise
<void
>
Removes points from the Cosmograph instance by their indices.
Parameters
Parameter | Type | Description |
---|---|---|
indices | number [] | The indices of the points to remove. |
removeAttachedLinks? | boolean | Whether to also remove links attached to the points. |
Returns
Promise
<void
>
A promise that resolves when the points have been removed.
removePointsByIds()
removePointsByIds(
ids
):Promise
<void
>
Removes points from the Cosmograph instance by their IDs.
Parameters
Parameter | Type | Description |
---|---|---|
ids | string [] | The IDs of the points to remove. |
Returns
Promise
<void
>
A promise that resolves when the points have been removed.
removeLinksByPointIdPairs()
removeLinksByPointIdPairs(
pairs
):Promise
<void
>
Removes links from the Cosmograph instance by their point ID pairs.
Parameters
Parameter | Type | Description |
---|---|---|
pairs | [string , string ][] | The point ID pairs of the links to remove. |
Returns
Promise
<void
>
A promise that resolves when the links have been removed.
removeLinksByPointIndicesPairs()
removeLinksByPointIndicesPairs(
pairs
):Promise
<void
>
Removes links from the Cosmograph instance by their point indices pairs.
Parameters
Parameter | Type | Description |
---|---|---|
pairs | [number , number ][] | The point indices pairs of the links to remove. |
Returns
Promise
<void
>
A promise that resolves when the links have been removed.