From 912e1b96bfa7d6c022d854fa744f719b49ca98d0 Mon Sep 17 00:00:00 2001 From: Georgios Andreadis Date: Tue, 21 Jul 2020 15:33:37 +0200 Subject: Add first plotting attempts for portfolios --- frontend/src/store/middlewares/dummy-middleware.js | 2 +- .../src/store/middlewares/viewport-adjustment.js | 27 ++++++---------------- 2 files changed, 8 insertions(+), 21 deletions(-) (limited to 'frontend/src/store') diff --git a/frontend/src/store/middlewares/dummy-middleware.js b/frontend/src/store/middlewares/dummy-middleware.js index ed5670c5..5ba35691 100644 --- a/frontend/src/store/middlewares/dummy-middleware.js +++ b/frontend/src/store/middlewares/dummy-middleware.js @@ -1,3 +1,3 @@ -export const dummyMiddleware = store => next => action => { +export const dummyMiddleware = (store) => (next) => (action) => { next(action) } diff --git a/frontend/src/store/middlewares/viewport-adjustment.js b/frontend/src/store/middlewares/viewport-adjustment.js index 84f2a3e9..b4472c54 100644 --- a/frontend/src/store/middlewares/viewport-adjustment.js +++ b/frontend/src/store/middlewares/viewport-adjustment.js @@ -9,7 +9,7 @@ import { } from '../../components/app/map/MapConstants' import { calculateRoomListBounds } from '../../util/tile-calculations' -export const viewportAdjustmentMiddleware = store => next => action => { +export const viewportAdjustmentMiddleware = (store) => (next) => (action) => { const state = store.getState() let topologyId = '-1' @@ -17,21 +17,15 @@ export const viewportAdjustmentMiddleware = store => next => action => { if (action.type === SET_CURRENT_TOPOLOGY && action.topologyId !== '-1') { topologyId = action.topologyId mapDimensions = state.map.dimensions - } else if ( - action.type === SET_MAP_DIMENSIONS && - state.currentTopologyId !== '-1' - ) { + } else if (action.type === SET_MAP_DIMENSIONS && state.currentTopologyId !== '-1') { topologyId = state.currentTopologyId mapDimensions = { width: action.width, height: action.height } } if (topologyId !== '-1') { const roomIds = state.objects.topology[topologyId].roomIds - const rooms = roomIds.map(id => Object.assign({}, state.objects.room[id])) - rooms.forEach( - room => - (room.tiles = room.tileIds.map(tileId => state.objects.tile[tileId])), - ) + const rooms = roomIds.map((id) => Object.assign({}, state.objects.room[id])) + rooms.forEach((room) => (room.tiles = room.tileIds.map((tileId) => state.objects.tile[tileId]))) let hasNoTiles = true for (let i in rooms) { @@ -42,11 +36,7 @@ export const viewportAdjustmentMiddleware = store => next => action => { } if (!hasNoTiles) { - const viewportParams = calculateParametersToZoomInOnRooms( - rooms, - mapDimensions.width, - mapDimensions.height, - ) + const viewportParams = calculateParametersToZoomInOnRooms(rooms, mapDimensions.width, mapDimensions.height) store.dispatch(setMapPosition(viewportParams.newX, viewportParams.newY)) store.dispatch(setMapScale(viewportParams.newScale)) } @@ -75,11 +65,8 @@ function calculateNewScale(bounds, mapWidth, mapHeight) { const width = bounds.max.x - bounds.min.x const height = bounds.max.y - bounds.min.y - const scaleX = - (mapWidth - 2 * SIDEBAR_WIDTH) / - (width * TILE_SIZE_IN_PIXELS + 2 * VIEWPORT_PADDING) - const scaleY = - mapHeight / (height * TILE_SIZE_IN_PIXELS + 2 * VIEWPORT_PADDING) + const scaleX = (mapWidth - 2 * SIDEBAR_WIDTH) / (width * TILE_SIZE_IN_PIXELS + 2 * VIEWPORT_PADDING) + const scaleY = mapHeight / (height * TILE_SIZE_IN_PIXELS + 2 * VIEWPORT_PADDING) const newScale = Math.min(scaleX, scaleY) return Math.min(Math.max(MAP_MIN_SCALE, newScale), MAP_MAX_SCALE) -- cgit v1.2.3