UNPKG

react-cohort-chart

Version:
69 lines (56 loc) 1.68 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.camelCased = exports.isValidHex = exports.getPercentage = exports.shadeCellWithColor = void 0; /** * Created by jyothi on 30/5/17. */ /** * Cell Shade color based on percentage * @param percent * @param color * @returns {string} */ var shadeCellWithColor = function shadeCellWithColor(percent) { var color = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "#3f83a3"; var rate = 1.0 - Math.ceil(percent / 10) / 10; var f = parseInt(color.slice(1), 16), t = rate < 0 ? 0 : 255, p = rate < 0 ? rate * -1 : rate, R = f >> 16, G = f >> 8 & 0x00FF, B = f & 0x0000FF; return "#\n ".concat(0x1000000 + (Math.round((t - R) * p) + R) * 0x10000 + (Math.round((t - G) * p) + G) * 0x100 + (Math.round((t - B) * p) + B)).toString(16).slice(1); }; /** * * @param total * @param value * @returns {number} */ exports.shadeCellWithColor = shadeCellWithColor; var getPercentage = function getPercentage(total, value) { return total ? Math.round(value / total * 100 * 100) / 100 : total; }; /** * * @param color * @returns {boolean} */ exports.getPercentage = getPercentage; var isValidHex = function isValidHex(color) { return /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(color); }; /** * * @returns {string} */ exports.isValidHex = isValidHex; var camelCased = function camelCased() { var text = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ""; return text.toLowerCase().replace(/\b\w/g, function (replaced) { return replaced.toUpperCase(); }); }; exports.camelCased = camelCased;