### Basic Configuration Example Source: https://cosmograph.app/docs-lib/data-requirements/data-kit A fundamental example demonstrating the basic setup for points and links. ```APIDOC ## Basic Configuration Example ### Description This example shows a basic configuration for both points and links. ### Code ```javascript const config = { points: { pointIdBy: 'id', // Required: Unique identifier for each point pointColorBy: 'color', // Optional: Color of the points pointSizeBy: 'value', // Optional: Size of the points }, links: { linkSourceBy: 'source', // Required: Source of the link linkTargetsBy: ['target'], // Required: Targets of the link linkColorBy: 'color', // Optional: Color of the links linkWidthBy: 'value', // Optional: Width of the links }, } ``` ``` -------------------------------- ### Fast Setup: ReactJS Cosmograph Component Source: https://cosmograph.app/docs-lib A complete React component example demonstrating how to load and prepare data using `prepareCosmographData` and then render the Cosmograph component with the processed data and configuration. ```typescript import React, { useEffect, useState } from 'react' import { Cosmograph, CosmographConfig, prepareCosmographData } from '@cosmograph/react' const rawPoints = [{ id: 'a' }, { id: 'b' }, { id: 'c' }] const rawLinks = [ { source: 'a', target: 'b' }, { source: 'b', target: 'c' }, { source: 'c', target: 'a' }, ] export const component = (): JSX.Element => { const [config, setConfig] = useState({}) // Create a config to map your data into Cosmograph's internal format const dataConfig = { points: { pointIdBy: 'id', }, links: { linkSourceBy: 'source', linkTargetsBy: ['target'], }, } const loadData = async (): Promise => { // Prepare data and config for Cosmograph const result = await prepareCosmographData(dataConfig, rawPoints, rawLinks) if (result) { // Update Cosmograph config with prepared output const { points, links, cosmographConfig } = result setConfig({ points, links, ...cosmographConfig }) } } // Load data when component is mounted useEffect(() => { loadData() }, []) return } ``` -------------------------------- ### Fast Setup: JavaScript/TypeScript Cosmograph Initialization Source: https://cosmograph.app/docs-lib An example of initializing Cosmograph in a plain JavaScript/TypeScript environment. It prepares data using `prepareCosmographData` and then creates a new `Cosmograph` instance with the processed data and configuration. ```typescript import { Cosmograph, prepareCosmographData } from '@cosmograph/cosmograph' const rawPoints = [{ id: 'a' }, { id: 'b' }, { id: 'c' }] const rawLinks = [ { source: 'a', target: 'b' }, { source: 'b', target: 'c' }, { source: 'c', target: 'a' }, ] // Create a config to map your data into Cosmograph's internal format const dataConfig = { points: { pointIdBy: 'id', }, links: { linkSourceBy: 'source', linkTargetsBy: ['target'], }, } const createCosmograph = async (container: HTMLElement): Promise => { // Prepare data and config for Cosmograph const result = await prepareCosmographData(dataConfig, rawPoints, rawLinks) // Create Cosmograph instance from prepared data and config if (result) { const { points, links, cosmographConfig } = result const cosmograph = new Cosmograph(container, { points, links, ...cosmographConfig }) } } // Render Cosmograph in the provided container createCosmograph(document.getElementById('cosmograph-container')) ``` -------------------------------- ### Example: Set Point Sizes Source: https://cosmograph.app/docs-lib/api/internal/classes/Graph Example of setting point sizes using a Float32Array. Each number in the array defines the size for a corresponding point. ```javascript new Float32Array([10, 20, 30]) ``` -------------------------------- ### onSimulationStart Source: https://cosmograph.app/docs-lib/api/internal/classes/CosmographEventManager Handles the start of a simulation. ```APIDOC ## Method onSimulationStart ### Description Handles the start of a simulation. ### Method `onSimulationStart( …args : [] )` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) `void` #### Response Example None ``` -------------------------------- ### Example: Set Image Data Source: https://cosmograph.app/docs-lib/api/internal/classes/Graph Example of providing an array of ImageData objects to be used as point images. ```javascript setImageData([imageData1, imageData2, imageData3]) ``` -------------------------------- ### onZoomStart Source: https://cosmograph.app/docs-lib/api/internal/classes/CosmographEventManager Handles the start of a zoom event. ```APIDOC ## Method onZoomStart ### Description Handles the start of a zoom event. ### Method `onZoomStart( …args : [D3ZoomEvent, boolean] )` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) `void` #### Response Example None ``` -------------------------------- ### Example: Set Point Positions Source: https://cosmograph.app/docs-lib/api/internal/classes/Graph Example of setting point positions using a Float32Array. Each pair of values in the array represents the x and y coordinates for a point. ```javascript new Float32Array([1, 2, 3, 4, 5, 6]) ``` -------------------------------- ### render Source: https://cosmograph.app/docs-lib/api/internal/classes/Graph Renders the graph and starts rendering. ```APIDOC ## render ### Description Renders the graph and starts rendering. Does not modify simulation state. ### Parameters #### Request Body - **simulationAlpha** (number) - Optional - Optional alpha value to set. ``` -------------------------------- ### Example: Set Point Colors Source: https://cosmograph.app/docs-lib/api/internal/classes/Graph Example of setting point colors using a Float32Array. Values range from 0 to 255 for RGB and 0 to 1 for Alpha. ```javascript new Float32Array([255, 0, 0, 1, 0, 255, 0, 1]) ``` -------------------------------- ### Drag Start Event Source: https://cosmograph.app/docs-lib/api/internal/classes/GraphConfig Callback function triggered when dragging starts. ```APIDOC ## onDragStart ### Description Callback function that will be called when dragging starts. First argument is a D3 Drag Event. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) None #### Response Example None ``` -------------------------------- ### Install Cosmograph React Library Source: https://cosmograph.app/docs-lib Use this command to install the Cosmograph React library via NPM. This is required for using Cosmograph within a React application. ```bash npm install @cosmograph/react ``` -------------------------------- ### Example: Dynamic Label Visibility Source: https://cosmograph.app/docs-lib/features/clustering Demonstrates dynamically switching between cluster labels and individual point labels based on zoom level. ```APIDOC ## Example: Dynamic Label Visibility ### Description This example shows a common use case: displaying cluster labels when zoomed out and individual point labels when zoomed in, by dynamically updating Cosmograph configuration based on zoom level. ### Code Example ```javascript import React, { useEffect, useRef, useState, useCallback } from 'react' import { CosmographProvider, Cosmograph, CosmographConfig, CosmographRef } from '@cosmograph/react' export const MyGraph = (): JSX.Element => { const cosmograph = useRef(null) const [config, setConfig] = useState({ // Initial config here }) // Data loading logic... const switchLabelsVisibility = useCallback(() => { const zoom = cosmograph.current?.getZoomLevel() if (zoom && zoom > 1.5) { setConfig({ ...config, showDynamicLabels: true, showTopLabels: true, showClusterLabels: false, }) } else { setConfig({ ...config, showDynamicLabels: false, showTopLabels: false, showClusterLabels: true, }) } }, [config]) return ( ) } ``` ``` -------------------------------- ### Sample Node and Link Data Source: https://cosmograph.app/docs-lib Example data structures for nodes and links, demonstrating different ways to define node properties like `id`, `color` (including RGBA format), and `index`. ```javascript export const nodes = [ { id: '1', color: '#88C6FF' }, { id: '2', color: '#FF99D2' }, { id: '3', color: [227, 17, 108, 1] }, { id: '4', index: 3, color: '#7B61FF' }, { id: '5', index: 4, color: '#00D084' }, { id: '6', index: 5, color: '#FCB900' }, ] export const links = [ { source: '1', target: '2' }, { source: '2', target: '3' }, { source: '3', target: '1' }, { source: '4', target: '1' }, { source: '5', target: '2' }, { source: '4', target: '5' }, { source: '5', target: '6' }, ] ``` -------------------------------- ### Install Cosmograph JavaScript Library Source: https://cosmograph.app/docs-lib Use this command to install the core Cosmograph JavaScript library via NPM. This is suitable for use in vanilla JavaScript projects or other frameworks. ```bash npm install @cosmograph/cosmograph ``` -------------------------------- ### Create Cosmograph Instance in JavaScript Source: https://cosmograph.app/docs-lib This example shows how to create a Cosmograph instance using the vanilla JavaScript library. It involves creating a container element and initializing Cosmograph with configuration. ```javascript import { Cosmograph, CosmographConfig } from '@cosmograph/cosmograph' // Create an HTML element const div = document.createElement('div') document.body.appendChild(div) // Define the configuration const cosmographConfig: CosmographConfig = { // ... } // Create a Cosmograph instance with this element const cosmograph = new Cosmograph(div, cosmographConfig) ``` -------------------------------- ### Initialize Cosmograph with DuckDB Source: https://cosmograph.app/docs-lib/data-requirements/external-duck-db-connection Example of initializing a Cosmograph instance with an external DuckDB connection in TypeScript. ```typescript // Assuming you have a DuckDB-Wasm instance with data somewhere // const db = new duckdb.AsyncDuckDB(logger, worker) // const connection = await db.connect() const config: CosmographConfig = { points: 'existing_points_table', links: 'existing_links_table', pointIdBy: 'id', pointIndexBy: 'idx', linkSourceBy: 'source', linkSourceIndexBy: 'sourceidx', linkTargetBy: 'target', linkTargetIndexBy: 'targetidx', } const cosmograph = new Cosmograph(htmlContainer, config, { duckdb: db, connection: connection }) ``` -------------------------------- ### Prepare and Upload Data in TypeScript Source: https://cosmograph.app/docs-lib/data-requirements/data-kit This TypeScript example demonstrates how to prepare data and initialize Cosmograph directly within a DOM element. It handles file input changes and updates the Cosmograph instance with the processed data. ```typescript import { Cosmograph, CosmographConfig, prepareCosmographData, CosmographData } from '@cosmograph/cosmograph' const typescriptExample = (container: HTMLElement): void => { let config: CosmographConfig = { // you can add some initial Cosmograph configuration here like simulation settings } const pointsInput = document.createElement('input') pointsInput.type = 'file' const linksInput = document.createElement('input') linksInput.type = 'file' container.appendChild(pointsInput) container.appendChild(linksInput) const cosmographConfig = { points: { pointIdBy: 'id', pointColorBy: 'color', pointSizeBy: 'value', }, links: { linkSourceBy: 'source', linkTargetsBy: ['target'], linkColorBy: 'color', linkWidthBy: 'value', }, } const cosmograph = new Cosmograph(container, config) const handleFileChange = async (event: Event): Promise => { const file = (event.target as HTMLInputElement).files?.[0] if (file) { const result = await prepareCosmographData(cosmographConfig, file) if (result) { const { points, links, cosmographConfig } = result config = {...config, ...cosmographConfig} cosmograph.setConfig({ ...config, points, links }) } } } pointsInput.addEventListener('change', handleFileChange) linksInput.addEventListener('change', handleFileChange) } export default typescriptExample ``` -------------------------------- ### Generate Points and Links from Links Only Source: https://cosmograph.app/docs-lib/data-requirements/data-kit Example of how to generate points and links when only link data is available. ```APIDOC ## Generate Points and Links from Links Only ### Description This configuration allows Cosmograph to create a points dataset even when the input data primarily consists of links. ### Code ```javascript const config = { points: { linkSourceBy: 'source_column', // Column containing the link source linkTargetsBy: ['target_column', 'target_column2'], // Columns containing the link targets }, links: { linkSourceBy: 'source_column', linkTargetsBy: ['target_column', 'target_column2'], // ... other link options }, }; ``` ``` -------------------------------- ### Configure DuckDB connection in React Source: https://cosmograph.app/docs-lib/data-requirements/external-duck-db-connection Example of providing a custom DuckDB connection within a React component. ```javascript // Assuming you have a DuckDB-Wasm instance with data somewhere // const db = new duckdb.AsyncDuckDB(logger, worker) // const connection = await db.connect() const [config, setConfig] = useState({ points: 'existing_points_table', links: 'existing_links_table', pointIdBy: 'id', pointIndexBy: 'idx', linkSourceBy: 'source', linkSourceIndexBy: 'sourceidx', linkTargetBy: 'target', linkTargetIndexBy: 'targetidx', }) return ( ) ``` -------------------------------- ### Render Graph Source: https://cosmograph.app/docs-lib/api/internal/classes/Graph Renders the graph and starts rendering. Does not modify simulation state; use separate methods to control the simulation. ```javascript render() ``` -------------------------------- ### Configure Cosmograph Data (JavaScript) Source: https://cosmograph.app/docs-lib Example of preparing raw point and link data for Cosmograph using the vanilla JavaScript library. This configuration maps your data fields to Cosmograph's expected format, specifying unique identifiers for points and sources/targets for links. ```javascript import { CosmographDataPrepConfig } from '@cosmograph/cosmograph' const rawPoints: Point[] = [{ id: 'a' }, { id: 'b' }, { id: 'c' }] const rawLinks: Link[] = [ { source: 'a', target: 'b' }, { source: 'b', target: 'c' }, { source: 'c', target: 'a' }, ] // Create a config to map your data to meet the Cosmograph's internal requirements const dataConfig: CosmographDataPrepConfig = { points: { pointIdBy: 'id', }, // If you don't have links data, you can include only `points` links: { linkSourceBy: 'source', linkTargetsBy: ['target'], }, } ``` -------------------------------- ### TypeScript: Upload Points and Links Data Source: https://cosmograph.app/docs-lib/upgrade This example demonstrates how to initialize Cosmograph and handle file uploads for points and links data using plain TypeScript and DOM manipulation. It requires a container element to render the Cosmograph instance. ```typescript import { Cosmograph, CosmographConfig } from '@cosmograph/cosmograph' export const typescriptExample = (container: HTMLElement): void => { let pointsFile: File let linksFile: File const pointsInput = document.createElement('input') pointsInput.type = 'file' pointsInput.id = 'points-input' const linksInput = document.createElement('input') linksInput.type = 'file' linksInput.id = 'links-input' container.appendChild(pointsInput) container.appendChild(linksInput) const config: CosmographConfig = { pointIdBy: 'id', pointIndexBy: 'idx', pointColorBy: 'color', pointSizeBy: 'value', linkSourceBy: 'source', linkSourceIndexBy: 'sourceidx', linkTargetBy: 'target', linkTargetIndexBy: 'targetidx', linkColorBy: 'color', linkWidthBy: 'value', } const cosmograph = new Cosmograph(container, config) const handlePointsFileChange = (event: Event): void => { const file = (event.target as HTMLInputElement).files?.[0] if (file) { pointsFile = file cosmograph.setConfig({ ...config, points: pointsFile, links: linksFile }) } } const handleLinksFileChange = (event: Event): void => { const file = (event.target as HTMLInputElement).files?.[0] if (file) { linksFile = file cosmograph.setConfig({ ...config, points: pointsFile, links: linksFile }) } } pointsInput.addEventListener('change', handlePointsFileChange) linksInput.addEventListener('change', handleLinksFileChange) } ``` -------------------------------- ### GET /getActiveSelectionSourceId Source: https://cosmograph.app/docs-lib/api/internal/interfaces/ICosmograph Gets the ID of the active selection source. ```APIDOC ## GET /getActiveSelectionSourceId ### Description Gets the id of the active selection source. ### Response #### Success Response (200) - **string | undefined** - The id of the active selection source, or undefined if no selection is active. ``` -------------------------------- ### Initialize Graph Source: https://cosmograph.app/docs-lib/api/internal/classes/Graph Instantiate a new Graph object. Requires an HTMLDivElement for rendering and optionally accepts configuration and a device promise. ```javascript new Graph(div, config?, devicePromise?) ``` -------------------------------- ### Example: Set Point Shapes Source: https://cosmograph.app/docs-lib/api/internal/classes/Graph Example of setting point shapes using a Float32Array. Values correspond to enum members like Circle (0), Square (1), Triangle (2), etc. ```javascript new Float32Array([0, 1, 2]) ``` -------------------------------- ### Button Constructor Source: https://cosmograph.app/docs-lib/api/internal/classes/Button Initializes a new Button instance. It requires an HTMLElement as a container and an optional configuration object. ```APIDOC ## new Button(container, config?) ### Description Initializes a new Button instance. ### Parameters #### Path Parameters - **container** (HTMLElement) - Required - The HTML element to which the button will be attached. - **config** (CosmographButtonConfigInterface) - Optional - Configuration object for the button. ### Returns `Button` - The newly created Button instance. ``` -------------------------------- ### PointsSelectionClient Constructor Source: https://cosmograph.app/docs-lib/api/internal/classes/PointsSelectionClient Initializes a new instance of the PointsSelectionClient. ```APIDOC ## Constructor ### Description Creates a new instance of the PointsSelectionClient. ### Parameters - **_internalApi** (ICosmographInternalApi) - Required - The internal API instance. ``` -------------------------------- ### getMosaicComponents Source: https://cosmograph.app/docs-lib/api/classes/Cosmograph Gets all registered Mosaic components. ```APIDOC ## getMosaicComponents ### Description Gets all registered Mosaic components. ### Response #### Success Response (200) - **ReadonlyMap | undefined** - A readonly map of component IDs to components ``` -------------------------------- ### Instance Methods Source: https://cosmograph.app/docs-lib/api/internal/classes/DuckDBInstance Methods available on an instance of the DuckDBInstance class. ```APIDOC ### destroy() > **destroy**(): `Promise`<`void`> #### Returns `Promise`<`void`> * * * ### dropTable() > **dropTable**(`tableName`): `Promise`<`void`> #### Parameters Parameter| Type ---|--- `tableName`| `string` #### Returns `Promise`<`void`> * * * ### query() > **query**(`query`): `Promise`<`Table`<`any`> | `undefined`> #### Parameters Parameter| Type ---|--- `query`| `string` #### Returns `Promise`<`Table`<`any`> | `undefined`> * * * ### exec() > **exec**(`query`): `Promise`<`void`> #### Parameters Parameter| Type ---|--- `query`| `string` #### Returns `Promise`<`void`> * * * ### send() > **send**(`query`, `callback`): `Promise`<`void`> #### Parameters Parameter| Type ---|--- `query`| `string` `callback`| (`result`) => `void` #### Returns `Promise`<`void`> * * * ### uploadData() > **uploadData**(`data`, `tableName`, `insert`, `csvParseTimeFormat?`, `csvColumns?`): `Promise`<{ `error?`: `unknown`; }> #### Parameters Parameter| Type| Default value ---|---|--- `data`| `string` | `Table`<`any`> | `Record`<`string`, `unknown`>[] | `ArrayBuffer` | `Uint8Array`<`ArrayBufferLike`> | `File`| `undefined` `tableName`| `string`| `undefined` `insert`| `boolean`| `false` `csvParseTimeFormat?`| `string`| `undefined` `csvColumns?`| `Record`<`string`, `string`>| `undefined` #### Returns `Promise`<{ `error?`: `unknown`; }> * * * ### uploadArrow() > **uploadArrow**(`table`, `tableName`): `Promise`<{ `error?`: `unknown`; }> #### Parameters Parameter| Type ---|--- `table`| `Table`<`any`> | `ArrayBuffer` | `Uint8Array`<`ArrayBufferLike`> `tableName`| `string` #### Returns `Promise`<{ `error?`: `unknown`; }> * * * ### exportTableToArrow() > **exportTableToArrow**(`tableName`): `Promise`<`Table`<`any`> | `undefined`> #### Parameters Parameter| Type ---|--- `tableName`| `string` #### Returns `Promise`<`Table`<`any`> | `undefined`> * * * ### exportTableToArrowBuffer() > **exportTableToArrowBuffer**(`tableName`): `Promise`<`Uint8Array`<`ArrayBufferLike`> | `undefined`> #### Parameters Parameter| Type ---|--- `tableName`| `string` #### Returns `Promise`<`Uint8Array`<`ArrayBufferLike`> | `undefined`> * * * ### exportTableToPq() > **exportTableToPq**(`tableName`): `Promise`<`Uint8Array`<`ArrayBufferLike`> | `undefined`> #### Parameters Parameter| Type ---|--- `tableName`| `string` #### Returns `Promise`<`Uint8Array`<`ArrayBufferLike`> | `undefined`> * * * ### exportTableToCSV() > **exportTableToCSV**(`tableName`): `Promise`<`Uint8Array`<`ArrayBufferLike`> | `undefined`> #### Parameters Parameter| Type ---|--- `tableName`| `string` #### Returns `Promise`<`Uint8Array`<`ArrayBufferLike`> | `undefined`> * * * ### uploadObject() > **uploadObject**(`data`, `tableName`, `insert`): `Promise`<{ `error?`: `unknown`; }> #### Parameters Parameter| Type| Default value ---|---|--- `data`| `Record`<`string`, `unknown`>[]| `undefined` `tableName`| `string`| `undefined` `insert`| `boolean`| `false` #### Returns `Promise`<{ `error?`: `unknown`; }> * * * ### logTable() > **logTable**(`tableName`, `full`): `Promise`<`void`> #### Parameters Parameter| Type| Default value ---|---|--- `tableName`| `string`| `undefined` `full`| `boolean`| `false` #### Returns `Promise`<`void`> ``` -------------------------------- ### Constructor: new GraphConfig() Source: https://cosmograph.app/docs-lib/api/internal/classes/GraphConfig Initializes a new instance of the GraphConfig class. ```APIDOC ## Constructor: new GraphConfig() ### Description Creates a new instance of the GraphConfig class, which implements the GraphConfigInterface. ### Returns - **GraphConfig** - A new instance of the GraphConfig class. ``` -------------------------------- ### onAnimationPlay Source: https://cosmograph.app/docs-lib/api/interfaces/CosmographTimelineConfig Callback triggered when the timeline animation starts playing. ```APIDOC ## onAnimationPlay ### Description Callback for the animation play that will be executed in playAnimation. Provides isAnimationRunning state and current selection of Timeline. ### Parameters #### Parameters - **isAnimationRunning** (boolean) - Required - Whether the animation is currently running - **selection** ((number | Date)[] | undefined) - Required - The current selection range ### Returns - **void** ``` -------------------------------- ### getPointScreenRadiusByIndex() Source: https://cosmograph.app/docs-lib/api/internal/interfaces/ICosmograph Gets the radius of a point in the screen coordinate system by its index. ```APIDOC ## getPointScreenRadiusByIndex() ### Description Get point screen radius by its index. ### Method `getPointScreenRadiusByIndex` ### Parameters #### Path Parameters - **index** (number) - Required - Index of the point. ### Returns `number | undefined` Radius of the point in the screen coordinate system. ``` -------------------------------- ### Static Methods Source: https://cosmograph.app/docs-lib/api/internal/classes/DuckDBInstance Static methods available on the DuckDBInstance class. ```APIDOC ## Methods ### getInstance() > `static` **getInstance**(): `Promise`<`DuckDBInstance`> #### Returns `Promise`<`DuckDBInstance`> * * * ``` -------------------------------- ### Configuration Options Source: https://cosmograph.app/docs-lib/api/interfaces/CosmographConfig Settings for canvas interaction, visual styling, and library licensing. ```APIDOC ## Configuration Options ### resetSelectionOnEmptyCanvasClick - **Type**: boolean (optional) - **Default**: true - **Description**: Resets the selection when the canvas is clicked and there are some points selected. ### unknownColor - **Type**: string (optional) - **Default**: 'rgba(205, 207, 213, 0.9)' - **Description**: The color to use for points and links when their data is unknown and current coloring strategy can’t resolve it. ### licenseKey - **Type**: string (optional) - **Default**: undefined - **Description**: The key of the library license. ``` -------------------------------- ### getPointDegrees() Source: https://cosmograph.app/docs-lib/api/internal/interfaces/ICosmograph Gets the in-degree and out-degree (link counts) for a point by its index. ```APIDOC ## getPointDegrees() ### Description Gets the in-degree and out-degree (link counts) for the point with the given index. ### Method `getPointDegrees` ### Parameters #### Path Parameters - **index** (number) - Required - The index of the point to get the degrees for. ### Returns `{ inDegree: number; outDegree: number; } | undefined` An object containing the in-degree (incoming links) and out-degree (outgoing links) for the point, or `undefined` if the cosmograph instance is not initialized or the point index is invalid. ``` -------------------------------- ### getConnectedPointIndices() Source: https://cosmograph.app/docs-lib/api/internal/interfaces/ICosmograph Gets the indices of the points connected to a given point index. ```APIDOC ## getConnectedPointIndices() ### Description Gets the indices of the points that are connected to the point with the given index. ### Method `getConnectedPointIndices` ### Parameters #### Path Parameters - **index** (number) - Required - The index of the point to get the connected points for. ### Returns `number[] | undefined` An array of indices of the connected points, or `undefined` if the point index is invalid or there are no connected points. ``` -------------------------------- ### Interaction and Simulation Settings Source: https://cosmograph.app/docs-lib/api/interfaces/CosmographConfig Configuration options for mouse interactions and simulation physics. ```APIDOC ## Interaction and Simulation Settings ### enableRightClickRepulsion * **Type**: `boolean` * **Description**: Enable or disable the repulsion force from mouse when right-clicking. When set to `true`, holding the right mouse button will activate the mouse repulsion force. When set to `false`, right-clicking will not trigger any repulsion force. * **Default Value**: `false` * **Inherited from**: `GraphConfigInterface.enableRightClickRepulsion` ### simulationCluster * **Type**: `number` * **Description**: Cluster coefficient for simulation physics. * **Default Value**: `0.1` * **Inherited from**: `GraphConfigInterface.simulationCluster` ### onClick * **Type**: `function` * **Description**: Callback function that will be called on every canvas click. If clicked on a point, its index will be passed as the first argument, position as the second argument and the corresponding mouse event as the third argument. * **Signature**: `(index: number | undefined, pointPosition: [number, number] | undefined, event: MouseEvent) => void` * **Default Value**: `undefined` ``` -------------------------------- ### Get Zoom Level Source: https://cosmograph.app/docs-lib/api/internal/classes/Graph Retrieves the current zoom level of the view. ```javascript getZoomLevel() ``` -------------------------------- ### GET /getSampledPointPositionsMap Source: https://cosmograph.app/docs-lib/api/internal/interfaces/ICosmograph Retrieves a map of visible point IDs and their screen coordinates. ```APIDOC ## GET /getSampledPointPositionsMap ### Description 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. ### Response #### Success Response (200) - **Map** - A Map where keys are the ids of the points and values are their corresponding X and Y coordinates. ``` -------------------------------- ### CosmographButtonFitView Constructor Source: https://cosmograph.app/docs-lib/api/classes/CosmographButtonFitView Initializes a new instance of CosmographButtonFitView. ```APIDOC ## new CosmographButtonFitView() ### Description Initializes a new instance of the CosmographButtonFitView class. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **cosmograph** (Cosmograph) - Required - The Cosmograph instance. - **targetElement** (HTMLElement) - Required - The HTML element to attach the view to. - **userConfig** (CosmographButtonFitViewConfigInterface) - Required - Configuration object for the view. ### Request Example ```javascript const buttonFitView = new CosmographButtonFitView(cosmographInstance, document.getElementById('myElement'), { /* config */ }); ``` ### Response #### Success Response (200) `CosmographButtonFitView` - The newly created instance of CosmographButtonFitView. #### Response Example ```javascript // No direct response example as it's a constructor ``` ``` -------------------------------- ### Constructor: new Graph Source: https://cosmograph.app/docs-lib/api/internal/classes/Graph Initializes a new instance of the Graph class. ```APIDOC ## Constructor: new Graph ### Description Creates a new Graph instance attached to a specific DOM element. ### Parameters #### Path Parameters - **div** (HTMLDivElement) - Required - The DOM element to render the graph in. - **config** (GraphConfigInterface) - Optional - Configuration object for the graph. - **devicePromise** (Promise) - Optional - A promise that resolves to a device instance. ### Returns - **Graph** - The initialized Graph instance. ``` -------------------------------- ### Get Cluster Positions Source: https://cosmograph.app/docs-lib/api/internal/classes/Graph Retrieves the current X and Y coordinates of all point clusters. ```javascript getClusterPositions() ``` -------------------------------- ### Get Point Positions Source: https://cosmograph.app/docs-lib/api/internal/classes/Graph Retrieves the current X and Y coordinates of all points in the graph. ```javascript getPointPositions() ``` -------------------------------- ### Configuration Parameters Source: https://cosmograph.app/docs-lib/api/internal/interfaces/GraphConfigInterface Overview of optional configuration parameters for controlling sampling, rescaling, and attribution. ```APIDOC ## Configuration Parameters ### pointSamplingDistance - **Type**: number - **Description**: Point sampling distance in pixels between neighboring points when calling the `getSampledPointPositionsMap` method. Determines sample density. Default: 150. ### linkSamplingDistance - **Type**: number - **Description**: Link sampling distance in pixels between neighboring links when calling the `getSampledLinks` method. Determines sample density based on link midpoints in screen space. Default: 150. ### rescalePositions - **Type**: boolean - **Description**: Controls automatic position adjustment of points. If undefined, behavior depends on simulation state. If true, forces rescaling; if false, disables it. ### attribution - **Type**: string - **Description**: Controls the text shown in the bottom right corner. If a non-empty string is provided, it is displayed as HTML. ``` -------------------------------- ### Point Position Retrieval Source: https://cosmograph.app/docs-lib/api/classes/Cosmograph Function to get the coordinates of a specific point by its index. ```APIDOC ## GET getPointPositionByIndex(index) ### Description Gets the current X and Y coordinates of a point by its index. ### Method GET ### Endpoint `/websites/cosmograph_app_docs-lib/getPointPositionByIndex` ### Parameters #### Query Parameters - **index** (number) - Required - Point index. ### Returns `[number, number] | undefined` Array with X and Y coordinates of the point, or `undefined` if the point index is invalid. ### Implementation of `ICosmograph`.`getPointPositionByIndex` ``` -------------------------------- ### GET /getSampledLinkPositionsMap Source: https://cosmograph.app/docs-lib/api/internal/interfaces/ICosmograph Retrieves a map of visible link indices and their midpoint coordinates and angles. ```APIDOC ## GET /getSampledLinkPositionsMap ### Description For the links that are currently visible on the screen, get a sample of link indices with their midpoint coordinates and angle. Each value is [x, y, angle]. ### Response #### Success Response (200) - **Map** - A Map where keys are link indices and values are [x, y, angle]. ``` -------------------------------- ### Point Configuration Options Source: https://cosmograph.app/docs-lib/api/internal/interfaces/CosmographDataPrepPointsConfig Options for configuring point size, clustering, labeling, and positioning. ```APIDOC ## pointSizeRange ### Description Defines the range for automatic point size scaling. Takes [min, max] values in pixels. When pointSizeBy column contains numeric values, they will be automatically remapped to fit within this range to prevent oversized points. Used when pointSizeStrategy is set to 'auto' or 'degree'. ### Default `[2, 9]` ### Method Optional ### Endpoint N/A ### Parameters #### Query Parameters - **pointSizeRange** (["number", "number"]) - Optional - Defines the range for automatic point size scaling. Takes [min, max] values in pixels. ### Response #### Success Response (200) N/A #### Response Example N/A ``` ```APIDOC ## pointSizeByFn ### Description Function that generates sizes for points based on values in the pointSizeBy column. Overrides the values in pointSizeBy column by processing them (values can be of any type, not just numbers). Has effect only when pointSizeBy is provided and pointSizeStrategy is undefined. ### See pointSizeStrategy ### Method Optional ### Endpoint N/A ### Parameters #### Query Parameters - **pointSizeByFn** (SizeAccessorFn | SizeAccessorFn | SizeAccessorFn | SizeAccessorFn) - Optional - Function that generates sizes for points based on values in the pointSizeBy column. ### Request Example ```javascript pointSizeByFn: (value: boolean) => value ? 8 : 4 pointSizeByFn: (value: unknown, index: number) => index % 2 === 0 ? 8 : 4 pointSizeByFn: (value: number) => Math.min(value * 2, 10) ``` ### Response #### Success Response (200) N/A #### Response Example N/A ``` ```APIDOC ## pointClusterBy ### Description Column name containing cluster assignments for points. Can be string or number. Cosmograph will automatically generate a mapping of cluster values to their indices that will be available in the clusterMapping getter. ### Method Optional ### Endpoint N/A ### Parameters #### Query Parameters - **pointClusterBy** (string) - Optional - Column name containing cluster assignments for points. ### Response #### Success Response (200) N/A #### Response Example N/A ``` ```APIDOC ## pointClusterByFn ### Description Function that generates cluster assignments for points based on values in the pointClusterBy column. Overrides the values in pointClusterBy column by processing them. Has effect only when pointClusterBy is provided. ### Parameters #### Path Parameters N/A #### Query Parameters - **pointClusterByFn** (function) - Optional - Function that generates cluster assignments for points. - **value** (any) - The value from the pointClusterBy column. - **index** (number) - Optional - The index of the point. ### Returns `unknown` - The generated cluster assignment. ### Request Example ```javascript pointClusterByFn: (value: string) => value.length ``` ### Response #### Success Response (200) N/A #### Response Example N/A ``` ```APIDOC ## pointClusterStrengthBy ### Description The `pointClusterStrengthBy` column defines how strongly each point is attracted to its assigned cluster during the simulation. The column should contain numeric values where higher values (closer to 1.0) = stronger attraction, point stays closer to its cluster, Lower values (closer to 0.0) = weaker attraction, point can move more freely away from its cluster. Has effect only when pointClusterBy is provided. ### Method Optional ### Endpoint N/A ### Parameters #### Query Parameters - **pointClusterStrengthBy** (string) - Optional - The column name defining the strength of attraction to the cluster. ### Response #### Success Response (200) N/A #### Response Example N/A ``` ```APIDOC ## pointLabelBy ### Description The column name for the point label. ### Method Optional ### Endpoint N/A ### Parameters #### Query Parameters - **pointLabelBy** (string) - Optional - The column name for the point label. ### Response #### Success Response (200) N/A #### Response Example N/A ``` ```APIDOC ## pointLabelWeightBy ### Description Specify the numeric column that will be used for the point label weight. Higher weight values make labels more likely to be shown. If not provided, the points labels will be sorted by pointSizeBy if provided or their total links count (degree) otherwise. ### Method Optional ### Endpoint N/A ### Parameters #### Query Parameters - **pointLabelWeightBy** (string) - Optional - The column name for the point label weight. ### Response #### Success Response (200) N/A #### Response Example N/A ``` ```APIDOC ## pointXBy ### Description The column name for the point’s x-coordinate. If provided with `pointYBy`, points will be positioned based on the values from `pointXBy` and `pointYBy` columns. ### Method Optional ### Endpoint N/A ### Parameters #### Query Parameters - **pointXBy** (string) - Optional - The column name for the point’s x-coordinate. ### Response #### Success Response (200) N/A #### Response Example N/A ``` ```APIDOC ## pointYBy ### Description The column name for the point’s y-coordinate. If provided with `pointXBy`, points will be positioned based on the values from `pointXBy` and `pointYBy` columns. ### Method Optional ### Endpoint N/A ### Parameters #### Query Parameters - **pointYBy** (string) - Optional - The column name for the point’s y-coordinate. ### Response #### Success Response (200) N/A #### Response Example N/A ``` ```APIDOC ## pointIncludeColumns ### Description An array of additional column names to include in the point data. These columns will be available on the point objects but not used by Cosmograph directly, can be used as accessors for Cosmograph components. Useful for storing additional information about the points. If provided with `*`, all columns will be included. ### Example ```javascript pointIncludeColumns: ['*'] // all columns will be included pointIncludeColumns: ['column1', 'column2'] // only column1 and column2 will be included ``` ### Method Optional ### Endpoint N/A ### Parameters #### Query Parameters - **pointIncludeColumns** (string[]) - Optional - An array of additional column names to include. ### Response #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### DisplayStateManager Constructor Source: https://cosmograph.app/docs-lib/api/internal/classes/DisplayStateManager Initializes a new instance of the DisplayStateManager. ```APIDOC ## Constructor ### Description Creates a new DisplayStateManager instance to manage UI states for a specific container. ### Parameters - **containerNode** (HTMLElement) - Required - The DOM element to manage. - **config** (DisplayStateConfigInterface) - Optional - Initial configuration for the state manager. ### Returns - **DisplayStateManager** - The initialized instance. ``` -------------------------------- ### Constructor: new CosmographRangeColorLegend Source: https://cosmograph.app/docs-lib/api/classes/CosmographRangeColorLegend Initializes a new instance of the CosmographRangeColorLegend component. ```APIDOC ## Constructor ### Description Constructs a filtering component that connects Cosmograph data to a UI component. ### Parameters #### Path Parameters - **cosmograph** (Cosmograph) - Required - The Cosmograph instance to connect to - **targetElement** (HTMLElement) - Required - HTML element for rendering the UI component - **config** (CosmographRangeColorLegendConfig) - Required - Configuration for the filtering component ### Returns - **CosmographRangeColorLegend** - The initialized component instance ``` -------------------------------- ### Simulation Control API Source: https://cosmograph.app/docs-lib/api/internal/interfaces/ICosmograph Methods for controlling the simulation state, including starting, pausing, unpausing, and stopping. ```APIDOC ## start() ### Description Starts the simulation. ### Method N/A (This is a method call, not a REST endpoint) ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript // Example of calling start with an alpha value start(0.5); ``` ### Response #### Success Response (200) N/A (This method returns void) #### Response Example N/A ``` ```APIDOC ## pause() ### Description Pauses the simulation. ### Method N/A (This is a method call, not a REST endpoint) ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript // Example of calling pause pause(); ``` ### Response #### Success Response (200) N/A (This method returns void) #### Response Example N/A ``` ```APIDOC ## unpause() ### Description Unpauses the simulation. ### Method N/A (This is a method call, not a REST endpoint) ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript // Example of calling unpause unpause(); ``` ### Response #### Success Response (200) N/A (This method returns void) #### Response Example N/A ``` ```APIDOC ## stop() ### Description Stops the simulation. ### Method N/A (This is a method call, not a REST endpoint) ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript // Example of calling stop stop(); ``` ### Response #### Success Response (200) N/A (This method returns void) #### Response Example N/A ``` ```APIDOC ## step() ### Description Renders only one frame of the simulation (stops the simulation if it was running). ### Method N/A (This is a method call, not a REST endpoint) ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript // Example of calling step step(); ``` ### Response #### Success Response (200) N/A (This method returns void) #### Response Example N/A ``` -------------------------------- ### Lifecycle and Data Management Methods Source: https://cosmograph.app/docs-lib/api/internal/interfaces/ICosmographInternalApi Methods for initializing the graph, managing local tables, and updating internal states. ```APIDOC ## dbReady() ### Description Checks if the database is ready. ### Returns - Promise ## dropLocalTables() ### Description Drops local database tables. ### Parameters - **linksOnly** (boolean) - Required - Whether to drop only link tables. ### Returns - Promise ## updateMessage() ### Description Updates the internal message state. ### Parameters - **msg** (string | null) - Required - The message string. ### Returns - void ## initializeCosmos() ### Description Initializes the graph instance. ### Returns - Promise ## initializeLabels() ### Description Initializes the graph labels. ### Returns - void ## updateStats() ### Description Updates the graph statistics. ### Returns - void ## updateSummary() ### Description Updates the graph summary information. ### Returns - Promise ```