Skip to content

Commit

Permalink
Merge pull request #21 from CarnegieLearningWeb/dev
Browse files Browse the repository at this point in the history
larger arrows for visibility
  • Loading branch information
emoltz authored Jun 27, 2024
2 parents a6120d6 + 366e219 commit ffb5c35
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions src/components/DirectedGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import ToggleTool from "@/components/ToggleTool";

// TODO make sure the node info is changed

type TODO = any

Check failure on line 15 in src/components/DirectedGraph.tsx

View workflow job for this annotation

GitHub Actions / deploy

'TODO' is declared but never used.
interface DirectedGraphProps {
graphData: GraphData;
}
Expand All @@ -27,6 +28,7 @@ export default function DirectedGraph({ graphData }: DirectedGraphProps) {
const [edgesThreshold, setEdgesThreshold] = useState<number>((graphData.maxEdgeCount ?? 100) * 0.1);
const [previousEdgesThreshold, setPreviousEdgesThreshold] = useState<number>(((graphData.maxEdgeCount ?? 100) * 0.1));
const initialContextMenuControls: ContextMenuControls = { visible: false, x: 0, y: 0, node: null };
const [arrowSize, setArrowSize] = useState(30);

Check failure on line 31 in src/components/DirectedGraph.tsx

View workflow job for this annotation

GitHub Actions / deploy

'arrowSize' is declared but its value is never read.

Check failure on line 31 in src/components/DirectedGraph.tsx

View workflow job for this annotation

GitHub Actions / deploy

'setArrowSize' is declared but its value is never read.

const [contextMenu, setContextMenu] = useState<ContextMenuControls>(initialContextMenuControls);

Expand Down Expand Up @@ -165,7 +167,7 @@ export default function DirectedGraph({ graphData }: DirectedGraphProps) {
// Assuming handleThresholdChange is correctly implemented to handle the initial state
handleThresholdChange(initialThreshold, previousEdgesThreshold);
}
}, 200); // Delay execution by 500ms to ensure graphData is loaded before applying logic.
}, 200); // Delay execution by 200ms to ensure graphData is loaded before applying logic.

// Cleanup function to clear the timeout if the component unmounts
return () => clearTimeout(timer);
Expand Down Expand Up @@ -427,7 +429,37 @@ export default function DirectedGraph({ graphData }: DirectedGraphProps) {
ctx.fillStyle = 'black';
ctx.fillText(label, node.x!, node.y! + labelOffsetY);
}}
linkDirectionalArrowLength={20}
// linkCanvasObject={(link, ctx, globalScale) => {
// const length = 30 / globalScale; // Adjust the arrow length based on global scale
// const sx = (link.source as Node).x;
// const sy = (link.source as Node).y;
// const tx = (link.target as Node).x;
// const ty = (link.target as Node).y;
// if (sx === undefined || sy === undefined || tx === undefined || ty === undefined) {
// return;
// }
// // calculate the direction of the arrow
// const dir = Math.atan2(ty - sy, tx - sx);

// // Draw the arrow
// ctx.beginPath();
// ctx.moveTo(sx, sy);
// ctx.lineTo(tx, ty);
// ctx.stroke();

// // Draw the arrow head
// ctx.beginPath();
// ctx.moveTo(tx, ty);
// ctx.lineTo(tx - length * Math.cos(dir - Math.PI / 6), ty - length * Math.sin(dir - Math.PI / 6));
// ctx.lineTo(tx - length * Math.cos(dir + Math.PI / 6), ty - length * Math.sin(dir + Math.PI / 6));
// ctx.closePath();
// ctx.fill();
// }}
linkDirectionalArrowLength={() => {
// `arrow` can be a param here
return 30;

}}
// linkDirectionalParticles={2}
// linkDirectionalParticleWidth={7}
linkDirectionalArrowColor={(link) => link.color || ''}
Expand Down

0 comments on commit ffb5c35

Please sign in to comment.