@qn-pandora/pandora-visualization
Version:
Pandora 通用可视化库
273 lines (272 loc) • 12.3 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 __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 mobx_1 = require("mobx");
var lodash_1 = require("lodash");
var moment_1 = __importDefault(require("moment"));
var bind_1 = __importDefault(require("../../../utils/bind"));
var normalizeTimeFormat_1 = require("../../../utils/normalizeTimeFormat");
var language_1 = __importStar(require("../../../services/language"));
var color_1 = require("../transforms/color");
var base_1 = __importDefault(require("../stores/base"));
var constants_1 = require("./constants");
require("moment/locale/zh-cn");
require("moment/locale/en-gb");
var Store = /** @class */ (function (_super) {
__extends(Store, _super);
function Store() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.timeline = null;
return _this;
}
Object.defineProperty(Store.prototype, "startFieldIndex", {
get: function () {
var _this = this;
var fields = this.dataset.fields;
return lodash_1.findIndex(fields, function (field) { return field.key === _this.chartStyleService.startField; });
},
enumerable: false,
configurable: true
});
Object.defineProperty(Store.prototype, "durationFieldIndex", {
get: function () {
var _this = this;
var fields = this.dataset.fields;
return lodash_1.findIndex(fields, function (field) { return field.key === _this.chartStyleService.durationField; });
},
enumerable: false,
configurable: true
});
Object.defineProperty(Store.prototype, "labelFieldIndex", {
get: function () {
var _this = this;
var fields = this.dataset.fields;
return lodash_1.findIndex(fields, function (field) { return field.key === _this.chartStyleService.labelField; });
},
enumerable: false,
configurable: true
});
Object.defineProperty(Store.prototype, "chartDataset", {
get: function () {
var _this = this;
var _a = this.dataset, fields = _a.fields, rows = _a.rows;
var startField = fields[this.startFieldIndex];
var durationField = fields[this.durationFieldIndex];
var labelField = fields[this.labelFieldIndex];
if (!startField || !labelField) {
return {
fields: [],
rows: []
};
}
if (!durationField) {
return {
fields: [startField, labelField],
rows: rows.map(function (line) { return [
line[_this.startFieldIndex],
line[_this.labelFieldIndex]
]; })
};
}
return {
fields: [startField, durationField, labelField],
rows: rows.map(function (line) { return [
line[_this.startFieldIndex],
line[_this.durationFieldIndex],
line[_this.labelFieldIndex]
]; })
};
},
enumerable: false,
configurable: true
});
Object.defineProperty(Store.prototype, "options", {
get: function () {
var locale = language_1.default.locale === language_1.Locale.enUS ? 'en-gb' : 'zh-cn';
var _a = this.chartStyleService, axisPosition = _a.axisPosition, minZoom = _a.minZoom, maxZoom = _a.maxZoom;
var minItem = lodash_1.minBy(this.items, function (item) { return moment_1.default(item.start).valueOf(); });
var maxItem = lodash_1.maxBy(this.items, function (item) {
return item.end ? moment_1.default(item.end).valueOf() : moment_1.default(item.start).valueOf();
});
this.items.map(function (item) { return item.start; });
return {
groupOrder: 'order',
width: '100%',
height: '100%',
stack: true,
showCurrentTime: false,
limitSize: true,
horizontalScroll: true,
verticalScroll: true,
zoomKey: 'ctrlKey',
orientation: {
axis: axisPosition,
item: 'top'
},
showTooltips: true,
tooltip: {
followMouse: true,
delay: 100,
overflowMethod: 'flip',
template: this.templateFormat
},
moment: function (date) {
return moment_1.default(date).locale(locale).utcOffset(8);
},
zoomMin: constants_1.ZoomTypeToMs[minZoom] || 10,
zoomMax: constants_1.ZoomTypeToMs[maxZoom] || constants_1.ZoomTypeToMs["year" /* Year */],
start: minItem
? moment_1.default(minItem.start)
: normalizeTimeFormat_1.normalizeTimeFormat(moment_1.default().subtract(1, 'days').valueOf()),
end: maxItem
? maxItem.end
? moment_1.default(maxItem.end)
: moment_1.default(maxItem.start)
: normalizeTimeFormat_1.normalizeTimeFormat(moment_1.default().valueOf())
};
},
enumerable: false,
configurable: true
});
Object.defineProperty(Store.prototype, "items", {
get: function () {
var _this = this;
var dataSize = this.chartStyleService.dataSize;
var _a = this.dataset, fields = _a.fields, rows = _a.rows;
var startField = fields[this.startFieldIndex];
var durationField = fields[this.durationFieldIndex];
var labelField = fields[this.labelFieldIndex];
if (!startField || !labelField) {
return [];
}
return rows.slice(0, dataSize).map(function (line, index) {
var duration = lodash_1.get(line, [_this.durationFieldIndex, 0]);
var content = lodash_1.toString(lodash_1.get(line, [_this.labelFieldIndex, 0]));
var start = moment_1.default((lodash_1.get(line, [_this.startFieldIndex, 0]) || 0));
var end = durationField && duration
? moment_1.default(moment_1.default(start).valueOf() + (lodash_1.toNumber(duration) || 0) * 1000)
: null;
return {
id: index,
title: content,
content: content.length > 30 ? content.slice(0, 30) + "..." : content,
start: start,
end: end
};
});
},
enumerable: false,
configurable: true
});
Object.defineProperty(Store.prototype, "itemStyle", {
get: function () {
var eventBackGround = this.chartStyleService.eventBackGround;
var timelineOpts = lodash_1.get(this.themeOption, 'timeline');
var background = eventBackGround || lodash_1.get(timelineOpts, 'eventBackGround');
var rgba = color_1.toRgbaObj(background);
return {
chartBackGround: lodash_1.get(timelineOpts, 'chartBackGround'),
background: "rgba(" + rgba.r + "," + rgba.g + "," + rgba.b + ", 0.5)",
borderColor: background,
color: background
};
},
enumerable: false,
configurable: true
});
Store.prototype.templateFormat = function (params) {
var start = params.start, end = params.end, title = params.title;
var startText = "\n <span style=\"font-size: 12px; display: inline-block; margin-bottom: 3px;\">" + normalizeTimeFormat_1.normalizeTimeFormat(start) + "</span><br />";
var endText = end
? "\n <span style=\"font-size: 12px; display: inline-block; margin-bottom: 3px;\">" + normalizeTimeFormat_1.normalizeTimeFormat(end) + "</span><br />"
: '';
var contentText = "<span style=\"font-size: 12px; display: inline-block; margin-bottom: 3px;word-wrap:break-word;white-space:pre-wrap;\">" + title + "</span>";
return "" + startText + endText + contentText;
};
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], Store.prototype, "startFieldIndex", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], Store.prototype, "durationFieldIndex", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], Store.prototype, "labelFieldIndex", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], Store.prototype, "chartDataset", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], Store.prototype, "options", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], Store.prototype, "items", null);
__decorate([
mobx_1.computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], Store.prototype, "itemStyle", null);
__decorate([
bind_1.default,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], Store.prototype, "templateFormat", null);
return Store;
}(base_1.default));
exports.default = Store;