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

feat(graph): hover updates #1298

Merged
merged 4 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type Props = {
size: number;
};

function HoverInfo({ node, camera, size, left, top }: Props) {
function HoverInfo({ node, camera, size, left, top, right }: Props) {
let l = left;
let t = top;

Expand Down Expand Up @@ -58,6 +58,7 @@ function HoverInfo({ node, camera, size, left, top }: Props) {
style={{
top: t,
left: l,
right,
}}
>
<ContentItem cid={node.id} />
Expand Down
29 changes: 23 additions & 6 deletions src/features/cyberlinks/GraphNew/GraphNew.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import GraphActionBar from '../graph/GraphActionBar/GraphActionBar';

const randomBoolean = (() => Math.random() > 0.5)();

export default function GraphNew({ address, data, size }) {
function GraphNew({ address, data, size }) {
const cosmograph = useRef<CosmographRef>();
// const histogram = useRef<CosmographHistogramRef<Node>>();
// const timeline = useRef<CosmographTimelineRef<Link>>();
Expand Down Expand Up @@ -164,14 +164,29 @@ export default function GraphNew({ address, data, size }) {
}, [nodes.length, links.length, limit]),
});

return (
<div className={styles.wrapper}>
function renderInfo(node, position?: string) {
const xOffset = 100;
const toRight = position === 'right';

return (
<GraphHoverInfo
node={hoverNode}
left={nodePostion?.x + 50}
top={nodePostion?.y}
node={node}
left={!toRight ? xOffset : undefined}
right={toRight ? xOffset : undefined}
top="42.5vh"
size={size || window.innerWidth}
/>
);
}

return (
<div className={styles.wrapper}>
{(selectedNodes[0] || (hoverNode && selectedNodes.length !== 1)) &&
renderInfo(
(selectedNodes.length !== 1 && hoverNode) || selectedNodes[0]
)}
{(selectedNodes[1] || (selectedNodes.length === 1 && hoverNode)) &&
renderInfo(hoverNode || selectedNodes[1], 'right')}

<CosmographProvider nodes={nodes} links={links}>
{/* <CosmographSearch
Expand Down Expand Up @@ -291,6 +306,8 @@ export default function GraphNew({ address, data, size }) {
);
}

export default GraphNew;

type Props2 = {
selectedNodes: CosmosInputNode[];
callback: () => void;
Expand Down