Skip to content

Commit

Permalink
Merge pull request #27 from concord-consortium/185606809-add-feedback…
Browse files Browse the repository at this point in the history
…-during-delete

feat: Added feedback during edge/node deletion [PT-185609197]
  • Loading branch information
dougmartin authored Jul 17, 2023
2 parents cd05ec6 + 42a5095 commit 7f0ac19
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/components/graph.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,11 @@
svg ellipse.can-add-edge:hover {
fill: lightgreen;
}
svg ellipse.can-delete:hover {
fill: lightcoral;
}
svg line.can-delete:hover {
stroke: lightcoral;
stroke-opacity: 1;
}
}
17 changes: 14 additions & 3 deletions src/components/graph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,14 @@ export const Graph = (props: Props) => {
.on("drag", dragging)
.on("end", dragEnd);

const circleClass = [
drawingMode === "addEdge" ? "can-add-edge" : "",
drawingMode === "delete" ? "can-delete" : "",
].join(" ");

const circles = nodes
.append("ellipse")
.attr("class", drawingMode === "addEdge" ? "can-add-edge" : "")
.attr("class", circleClass)
.attr("fill", "#fff")
.attr("stroke", "#999")
.attr("stroke-width", d => 2)
Expand Down Expand Up @@ -452,13 +457,18 @@ export const Graph = (props: Props) => {
d3Graph.edges = calculateEdges(d3Graph.edges);
// d3Graph.nodes = calculateLoops(d3Graph);

const lineBackgroundClass = [
"edge-background",
drawingMode === "delete" ? "can-delete" : "",
].join(" ");

// draw backgrounds for edges to increase click area
const lineBackgrounds = svg
.selectAll("line.edge-background")
.data(d3Graph.edges)
.enter()
.append("line")
.attr("class", "edge-background")
.attr("class", lineBackgroundClass)
.attr("stroke", "#000")
.attr("stroke-opacity", 0)
.attr("stroke-width", 15)
Expand Down Expand Up @@ -487,8 +497,9 @@ export const Graph = (props: Props) => {
.attr("y1", d => d.sourceY)
.attr("y2", d => d.targetY)
.attr("marker-end", "url(#arrow)")
.attr("style", drawingMode === "delete" ? "cursor: pointer" : "")
.attr("style", drawingMode === "delete" ? "pointer-events: none" : "")
.on("click", (e, d) => {
// this is not really needed as the pointer events are off
onEdgeClick?.({from: d.source.id, to: d.target.id});
})
;
Expand Down

0 comments on commit 7f0ac19

Please sign in to comment.