Skip to content

Commit

Permalink
Merge pull request #19 from concord-consortium/185572251-increase-edg…
Browse files Browse the repository at this point in the history
…e-click-target

feat: Increase "hit" target to delete edges [PT-185572251]
  • Loading branch information
dougmartin authored Jul 11, 2023
2 parents 86d306e + b774dff commit c006048
Showing 1 changed file with 44 additions and 2 deletions.
46 changes: 44 additions & 2 deletions src/components/graph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -414,12 +414,19 @@ export const Graph = (props: Props) => {

d3Graph.edges = calculateEdges(d3Graph.edges);

lineBackgrounds
.attr("x1", d => d.sourceX)
.attr("x2", d => d.targetX)
.attr("y1", d => d.sourceY)
.attr("y2", d => d.targetY);

lines
.attr("x1", d => d.sourceX)
.attr("x2", d => d.targetX)
.attr("y1", d => d.sourceY)
.attr("y2", d => d.targetY);

loopBackgrounds.attr("d", nodeLoopPath);
loops.attr("d", nodeLoopPath);
};

Expand All @@ -444,6 +451,26 @@ export const Graph = (props: Props) => {
d3Graph.edges = calculateEdges(d3Graph.edges);
// d3Graph.nodes = calculateLoops(d3Graph);

// 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("stroke", "#000")
.attr("stroke-opacity", 0)
.attr("stroke-width", 15)
.attr("x1", d => d.sourceX)
.attr("x2", d => d.targetX)
.attr("y1", d => d.sourceY)
.attr("y2", d => d.targetY)
.attr("style", drawingMode === "delete" ? "cursor: pointer" : "")
.on("click", (e, d) => {
onEdgeClick?.({from: d.source.id, to: d.target.id});
})
;

// draw edges
const lines = svg
.selectAll("line.edge")
Expand All @@ -458,15 +485,30 @@ export const Graph = (props: Props) => {
.attr("x2", d => d.targetX)
.attr("y1", d => d.sourceY)
.attr("y2", d => d.targetY)
.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});
})
;

const loopBackgrounds = svg
.selectAll("path.loop-background")
.data(d3Graph.nodes.filter(n => n.loops))
.enter()
.append("path")
.attr("class", "loop-background")
.attr("d", nodeLoopPath)
.attr("stroke", "#000")
.attr("stroke-opacity", 0)
.attr("fill-opacity", 0)
.attr("stroke-width", 15)
.attr("style", drawingMode === "delete" ? "cursor: pointer" : "")
.on("click", (e, d) => {
onNodeClick?.(d.id, true);
})
;

const loops = svg
.selectAll("path.loop")
.data(d3Graph.nodes.filter(n => n.loops))
Expand Down

0 comments on commit c006048

Please sign in to comment.