Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRAFT: Start port to luma.gl #124

Draft
wants to merge 53 commits into
base: next
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
67d5aab
Set data for nodes and links as arrays of numbers
Stukova Mar 21, 2024
2b44700
Fit view fixed
Stukova Apr 4, 2024
38af7f6
Low level major refactoring
Stukova May 13, 2024
f379099
Add `screenToSpacePosition` and rename `flatten` and `pair`
Stukova May 15, 2024
9c8b8d6
Renaming config values and fix graph data updates
Stukova May 16, 2024
ac234e8
defaultLinkArrows: false
Stukova May 16, 2024
0e2b90f
Renaming `nodes` -> `points`
Stukova May 17, 2024
da9c673
`fitViewByPointPositions` API
Stukova May 17, 2024
d1d93c4
Update graph even if no points or links exist
Stukova May 20, 2024
629ed9e
Fix - `getTransform` with one point coordinate
Stukova May 20, 2024
6b53e53
Migration notes for Cosmos v2.0
Stukova May 23, 2024
6d4b15c
Refactor shader attribute names and uniform consistency across modules
Stukova May 29, 2024
a0dc5cc
Validation logic for numeric values in GraphData
Stukova May 29, 2024
9b52548
Fixed iteration over tracked indices when reading
Stukova Jun 9, 2024
aac73f3
Added `setLinkStrength` feature
Stukova Jun 10, 2024
9743a4a
Fixed finding hovered point
Stukova Jun 12, 2024
80bbea7
Added ability to drag points
Stukova Jun 14, 2024
85154bc
Add JSDoc to public methods
Stukova Jun 19, 2024
239f0de
Drag points improvements
Stukova Jun 26, 2024
1bd4c3a
Stop frames when no data is sent
Stukova Jun 28, 2024
f761811
Upgrade TypeScript to latest version 5.5.2
Stukova Jun 28, 2024
443d4d1
JSDoc and JS comments updates
Stukova Jun 30, 2024
36a32d6
Tweak default values in config and variables
Stukova Jul 4, 2024
69ab317
fix: sync up tracked points on update
Stukova Jul 25, 2024
b56dff0
feat: add configurable cursor style for hovered points
Stukova Jul 26, 2024
33a0f6b
feat: expand color options for default point and link colors
Stukova Jul 26, 2024
557897e
feat(simulation): adjust force-directed graph parameters
Stukova Jul 29, 2024
78282c1
feat(config): enhance `fitViewOnInit` functionality
Stukova Aug 8, 2024
a0b7418
fix: clear canvas after destroying particle system
Stukova Aug 8, 2024
4aad455
feat(config): extend color options for graph background and point rings
Stukova Aug 8, 2024
c0e5a06
Rename `disableDrag` to `enableDrag` in config
Stukova Aug 8, 2024
10041f6
JSDoc tweaks
Stukova Aug 8, 2024
a34f9ee
Add `getPointsInRange` method
Stukova Aug 9, 2024
c277f7a
Add config option for setting focused point by index
Stukova Aug 15, 2024
026e05c
Refactor particle system destruction
Stukova Sep 6, 2024
6501104
fix: create method
Stukova Sep 9, 2024
1ac559a
fix: separate input and processed data for points and links
Stukova Oct 4, 2024
ac15d0c
fix: `getAdjacentIndices` method
Stukova Oct 4, 2024
0ab7ead
Improve webgl texture, buffer and command updates
Stukova Oct 4, 2024
4e4aa81
Update `render` and `update` methods to use `simulationAlpha` instead…
Stukova Oct 6, 2024
ef95bf4
Destroy `sampledPointsFbo` on data update
Stukova Oct 9, 2024
ff62932
fix: update point color and size
Stukova Nov 14, 2024
67febbf
fix: update webgl buffers on render
Stukova Nov 14, 2024
64829d5
feature: cluster forces
Stukova Nov 15, 2024
2c4e950
feat(clusters): enhance graph clustering with custom positions and co…
Stukova Nov 25, 2024
9cdc96f
Update README.md to fix the showcase video
rokotyan Nov 18, 2024
f98a2d9
Bump rollup from 2.76.0 to 2.79.2
dependabot[bot] Sep 27, 2024
e2a4b3a
Project: Storybook and experimental Vite build
rokotyan Nov 23, 2024
e982c34
Project: Readme update
rokotyan Nov 24, 2024
99aa9e8
Storybook: update welcome story with video and style improvements
Stukova Nov 27, 2024
804aeda
Storybook: add cluster stories
Stukova Nov 27, 2024
370e65d
Storybook: add cluster radial story
Stukova Nov 27, 2024
12a4ac7
wip
ibgreen Nov 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,17 @@
"import/no-default-export": "error",
"import/prefer-default-export": 0,
"import/first": ["error", "absolute-first"],
"import/order": ["error", {"groups": ["builtin", "external", "parent", "sibling", "index", "object"]}],
"import/order": ["error",
{
"groups": ["builtin", "external", "internal", "parent", "sibling", "index", "object"],
"pathGroups": [
{
"pattern": "@/**",
"group": "internal"
}
],
}
],
"comma-dangle": ["error", {
"arrays": "always-multiline",
"objects": "always-multiline",
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
node_modules
dist
yarn.lock
.eslintcache
.eslintcache
*storybook.log
15 changes: 15 additions & 0 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { StorybookConfig } from "@storybook/html-vite";

const config: StorybookConfig = {
stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"],
addons: [
"@storybook/addon-essentials",
"@chromatic-com/storybook",
"@storybook/addon-interactions",
],
framework: {
name: "@storybook/html-vite",
options: {},
},
};
export default config;
6 changes: 6 additions & 0 deletions .storybook/manager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { addons } from '@storybook/manager-api';
import { themes } from '@storybook/theming';

addons.setConfig({
theme: themes.dark,
});
26 changes: 26 additions & 0 deletions .storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { Preview } from "@storybook/html";
import { themes } from '@storybook/theming';

const preview: Preview = {
parameters: {
layout: 'fullscreen',
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/i,
},
},
docs: {
theme: themes.dark,
},
backgrounds: {
default: 'dark',
values: [
{ name: 'light', value: '#fff' },
{ name: 'dark', value: '#192132' },
],
},
},
};

