feat(fitView): add padding option

This commit is contained in:
moklick
2019-07-26 00:57:03 +02:00
parent bb17c2fcb6
commit a6d191355a
5 changed files with 20 additions and 13 deletions
+2 -1
View File
@@ -69,7 +69,8 @@ export const reducer = (state, action) => {
}
case FIT_VIEW: {
const bounds = getBoundingBox(state.nodes);
const k = Math.min(state.width, state.height) / Math.max(bounds.width, bounds.height);
const maxBoundsSize = Math.max(bounds.width, bounds.height);
const k = Math.min(state.width, state.height) / (maxBoundsSize + (maxBoundsSize * action.payload.padding));
const boundsCenterX = bounds.x + (bounds.width / 2);
const boundsCenterY = bounds.y + (bounds.height / 2);
const transform = [(state.width / 2) - (boundsCenterX * k), (state.height / 2) - (boundsCenterY * k)];