kepler.gl
Version:
kepler.gl is a webgl based application to visualize large scale location data in the browser
212 lines (167 loc) • 17.6 kB
JavaScript
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
var _getPrototypeOf3 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
var _react = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _styledComponents = _interopRequireDefault(require("styled-components"));
var _d3Selection = require("d3-selection");
var _d3Brush = require("d3-brush");
function _templateObject() {
var data = (0, _taggedTemplateLiteral2["default"])(["\n .selection {\n stroke: none;\n fill: ", ";\n opacity: 1;\n }\n"]);
_templateObject = function _templateObject() {
return data;
};
return data;
}
var StyledG = _styledComponents["default"].g(_templateObject(), function (props) {
return props.theme.rangeBrushBgd;
});
var RangeBrush =
/*#__PURE__*/
function (_Component) {
(0, _inherits2["default"])(RangeBrush, _Component);
function RangeBrush() {
var _getPrototypeOf2;
var _this;
(0, _classCallCheck2["default"])(this, RangeBrush);
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = (0, _possibleConstructorReturn2["default"])(this, (_getPrototypeOf2 = (0, _getPrototypeOf3["default"])(RangeBrush)).call.apply(_getPrototypeOf2, [this].concat(args)));
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "rootContainer", (0, _react.createRef)());
return _this;
}
(0, _createClass2["default"])(RangeBrush, [{
key: "componentDidMount",
value: function componentDidMount() {
var _this2 = this;
// We want the React app to respond to brush state and vice-versa
// but d3-brush fires the same events for both user-initiated brushing
// and programmatic brushing (brush.move). We need these flags to
// distinguish between the uses.
//
// We don't use state because that would trigger another `componentDidUpdate`
this.brushing = false;
this.moving = false;
this.root = (0, _d3Selection.select)(this.rootContainer.current);
this.brush = (0, _d3Brush.brushX)().on('start', function () {
_this2.brushing = true;
}).on('brush', function () {
if (_this2.moving) {
return;
}
_d3Selection.event.selection === null ? _this2._reset() : _this2._brush(_d3Selection.event.selection);
}).on('end', function () {
if (!_this2.moving && _d3Selection.event.selection === null) {
_this2._reset();
}
_this2.brushing = false;
_this2.moving = false;
});
this.root.call(this.brush);
}
}, {
key: "componentDidUpdate",
value: function componentDidUpdate(prevProps) {
var _this$props = this.props,
_this$props$value = (0, _slicedToArray2["default"])(_this$props.value, 2),
val0 = _this$props$value[0],
val1 = _this$props$value[1],
width = _this$props.width;
var _prevProps$value = (0, _slicedToArray2["default"])(prevProps.value, 2),
prevVal0 = _prevProps$value[0],
prevVal1 = _prevProps$value[1];
if (prevProps.width !== width) {
// width change should not trigger this._brush
this.moving = true;
this.root.call(this.brush);
this._move(val0, val1);
}
if (!this.brushing && !this.moving) {
if (prevVal0 !== val0 || prevVal1 !== val1) {
this.moving = true;
this._move(val0, val1);
}
}
}
}, {
key: "_reset",
value: function _reset() {
var _this$props$range = (0, _slicedToArray2["default"])(this.props.range, 2),
minValue = _this$props$range[0],
maxValue = _this$props$range[1];
this._onBrush(minValue, maxValue);
}
}, {
key: "_move",
value: function _move(val0, val1) {
var _this$props2 = this.props,
_this$props2$domain = (0, _slicedToArray2["default"])(_this$props2.domain, 2),
min = _this$props2$domain[0],
max = _this$props2$domain[1],
width = _this$props2.width;
var scale = function scale(x) {
return (x - min) * width / (max - min);
};
this.brush.move(this.root, [scale(val0), scale(val1)]);
}
}, {
key: "_brush",
value: function _brush(_ref) {
var _ref2 = (0, _slicedToArray2["default"])(_ref, 2),
sel0 = _ref2[0],
sel1 = _ref2[1];
var _this$props3 = this.props,
_this$props3$domain = (0, _slicedToArray2["default"])(_this$props3.domain, 2),
min = _this$props3$domain[0],
max = _this$props3$domain[1],
width = _this$props3.width;
var invert = function invert(x) {
return x * (max - min) / width + min;
};
this._onBrush(invert(sel0), invert(sel1));
}
}, {
key: "_onBrush",
value: function _onBrush(val0, val1) {
var _this$props$value2 = (0, _slicedToArray2["default"])(this.props.value, 2),
currentVal0 = _this$props$value2[0],
currentVal1 = _this$props$value2[1];
if (currentVal0 === val0 && currentVal1 === val1) {
return;
}
this.props.onBrush(val0, val1);
}
}, {
key: "render",
value: function render() {
return _react["default"].createElement(StyledG, {
className: "kg-range-slider__brush",
ref: this.rootContainer
});
}
}]);
return RangeBrush;
}(_react.Component);
exports["default"] = RangeBrush;
(0, _defineProperty2["default"])(RangeBrush, "propTypes", {
domain: _propTypes["default"].arrayOf(_propTypes["default"].number).isRequired,
onBrush: _propTypes["default"].func.isRequired,
range: _propTypes["default"].arrayOf(_propTypes["default"].number).isRequired,
value: _propTypes["default"].arrayOf(_propTypes["default"].number).isRequired,
width: _propTypes["default"].number.isRequired
});
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9jb21wb25lbnRzL2NvbW1vbi9yYW5nZS1icnVzaC5qcyJdLCJuYW1lcyI6WyJTdHlsZWRHIiwic3R5bGVkIiwiZyIsInByb3BzIiwidGhlbWUiLCJyYW5nZUJydXNoQmdkIiwiUmFuZ2VCcnVzaCIsImJydXNoaW5nIiwibW92aW5nIiwicm9vdCIsInJvb3RDb250YWluZXIiL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