UNPKG

rumble-charts

Version:

Truly declarative React charts components

87 lines (82 loc) 2.75 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var isString = require('./isString.js'); var isUndefined = require('./isUndefined.js'); var normalizeNumber = require('./normalizeNumber.js'); var isNumber = require('./isNumber.js'); var TOP = 'top'; var BOTTOM = 'bottom'; var MIDDLE = 'middle'; var LEFT = 'left'; var RIGHT = 'right'; var CENTER = 'center'; var HORIZONTAL = [TOP, BOTTOM, MIDDLE]; var VERTICAL = [LEFT, RIGHT, CENTER]; function getCoords(position, layerWidth, layerHeight, width, height) { if (layerWidth === void 0) { layerWidth = 0; } if (layerHeight === void 0) { layerHeight = 0; } if (width === void 0) { width = 0; } if (height === void 0) { height = 0; } if (isString.isString(position)) { position = position.trim().split(' ').map(function (value) { return value.trim(); }); } if (Array.isArray(position)) { var cleanPosition = position.map(function (pos) { return isString.isString(pos) ? pos.trim().toLowerCase() : pos; }); var _x = cleanPosition[0], _y = cleanPosition[1]; if (isString.isString(cleanPosition[0]) && HORIZONTAL.indexOf(cleanPosition[0]) !== -1) { _y = cleanPosition[0]; } if (isString.isString(cleanPosition[1]) && VERTICAL.indexOf(cleanPosition[1]) !== -1) { _x = cleanPosition[1]; } var result = { x: 0, y: 0 }; if (isString.isString(_x)) { if (_x === LEFT) { result.x = 0; } else if (_x === RIGHT) { result.x = layerWidth - width; } else if (_x === CENTER) { result.x = (layerWidth - width) / 2; } else { result.x = normalizeNumber.normalizeNumber(_x, layerWidth); } } else if (isNumber.isNumber(_x)) { result.x = _x; } else if (isUndefined.isUndefined(_x)) { result.x = 0; } if (isString.isString(_y)) { if (_y === TOP) { result.y = 0; } else if (_y === BOTTOM) { result.y = layerHeight - height; } else if (_y === MIDDLE) { result.y = (layerHeight - height) / 2; } else { result.y = normalizeNumber.normalizeNumber(_y, layerHeight); } } else if (isNumber.isNumber(_y)) { result.y = _y; } else if (isUndefined.isUndefined(_y)) { result.y = 0; } return result; } else { return { x: 0, y: 0 }; } } exports.getCoords = getCoords;