UNPKG

kepler.gl

Version:

kepler.gl is a webgl based application to visualize large scale location data in the browser

229 lines (181 loc) 22.1 kB
"use strict"; var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.LegendRow = exports["default"] = void 0; 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 _reselect = require("reselect"); var _d3Format = require("d3-format"); var _moment = _interopRequireDefault(require("moment")); var _defaultSettings = require("../../constants/default-settings"); var _filterUtils = require("../../utils/filter-utils"); function _templateObject() { var data = (0, _taggedTemplateLiteral2["default"])(["\n ", ";\n\n max-height: 150px;\n overflow-y: auto;\n\n svg {\n text {\n font-size: 9px;\n fill: ", ";\n }\n }\n"]); _templateObject = function _templateObject() { return data; }; return data; } var ROW_H = 10; var GAP = 4; var RECT_W = 20; var StyledLegend = _styledComponents["default"].div(_templateObject(), function (props) { return props.theme.sidePanelScrollBar; }, function (props) { return props.theme.textColor; }); var defaultFormat = function defaultFormat(d) { return d; }; var getTimeLabelFormat = function getTimeLabelFormat(domain) { var formatter = (0, _filterUtils.getTimeWidgetHintFormatter)(domain); return function (val) { return _moment["default"].utc(val).format(formatter); }; }; var getNumericLabelFormat = function getNumericLabelFormat(domain) { var diff = domain[1] - domain[0]; if (diff < 10) { return (0, _d3Format.format)('.2f'); } return (0, _d3Format.format)('.1f'); }; var getQuantLabelFormat = function getQuantLabelFormat(domain, fieldType) { // quant scale can only be assigned to linear Fields: real, timestamp, integer return fieldType === _defaultSettings.ALL_FIELD_TYPES.timestamp ? getTimeLabelFormat(domain) : !fieldType ? defaultFormat : getNumericLabelFormat(domain); }; var getOrdinalLegends = function getOrdinalLegends(scale) { var domain = scale.domain(); return { data: domain.map(scale), labels: domain }; }; var getQuantLegends = function getQuantLegends(scale, labelFormat) { if (typeof scale.invertExtent !== 'function') { // only quantile, quantize, threshold scale has invertExtent method return { data: [], labels: [] }; } var labels = scale.range().map(function (d) { var invert = scale.invertExtent(d); return "".concat(labelFormat(invert[0]), " to ").concat(labelFormat(invert[1])); }); return { data: scale.range(), labels: labels }; }; var ColorLegend = /*#__PURE__*/ function (_Component) { (0, _inherits2["default"])(ColorLegend, _Component); function ColorLegend() { var _getPrototypeOf2; var _this; (0, _classCallCheck2["default"])(this, ColorLegend); 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"])(ColorLegend)).call.apply(_getPrototypeOf2, [this].concat(args))); (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "domainSelector", function (props) { return props.domain; }); (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "rangeSelector", function (props) { return props.range; }); (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "labelFormatSelector", function (props) { return props.labelFormat; }); (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "scaleTypeSelector", function (props) { return props.scaleType; }); (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "fieldTypeSelector", function (props) { return props.fieldType; }); (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "legendsSelector", (0, _reselect.createSelector)(_this.domainSelector, _this.rangeSelector, _this.scaleTypeSelector, _this.labelFormatSelector, _this.fieldTypeSelector, function (domain, range, scaleType, labelFormat, fieldType) { var scaleFunction = _defaultSettings.SCALE_FUNC[scaleType]; // color scale can only be quantize, quantile or ordinal var scale = scaleFunction().domain(domain).range(range); if (scaleType === _defaultSettings.SCALE_TYPES.ordinal) { return getOrdinalLegends(scale); } var formatLabel = labelFormat || getQuantLabelFormat(scale.domain(), fieldType); return getQuantLegends(scale, formatLabel); })); return _this; } (0, _createClass2["default"])(ColorLegend, [{ key: "render", value: function render() { var _this$props = this.props, width = _this$props.width, scaleType = _this$props.scaleType, domain = _this$props.domain, range = _this$props.range, _this$props$displayLa = _this$props.displayLabel, displayLabel = _this$props$displayLa === void 0 ? true : _this$props$displayLa; if (!domain || !range || !scaleType) { return null; } var legends = this.legendsSelector(this.props); var height = legends.data.length * (ROW_H + GAP); return _react["default"].createElement(StyledLegend, null, _react["default"].createElement("svg", { width: width - 24, height: height }, legends.data.map(function (color, idx) { return _react["default"].createElement(LegendRow, { key: idx, label: legends.labels[idx], displayLabel: displayLabel, color: color, idx: idx }); }))); } }]); return ColorLegend; }(_react.Component); exports["default"] = ColorLegend; (0, _defineProperty2["default"])(ColorLegend, "propTypes", { width: _propTypes["default"].number.isRequired, scaleType: _propTypes["default"].string, domain: _propTypes["default"].oneOfType([_propTypes["default"].array, _propTypes["default"].object]), fieldType: _propTypes["default"].string, range: _propTypes["default"].arrayOf(_propTypes["default"].string), labelFormat: _propTypes["default"].func }); var LegendRow = function LegendRow(_ref) { var _ref$label = _ref.label, label = _ref$label === void 0 ? '' : _ref$label, displayLabel = _ref.displayLabel, color = _ref.color, idx = _ref.idx; return _react["default"].createElement("g", { transform: "translate(0, ".concat(idx * (ROW_H + GAP), ")") }, _react["default"].createElement("rect", { width: RECT_W, height: ROW_H, style: { fill: color } }), _react["default"].createElement("text", { x: RECT_W + 8, y: ROW_H - 1 }, displayLabel ? label.toString() : '')); }; exports.LegendRow = LegendRow; //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9jb21wb25lbnRzL2NvbW1vbi9jb2xvci1sZWdlbmQuanMiXSwibmFtZXMiOlsiUk9XX0giLCJHQVAiLCJSRUNUX1ciLCJTdHlsZWRMZWdlbmQiLCJzdHlsZWQiLCJkaXYiLCJwcm9wcyIsInRoZW1lIiwic2lkZVBhbmVsU2Nyb2xsQmFyIiwidGV4dENvbG9yIiwiZGVmYXVsdEZvcm1hdCIsImQiLCJnZXRUaW1lTGFiZWxGb3JtYXQiLCJkb21haW4iLCJmb3JtYXR0ZXIiLCJ2YWwiLCJtb21lbnQiLCJ1dGMiLCJmb3JtYXQiLCJnZXROdW1lcmljTGFiZWxGb3JtYXQiLCJkaWZmIiwiZ2V0UXVhbnRMYWJlbEZvcm1hdCIsImZpZWxkVHlwZSIsIkFMTF9GSUVMRF9UWVBFUyIsInRpbWVzdGFtcCIsImdldE9yZGluYWxMZWdlbmRzIiwic2NhbGUiLCJkYXRhIiwibWFwIiwibGFiZWxzIiwiZ2V0UXVhbnRMZWdlbmRzIiwibGFiZWxGb3JtYXQiLCJpbnZlcnRFeHRlbnQiLCJyYW5nZSIsImludmVydCIsIkNvbG9yTGVnZW5kIiwic2NhbGVUeXBlIiwiZG9tYWluU2VsZWN0b3IiLCJyYW5nZVNlbGVjdG9yIiwic2NhbGVUeXBlU2VsZWN0b3IiLCJsYWJlbEZvcm1hdFNlbGVjdG9yIiwiZmllbGRUeXBlU2VsZWN0b3IiLCJzY2FsZUZ1bmN0aW9uIiwiU0NBTEVfRlVOQyIsIlNDQUxFX1RZUEVTIiwib3JkaW5hbCIsImZvcm1hdExhYmVsIiwid2lkdGgiLCJkaXNwbGF5TGFiZWwiLCJsZWdlbmRzIiwibGVnZW5kc1NlbGVjdG9yIiwiaGVpZ2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