react-meteo-chart
Version:
pre alpha of meteo chart
219 lines (180 loc) • 10.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _react = _interopRequireDefault(require("react"));
var _BufrChart = _interopRequireDefault(require("../Bufr/BufrChart"));
var _reactApollo = require("react-apollo");
var _moment = _interopRequireDefault(require("moment"));
var _apolloBoost = _interopRequireDefault(require("apollo-boost"));
var _reactLoading = _interopRequireDefault(require("react-loading"));
var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
var color = _interopRequireWildcard(require("../Bufr/color-utils"));
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _templateObject() {
var data = _taggedTemplateLiteral(["\n query($token: String!, $at: DateTime, $dataType: String!, $line: [Float]!) {\n bufrSlice(\n token: $token\n\n dataType: $dataType\n line: $line\n at: $at\n ) {\n station {\n id\n name\n }\n slice {\n rows {\n data\n height1\n height2\n }\n ordinates\n }\n }\n }\n"]);
_templateObject = function _templateObject() {
return data;
};
return data;
}
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
var BUFR_SLICE_QUERY = (0, _graphqlTag["default"])(_templateObject());
function measure(lat1, lon1, lat2, lon2) {
// generally used geo measurement function
var R = 6378.137; // Radius of earth in KM
var dLat = lat2 * Math.PI / 180 - lat1 * Math.PI / 180;
var dLon = lon2 * Math.PI / 180 - lon1 * Math.PI / 180;
var a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(lat1 * Math.PI / 180) * Math.cos(lat2 * Math.PI / 180) * Math.sin(dLon / 2) * Math.sin(dLon / 2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
var d = R * c;
return d; // meters
}
var BufrChartGen =
/*#__PURE__*/
function (_React$PureComponent) {
_inherits(BufrChartGen, _React$PureComponent);
function BufrChartGen(props) {
var _this;
_classCallCheck(this, BufrChartGen);
_this = _possibleConstructorReturn(this, _getPrototypeOf(BufrChartGen).call(this, props));
_this.state = {
token: _this.props.token,
dataType: _this.props.dataType,
line: _this.props.line,
at: _this.props.time ? (0, _moment["default"])(_this.props.time).format("YYYY-MM-DDTHH:mm:ss") : (0, _moment["default"])().format("YYYY-MM-DDTHH:mm:ss")
};
_this.deep = true;
_this.apollo = new _apolloBoost["default"]({
uri: _this.props.client
});
return _this;
}
_createClass(BufrChartGen, [{
key: "componentDidUpdate",
value: function componentDidUpdate() {
if (this.state.line !== this.props.line) {
this.setState({
line: this.props.line
});
}
if (this.state.dataType !== this.props.dataType) {
this.setState({
dataType: this.props.dataType
});
}
if (this.state.at !== (0, _moment["default"])(this.props.time).format("YYYY-MM-DDTHH:mm:ss")) {
this.setState({
at: (0, _moment["default"])(this.props.time).format("YYYY-MM-DDTHH:mm:ss")
});
}
}
}, {
key: "render",
value: function render() {
var _this2 = this;
var variables = {
token: this.state.token,
dataType: this.state.dataType,
line: this.state.line,
at: this.state.at ? (0, _moment["default"])(this.state.at).format("YYYY-MM-DDTHH:mm:ss") : (0, _moment["default"])().format("YYYY-MM-DDTHH:mm:ss")
};
return _react["default"].createElement(_reactApollo.ApolloProvider, {
client: this.apollo
}, _react["default"].createElement("div", {
className: "bufrGraph",
style: {
width: "100%",
height: "100%"
}
}, _react["default"].createElement(_reactApollo.Query, {
query: BUFR_SLICE_QUERY,
variables: variables,
partialRefetch: true
}, function (_ref) {
var loading = _ref.loading,
error = _ref.error,
plotdata = _ref.data,
refetch = _ref.refetch,
client = _ref.client;
if (loading) return _react["default"].createElement("div", {
style: {
display: "flex",
justifyContent: "center",
alignContent: "center",
alignItems: "center",
flexDirection: "column",
fontSize: "17px",
height: "100%"
}
}, _react["default"].createElement(_reactLoading["default"], {
type: "balls",
color: "#333333",
height: 25,
width: 50
}), " ", _react["default"].createElement("p", null, " \u0417\u0430\u0433\u0440\u0443\u0437\u043A\u0430 \u0433\u0440\u0430\u0444\u0438\u043A\u043E\u0432 "));
if (error) return setTimeout(function () {
return refetch();
}, 5000);
if (plotdata) {
var ignoreBounds = _this2.props.getIgnoreBufrs(_this2.props.dataType) || [-100, 100000];
var data = plotdata.bufrSlice.map(function (st) {
return st.slice.rows.map(function (row) {
return row.data.map(function (d, d_indx) {
return {
// x: +(st.slice.ordinates[d_indx + 1] * 1000).toFixed(3),
// x0: +(st.slice.ordinates[d_indx] * 1000).toFixed(3),
x0: measure(st.slice.ordinates[0], st.slice.ordinates[1], st.slice.ordinates[d_indx * 2], st.slice.ordinates[d_indx * 2 + 1]),
x: measure(st.slice.ordinates[0], st.slice.ordinates[1], st.slice.ordinates[(d_indx + 1) * 2], st.slice.ordinates[(d_indx + 1) * 2 + 1]),
y: row.height2 == 0 ? color.getHeightlessElevation(d, _this2.props.dataType) : row.height2,
y0: row.height1 == -1 ? 0 : row.height1,
color: _this2.props.getColorByType ? _this2.props.getColorByType(_this2.props.dataType, d, "hex") : color.getColorByType(_this2.props.dataType, d),
opacity: d >= ignoreBounds[0] && d <= ignoreBounds[1] ? 1 : 0,
valu: d,
measure: color.getMeasureByType(_this2.props.dataType)
};
});
});
});
var stations = plotdata.bufrSlice.map(function (d, indx) {
return {
title: d.station.name,
index: indx
};
});
var fulldata = [];
data.forEach(function (d, indx) {
return d.forEach(function (s) {
if (!fulldata[indx]) fulldata[indx] = [];
fulldata[indx] = fulldata[indx].concat(s);
});
});
return _react["default"].createElement(_BufrChart["default"], {
opacity: _this2.props.opacity,
superArr: fulldata,
stations: stations,
dataType: _this2.props.dataType,
line: variables.line,
getBufrTranlation: _this2.props.getBufrTranlation,
isBufrWithHeight: _this2.props.isBufrWithHeight // plotHeight={150}
});
return null;
}
})), " ");
}
}]);
return BufrChartGen;
}(_react["default"].PureComponent);
var _default = BufrChartGen;
exports["default"] = _default;