UNPKG

react-meteo-chart

Version:

pre alpha of meteo chart

221 lines (172 loc) 8.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getColorByType = getColorByType; exports.getIgnoreBufrs = getIgnoreBufrs; exports.getMeasureByType = getMeasureByType; exports.getHeightlessElevation = getHeightlessElevation; exports.isBufrWithHeight = isBufrWithHeight; var _hexToRgb = _interopRequireDefault(require("hex-to-rgb")); var _rgbToHex = _interopRequireDefault(require("rgb-to-hex")); var _colorConvert = _interopRequireDefault(require("color-convert")); var _colours = require("../shared/colours"); var _colourGetter = _interopRequireDefault(require("../shared/colourGetter")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } function getIgnoreBufrs(type) { if (type.search(/PRECIPITATION/) !== -1) return [0.01, 500]; switch (type) { case "DOPPLER MEAN VELOCITY (RADIAL)": return [-30, 30]; case "HORIZONTAL REFLECTIVITY": return [-20, 100]; // return [-100, 100]; break; case "DIFFERENTIAL REFLECTIVITY": return [0, 100]; break; case "RADAR RAINFALL INTENSITY": return [0.2 / 36000000, 100]; case "ECHO TOPS": return [1, 100000]; case "HAZARDOUS PHENOMENA": return [1, 16]; default: return [-100, 100000]; } } function getbufrColor(num) { if (num > -50 && num <= -30) return [0, 0, 170]; if (num > -30 && num <= -20) return [0, 0, 204]; if (num > -20 && num <= -10) return [0, 0, 238]; if (num > -10 && num <= 0) return [85, 0, 255]; if (num > 0 && num <= 10) return [119, 0, 204]; if (num > 10 && num <= 20) return [153, 0, 170]; if (num > 20 && num <= 30) return [187, 0, 119]; if (num > 30 && num <= 40) return [221, 0, 51]; return [100, 100, 100]; } function getbufrdopplermeanColor(num) { if (num > -30 && num <= -25) return "#c4e5af"; if (num > -25 && num <= -20) return "#85ccbb"; if (num > -20 && num <= -15) return "#45b7c1"; if (num > -15 && num <= -10) return "#1e91c1"; if (num > -10 && num <= -5) return "#1c60a9"; if (num > -5 && num < 0) return "#00327f"; if (num == 0) return "#a8ae9d"; if (num > 0 && num <= 5) return "#b00124"; if (num > 5 && num <= 10) return "#e7171b"; if (num > 10 && num <= 15) return "#f75635"; if (num > 15 && num <= 20) return "#fe8c39"; if (num > 20 && num <= 25) return "#fbb35e"; if (num > 25 && num <= 30) return "#f0dc76"; return ""; } function getbufrechoColor(num) { num /= 1000; // console.log(num); if (num > 0 && num <= 3) return "#01f4f5"; if (num > 3 && num <= 5) return "#02978f"; if (num > 5 && num <= 6) return "#009b43"; if (num > 6 && num <= 7) return "#03b54d"; if (num > 7 && num <= 9) return "#00d108"; if (num > 9 && num < 11) return "#35f750"; if (num > 11 && num < 12) return "#fefc3e"; if (num > 12 && num <= 13) return "#fae909"; if (num > 13 && num <= 14) return "#ffbe01"; if (num > 14 && num <= 15) return "#ffb702"; if (num > 15 && num <= 16) return "#fd9c03"; if (num > 16 && num <= 17) return "#fe6403"; if (num > 17 && num <= 19) return "#fd3104"; if (num > 19 && num <= 20) return "#c32463"; if (num > 20) return "#ee37d2"; return "#FF0000"; } function getbufrhorizColor(num) { num /= 1000; // console.log(num); if (num > -20 && num <= -10) return "#dcdaff"; if (num > -10 && num <= -5) return "#6e6fff"; if (num > -5 && num <= 0) return "#090bfe"; if (num > 0 && num <= 10) return "#0dac12"; if (num > 10 && num <= 20) return "#7fd70c"; if (num > 20 && num < 30) return "#fafe01"; if (num > 30 && num < 40) return "#fecf01"; if (num > 40 && num <= 50) return "#fae909"; if (num > 13 && num <= 14) return "#fd8303"; if (num > 50) return "#fe0000"; return "#FF0000"; } var ZDRColor = [[0, 0, 0], [60, 60, 60], [92, 92, 92], [120, 120, 120], [145, 145, 145], [173, 173, 173], [113, 96, 144], [16, 12, 125], [52, 193, 169], [0, 162, 255], [0, 255, 162], [0, 255, 255], [119, 255, 0], [255, 220, 0], [255, 85, 0], [176, 0, 0], [255, 0, 0], [213, 0, 255], [115, 0, 255], [90, 0, 150]]; function zdr2color(num) { if (num <= -4.0) return ZDRColor[0];else if (num <= -3.5) return ZDRColor[1];else if (num <= -3.0) return ZDRColor[2];else if (num <= -2.5) return ZDRColor[3];else if (num <= -0.5) return ZDRColor[4];else if (num <= -0) return ZDRColor[5];else if (num <= 0.25) return ZDRColor[6];else if (num <= 0.5) return ZDRColor[7];else if (num <= 1) return ZDRColor[8];else if (num <= 1.25) return ZDRColor[9];else if (num <= 1.5) return ZDRColor[10];else if (num <= 2) return ZDRColor[11];else if (num <= 2.5) return ZDRColor[12];else if (num <= 3) return ZDRColor[13];else if (num <= 3.5) return ZDRColor[14];else if (num <= 4) return ZDRColor[15];else if (num <= 5) return ZDRColor[16];else if (num <= 6) return ZDRColor[17];else return ZDRColor[18]; } var rainfallColor = [[0, 0, 0], [200, 200, 200], [180, 180, 255], [120, 120, 255], [20, 20, 255], [0, 216, 195], [0, 150, 144], [0, 102, 102], [255, 255, 0], [255, 200, 0], [255, 155, 0], [255, 100, 0], [255, 0, 0], [200, 0, 0], [120, 0, 0], [40, 0, 0]]; var RAINFALL_CONST = 36000000; function rainfall2color(num) { num *= RAINFALL_CONST; if (num <= 0.2) return rainfallColor[0];else if (num <= 0.5) return rainfallColor[1];else if (num <= 1.5) return rainfallColor[2];else if (num <= 2.5) return rainfallColor[3];else if (num <= 4) return rainfallColor[4];else if (num <= 6) return rainfallColor[5];else if (num <= 10) return rainfallColor[6];else if (num <= 15) return rainfallColor[7];else if (num <= 20) return rainfallColor[8];else if (num <= 35) return rainfallColor[9];else if (num <= 50) return rainfallColor[10];else if (num <= 80) return rainfallColor[11];else if (num <= 120) return rainfallColor[12];else if (num <= 200) return rainfallColor[13];else if (num <= 300) return rainfallColor[14];else return rainfallColor[1]; } function getPreciptionColor(num) { return (0, _colourGetter["default"])(num, _colours.precipColours); } function normalizeHeight(h) { if (h == 0) return 0;else if (h <= 1000) return 1;else if (h <= 2000) return 2;else if (h <= 3000) return 3;else if (h <= 4000) return 4;else if (h <= 5000) return 5;else if (h <= 6000) return 6;else if (h <= 7000) return 7;else if (h <= 8000) return 8;else if (h <= 9000) return 9;else if (h <= 10000) return 10; return 11; } function hazardousColor(h) { return hazardColors[h - 1]; } function getColorByType(type, color) { // console.log(rgbToHEx); if (color == null) return "#ffffff00"; if (type.search(/PRECIPITATION/) !== -1) return getPreciptionColor(color); switch (type) { case "DOPPLER MEAN VELOCITY (RADIAL)": return getbufrdopplermeanColor(color); case "HORIZONTAL REFLECTIVITY": return getbufrhorizColor(color); case "DIFFERENTIAL REFLECTIVITY": { return "#".concat(_colorConvert["default"].rgb.hex(zdr2color(color))); } case "ECHO TOPS": return getbufrechoColor(color); case "RADAR RAINFALL INTENSITY": return "#".concat(_colorConvert["default"].rgb.hex(rainfall2color(color))); case "HAZARDOUS PHENOMENA": return "#".concat(_colorConvert["default"].rgb.hex(hazardousColor(color))); default: return "#".concat(_colorConvert["default"].rgb.hex(getbufrColor(color))); } } function getMeasureByType(type) { // console.log(rgbToHEx); if (type.search(/PRECIPITATION/) !== -1) return "кг/м²"; switch (type) { case "DOPPLER MEAN VELOCITY (RADIAL)": return "м/c"; case "HORIZONTAL REFLECTIVITY": return "дБ"; case "DIFFERENTIAL REFLECTIVITY": { return "дБ"; } case "ECHO TOPS": return "дБ"; case "RADAR RAINFALL INTENSITY": return "\u043C\u043C/\u0441"; case "HAZARDOUS PHENOMENA": return ""; default: return ""; } } function isBufrWithHeight(type) { if (type.search(/PRECIPITATION PAST/) !== -1 || type == "HAZARDOUS PHENOMENA") return false; return true; } function getHeightlessElevation(value, type) { if (type.search(/PRECIPITATION/) !== -1) { return value ? value.toFixed(3) : value; } return 1000; } var hazardColors = [[182, 182, 180], [169, 168, 174], [101, 144, 117], [67, 207, 85], [85, 170, 77], [240, 220, 169], [86, 154, 217], [0, 33, 209], [1, 1, 111], [221, 163, 125], [213, 109, 132], [211, 1, 10], [220, 108, 32], [151, 55, 7], [83, 8, 5], [222, 201, 216], [236, 97, 224], [210, 5, 172], [76, 75, 106]];