Skip to content

Commit

Permalink
chore: example with tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeldking committed Jun 21, 2023
1 parent ff10265 commit 5c1d0db
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 1 deletion.
2 changes: 1 addition & 1 deletion stories/Connections.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { startTransition, useRef, useState } from 'react';
import { Meta, Story } from '@storybook/react';
import { Meta } from '@storybook/react';
import {
Axes,
PointBaseProps,
Expand Down
73 changes: 73 additions & 0 deletions stories/Tooltip.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { Meta, Story } from '@storybook/react';
import { startTransition, useState } from 'react';
import { Container, ToolName } from './components';
import {
Axes,
PointBaseProps,
Points,
ThreeDimensionalBounds,
ThreeDimensionalCanvas,
ThreeDimensionalControls,
ThreeDimensionalPoint,
getThreeDimensionalBounds,
} from '../src';
import React from 'react';
import { Html } from '@react-three/drei';
import _data from './data/point-cloud-3d.json';
import { Vector3 } from 'three';
const data = _data as unknown as Array<PointBaseProps>;

const meta: Meta = {
title: 'Tooltip',
};

export default meta;

export function Default() {
const [tool, setTool] = useState<ToolName>('move');
const bounds = React.useMemo(() => {
return getThreeDimensionalBounds([
...data.map((d) => d.position as ThreeDimensionalPoint),
]);
}, []);
const [selectedPoint, setSelectedPoint] =
useState<PointBaseProps | null>(null);

return (
<Container showToolbar selectedTool={tool} onToolChange={setTool}>
<ThreeDimensionalCanvas camera={{ zoom: 1, up: [0, 0, 1] }}>
<ambientLight intensity={0.5} />
<pointLight position={[0, 0, 10]} />
<ThreeDimensionalControls />
<ThreeDimensionalBounds bounds={bounds}>
<Axes size={bounds.maxX - bounds.minX} />
<Points
data={data}
pointProps={{
color: 'limegreen',
}}
onPointHovered={(point) => {
startTransition(() => {
setSelectedPoint(point);
});
}}
onPointerLeave={() => {
startTransition(() => {
setSelectedPoint(null);
});
}}
/>
</ThreeDimensionalBounds>
{selectedPoint ? (
<Html position={selectedPoint.position as unknown as Vector3}>
<div style={{ color: 'white', padding: '10px 10px' }}>
<section style={{ background: 'gray', borderRadius: '4px' }}>
{selectedPoint.metaData.uuid}
</section>
</div>
</Html>
) : null}
</ThreeDimensionalCanvas>
</Container>
);
}

0 comments on commit 5c1d0db

Please sign in to comment.