UNPKG

@qn-pandora/pandora-visualization

Version:

Pandora 通用可视化库

377 lines (376 loc) 15.7 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); }; var __read = (this && this.__read) || function (o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; }; import * as _ from 'lodash'; import { computed } from 'mobx'; import RelationBaseChartStore from '../stores/relation-base'; import { BaseLocale } from '../../../constants/language/base/type'; import { RelationLocale } from '../../../constants/language/relation/type'; import { MapLocale } from '../../../constants/language/map/type'; import { formatString } from '../../../services/language'; import bind from '../../../utils/bind'; import { RelationChartDrillDownService } from '../../../services/chart-drill-down'; import { RelationChartActionService } from '../../../services/chart-common-action'; import { ESizeType } from '../../../constants/chart-style'; import { EGeoLevel } from '../../../constants/map-style'; import { MapType } from '../constants/map/map'; import { getMapPosition } from '../transforms/map-chart'; import { getTooltip } from './constants'; var MigrationChartStore = /** @class */ (function (_super) { __extends(MigrationChartStore, _super); function MigrationChartStore() { return _super !== null && _super.apply(this, arguments) || this; } Object.defineProperty(MigrationChartStore.prototype, "relationRange", { get: function () { var relationSizes = this.datas.relations.map(function (r) { return r.size; }); return { max: _.max(relationSizes) || 0, min: _.min(relationSizes) || 0 }; }, enumerable: false, configurable: true }); Object.defineProperty(MigrationChartStore.prototype, "containCitySansha", { get: function () { var geoLevel = this.chartStyleService.geoLevel; return (this.mapType === MapType.China && geoLevel === EGeoLevel.CITY && !!this.datas.citys.filter(function (data) { return data.name === formatString(MapLocale.city.sansha); }).length); }, enumerable: false, configurable: true }); Object.defineProperty(MigrationChartStore.prototype, "geoLevalType", { get: function () { var geoLevel = this.chartStyleService.geoLevel; switch (this.mapType) { case MapType.China: switch (geoLevel) { case EGeoLevel.AREA: return "area" /* AREA */; case EGeoLevel.CITY: return "city" /* CITY */; default: return "province" /* PROVINCE */; } default: return "world" /* WORLD */; } }, enumerable: false, configurable: true }); Object.defineProperty(MigrationChartStore.prototype, "map", { get: function () { return this.geoLevalType === "province" /* PROVINCE */ ? MapType.China : this.geoLevalType === "city" /* CITY */ && this.containCitySansha ? EGeoLevel.CITYMax : this.geoLevalType; }, enumerable: false, configurable: true }); Object.defineProperty(MigrationChartStore.prototype, "mapPosition", { get: function () { return getMapPosition(this.mapType, this.chartHeight, this.chartWidth); }, enumerable: false, configurable: true }); Object.defineProperty(MigrationChartStore.prototype, "defaultColors", { get: function () { return (_.get(this.themeOption, ['effectScatter', 'color']) || this.themeOption.color); }, enumerable: false, configurable: true }); Object.defineProperty(MigrationChartStore.prototype, "gradientColor", { get: function () { var gradientColor = this.chartStyleService.gradientColor; return gradientColor.length > 0 ? gradientColor : _.get(this.themeOption, ['effectScatter', 'selectColors']); }, enumerable: false, configurable: true }); Object.defineProperty(MigrationChartStore.prototype, "options", { get: function () { var _this = this; var _a = this.relationRange, max = _a.max, min = _a.min; var unitTransformer = this.chartStyleService.unitTransformer; return { tooltip: { padding: [4, 8], trigger: 'item', position: function (_point, _params, dom) { dom.style.transform = 'translateZ(0)'; }, formatter: function (params) { var _a, _b; if (params.data === undefined) { return formatString(BaseLocale.status.empty); } if (params.seriesType === 'effectScatter') { return getTooltip(params.data.title, (_a = {}, _a[formatString(RelationLocale.inflow_text)] = unitTransformer(params.data.inflowSize), _a[formatString(RelationLocale.outflow_text)] = unitTransformer(params.data.outflowSize), _a)); } return getTooltip(params.data.title, (_b = {}, _b[_this.metricDisplayName] = unitTransformer(params.data.size), _b)); } }, visualMap: { calculable: true, show: max !== min, inRange: { color: this.gradientColor }, textStyle: { color: '#7a869a' }, formatter: function (val) { return unitTransformer(val); }, max: max, min: min }, geo: __assign(__assign({ map: this.map }, this.mapPosition), { label: { emphasis: { show: false } }, roam: true, scaleLimit: { min: 1, max: 4 }, silent: true }), legend: { show: false }, series: this.generateSeries() }; }, enumerable: false, configurable: true }); Object.defineProperty(MigrationChartStore.prototype, "symbolSize", { get: function () { var citys = this.datas.citys; var outflowSizes = citys.map(function (c) { return c.outflowSize; }); // 计算所有城市的最大最小流出量,方便后续进行bubbleMaxSize,bubbleMinSize的换算 var cityMaxSize = _.max(outflowSizes) || 0; var cityMinSize = _.min(outflowSizes) || 0; var _a = this.chartStyleService, bubbleMaxSize = _a.bubbleMaxSize, bubbleMinSize = _a.bubbleMinSize, sizeType = _a.sizeType, maxDiameter = _a.maxDiameter, minDiameter = _a.minDiameter; return function (_, param) { var maxVal = sizeType === ESizeType.Dynamic ? cityMaxSize || 0 : maxDiameter || maxDiameter === 0 ? maxDiameter : minDiameter || 0; var minVal = sizeType === ESizeType.Dynamic ? cityMinSize || 0 : minDiameter || minDiameter === 0 ? minDiameter : maxDiameter || 0; if (maxVal - minVal) { var interval = (bubbleMaxSize - bubbleMinSize) / (maxVal - minVal); return bubbleMinSize + (param.data.outflowSize - minVal) * interval; } if (!(maxVal - minVal)) { return bubbleMinSize; } }; }, enumerable: false, configurable: true }); MigrationChartStore.prototype.generateSeries = function () { var _this = this; var _a = this.chartStyleService, inflowColor = _a.inflowColor, outflowColor = _a.outflowColor; var _b = this.datas, citys = _b.citys, relations = _b.relations; return [ { type: 'lines', zlevel: 1, coordinateSystem: 'geo', symbol: ['none', 'none'], lineStyle: { normal: { opacity: 0.4, width: 2, curveness: 0.3 } }, data: relations }, { type: 'lines', zlevel: 2, coordinateSystem: 'geo', symbol: ['none', 'none'], effect: { show: true, constantSpeed: 20, trailLength: 0.2, symbolSize: 2.5 }, lineStyle: { normal: { width: 0, curveness: 0.3 } }, silent: true, data: relations }, { type: 'effectScatter', zlevel: 3, coordinateSystem: 'geo', data: citys.map(function (city) { var color = city.inflowSize > city.outflowSize ? inflowColor || _this.defaultColors[0] : outflowColor || _this.defaultColors[1]; return __assign(__assign({}, city), { itemStyle: { color: color, borderColor: color } }); }), symbol: 'circle', symbolSize: this.symbolSize, hoverAnimation: true, rippleEffect: { brushType: 'stroke' }, label: { normal: { formatter: function (params) { return params.data.title; }, position: 'right', show: true } }, itemStyle: { normal: { borderWidth: 1, shadowColor: 'rgba(0,0,0,.2)', shadowBlur: 4 } } } ]; }; MigrationChartStore.prototype.handleDrillDown = function (params) { if (params.seriesType !== 'lines') { return; } var _a = __read(_.split(_.get(params, ['data', 'title']), ' -> '), 2), fromFieldValue = _a[0], toFieldValue = _a[1]; this.onAction({ fromField: _.get(this.chartStyleService.currentBuckets, 0), toField: _.get(this.chartStyleService.currentBuckets, 1), fromFieldValue: fromFieldValue, toFieldValue: toFieldValue, metricField: _.get(this.chartStyleService.currentMetrics, 0), metricValue: _.get(params, 'value'), fields: this.fields }, RelationChartDrillDownService, RelationChartActionService); }; __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], MigrationChartStore.prototype, "relationRange", null); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], MigrationChartStore.prototype, "containCitySansha", null); __decorate([ computed, __metadata("design:type", String), __metadata("design:paramtypes", []) ], MigrationChartStore.prototype, "geoLevalType", null); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], MigrationChartStore.prototype, "map", null); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], MigrationChartStore.prototype, "mapPosition", null); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], MigrationChartStore.prototype, "defaultColors", null); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], MigrationChartStore.prototype, "gradientColor", null); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], MigrationChartStore.prototype, "options", null); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], MigrationChartStore.prototype, "symbolSize", null); __decorate([ bind, __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", void 0) ], MigrationChartStore.prototype, "handleDrillDown", null); return MigrationChartStore; }(RelationBaseChartStore)); export default MigrationChartStore;