react-meteo-chart
Version:
pre alpha of meteo chart
401 lines (344 loc) • 15.7 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _react = _interopRequireWildcard(require("react"));
var _BasicChart = _interopRequireWildcard(require("../BasicChart"));
var _moment = _interopRequireDefault(require("moment"));
var _reactVis = require("react-vis");
var _LevelsLegend = require("./LevelsLegend");
var _reactSizeme = _interopRequireDefault(require("react-sizeme"));
var _GridDates = _interopRequireDefault(require("../GridDates"));
var _LevelsCrossFormat = require("./LevelsCrossFormat");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
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 _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 _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 _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
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 _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
var gaps = [[1, "h"], [3, "h"], [6, "h"], [24, "h"]];
var MiddleVerticalRectSeries =
/*#__PURE__*/
function (_VerticalRectSeries) {
_inherits(MiddleVerticalRectSeries, _VerticalRectSeries);
function MiddleVerticalRectSeries() {
var _getPrototypeOf2;
var _this;
_classCallCheck(this, MiddleVerticalRectSeries);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(MiddleVerticalRectSeries)).call.apply(_getPrototypeOf2, [this].concat(args)));
_defineProperty(_assertThisInitialized(_this), "_handleNearestX", function (event) {
var _props3 = this.props,
onNearestX = _props3.onNearestX,
data = _props3.data;
var minDistance = -Number.POSITIVE_INFINITY;
var value = null;
var valueIndex = null;
var coordinate = this._getXYCoordinateInContainer(event);
var xScaleFn = this._getAttributeFunctor("x");
data.forEach(function (item, i) {
var currentCoordinate = xScaleFn(item);
var newDistance = coordinate.x - currentCoordinate;
if (newDistance <= 0 && newDistance > minDistance) {
minDistance = newDistance;
value = item;
valueIndex = i;
}
});
if (!value) {
return;
}
onNearestX(value, {
innerX: xScaleFn(value),
index: valueIndex,
event: event.nativeEvent
});
});
return _this;
}
return MiddleVerticalRectSeries;
}(_reactVis.VerticalRectSeries);
var LevelsChart =
/*#__PURE__*/
function (_Component) {
_inherits(LevelsChart, _Component);
function LevelsChart() {
var _getPrototypeOf3;
var _this2;
_classCallCheck(this, LevelsChart);
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
_this2 = _possibleConstructorReturn(this, (_getPrototypeOf3 = _getPrototypeOf(LevelsChart)).call.apply(_getPrototypeOf3, [this].concat(args)));
_defineProperty(_assertThisInitialized(_this2), "state", {
cross: null,
dailySum: true,
showLWCross: false,
showTWCross: false,
show6hCross: false,
show24hCross: false,
LW: true,
TW: true,
hsum6: true,
hsum24: true,
data: null
});
_defineProperty(_assertThisInitialized(_this2), "getCrossTime", function (value, span, index) {
if (value.x - value.x0 < span) {
if (index == 0) return _moment["default"].unix(value.x / 1000);else return _moment["default"].unix(value.x0 / 1000).add(span, "ms");
}
return _moment["default"].unix(value.x / 1000);
});
return _this2;
}
_createClass(LevelsChart, [{
key: "render",
value: function render() {
var _this3 = this;
var width = this.props.size.width;
var _this$props = this.props,
superArr = _this$props.superArr,
dateFrom = _this$props.dateFrom,
dateTo = _this$props.dateTo,
_this$props$plotHeigh = _this$props.plotHeight,
plotHeight = _this$props$plotHeigh === void 0 ? 270 : _this$props$plotHeigh,
_this$props$plotWidth = _this$props.plotWidth,
plotWidth = _this$props$plotWidth === void 0 ? width : _this$props$plotWidth;
var _this$state = this.state,
cross = _this$state.cross,
dailySum = _this$state.dailySum,
showLWCross = _this$state.showLWCross,
showTWCross = _this$state.showTWCross,
LW = _this$state.LW,
TW = _this$state.TW,
data = _this$state.data;
var domainFrom = (0, _moment["default"])(_moment["default"].utc(dateFrom).local().format("YYYY-MM-DDTHH:mm"));
var domainTo = (0, _moment["default"])(_moment["default"].utc(dateTo).local().format("YYYY-MM-DD:HH:mm"));
var day = 86400000;
var dateThreshold = day * 5;
var gridDates = (0, _GridDates["default"])(dateFrom, dateTo);
var isAdmin = this.props.isAdmin;
var daySpan = (0, _moment["default"])(dateTo) - (0, _moment["default"])(dateFrom);
var showDirectionThreshold = day * 30;
var setVal = function setVal(data, name) {
_this3.setState(_defineProperty({}, name, !data));
}; // const plotHeight = 270;
// const plotWidth = 1400;
return _react["default"].createElement(_react["default"].Fragment, null, _react["default"].createElement(_BasicChart["default"], {
opacity: this.props.opacity,
superArr: superArr,
dateFrom: dateFrom,
dateTo: dateTo,
plotHeight: plotHeight > 120 ? plotHeight : 120,
plotWidth: plotWidth
}, _react["default"].createElement(_reactVis.FlexibleXYPlot, {
height: plotHeight > 120 ? plotHeight : 120 // width={plotWidth}
,
className: "mainPlot",
margin: {
left: 65
},
onMouseLeave: function onMouseLeave() {
_this3.setState({
showLWCross: false
});
} // xType="time"
,
xDomain: [domainFrom, domainTo],
yPadding: 40
}, _react["default"].createElement(_reactVis.YAxis, {
left: 0,
tickFormat: function tickFormat(v) {
return "".concat(v, " \u043C\u043C");
}
}), _react["default"].createElement(_reactVis.HorizontalGridLines, null), superArr[0] && LW && _react["default"].createElement(_reactVis.LineMarkSeries, {
getNull: function getNull(d) {
return d.y !== null;
},
data: superArr[0],
fill: "".concat(_LevelsLegend.COLORS.LWColor),
stroke: "".concat(_LevelsLegend.COLORS.LWColor),
curve: "linear",
size: "1",
onNearestX: function onNearestX(value, _ref) {
var index = _ref.index;
var xx = superArr.map(function (d) {
return Math.max.apply(Math, d.map(function (x) {
return x.x;
}).filter(function (x) {
return x <= value.x;
}));
});
var cress = superArr.map(function (d, indx) {
return d.filter(function (asd, id) {
return asd.x == xx[indx];
});
});
_this3.setState({
cross: superArr.map(function (d, indx) {
return {
x: value.x,
y: cress[indx][0] ? cress[indx][0].y : null
};
}),
data: superArr.map(function (d, indx) {
return {
x: _this3.getCrossTime(value, day / 24, index),
info: cress[indx][0] ? cress[indx][0] : null
};
}),
showLWCross: true
});
}
}), _react["default"].createElement(_reactVis.Crosshair, {
values: cross
}, showLWCross ? _react["default"].createElement(_LevelsCrossFormat.LevelsCrossFormat, {
superArr: superArr,
cross: cross,
data: data
}) : _react["default"].createElement(_LevelsCrossFormat.EmptyCrossFormat, null))), isAdmin && _react["default"].createElement(_LevelsLegend.LegendLW, {
setVal: setVal,
isAdmin: true
}), isAdmin && _react["default"].createElement(_LevelsLegend.LegendTWr, {
setVal: setVal,
isAdmin: true
})), superArr[1] !== undefined && superArr[1].length > 0 && TW ? _react["default"].createElement("div", {
style: {
// border: "1px solid #7d9cb8",
backgroundColor: (0, _BasicChart.rgbToHex)(255, 255, 255, this.props.opacity)
}
}, _react["default"].createElement(_reactVis.FlexibleXYPlot, {
height: plotHeight > 120 ? plotHeight : 120 // width={plotWidth}
,
className: "dailySumPlot",
margin: {
left: 65
},
onMouseLeave: function onMouseLeave() {
_this3.setState({
showTWCross: false
});
},
xDomain: [domainFrom, domainTo],
xType: "time"
}, _react["default"].createElement(_reactVis.YAxis, {
left: 0,
tickFormat: function tickFormat(v) {
return v ? "".concat(v, " C\xB0") : "";
}
}), _react["default"].createElement(_reactVis.XAxis, {
tickFormat: function tickFormat(d) {
return (0, _moment["default"])(d).format("HH:mm") == "00:00" ? "" : "".concat((0, _moment["default"])(d).format("HH:mm"));
},
tickTotal: width * 0.01
}), _react["default"].createElement(_reactVis.XAxis, {
tickFormat: function tickFormat(d) {
return (0, _moment["default"])(d).format("HH:mm") == "00:00" ? "".concat((0, _moment["default"])(d).format("D.MM")) : "";
},
style: {
line: {
stroke: "#ADDDE1"
},
ticks: {
stroke: "#ADDDE1"
},
text: {
stroke: "none",
fill: "#000000",
fontWeight: 750,
fontSize: 12
}
},
tickTotal: width * 0.01
}), _react["default"].createElement(_reactVis.HorizontalGridLines, null), _react["default"].createElement(_reactVis.VerticalGridLines, null), gridDates.map(function (date) {
return _react["default"].createElement(_reactVis.DecorativeAxis, {
key: "".concat(date, "-axis"),
className: "decaxis",
axisDomain: [],
axisStart: {
x: (0, _moment["default"])(date.format("YYYY-MM-DD")),
y: 0
},
axisEnd: {
x: (0, _moment["default"])(date.format("YYYY-MM-DD")),
y: 1
},
tickTotal: 0,
style: {
ticks: {
display: "none"
},
text: {
display: "none"
}
}
});
}), _react["default"].createElement(_reactVis.LineSeries, {
getNull: function getNull(d) {
return d.y !== null;
},
data: superArr[1],
fill: "".concat(_LevelsLegend.COLORS.TWColor),
stroke: "".concat(_LevelsLegend.COLORS.TWColor),
onNearestX: function onNearestX(value, _ref2) {
var index = _ref2.index;
var xx = superArr.map(function (d) {
return Math.max.apply(Math, d.map(function (x) {
return x.x;
}).filter(function (x) {
return x <= value.x;
}));
});
var cress = superArr.map(function (d, indx) {
return d.filter(function (asd, id) {
return asd.x == xx[indx];
});
});
_this3.setState({
cross: superArr.map(function (d, indx) {
return {
x: value.x,
y: cress[indx][0] ? cress[indx][0].y : null
};
}),
data: superArr.map(function (d, indx) {
return {
x: _this3.getCrossTime(value, day, index),
info: cress[indx][0] ? cress[indx][0] : null
};
}),
showTWCross: true
});
}
}), _react["default"].createElement(_reactVis.Crosshair, {
values: cross
}, showTWCross ? _react["default"].createElement(_LevelsCrossFormat.LevelsCrossFormat, {
superArr: superArr,
cross: cross,
data: data
}) : _react["default"].createElement(_LevelsCrossFormat.EmptyCrossFormat, null)))) : _react["default"].createElement(_BasicChart["default"], {
opacity: this.props.opacity,
superArr: superArr,
dateFrom: dateFrom,
dateTo: dateTo,
plotHeight: plotHeight > 120 ? plotHeight : 120,
plotWidth: plotWidth
}), !isAdmin && _react["default"].createElement(_LevelsLegend.FullLevelsLegend, {
setVal: setVal,
isAdmin: true
}));
}
}]);
return LevelsChart;
}(_react.Component);
var _default = (0, _reactSizeme["default"])()(LevelsChart);
exports["default"] = _default;