export default preview;
93 changes: 65 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@

<p align="center" style="color: #444">
<h1 align="center">🌌 Cosmos</h1>
</p>
<p align="center" style="font-size: 1.2rem;">GPU-accelerated Force Graph</p>

Cosmos is a WebGL Force Graph layout algorithm and rendering engine. All the computations and drawing are happening on the GPU in fragment and vertex shaders avoiding expensive memory operations.
**Cosmos** is a WebGL Force Graph layout algorithm and rendering engine. All the computations and drawing are happening on the GPU in fragment and vertex shaders, avoiding expensive memory operations.

It enables real-time simulation of network graphs consisting of hundreds of thousands of nodes and edges on modern hardware.
It enables real-time simulation of network graphs consisting of hundreds of thousands of points and links on modern hardware.

![](https://user-images.githubusercontent.com/755708/173392407-9b05cbb6-d39e-4c2c-ab41-50900cfda823.mp4)
<img src="https://user-images.githubusercontent.com/755708/173392407-9b05cbb6-d39e-4c2c-ab41-50900cfda823.mp4" autoplay controls>
</img>

[📺 Comparison with other libraries](https://www.youtube.com/watch?v=HWk78hP8aEE)

[🎮 Try Cosmos on CodeSandbox](https://codesandbox.io/s/cosmos-example-fmuf1x?file=/src/index.ts)
[🎮 Try Cosmos on CodeSandbox](https://stackblitz.com/edit/how-to-use-cosmos?file=src%2Fmain.ts)

---

### Quick Start

Expand All @@ -21,56 +25,89 @@ Install the package:
npm install @cosmograph/cosmos
```

Get the data, [configure](https://github.com/cosmograph-org/cosmos/wiki/Cosmos-configuration) the graph and run the simulation:
Configure the graph, set data, and run the simulation:

```javascript
import { Graph } from '@cosmograph/cosmos'
import { nodes, links } from './data'
import { Graph } from '@cosmograph/cosmos';
import { pointPositions, links } from './data';

const canvas = document.querySelector('canvas')
const canvas = document.querySelector('canvas');
const config = {
simulation: {
repulsion: 0.5,
},
renderLinks: true,
linkColor: link => link.color,
nodeColor: node => node.color,
events: {
onClick: node => { console.log('Clicked node: ', node) },
onClick: (pointIndex) => {
console.log('Clicked point index: ', pointIndex);
},
},
/* ... */
}
};

const graph = new Graph(canvas, config)
const graph = new Graph(canvas, config);

graph.setData(nodes, links)
graph.setPointPositions(pointPositions);
graph.setLinks(links);
graph.render();
```

- **`pointPositions`**: An array of `[x1, y1, x2, y2, ..., xN, yN]`.
- **`links`**: An array of `[sourceIndex1, targetIndex1, ..., sourceIndexN, targetIndexN]`.

> **Note**
> If your canvas element has no width and height styles (either CSS or inline) Cosmos will automatically set them to 100%.
> If your canvas element has no width and height styles (either CSS or inline), Cosmos will automatically set them to 100%.

---

> **Warning**
> If you're going to create a new graph within the same HTML canvas element that already has a graph, **destroy** the previous graph using `graph.destroy()` to prevent unexpected glitches.
### What's New in v2.0?

Check out the [Wiki](https://github.com/cosmograph-org/cosmos/wiki) for more information on 🛠 [Configuration](https://github.com/cosmograph-org/cosmos/wiki/Cosmos-configuration) and ⚙️ [API Reference](https://github.com/cosmograph-org/cosmos/wiki/API-Reference).
Cosmos v2.0 introduces significant improvements in performance and data handling:

- Enhanced data structures with WebGL-compatible formats.
- Methods like `setPointPositions` and `setLinks` replace `setData` for improved efficiency.
- Direct control over point and link attributes via arrays (e.g., colors, sizes, widths).
- Updated event handling based on indices instead of objects.

Check the [Migration Guide](https://github.com/cosmograph-org/cosmos/tree/next/cosmos-2-0-migration-notes.md) for details.

---

### Examples
- [Basic Set-Up](https://codesandbox.io/s/cosmos-example-fmuf1x?file=/src/index.ts)
- [Adding Node Labels](https://codesandbox.io/s/cosmos-node-labels-hkfplk) (via [`@interacta/css-labels`](https://www.npmjs.com/package/@interacta/css-labels))

- [Basic Set-Up](https://stackblitz.com/edit/how-to-use-cosmos?file=src%2Fmain.ts)

---

### Showcase (via [cosmograph.app](https://cosmograph.app))
- [Silk Road Case: Bitcoin Transactions](https://cosmograph.app/run/?data=https://cosmograph.app/data/184R7cFG-4lv.csv) ([📄 Read about the case](https://medium.com/@cosmograph.app/visualizing-darknet-6846dec7f1d7))
- [ABACUS Shell](https://cosmograph.app/run/?&decay=100000&link-distance=1&link-spring=2&data=https://cosmograph.app/data/ABACUS_shell_hd.csv) ([source](http://sparse.tamu.edu/Puri/ABACUS_shell_hd))

- [Silk Road Case: Bitcoin Transactions](https://cosmograph.app/run/?data=https://cosmograph.app/data/184R7cFG-4lv.csv) ([📄 Read more](https://medium.com/@cosmograph.app/visualizing-darknet-6846dec7f1d7))
- [ABACUS Shell](https://cosmograph.app/run/?data=https://cosmograph.app/data/ABACUS_shell_hd.csv) ([source](http://sparse.tamu.edu/Puri/ABACUS_shell_hd))
- [The MathWorks, Inc: symmetric positive definite matrix](https://cosmograph.app/run/?data=https://cosmograph.app/data/Kuu.csv) ([source](https://sparse.tamu.edu/MathWorks/Kuu))
- [4 Tower Silo](https://cosmograph.app/run/?data=https://cosmograph.app/data/pkustk10.csv) ([source](https://sparse.tamu.edu/Chen/pkustk10))
- [Jacobian from Bank of Canada ‘jan99’ model](https://cosmograph.app/run/?data=https://cosmograph.app/data/jan99jac040sc.csv) ([source](https://sparse.tamu.edu/Hollinger/jan99jac040sc))

---

### Known Issues
Starting from version 15.4, iOS has stopped supporting the key WebGL extension powering our Many-Body force implementation (EXT_float_blend). We're trying to figure out why that happened and hope to find a way to solve the problem in the future.

- Starting from version 15.4, iOS has stopped supporting the key WebGL extension powering our Many-Body force implementation (`EXT_float_blend`). We're investigating this issue and exploring solutions.

---

### Documentation

- 🛠 [Configuration](https://github.com/cosmograph-org/cosmos/wiki/Cosmos-v2-(Beta-version)-configuration)
- ⚙️ [API Reference](https://github.com/cosmograph-org/cosmos/wiki/Cosmos-v2-(Beta-version)-API-Reference)
- 🚀 [Migration Guide](https://github.com/cosmograph-org/cosmos/tree/next/cosmos-2-0-migration-notes.md)

---

### License
CC-BY-NC-4.0

Cosmos is free non-commercial usage. If you're a scientist, artist, educator, journalist, student, ..., we would love to hear about your project and how you use Cosmos! If you want to use it in a commercial project, please reach out to us.
**CC-BY-NC-4.0**

Cosmos is free for non-commercial usage. If you're a scientist, artist, educator, journalist, or student, we'd love to hear how you're using Cosmos! For commercial projects, please [reach out](mailto:[email protected]).

---

### Contact

[📩 [email protected]](mailto:[email protected])
79 changes: 79 additions & 0 deletions cosmos-2-0-migration-notes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
### Migration Guide @cosmograph/cosmos v2.0

#### Introduction

Welcome to the updated @cosmograph/cosmos library! Version 2.0 introduces significant improvements in data handling and performance, marking a major milestone for the library. This guide will help you transition to the new version smoothly.

#### Key Changes in Data Handling

This update is centered on enhancing data performance by utilizing formats directly compatible with WebGL. Since WebGL operates with buffers and framebuffers created from arrays of numbers, we have introduced new methods to handle data more efficiently.

#### Replacing `setData`

The `setData` method has been replaced with `setPointPositions` and `setLinks`. These new methods accept arrays of numbers, which are directly used to create WebGL textures.

**Before:**
```js
graph.setData(
[{ id: 'a' }, { id: 'b' }], // Nodes
[{ source: 'a', target: 'b' }] // Links
);
```

**After:**
```js
graph.setPointPositions([
400, 400, // x and y of the first point
500, 500, // x and y of the second point
]);
graph.setLinks([
0, 1 // Link between the first and second point
]);
```

#### Configuration Updates

Accessor functions for styling such as `nodeColor`, `nodeSize`, `linkColor`, `linkWidth`, and `linkArrows`, are eliminated. You can now set these attributes directly using arrays of numbers.

**Old Method for Setting Node Color:**
```js
config.nodeColor = node => node.color;
```

**New Method for Setting Point Colors:**
```js
graph.setPointColors([
0.5, 0.5, 1, 1, // r, g, b, alpha for the first point
0.5, 1, 0.5, 1, // r, g, b, alpha for the second point
]);
```

If you don't set point colors, sizes, link colors, widths, or arrows, default values from the new config parameters (`defaultPointColor`, `defaultPointSize`, `defaultLinkColor`, `defaultLinkWidth`, and `defaultLinkArrow`) will be applied.

**Example:**
```js
const config = {
defaultPointColor: 'navajowhite'
};
```

**Modifying Event Handling**

Event handling now focuses on point indices instead of node objects.

**Old Event Handling:**
```js
config.events.onNodeMouseOver = (node, index, pos) => console.log(`Hovered over node ${node.id}`);
```

**New Event Handling:**
```js
config.events.onPointMouseOver = (index, pos) => console.log(`Hovered over point at index ${index}`);
```

**Summary of Additional Changes**

- **Terminology Update:** "Node" is now "Point," but "Link" remains unchanged.
- **API Modifications:** All methods that focused on node objects have been updated or replaced to handle indices.
- **Manual Rendering:** After setting data or updating point/link properties, remember to run `graph.render()` to update WebGL textures and render the graph with the new data.

Loading