@qn-pandora/pandora-visualization
Version:
Pandora 通用可视化库
174 lines (173 loc) • 7.72 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 __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 _ from 'lodash';
import { computed } from 'mobx';
import RelationBaseChartStore from '../stores/relation-base';
import { formatString } from '../../../services/language';
import { BaseLocale } from '../../../constants/language/base/type';
import { hasRing, transformSankeyData } from './utils';
import bind from '../../../utils/bind';
import { ESankeyMode } from '../../../constants/chart-style';
import { RelationChartDrillDownService } from '../../../services/chart-drill-down';
import { RelationChartActionService } from '../../../services/chart-common-action';
var SankeyChartStore = /** @class */ (function (_super) {
__extends(SankeyChartStore, _super);
function SankeyChartStore() {
return _super !== null && _super.apply(this, arguments) || this;
}
Object.defineProperty(SankeyChartStore.prototype, "options", {
get: function () {
var _this = this;
return {
tooltip: {
padding: [4, 8],
trigger: 'item',
triggerOn: 'mousemove',
formatter: function (params) {
if (params.data === undefined) {
return formatString(BaseLocale.status.empty);
}
if (params.dataType === 'node') {
return;
}
var unitTransformer = _this.chartStyleService.unitTransformer;
return "\n <span style=\"font-size: 14px; display: inline-block; margin-bottom: 3px;\">" + params.data.title + "</span> <br/>\n <span style=\"font-size: 12px;color:#2c6dd2;\">\n <span >" + _this.metricDisplayName + ":</span> " + unitTransformer(params.data.size) + "\n </span>";
}
},
polar: {},
radiusAxis: {
show: false
},
angleAxis: {
type: 'value',
show: false
},
legend: { show: false },
series: [this.generateSery()]
};
},
enumerable: false,
configurable: true
});
Object.defineProperty(SankeyChartStore.prototype, "hasRing", {
get: function () {
var _a = this.datas, nodes = _a.nodes, links = _a.links;
return hasRing(nodes, links);
},
enumerable: false,
configurable: true
});
Object.defineProperty(SankeyChartStore.prototype, "datas", {
get: function () {
var _a = this.chartStyleService, currentBuckets = _a.currentBuckets, mode = _a.mode;
return transformSankeyData(currentBuckets, this.dataset, mode, this.metricIndex);
},
enumerable: false,
configurable: true
});
SankeyChartStore.prototype.generateSery = function () {
var _a = this.datas, nodes = _a.nodes, links = _a.links;
var sankeyColor = _.get(this.themeOption, ['sankey', 'color']);
var defaultColor = sankeyColor && sankeyColor.length
? sankeyColor
: _.get(this.themeOption, 'color');
return {
type: 'sankey',
data: nodes.map(function (node, index) {
return __assign(__assign({}, node), { itemStyle: {
color: defaultColor[index % defaultColor.length]
} });
}),
links: links,
focusNodeAdjacency: true,
draggable: false,
label: {
normal: {
formatter: function (params) { return params.data.displayName; }
}
},
lineStyle: {
normal: {
color: 'source',
opacity: 0.4,
curveness: 0.5
}
}
};
};
SankeyChartStore.prototype.handleDrillDown = function (params) {
if (params.dataType !== 'edge') {
return;
}
var _a = this.chartStyleService, currentBuckets = _a.currentBuckets, mode = _a.mode;
var fromBucket = _.get(params, ['data', 'fromBucket']) || '';
var toBucket = _.get(params, ['data', 'toBucket']) || '';
this.onAction({
fromField: fromBucket,
toField: toBucket,
fromFieldValue: currentBuckets.length === 2 && mode === ESankeyMode.Multistage
? _.get(params, ['data', 'source'])
: _.get(params, ['data', 'source']).replace(fromBucket + "-", ''),
toFieldValue: currentBuckets.length === 2 && mode === ESankeyMode.Multistage
? _.get(params, ['data', 'target'])
: _.get(params, ['data', 'target']).replace(toBucket + "-", ''),
metricValue: _.get(params, 'value'),
fields: this.fields,
metricField: _.get(this.chartStyleService.currentMetrics, 0)
}, RelationChartDrillDownService, RelationChartActionService);
};
__decorate([
computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], SankeyChartStore.prototype, "options", null);
__decorate([
computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], SankeyChartStore.prototype, "hasRing", null);
__decorate([
computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], SankeyChartStore.prototype, "datas", null);
__decorate([
bind,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], SankeyChartStore.prototype, "handleDrillDown", null);
return SankeyChartStore;
}(RelationBaseChartStore));
export default SankeyChartStore;