diff --git a/src/components/drawing.tsx b/src/components/drawing.tsx index 66ccfc6..ee3747b 100644 --- a/src/components/drawing.tsx +++ b/src/components/drawing.tsx @@ -2,7 +2,7 @@ import React, { useCallback, useEffect, useRef, useState } from "react"; import { clsx } from "clsx"; import { nanoid } from "nanoid"; -import { Graph, Point, RubberBand } from "./graph"; +import { DrawingMode, Graph, Point, RubberBand } from "./graph"; import { Edge, GraphData, Node } from "../type"; import SelectIcon from "../assets/select-icon.svg"; @@ -12,8 +12,6 @@ import DeleteIcon from "../assets/delete-icon.svg"; import "./drawing.scss"; -type DrawingMode = "select"|"addNode"|"addEdge"|"delete"; - interface NodeModalProps { node?: Node, onChange: (id: string, newNode: Node) => void, @@ -327,6 +325,7 @@ export const Drawing = (props: Props) => { ) => void; onMouseUp?: (e: React.MouseEvent) => void; onNodeClick?: (id: string, onLoop?: boolean) => void; @@ -211,7 +215,7 @@ const calculateNodeFontSize = (d: D3Node) => { export const Graph = (props: Props) => { const {graph, highlightNode, highlightLoopOnNode, highlightEdge, highlightAllNextNodes, - highlightColor, allowDragging, autoArrange, mode, rubberBand, + highlightColor, allowDragging, autoArrange, mode, rubberBand, drawingMode, onClick, onMouseUp, onNodeClick, onNodeDoubleClick, onEdgeClick, onDragStop} = props; const svgRef = useRef(null); const wrapperRef = useRef(null); @@ -370,6 +374,7 @@ export const Graph = (props: Props) => { .attr("ry", d => ry(d.radius)) .attr("cx", d => d.x) .attr("cy", d => d.y) + .attr("style", drawingMode !== "addNode" ? "cursor: pointer" : "") .on("click", (e, d) => { if (waitForDoubleRef.current) { clearTimeout(waitForDoubleRef.current); @@ -456,6 +461,7 @@ export const Graph = (props: Props) => { .attr("data-from", d => d.source.id) .attr("data-to", d => d.target.id) .attr("marker-end", "url(#arrow)") + .attr("style", drawingMode === "delete" ? "cursor: pointer" : "") .on("click", (e, d) => { onEdgeClick?.({from: d.source.id, to: d.target.id}); }) @@ -473,6 +479,7 @@ export const Graph = (props: Props) => { .attr("fill-opacity", 0) .attr("stroke-width", d => d.loopWeight) .attr("marker-end", "url(#arrow)") + .attr("style", drawingMode === "delete" ? "cursor: pointer" : "") .on("click", (e, d) => { onNodeClick?.(d.id, true); }) @@ -497,7 +504,7 @@ export const Graph = (props: Props) => { .attr("marker-end", "url(#arrow)"); } - }, [svgRef, d3Graph, allowDragging, autoArrange, rubberBand, + }, [svgRef, d3Graph, allowDragging, autoArrange, rubberBand, drawingMode, onNodeClick, onNodeDoubleClick, onEdgeClick, onDragStop]); // animate the node if needed