Skip to content

Commit

Permalink
Update readme and fix CI (#34)
Browse files Browse the repository at this point in the history
* Update readme

* Remove cache from github action

* Rename eslint config to support cjs

* Add prettier to dev deps to support CI
  • Loading branch information
cephalization authored Dec 6, 2024
1 parent edf9af9 commit fc34ce5
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 18 deletions.
File renamed without changes.
2 changes: 0 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: "20.x"
cache: "pnpm"
- name: Install deps
run: pnpm install
- name: Lint
Expand Down Expand Up @@ -42,7 +41,6 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
cache: "pnpm"

- name: Install deps
run: pnpm install
Expand Down
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,46 @@
</p>

A point cloud library for visualizing point clouds using 2D and 3D canvases.

## Installation

```bash
# or pnpm, yarn, etc
npm install @arizeai/point-cloud @react-three/drei
```

## Usage

Basic usage:

```tsx
import { ThreeDimensionalCanvas, ThreeDimensionalControls, Points, type PointBaseProps } from '@arizeai/point-cloud';

const data: PointBaseProps[] = [
{ position: [0, 0, 0], metaData: {} },
{ position: [1, 1, 1], metaData: {} },
];

export const PointCloud = () => {
return (
<ThreeDimensionalCanvas>
<ThreeDimensionalControls />
<Points data={data} pointProps={{ color: '#7BFFFF' }} />
</ThreeDimensionalCanvas>
);
};
```

See additional usage examples in Storybook.

```bash
npm run storybook
```

## Usage with React 19

React 19 is not yet supported by stable versions of `@react-three/drei`. To use this library with React 19, you can try the following:

```bash
npm install @arizeai/point-cloud @react-three/drei@alpha
```
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-unused-imports": "^3.1.0",
"husky": "^7.0.4",
"prettier": "^3.4.2",
"react": "18",
"react-dom": "18",
"react-is": "^18.1.0",
Expand Down
2 changes: 1 addition & 1 deletion src/Cluster.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function Cluster({
const geometries: THREE.SphereGeometry[] = [];
// Keep track of the points added so that we can remove duplicates
const pointSet = new Set();
data.forEach(point => {
data.forEach((point) => {
const { position } = point;
// Remove duplicates
if (!pointSet.has(position.join(","))) {
Expand Down
8 changes: 3 additions & 5 deletions src/LassoSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,8 @@ export function LassoSelect({

// Animation frames to draw the selections
useFrame(({ camera }) => {
const {
selectionShapeNeedsUpdate,
selectionPoints,
} = selectionState.current;
const { selectionShapeNeedsUpdate, selectionPoints } =
selectionState.current;
// Update the selection lasso lines
if (selectionShapeNeedsUpdate) {
const ogLength = selectionPoints.length;
Expand Down Expand Up @@ -270,7 +268,7 @@ function updateSelection({

// A vector to re-use in calculating it's intersection with the polygon
const pointVector = new THREE.Vector3();
points.forEach(point => {
points.forEach((point) => {
const isThreeD = point.position.length === 3;
// Initialize the point vector from the point position
const pointPosition = isThreeD
Expand Down
10 changes: 5 additions & 5 deletions src/Points.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,26 +208,26 @@ export function Points({
<instancedMesh
args={[undefined, undefined, data.length]}
ref={meshRef}
onPointerUp={e => {
onPointerUp={(e) => {
if (e.intersections) {
const instanceIds = e.intersections
.map(e => e?.instanceId)
.map((e) => e?.instanceId)
.filter((i): i is NonNullable<typeof i> => i != null);

// Multi click
onPointsClicked &&
onPointsClicked(instanceIds.map(i => data[i]));
onPointsClicked(instanceIds.map((i) => data[i]));

// Single click
instanceIds.length > 0 &&
onPointClicked &&
onPointClicked(data[instanceIds[0]]);
}
}}
onPointerOver={e => {
onPointerOver={(e) => {
if (e.intersections) {
const instanceIds = e.intersections
.map(e => e?.instanceId)
.map((e) => e?.instanceId)
.filter((i): i is NonNullable<typeof i> => i != null);

// Single instance callback
Expand Down
5 changes: 2 additions & 3 deletions src/ThreeDimensionalBounds.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,8 @@ export function ThreeDimensionalBounds({
camera.zoom =
Math.min(width / boundsWidth, height / boundsHeight) *
boundsZoomPaddingFactor;
const furthestPointDim = getMaxDimensionFromThreeDimensionalBounds(
bounds,
);
const furthestPointDim =
getMaxDimensionFromThreeDimensionalBounds(bounds);

// Set the camera position to be a bit further away than the furthest coordinate value, to allow for rotation of the cloud without clipping through the near plane
// The default near value is .1, so if we move the camera back this far, we are guaranteed to be not clip the near plane
Expand Down
2 changes: 1 addition & 1 deletion src/utils/threeDimensionalUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function getThreeDimensionalBounds(
minZ = Infinity,
maxZ = -Infinity;

points.forEach(p => {
points.forEach((p) => {
minX = Math.min(minX, p[0]);
minY = Math.min(minY, p[1]);
minZ = Math.min(minZ, p[2]);
Expand Down
2 changes: 1 addition & 1 deletion src/utils/twoDimensionalUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function getTwoDimensionalBounds(
maxX = -Infinity,
maxY = -Infinity;

points.forEach(p => {
points.forEach((p) => {
minX = Math.min(minX, p[0]);
minY = Math.min(minY, p[1]);
maxX = Math.max(maxX, p[0]);
Expand Down

0 comments on commit fc34ce5

Please sign in to comment.