@qn-pandora/pandora-visualization
Version:
Pandora 通用可视化库
401 lines (400 loc) • 17.1 kB
JavaScript
"use strict";
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 __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;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var _ = __importStar(require("lodash"));
var mobx_1 = require("mobx");
var relation_base_1 = __importDefault(require("../stores/relation-base"));
var type_1 = require("../../../constants/language/base/type");
var type_2 = require("../../../constants/language/relation/type");
var type_3 = require("../../../constants/language/map/type");
var language_1 = require("../../../services/language");
var bind_1 = __importDefault(require("../../../utils/bind"));
var chart_drill_down_1 = require("../../../services/chart-drill-down");
var chart_common_action_1 = require("../../../services/chart-common-action");
var chart_style_1 = require("../../../constants/chart-style");
var map_style_1 = require("../../../constants/map-style");
var map_1 = require("../constants/map/map");
var map_chart_1 = require("../transforms/map-chart");
var constants_1 = require("./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 === map_1.MapType.China &&
geoLevel === map_style_1.EGeoLevel.CITY &&
!!this.datas.citys.filter(function (data) { return data.name === language_1.formatString(type_3.MapLocale.city.sansha); }).length);
},
enumerable: false,
configurable: true
});
Object.defineProperty(MigrationChartStore.prototype, "geoLevalType", {
get: function () {
var geoLevel = this.chartStyleService.geoLevel;
switch (this.mapType) {
case map_1.MapType.China:
switch (geoLevel) {
case map_style_1.EGeoLevel.AREA:
return "area" /* AREA */;
case map_style_1.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 */
? map_1.MapType.China
: this.geoLevalType === "city" /* CITY */ && this.containCitySansha
? map_style_1.EGeoLevel.CITYMax
: this.geoLevalType;
},
enumerable: false,
configurable: true
});
Object.defineProperty(MigrationChartStore.prototype, "mapPosition", {
get: function () {
return map_chart_1.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 language_1.formatString(type_1.BaseLocale.status.empty);
}
if (params.seriesType === 'effectScatter') {
return constants_1.getTooltip(params.data.title, (_a = {},
_a[language_1.formatString(type_2.RelationLocale.inflow_text)] = unitTransformer(params.data.inflowSize),
_a[language_1.formatString(type_2.RelationLocale.outflow_text)] = unitTransformer(params.data.outflowSize),
_a));
}
return constants_1.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 === chart_style_1.ESizeType.Dynamic
? cityMaxSize || 0
: maxDiameter || maxDiameter === 0
? maxDiameter
: minDiameter || 0;
var minVal = sizeType === chart_style_1.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
}, chart_drill_down_1.RelationChartDrillDownService, chart_common_action_1.RelationChartActionService);
};
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], MigrationChartStore.prototype, "relationRange", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], MigrationChartStore.prototype, "containCitySansha", null);
__decorate([
mobx_1.computed,
__metadata("design:type", String),
__metadata("design:paramtypes", [])
], MigrationChartStore.prototype, "geoLevalType", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], MigrationChartStore.prototype, "map", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], MigrationChartStore.prototype, "mapPosition", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], MigrationChartStore.prototype, "defaultColors", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], MigrationChartStore.prototype, "gradientColor", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], MigrationChartStore.prototype, "options", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], MigrationChartStore.prototype, "symbolSize", null);
__decorate([
bind_1.default,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], MigrationChartStore.prototype, "handleDrillDown", null);
return MigrationChartStore;
}(relation_base_1.default));
exports.default = MigrationChartStore;