Skip to content

Commit

Permalink
Merge pull request #18 from concord-consortium/185586321-update-mouse…
Browse files Browse the repository at this point in the history
…-pointers

feat: Update mouse pointer based on drawing mode [PT-185586321]
  • Loading branch information
dougmartin authored Jul 11, 2023
2 parents 900248c + 82894b5 commit 86d306e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
5 changes: 2 additions & 3 deletions src/components/drawing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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,
Expand Down Expand Up @@ -327,6 +325,7 @@ export const Drawing = (props: Props) => {
</div>
<Graph
mode="drawing"
drawingMode={drawingMode}
graph={graph}
highlightNode={highlightNode}
highlightEdge={highlightEdge}
Expand Down
11 changes: 9 additions & 2 deletions src/components/graph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import { ViewMode } from "../hooks/use-codap";

import "./graph.scss";

export type DrawingMode = "select"|"addNode"|"addEdge"|"delete";


export type GraphSettings = {
minRadius: number;
maxRadius: number;
Expand All @@ -31,6 +34,7 @@ type Props = {
allowDragging: boolean;
autoArrange: boolean;
rubberBand?: RubberBand;
drawingMode?: DrawingMode;
onClick?: (e: React.MouseEvent<HTMLDivElement>) => void;
onMouseUp?: (e: React.MouseEvent<HTMLDivElement>) => void;
onNodeClick?: (id: string, onLoop?: boolean) => void;
Expand Down Expand Up @@ -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<SVGSVGElement | null>(null);
const wrapperRef = useRef<HTMLDivElement | null>(null);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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});
})
Expand All @@ -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);
})
Expand All @@ -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
Expand Down

0 comments on commit 86d306e

Please sign in to comment.