feat(selection): selected nodes rect

This commit is contained in:
moklick
2019-07-18 11:14:11 +02:00
parent 3cf627668b
commit 4ab04a4379
3 changed files with 13 additions and 3 deletions

View File

@@ -74,7 +74,7 @@ const GraphView = (props) => {
<div className="react-graph__renderer">
<NodeRenderer nodeTypes={props.nodeTypes} />
<EdgeRenderer width={graphContext.state.width} height={graphContext.state.height} />
{shiftPressed && <Selection />}
{(shiftPressed || graphContext.state.selectedNodeIds.length) && <Selection />}
<div
className="react-graph__zoompane"
ref={zoomPane}

View File

@@ -88,7 +88,7 @@ export default () => {
className="react-graph__selectionpane"
ref={selectionPane}
>
{selectionRect.draw && (
{(rect.draw || rect.fixed) && (
<div
className="react-graph__selection"
style={{

View File

@@ -78,7 +78,17 @@ export const reducer = (state, action) => {
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: