summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorGeorgios Andreadis <G.Andreadis@student.tudelft.nl>2017-10-04 23:23:09 +0200
committerGitHub <noreply@github.com>2017-10-04 23:23:09 +0200
commitfcaaae65d34003874c76e0c01134dedf94248e09 (patch)
tree2aae1422168651e832a1904623f6f5b100fc17ec /src/util
parent0a62dfb55c5700013d42a589b930c7448e5bff71 (diff)
parent606d1de0be09f3597165248f65d54e158a13860c (diff)
Merge pull request #42 from atlarge-research/auto-reformat
Standardize code format
Diffstat (limited to 'src/util')
-rw-r--r--src/util/authorizations.js12
-rw-r--r--src/util/date-time.js121
-rw-r--r--src/util/date-time.test.js56
-rw-r--r--src/util/room-types.js10
-rw-r--r--src/util/simulation-load.js51
-rw-r--r--src/util/tile-calculations.js412
-rw-r--r--src/util/timeline.js22
7 files changed, 355 insertions, 329 deletions
diff --git a/src/util/authorizations.js b/src/util/authorizations.js
index 9a7d4e36..ef649c9c 100644
--- a/src/util/authorizations.js
+++ b/src/util/authorizations.js
@@ -1,11 +1,11 @@
export const AUTH_ICON_MAP = {
- "OWN": "home",
- "EDIT": "pencil",
- "VIEW": "eye",
+ OWN: "home",
+ EDIT: "pencil",
+ VIEW: "eye"
};
export const AUTH_DESCRIPTION_MAP = {
- "OWN": "Own",
- "EDIT": "Can Edit",
- "VIEW": "Can View",
+ OWN: "Own",
+ EDIT: "Can Edit",
+ VIEW: "Can View"
};
diff --git a/src/util/date-time.js b/src/util/date-time.js
index e9d7664f..2664b8ca 100644
--- a/src/util/date-time.js
+++ b/src/util/date-time.js
@@ -7,7 +7,7 @@
* @returns {string} A human-friendly string version of that date and time.
*/
export function parseAndFormatDateTime(dateTimeString) {
- return formatDateTime(parseDateTime(dateTimeString));
+ return formatDateTime(parseDateTime(dateTimeString));
}
/**
@@ -19,27 +19,27 @@ export function parseAndFormatDateTime(dateTimeString) {
* @returns {object} An rack with the parsed date and time information as content.
*/
export function parseDateTime(dateTimeString) {
- const output = {
- year: 0,
- month: 0,
- day: 0,
- hour: 0,
- minute: 0,
- second: 0,
- };
+ const output = {
+ year: 0,
+ month: 0,
+ day: 0,
+ hour: 0,
+ minute: 0,
+ second: 0
+ };
- const dateAndTime = dateTimeString.split("T");
- const dateComponents = dateAndTime[0].split("-");
- output.year = parseInt(dateComponents[0], 10);
- output.month = parseInt(dateComponents[1], 10);
- output.day = parseInt(dateComponents[2], 10);
+ const dateAndTime = dateTimeString.split("T");
+ const dateComponents = dateAndTime[0].split("-");
+ output.year = parseInt(dateComponents[0], 10);
+ output.month = parseInt(dateComponents[1], 10);
+ output.day = parseInt(dateComponents[2], 10);
- const timeComponents = dateAndTime[1].split(":");
- output.hour = parseInt(timeComponents[0], 10);
- output.minute = parseInt(timeComponents[1], 10);
- output.second = parseInt(timeComponents[2], 10);
+ const timeComponents = dateAndTime[1].split(":");
+ output.hour = parseInt(timeComponents[0], 10);
+ output.minute = parseInt(timeComponents[1], 10);
+ output.second = parseInt(timeComponents[2], 10);
- return output;
+ return output;
}
/**
@@ -49,25 +49,34 @@ export function parseDateTime(dateTimeString) {
* @returns {string} A human-friendly string version of that date and time.
*/
export function formatDateTime(dateTime) {
- let date;
- const currentDate = new Date();
+ let date;
+ const currentDate = new Date();
- date = addPaddingToTwo(dateTime.day) + "/" +
- addPaddingToTwo(dateTime.month) + "/" +
- addPaddingToTwo(dateTime.year);
+ date =
+ addPaddingToTwo(dateTime.day) +
+ "/" +
+ addPaddingToTwo(dateTime.month) +
+ "/" +
+ addPaddingToTwo(dateTime.year);
- if (dateTime.year === currentDate.getFullYear() &&
- dateTime.month === currentDate.getMonth() + 1) {
- if (dateTime.day === currentDate.getDate()) {
- date = "Today";
- } else if (dateTime.day === currentDate.getDate() - 1) {
- date = "Yesterday";
- }
+ if (
+ dateTime.year === currentDate.getFullYear() &&
+ dateTime.month === currentDate.getMonth() + 1
+ ) {
+ if (dateTime.day === currentDate.getDate()) {
+ date = "Today";
+ } else if (dateTime.day === currentDate.getDate() - 1) {
+ date = "Yesterday";
}
+ }
- return date + ", " +
- addPaddingToTwo(dateTime.hour) + ":" +
- addPaddingToTwo(dateTime.minute);
+ return (
+ date +
+ ", " +
+ addPaddingToTwo(dateTime.hour) +
+ ":" +
+ addPaddingToTwo(dateTime.minute)
+ );
}
/**
@@ -77,25 +86,27 @@ export function formatDateTime(dateTime) {
* @returns {string} A string representation of that amount of second, in the from of HH:MM:SS.
*/
export function convertSecondsToFormattedTime(seconds) {
- if (seconds <= 0) {
- return "0s";
- }
+ if (seconds <= 0) {
+ return "0s";
+ }
- let hour = Math.floor(seconds / 3600);
- let minute = Math.floor(seconds / 60) % 60;
- let second = seconds % 60;
+ let hour = Math.floor(seconds / 3600);
+ let minute = Math.floor(seconds / 60) % 60;
+ let second = seconds % 60;
- hour = isNaN(hour) ? 0 : hour;
- minute = isNaN(minute) ? 0 : minute;
- second = isNaN(second) ? 0 : second;
+ hour = isNaN(hour) ? 0 : hour;
+ minute = isNaN(minute) ? 0 : minute;
+ second = isNaN(second) ? 0 : second;
- if (hour === 0 && minute === 0) {
- return second + "s";
- } else if (hour === 0) {
- return minute + "m" + addPaddingToTwo(second) + "s";
- } else {
- return hour + "h" + addPaddingToTwo(minute) + "m" + addPaddingToTwo(second) + "s";
- }
+ if (hour === 0 && minute === 0) {
+ return second + "s";
+ } else if (hour === 0) {
+ return minute + "m" + addPaddingToTwo(second) + "s";
+ } else {
+ return (
+ hour + "h" + addPaddingToTwo(minute) + "m" + addPaddingToTwo(second) + "s"
+ );
+ }
}
/**
@@ -105,9 +116,9 @@ export function convertSecondsToFormattedTime(seconds) {
* @returns {string} A string containing the padded integer.
*/
function addPaddingToTwo(integer) {
- if (integer < 10) {
- return "0" + integer.toString();
- } else {
- return integer.toString();
- }
+ if (integer < 10) {
+ return "0" + integer.toString();
+ } else {
+ return integer.toString();
+ }
}
diff --git a/src/util/date-time.test.js b/src/util/date-time.test.js
index 9dce202b..958428af 100644
--- a/src/util/date-time.test.js
+++ b/src/util/date-time.test.js
@@ -1,35 +1,35 @@
-import {convertSecondsToFormattedTime, parseDateTime} from "./date-time";
+import { convertSecondsToFormattedTime, parseDateTime } from "./date-time";
describe("date-time parsing", () => {
- it("reads components properly", () => {
- const dateString = "2017-09-27T20:55:01";
- const parsedDate = parseDateTime(dateString);
+ it("reads components properly", () => {
+ const dateString = "2017-09-27T20:55:01";
+ const parsedDate = parseDateTime(dateString);
- expect(parsedDate.year).toEqual(2017);
- expect(parsedDate.month).toEqual(9);
- expect(parsedDate.day).toEqual(27);
- expect(parsedDate.hour).toEqual(20);
- expect(parsedDate.minute).toEqual(55);
- expect(parsedDate.second).toEqual(1);
- });
+ expect(parsedDate.year).toEqual(2017);
+ expect(parsedDate.month).toEqual(9);
+ expect(parsedDate.day).toEqual(27);
+ expect(parsedDate.hour).toEqual(20);
+ expect(parsedDate.minute).toEqual(55);
+ expect(parsedDate.second).toEqual(1);
+ });
});
describe("tick formatting", () => {
- it("returns '0s' for numbers <= 0", () => {
- expect(convertSecondsToFormattedTime(-1)).toEqual("0s");
- expect(convertSecondsToFormattedTime(0)).toEqual("0s");
- });
- it("returns only seconds for values under a minute", () => {
- expect(convertSecondsToFormattedTime(1)).toEqual("1s");
- expect(convertSecondsToFormattedTime(59)).toEqual("59s");
- });
- it("returns seconds and minutes for values under an hour", () => {
- expect(convertSecondsToFormattedTime(60)).toEqual("1m00s");
- expect(convertSecondsToFormattedTime(61)).toEqual("1m01s");
- expect(convertSecondsToFormattedTime(3599)).toEqual("59m59s");
- });
- it("returns full time for values over an hour", () => {
- expect(convertSecondsToFormattedTime(3600)).toEqual("1h00m00s");
- expect(convertSecondsToFormattedTime(3601)).toEqual("1h00m01s");
- });
+ it("returns '0s' for numbers <= 0", () => {
+ expect(convertSecondsToFormattedTime(-1)).toEqual("0s");
+ expect(convertSecondsToFormattedTime(0)).toEqual("0s");
+ });
+ it("returns only seconds for values under a minute", () => {
+ expect(convertSecondsToFormattedTime(1)).toEqual("1s");
+ expect(convertSecondsToFormattedTime(59)).toEqual("59s");
+ });
+ it("returns seconds and minutes for values under an hour", () => {
+ expect(convertSecondsToFormattedTime(60)).toEqual("1m00s");
+ expect(convertSecondsToFormattedTime(61)).toEqual("1m01s");
+ expect(convertSecondsToFormattedTime(3599)).toEqual("59m59s");
+ });
+ it("returns full time for values over an hour", () => {
+ expect(convertSecondsToFormattedTime(3600)).toEqual("1h00m00s");
+ expect(convertSecondsToFormattedTime(3601)).toEqual("1h00m01s");
+ });
});
diff --git a/src/util/room-types.js b/src/util/room-types.js
index ec0c4473..5cfe3887 100644
--- a/src/util/room-types.js
+++ b/src/util/room-types.js
@@ -1,7 +1,7 @@
export const ROOM_TYPE_TO_NAME_MAP = {
- "SERVER": "Server room",
- "HALLWAY": "Hallway",
- "OFFICE": "Office",
- "POWER": "Power room",
- "COOLING": "Cooling room",
+ SERVER: "Server room",
+ HALLWAY: "Hallway",
+ OFFICE: "Office",
+ POWER: "Power room",
+ COOLING: "Cooling room"
};
diff --git a/src/util/simulation-load.js b/src/util/simulation-load.js
index 4b6233be..95e17fed 100644
--- a/src/util/simulation-load.js
+++ b/src/util/simulation-load.js
@@ -1,32 +1,37 @@
-import {SIM_HIGH_COLOR, SIM_LOW_COLOR, SIM_MID_HIGH_COLOR, SIM_MID_LOW_COLOR} from "./colors";
+import {
+ SIM_HIGH_COLOR,
+ SIM_LOW_COLOR,
+ SIM_MID_HIGH_COLOR,
+ SIM_MID_LOW_COLOR
+} from "./colors";
export const LOAD_NAME_MAP = {
- LOAD: "computational load",
- TEMPERATURE: "temperature",
- MEMORY: "memory use",
+ LOAD: "computational load",
+ TEMPERATURE: "temperature",
+ MEMORY: "memory use"
};
export function convertLoadToSimulationColor(load) {
- if (load <= 0.25) {
- return SIM_LOW_COLOR;
- } else if (load <= 0.5) {
- return SIM_MID_LOW_COLOR;
- } else if (load <= 0.75) {
- return SIM_MID_HIGH_COLOR;
- } else {
- return SIM_HIGH_COLOR;
- }
+ if (load <= 0.25) {
+ return SIM_LOW_COLOR;
+ } else if (load <= 0.5) {
+ return SIM_MID_LOW_COLOR;
+ } else if (load <= 0.75) {
+ return SIM_MID_HIGH_COLOR;
+ } else {
+ return SIM_HIGH_COLOR;
+ }
}
export function getStateLoad(loadMetric, state) {
- switch (loadMetric) {
- case "LOAD":
- return state.loadFraction;
- case "TEMPERATURE":
- return state.temperatureC / 100.0;
- case "MEMORY":
- return state.inUseMemoryMb / 10000.0;
- default:
- return -1;
- }
+ switch (loadMetric) {
+ case "LOAD":
+ return state.loadFraction;
+ case "TEMPERATURE":
+ return state.temperatureC / 100.0;
+ case "MEMORY":
+ return state.inUseMemoryMb / 10000.0;
+ default:
+ return -1;
+ }
}
diff --git a/src/util/tile-calculations.js b/src/util/tile-calculations.js
index 31b5d8aa..9a1dc1c0 100644
--- a/src/util/tile-calculations.js
+++ b/src/util/tile-calculations.js
@@ -1,243 +1,253 @@
export function deriveWallLocations(tiles) {
- const verticalWalls = {};
- const horizontalWalls = {};
-
- // Determine wall segments
-
- tiles.forEach(tile => {
- const x = tile.positionX, y = tile.positionY;
- for (let dX = -1; dX <= 1; dX++) {
- for (let dY = -1; dY <= 1; dY++) {
- if (Math.abs(dX) === Math.abs(dY)) {
- continue;
- }
-
- let doInsert = true;
- tiles.forEach(otherTile => {
- if (otherTile.positionX === x + dX && otherTile.positionY === y + dY) {
- doInsert = false;
- }
- });
- if (!doInsert) {
- continue;
- }
-
- if (dX === -1) {
- if (verticalWalls[x] === undefined) {
- verticalWalls[x] = [];
- }
- if (verticalWalls[x].indexOf(y) === -1) {
- verticalWalls[x].push(y);
- }
- } else if (dX === 1) {
- if (verticalWalls[x + 1] === undefined) {
- verticalWalls[x + 1] = [];
- }
- if (verticalWalls[x + 1].indexOf(y) === -1) {
- verticalWalls[x + 1].push(y);
- }
- } else if (dY === -1) {
- if (horizontalWalls[y] === undefined) {
- horizontalWalls[y] = [];
- }
- if (horizontalWalls[y].indexOf(x) === -1) {
- horizontalWalls[y].push(x);
- }
- } else if (dY === 1) {
- if (horizontalWalls[y + 1] === undefined) {
- horizontalWalls[y + 1] = [];
- }
- if (horizontalWalls[y + 1].indexOf(x) === -1) {
- horizontalWalls[y + 1].push(x);
- }
- }
- }
+ const verticalWalls = {};
+ const horizontalWalls = {};
+
+ // Determine wall segments
+
+ tiles.forEach(tile => {
+ const x = tile.positionX,
+ y = tile.positionY;
+ for (let dX = -1; dX <= 1; dX++) {
+ for (let dY = -1; dY <= 1; dY++) {
+ if (Math.abs(dX) === Math.abs(dY)) {
+ continue;
}
- });
-
- // Merge walls into longer segments
- const result = [];
- const walls = [verticalWalls, horizontalWalls];
- for (let i = 0; i < 2; i++) {
- const wallList = walls[i];
- for (let a in wallList) {
- a = parseInt(a, 10);
-
- wallList[a].sort((a, b) => {
- return a - b;
- });
+ let doInsert = true;
+ tiles.forEach(otherTile => {
+ if (
+ otherTile.positionX === x + dX &&
+ otherTile.positionY === y + dY
+ ) {
+ doInsert = false;
+ }
+ });
+ if (!doInsert) {
+ continue;
+ }
- let startPos = wallList[a][0];
- const isHorizontal = i === 1;
-
- if (wallList[a].length === 1) {
- const startPosX = isHorizontal ? startPos : a;
- const startPosY = isHorizontal ? a : startPos;
- result.push({
- startPosX,
- startPosY,
- isHorizontal,
- length: 1
- });
- } else {
- let consecutiveCount = 1;
- for (let b = 0; b < wallList[a].length - 1; b++) {
- if (b + 1 === wallList[a].length - 1) {
- if (wallList[a][b + 1] - wallList[a][b] > 1) {
- const startPosX = isHorizontal ? startPos : a;
- const startPosY = isHorizontal ? a : startPos;
- result.push({
- startPosX,
- startPosY,
- isHorizontal,
- length: consecutiveCount
- });
- consecutiveCount = 0;
- startPos = wallList[a][b + 1];
- }
- const startPosX = isHorizontal ? startPos : a;
- const startPosY = isHorizontal ? a : startPos;
- result.push({
- startPosX,
- startPosY,
- isHorizontal,
- length: consecutiveCount + 1
- });
- break;
- } else if (wallList[a][b + 1] - wallList[a][b] > 1) {
- const startPosX = isHorizontal ? startPos : a;
- const startPosY = isHorizontal ? a : startPos;
- result.push({
- startPosX,
- startPosY,
- isHorizontal,
- length: consecutiveCount
- });
- startPos = wallList[a][b + 1];
- consecutiveCount = 0;
- }
- consecutiveCount++;
- }
+ if (dX === -1) {
+ if (verticalWalls[x] === undefined) {
+ verticalWalls[x] = [];
+ }
+ if (verticalWalls[x].indexOf(y) === -1) {
+ verticalWalls[x].push(y);
+ }
+ } else if (dX === 1) {
+ if (verticalWalls[x + 1] === undefined) {
+ verticalWalls[x + 1] = [];
+ }
+ if (verticalWalls[x + 1].indexOf(y) === -1) {
+ verticalWalls[x + 1].push(y);
+ }
+ } else if (dY === -1) {
+ if (horizontalWalls[y] === undefined) {
+ horizontalWalls[y] = [];
+ }
+ if (horizontalWalls[y].indexOf(x) === -1) {
+ horizontalWalls[y].push(x);
+ }
+ } else if (dY === 1) {
+ if (horizontalWalls[y + 1] === undefined) {
+ horizontalWalls[y + 1] = [];
+ }
+ if (horizontalWalls[y + 1].indexOf(x) === -1) {
+ horizontalWalls[y + 1].push(x);
+ }
+ }
+ }
+ }
+ });
+
+ // Merge walls into longer segments
+
+ const result = [];
+ const walls = [verticalWalls, horizontalWalls];
+ for (let i = 0; i < 2; i++) {
+ const wallList = walls[i];
+ for (let a in wallList) {
+ a = parseInt(a, 10);
+
+ wallList[a].sort((a, b) => {
+ return a - b;
+ });
+
+ let startPos = wallList[a][0];
+ const isHorizontal = i === 1;
+
+ if (wallList[a].length === 1) {
+ const startPosX = isHorizontal ? startPos : a;
+ const startPosY = isHorizontal ? a : startPos;
+ result.push({
+ startPosX,
+ startPosY,
+ isHorizontal,
+ length: 1
+ });
+ } else {
+ let consecutiveCount = 1;
+ for (let b = 0; b < wallList[a].length - 1; b++) {
+ if (b + 1 === wallList[a].length - 1) {
+ if (wallList[a][b + 1] - wallList[a][b] > 1) {
+ const startPosX = isHorizontal ? startPos : a;
+ const startPosY = isHorizontal ? a : startPos;
+ result.push({
+ startPosX,
+ startPosY,
+ isHorizontal,
+ length: consecutiveCount
+ });
+ consecutiveCount = 0;
+ startPos = wallList[a][b + 1];
}
+ const startPosX = isHorizontal ? startPos : a;
+ const startPosY = isHorizontal ? a : startPos;
+ result.push({
+ startPosX,
+ startPosY,
+ isHorizontal,
+ length: consecutiveCount + 1
+ });
+ break;
+ } else if (wallList[a][b + 1] - wallList[a][b] > 1) {
+ const startPosX = isHorizontal ? startPos : a;
+ const startPosY = isHorizontal ? a : startPos;
+ result.push({
+ startPosX,
+ startPosY,
+ isHorizontal,
+ length: consecutiveCount
+ });
+ startPos = wallList[a][b + 1];
+ consecutiveCount = 0;
+ }
+ consecutiveCount++;
}
+ }
}
+ }
- return result;
+ return result;
}
export function deriveValidNextTilePositions(rooms, selectedTiles) {
- const result = [], newPosition = {x: 0, y: 0};
- let isSurroundingTile;
-
- selectedTiles.forEach((tile) => {
- const x = tile.positionX;
- const y = tile.positionY;
- result.push({x, y});
-
- for (let dX = -1; dX <= 1; dX++) {
- for (let dY = -1; dY <= 1; dY++) {
- if (Math.abs(dX) === Math.abs(dY)) {
- continue;
- }
-
- newPosition.x = x + dX;
- newPosition.y = y + dY;
-
- isSurroundingTile = true;
- for (let index in selectedTiles) {
- if (selectedTiles[index].positionX === newPosition.x
- && selectedTiles[index].positionY === newPosition.y) {
- isSurroundingTile = false;
- break;
- }
- }
-
- if (isSurroundingTile && findPositionInRooms(rooms, newPosition.x, newPosition.y) === -1) {
- result.push({x: newPosition.x, y: newPosition.y});
- }
- }
+ const result = [],
+ newPosition = { x: 0, y: 0 };
+ let isSurroundingTile;
+
+ selectedTiles.forEach(tile => {
+ const x = tile.positionX;
+ const y = tile.positionY;
+ result.push({ x, y });
+
+ for (let dX = -1; dX <= 1; dX++) {
+ for (let dY = -1; dY <= 1; dY++) {
+ if (Math.abs(dX) === Math.abs(dY)) {
+ continue;
}
- });
- return result;
+ newPosition.x = x + dX;
+ newPosition.y = y + dY;
+
+ isSurroundingTile = true;
+ for (let index in selectedTiles) {
+ if (
+ selectedTiles[index].positionX === newPosition.x &&
+ selectedTiles[index].positionY === newPosition.y
+ ) {
+ isSurroundingTile = false;
+ break;
+ }
+ }
+
+ if (
+ isSurroundingTile &&
+ findPositionInRooms(rooms, newPosition.x, newPosition.y) === -1
+ ) {
+ result.push({ x: newPosition.x, y: newPosition.y });
+ }
+ }
+ }
+ });
+
+ return result;
}
export function findPositionInPositions(positions, positionX, positionY) {
- for (let i = 0; i < positions.length; i++) {
- const position = positions[i];
- if (positionX === position.x && positionY === position.y) {
- return i;
- }
+ for (let i = 0; i < positions.length; i++) {
+ const position = positions[i];
+ if (positionX === position.x && positionY === position.y) {
+ return i;
}
+ }
- return -1;
+ return -1;
}
export function findPositionInRooms(rooms, positionX, positionY) {
- for (let i = 0; i < rooms.length; i++) {
- const room = rooms[i];
- if (findPositionInTiles(room.tiles, positionX, positionY) !== -1) {
- return i;
- }
+ for (let i = 0; i < rooms.length; i++) {
+ const room = rooms[i];
+ if (findPositionInTiles(room.tiles, positionX, positionY) !== -1) {
+ return i;
}
+ }
- return -1;
+ return -1;
}
function findPositionInTiles(tiles, positionX, positionY) {
- let index = -1;
+ let index = -1;
- for (let i = 0; i < tiles.length; i++) {
- const tile = tiles[i];
- if (positionX === tile.positionX && positionY === tile.positionY) {
- index = i;
- break;
- }
+ for (let i = 0; i < tiles.length; i++) {
+ const tile = tiles[i];
+ if (positionX === tile.positionX && positionY === tile.positionY) {
+ index = i;
+ break;
}
+ }
- return index;
+ return index;
}
export function findTileWithPosition(tiles, positionX, positionY) {
- for (let i = 0; i < tiles.length; i++) {
- if (tiles[i].positionX === positionX && tiles[i].positionY === positionY) {
- return tiles[i];
- }
+ for (let i = 0; i < tiles.length; i++) {
+ if (tiles[i].positionX === positionX && tiles[i].positionY === positionY) {
+ return tiles[i];
}
+ }
- return null;
+ return null;
}
export function calculateRoomListBounds(rooms) {
- const min = {x: Number.MAX_VALUE, y: Number.MAX_VALUE};
- const max = {x: -1, y: -1};
-
- rooms.forEach((room) => {
- room.tiles.forEach((tile) => {
- if (tile.positionX < min.x) {
- min.x = tile.positionX;
- }
- if (tile.positionY < min.y) {
- min.y = tile.positionY;
- }
-
- if (tile.positionX > max.x) {
- max.x = tile.positionX;
- }
- if (tile.positionY > max.y) {
- max.y = tile.positionY;
- }
- });
+ const min = { x: Number.MAX_VALUE, y: Number.MAX_VALUE };
+ const max = { x: -1, y: -1 };
+
+ rooms.forEach(room => {
+ room.tiles.forEach(tile => {
+ if (tile.positionX < min.x) {
+ min.x = tile.positionX;
+ }
+ if (tile.positionY < min.y) {
+ min.y = tile.positionY;
+ }
+
+ if (tile.positionX > max.x) {
+ max.x = tile.positionX;
+ }
+ if (tile.positionY > max.y) {
+ max.y = tile.positionY;
+ }
});
+ });
- max.x++;
- max.y++;
+ max.x++;
+ max.y++;
- const center = {
- x: min.x + (max.x - min.x) / 2.0,
- y: min.y + (max.y - min.y) / 2.0
- };
+ const center = {
+ x: min.x + (max.x - min.x) / 2.0,
+ y: min.y + (max.y - min.y) / 2.0
+ };
- return {min, center, max};
+ return { min, center, max };
}
diff --git a/src/util/timeline.js b/src/util/timeline.js
index c6828ad7..e20d5823 100644
--- a/src/util/timeline.js
+++ b/src/util/timeline.js
@@ -1,19 +1,19 @@
export function convertTickToPercentage(tick, maxTick) {
- if (maxTick === 0) {
- return "0%";
- } else if (tick > maxTick) {
- return ((maxTick / (maxTick + 1)) * 100) + "%";
- }
+ if (maxTick === 0) {
+ return "0%";
+ } else if (tick > maxTick) {
+ return maxTick / (maxTick + 1) * 100 + "%";
+ }
- return ((tick / (maxTick + 1)) * 100) + "%";
+ return tick / (maxTick + 1) * 100 + "%";
}
export function getDatacenterIdOfTick(tick, sections) {
- for (let i in sections.reverse()) {
- if (tick >= sections[i].startTick) {
- return sections[i].datacenterId;
- }
+ for (let i in sections.reverse()) {
+ if (tick >= sections[i].startTick) {
+ return sections[i].datacenterId;
}
+ }
- return -1;
+ return -1;
}