From 4ab04a43790f45e47ded214d86817b5b9a941132 Mon Sep 17 00:00:00 2001 From: moklick Date: Thu, 18 Jul 2019 11:14:11 +0200 Subject: [PATCH] feat(selection): selected nodes rect --- src/GraphView/index.js | 2 +- src/Selection/index.js | 2 +- src/state/index.js | 12 +++++++++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/GraphView/index.js b/src/GraphView/index.js index 32a8edc2..5db21b83 100644 --- a/src/GraphView/index.js +++ b/src/GraphView/index.js @@ -74,7 +74,7 @@ const GraphView = (props) => {
- {shiftPressed && } + {(shiftPressed || graphContext.state.selectedNodeIds.length) && }
{ className="react-graph__selectionpane" ref={selectionPane} > - {selectionRect.draw && ( + {(rect.draw || rect.fixed) && (
{ const selectedNodesBbox = getBoundingBox(selectedNodes); const selectedNodeIds = selectedNodes.map(n => n.data.id); - return { ...state, ...action.payload, selectedNodeIds, selectedNodesBbox }; + const bboxPos = { + x: ((selectedNodesBbox.x * state.transform[2]) + (state.transform[0] * (1 / 1.0))), + y: ((selectedNodesBbox.y * state.transform[2]) + (state.transform[1] * (1 / 1.0))) + }; + let bboxWidth = (selectedNodesBbox.width * state.transform[2]) + 10; + let bboxHeight = (selectedNodesBbox.height * state.transform[2]) + 10; + + bboxPos.x -= 5; + bboxPos.y -= 5; + + return { ...state, ...action.payload, selectedNodeIds, selectedNodesBbox: { ...bboxPos, width: bboxWidth, height: bboxHeight } }; } case SET_NODES: case SET_EDGES: