@qn-pandora/pandora-visualization
Version:
Pandora 通用可视化库
229 lines (228 loc) • 10.7 kB
JavaScript
;
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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
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 __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var React = __importStar(require("react"));
var antd_1 = require("antd");
var mobx_react_1 = require("mobx-react");
var react_mapbox_gl_1 = require("react-mapbox-gl");
var bind_1 = __importDefault(require("../../../../utils/bind"));
var services_1 = require("../../../../services");
var type_1 = require("../../../../constants/language/base/type");
var constants_1 = require("../constants");
var base_1 = __importDefault(require("../base"));
var style = __importStar(require("./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(react_mapbox_gl_1.Marker, { key: coordinates.toString(), anchor: "bottom", coordinates: coordinates, onMouseEnter: this.clusterEnter.bind(this, coordinates, pointCount, getLeaves) },
React.createElement(antd_1.Tooltip, { title: this.renderPopup(), autoAdjustOverflow: true },
React.createElement("div", { className: style.clusterMarker }, pointCount))));
};
MapboxClusterChart.prototype.clusterEnter = function (coordinates, total, getLeaves) {
var leaves = getLeaves(constants_1.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, services_1.formatString(type_1.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(react_mapbox_gl_1.Marker, { key: key, anchor: "bottom", coordinates: feature.geometry.coordinates, "data-feature": feature, onMouseEnter: function () { return _this.markerEnter(feature); } },
React.createElement(antd_1.Tooltip, { title: _this.renderPopup(), autoAdjustOverflow: true },
React.createElement("div", { className: style.marker }, "1")))); });
};
MapboxClusterChart.prototype.render = function () {
return (React.createElement(base_1.default, __assign({}, this.props),
React.createElement(react_mapbox_gl_1.Cluster, { ClusterMarkerFactory: this.clusterMarker }, this.renderMarkers())));
};
__decorate([
bind_1.default,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Array, Number, Function]),
__metadata("design:returntype", void 0)
], MapboxClusterChart.prototype, "clusterMarker", null);
__decorate([
bind_1.default,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Array, Number, Function]),
__metadata("design:returntype", void 0)
], MapboxClusterChart.prototype, "clusterEnter", null);
__decorate([
bind_1.default,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], MapboxClusterChart.prototype, "markerEnter", null);
__decorate([
bind_1.default,
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], MapboxClusterChart.prototype, "getNameAndMetric", null);
__decorate([
bind_1.default,
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, String]),
__metadata("design:returntype", void 0)
], MapboxClusterChart.prototype, "isEmptyPopupDisplay", null);
__decorate([
bind_1.default,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object, Number]),
__metadata("design:returntype", void 0)
], MapboxClusterChart.prototype, "renderPopupItem", null);
__decorate([
bind_1.default,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object, Object]),
__metadata("design:returntype", void 0)
], MapboxClusterChart.prototype, "renderMarkerPopup", null);
__decorate([
bind_1.default,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object, Object]),
__metadata("design:returntype", void 0)
], MapboxClusterChart.prototype, "renderClusterPopup", null);
__decorate([
bind_1.default,
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], MapboxClusterChart.prototype, "renderPopup", null);
__decorate([
bind_1.default,
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], MapboxClusterChart.prototype, "renderMarkers", null);
MapboxClusterChart = __decorate([
mobx_react_1.observer
], MapboxClusterChart);
return MapboxClusterChart;
}(React.Component));
exports.default = MapboxClusterChart;