UNPKG

@qn-pandora/pandora-visualization

Version:

Pandora 通用可视化库

205 lines (204 loc) 9.37 kB
var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; import * as React from 'react'; import { Tooltip } from 'antd'; import { observer } from 'mobx-react'; import { Marker, Cluster } from 'react-mapbox-gl'; import bind from '../../../../utils/bind'; import { formatString } from '../../../../services'; import { BaseLocale } from '../../../../constants/language/base/type'; import { MAX_TOOLTIP_LINE } from '../constants'; import BaseMapboxChart from '../base'; import * as style from './style.mless'; var MapboxClusterChart = /** @class */ (function (_super) { __extends(MapboxClusterChart, _super); function MapboxClusterChart() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.store = _this.props.store; _this.state = { popup: undefined }; return _this; } MapboxClusterChart.prototype.clusterMarker = function (coordinates, pointCount, getLeaves) { return (React.createElement(Marker, { key: coordinates.toString(), anchor: "bottom", coordinates: coordinates, onMouseEnter: this.clusterEnter.bind(this, coordinates, pointCount, getLeaves) }, React.createElement(Tooltip, { title: this.renderPopup(), autoAdjustOverflow: true }, React.createElement("div", { className: style.clusterMarker }, pointCount)))); }; MapboxClusterChart.prototype.clusterEnter = function (coordinates, total, getLeaves) { var leaves = getLeaves(MAX_TOOLTIP_LINE); this.setState({ popup: { coordinates: coordinates, total: total, leaves: leaves } }); }; MapboxClusterChart.prototype.markerEnter = function (feature) { this.setState({ popup: { feature: feature } }); }; MapboxClusterChart.prototype.getNameAndMetric = function () { var chartStyleService = this.store.chartStyleService; var currentBuckets = chartStyleService.currentBuckets, currentMetrics = chartStyleService.currentMetrics; var name = currentBuckets.length ? currentBuckets[0] : ''; var metricName = currentMetrics.length ? currentMetrics[0] : ''; return { name: name, metricName: metricName }; }; MapboxClusterChart.prototype.isEmptyPopupDisplay = function (name, metricName) { return !name && !metricName; }; MapboxClusterChart.prototype.renderPopupItem = function (feature, index) { var unitTransformer = this.store.chartStyleService.unitTransformer; var _a = this.getNameAndMetric(), name = _a.name, metricName = _a.metricName; if (this.isEmptyPopupDisplay(name, metricName)) return null; var properties = feature.properties; return (React.createElement("div", { key: index }, name && React.createElement("span", null, properties[name]), metricName && (React.createElement("span", null, ": ", unitTransformer(properties[metricName]))))); }; MapboxClusterChart.prototype.renderMarkerPopup = function (popup, empty) { var popupItem = this.renderPopupItem(popup.feature, 0); return popupItem || empty; }; MapboxClusterChart.prototype.renderClusterPopup = function (popup, empty) { var _this = this; var popupItems = popup.leaves .map(function (leaf, index) { return _this.renderPopupItem(leaf.props['data-feature'], index); }) .filter(function (item) { return !!item; }); if (!popupItems.length) return empty; return (React.createElement("div", null, popupItems, popup.total > popup.leaves.length ? React.createElement("div", null, "...") : null)); }; MapboxClusterChart.prototype.renderPopup = function () { var popup = this.state.popup; if (!popup) return; var empty = React.createElement("div", null, formatString(BaseLocale.status.empty)); if (popup.feature) { return this.renderMarkerPopup(popup, empty); } return this.renderClusterPopup(popup, empty); }; MapboxClusterChart.prototype.renderMarkers = function () { var _this = this; var geojson = this.store.geojson; return geojson.features.map(function (feature, key) { return (React.createElement(Marker, { key: key, anchor: "bottom", coordinates: feature.geometry.coordinates, "data-feature": feature, onMouseEnter: function () { return _this.markerEnter(feature); } }, React.createElement(Tooltip, { title: _this.renderPopup(), autoAdjustOverflow: true }, React.createElement("div", { className: style.marker }, "1")))); }); }; MapboxClusterChart.prototype.render = function () { return (React.createElement(BaseMapboxChart, __assign({}, this.props), React.createElement(Cluster, { ClusterMarkerFactory: this.clusterMarker }, this.renderMarkers()))); }; __decorate([ bind, __metadata("design:type", Function), __metadata("design:paramtypes", [Array, Number, Function]), __metadata("design:returntype", void 0) ], MapboxClusterChart.prototype, "clusterMarker", null); __decorate([ bind, __metadata("design:type", Function), __metadata("design:paramtypes", [Array, Number, Function]), __metadata("design:returntype", void 0) ], MapboxClusterChart.prototype, "clusterEnter", null); __decorate([ bind, __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", void 0) ], MapboxClusterChart.prototype, "markerEnter", null); __decorate([ bind, __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", void 0) ], MapboxClusterChart.prototype, "getNameAndMetric", null); __decorate([ bind, __metadata("design:type", Function), __metadata("design:paramtypes", [String, String]), __metadata("design:returntype", void 0) ], MapboxClusterChart.prototype, "isEmptyPopupDisplay", null); __decorate([ bind, __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Number]), __metadata("design:returntype", void 0) ], MapboxClusterChart.prototype, "renderPopupItem", null); __decorate([ bind, __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object]), __metadata("design:returntype", void 0) ], MapboxClusterChart.prototype, "renderMarkerPopup", null); __decorate([ bind, __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object]), __metadata("design:returntype", void 0) ], MapboxClusterChart.prototype, "renderClusterPopup", null); __decorate([ bind, __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", void 0) ], MapboxClusterChart.prototype, "renderPopup", null); __decorate([ bind, __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", void 0) ], MapboxClusterChart.prototype, "renderMarkers", null); MapboxClusterChart = __decorate([ observer ], MapboxClusterChart); return MapboxClusterChart; }(React.Component)); export default MapboxClusterChart;