@qn-pandora/pandora-visualization
Version:
Pandora 通用可视化库
249 lines (248 loc) • 10.8 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 __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 { computed } from 'mobx';
import { get, findIndex, maxBy, minBy, toString, toNumber } from 'lodash';
import moment from 'moment';
import bind from '../../../utils/bind';
import { normalizeTimeFormat } from '../../../utils/normalizeTimeFormat';
import languageService, { Locale } from '../../../services/language';
import { toRgbaObj } from '../transforms/color';
import BaseChartStore from '../stores/base';
import { ZoomTypeToMs } from './constants';
import 'moment/locale/zh-cn';
import '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 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 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 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 = languageService.locale === Locale.enUS ? 'en-gb' : 'zh-cn';
var _a = this.chartStyleService, axisPosition = _a.axisPosition, minZoom = _a.minZoom, maxZoom = _a.maxZoom;
var minItem = minBy(this.items, function (item) { return moment(item.start).valueOf(); });
var maxItem = maxBy(this.items, function (item) {
return item.end ? moment(item.end).valueOf() : moment(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(date).locale(locale).utcOffset(8);
},
zoomMin: ZoomTypeToMs[minZoom] || 10,
zoomMax: ZoomTypeToMs[maxZoom] || ZoomTypeToMs["year" /* Year */],
start: minItem
? moment(minItem.start)
: normalizeTimeFormat(moment().subtract(1, 'days').valueOf()),
end: maxItem
? maxItem.end
? moment(maxItem.end)
: moment(maxItem.start)
: normalizeTimeFormat(moment().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 = get(line, [_this.durationFieldIndex, 0]);
var content = toString(get(line, [_this.labelFieldIndex, 0]));
var start = moment((get(line, [_this.startFieldIndex, 0]) || 0));
var end = durationField && duration
? moment(moment(start).valueOf() + (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 = get(this.themeOption, 'timeline');
var background = eventBackGround || get(timelineOpts, 'eventBackGround');
var rgba = toRgbaObj(background);
return {
chartBackGround: 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(start) + "</span><br />";
var endText = end
? "\n <span style=\"font-size: 12px; display: inline-block; margin-bottom: 3px;\">" + 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([
computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], Store.prototype, "startFieldIndex", null);
__decorate([
computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], Store.prototype, "durationFieldIndex", null);
__decorate([
computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], Store.prototype, "labelFieldIndex", null);
__decorate([
computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], Store.prototype, "chartDataset", null);
__decorate([
computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], Store.prototype, "options", null);
__decorate([
computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], Store.prototype, "items", null);
__decorate([
computed,
__metadata("design:type", Object),
__metadata("design:paramtypes", [])
], Store.prototype, "itemStyle", null);
__decorate([
bind,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], Store.prototype, "templateFormat", null);
return Store;
}(BaseChartStore));
export default Store;