UNPKG

@qn-pandora/pandora-visualization

Version:

Pandora 通用可视化库

407 lines (406 loc) 16.8 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; }; var __spread = (this && this.__spread) || function () { for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); return ar; }; import { computed, action, observable } from 'mobx'; import { keys, get, set, isNil, cloneDeep, sortBy, isUndefined } from 'lodash'; import { EChartConditionType } from '@qn-pandora/app-sdk'; import bind from '../../../../../utils/bind'; import { DefaultColumnSuffix, FilterColumnKeys, InitTitleFont, DEFAULT_AUTO_PLAY_SPEED } from '../../../../../constants/table-style'; import { SparkLineChartType } from '../../../../../constants/sparkline'; import Compare from '../../../chart-style/components/compare'; import SparkLineConfig from '../../../chart-style/components/sparkline'; import ChartStyleService, { styleOption } from '../base'; var TableChartStyleService = /** @class */ (function (_super) { __extends(TableChartStyleService, _super); function TableChartStyleService(option) { var _this = _super.call(this, option) || this; // table 的列配置项, _this._filterColumns = []; _this.textDisplayMode = "omit" /* Omit */; _this.pagination = true; _this.tablePageSize = 10; // 原始数据的列 _this.columns = []; // 原始数据的源数据 _this.dataSource = []; _this.tableTitleFont = InitTitleFont; _this.tableTitleBgColor = ''; _this.scroll = false; _this.autoplaySpeed = DEFAULT_AUTO_PLAY_SPEED; _this.textDisplayMode = option.textDisplayMode || "omit" /* Omit */; _this._filterColumns = option.filterColumns || []; _this.pagination = isUndefined(option.pagination) ? true : option.pagination; _this.tablePageSize = option.tablePageSize || 10; _this.compare = new Compare(option.compare || { method: "none" /* None */ }); _this.columns = option.columns || []; _this.dataSource = option.dataSource || []; _this.sparkline = new SparkLineConfig(option.sparkline || { type: SparkLineChartType.Line }); _this.bordered = option.bordered; _this.tableTitleFont = option.tableTitleFont || InitTitleFont; _this.tableTitleBgColor = option.tableTitleBgColor; _this.scroll = isUndefined(option.scroll) ? false : option.scroll; return _this; } TableChartStyleService.getChartInitStyle = function (options) { return options; }; Object.defineProperty(TableChartStyleService.prototype, "hasSparkline", { get: function () { return this.columns.find(function (col) { return col.type === EChartConditionType.SparkLine; }); }, enumerable: false, configurable: true }); Object.defineProperty(TableChartStyleService.prototype, "hasColumnsConfig", { // 是否有列配置 get: function () { return !!this._filterColumns.length; }, enumerable: false, configurable: true }); Object.defineProperty(TableChartStyleService.prototype, "filterColumns", { // 样式表单里供设置的列 get: function () { var _this = this; if (!this.columns.length) return this._filterColumns; var columnsConfig = __spread(this._filterColumns); // 如果没有配置项 var columns = cloneDeep(this.columns); columns = this.sortColByConfigCol(columns, columnsConfig); // 为所有的columns设置一些默认属性 columns.forEach(this.initDefaultColumn); // 将配置还原到columns中 columns.forEach(function (column) { var columnConfig = columnsConfig.find(function (config) { return config.dataIndex === column.dataIndex; }); if (columnConfig) { FilterColumnKeys.forEach(function (key) { _this.setColumnConfig(column, columnConfig, key); }); } }); return columns; }, enumerable: false, configurable: true }); TableChartStyleService.prototype.setColumnConfig = function (columnItem, confItem, key) { if (!isNil(confItem[key])) { columnItem[key] = confItem[key]; } }; TableChartStyleService.prototype.getOptions = function () { var sparklineOption = this.hasSparkline ? { sparkline: this.sparkline.option } : {}; var filterColumns = this._filterColumns.length === 0 ? [] : this.filterColumns; return __assign({ chartType: this.chartType, textDisplayMode: this.textDisplayMode, filterColumns: filterColumns, pagination: this.pagination, tablePageSize: this.tablePageSize, compare: this.compare.option, bordered: this.bordered, tableTitleFont: this.tableTitleFont, tableTitleBgColor: this.tableTitleBgColor, scroll: this.scroll, autoplaySpeed: this.autoplaySpeed }, sparklineOption); }; Object.defineProperty(TableChartStyleService.prototype, "contextOption", { get: function () { return __assign(__assign({}, this.getOptions()), { metrics: [], buckets: [], filterColumns: [] }); }, enumerable: false, configurable: true }); // 按照columnConfig中的顺序排序columns TableChartStyleService.prototype.sortColByConfigCol = function (columns, columnsConfig) { return sortBy(columns, function (item) { var index = columnsConfig .map(function (col) { return col.dataIndex; }) .indexOf(item.dataIndex); return index === -1 ? undefined : index; }); }; TableChartStyleService.prototype.initDefaultColumn = function (col) { if (isNil(col.isNumeric)) { col.isNumeric = col.type === 'metric'; } keys(DefaultColumnSuffix).map(function (key) { if (isNil(get(col, key))) { set(col, key, get(DefaultColumnSuffix, key)); } }); }; TableChartStyleService.prototype.setPagination = function (pagination) { this.pagination = pagination; }; TableChartStyleService.prototype.setTablePageSize = function (tablePageSize) { this.tablePageSize = tablePageSize; }; TableChartStyleService.prototype.setTextDisplayMode = function (textDisplayMode) { this.textDisplayMode = textDisplayMode; }; TableChartStyleService.prototype.setFilterColumns = function (filterColumns) { this._filterColumns = filterColumns; }; TableChartStyleService.prototype.setColumns = function (columns) { if (columns === void 0) { columns = []; } this.columns = columns; }; TableChartStyleService.prototype.setDataSource = function (data) { if (data === void 0) { data = []; } this.dataSource = data; }; TableChartStyleService.prototype.setBordered = function (bordered) { this.bordered = bordered; }; TableChartStyleService.prototype.setTableTitleFont = function (tableTitleFont) { this.tableTitleFont = tableTitleFont; }; TableChartStyleService.prototype.setTableTitleBgColor = function (tableTitleBgColor) { this.tableTitleBgColor = tableTitleBgColor; }; TableChartStyleService.prototype.setScroll = function (scroll) { this.scroll = scroll; if (scroll) { this.pagination = false; } }; TableChartStyleService.prototype.setAutoplaySpeed = function (autoplaySpeed) { this.autoplaySpeed = autoplaySpeed; }; TableChartStyleService.prototype.set = function (key, value) { var _this = this; _super.prototype.set.call(this, key, value); if (typeof key !== 'object') { return; } var allowNil = !!value; var obj = key; this.executeFieldHandlers(obj, [ { field: 'compare', handler: function (compare) { _this.compare.set(compare); } }, { field: 'filterColumns', handler: this.setFilterColumns } ], allowNil); }; __decorate([ observable.ref, __metadata("design:type", Array) ], TableChartStyleService.prototype, "_filterColumns", void 0); __decorate([ styleOption(), __metadata("design:type", String) ], TableChartStyleService.prototype, "textDisplayMode", void 0); __decorate([ styleOption(), __metadata("design:type", Boolean) ], TableChartStyleService.prototype, "pagination", void 0); __decorate([ styleOption(), __metadata("design:type", Number) ], TableChartStyleService.prototype, "tablePageSize", void 0); __decorate([ styleOption(), __metadata("design:type", Array) ], TableChartStyleService.prototype, "columns", void 0); __decorate([ styleOption(), __metadata("design:type", Array) ], TableChartStyleService.prototype, "dataSource", void 0); __decorate([ styleOption(), __metadata("design:type", Boolean) ], TableChartStyleService.prototype, "bordered", void 0); __decorate([ styleOption(), __metadata("design:type", Object) ], TableChartStyleService.prototype, "tableTitleFont", void 0); __decorate([ styleOption(), __metadata("design:type", String) ], TableChartStyleService.prototype, "tableTitleBgColor", void 0); __decorate([ styleOption(), __metadata("design:type", Boolean) ], TableChartStyleService.prototype, "scroll", void 0); __decorate([ styleOption(), __metadata("design:type", Number) ], TableChartStyleService.prototype, "autoplaySpeed", void 0); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], TableChartStyleService.prototype, "hasSparkline", null); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], TableChartStyleService.prototype, "hasColumnsConfig", null); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], TableChartStyleService.prototype, "filterColumns", null); __decorate([ bind, __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object, String]), __metadata("design:returntype", void 0) ], TableChartStyleService.prototype, "setColumnConfig", null); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], TableChartStyleService.prototype, "contextOption", null); __decorate([ bind, __metadata("design:type", Function), __metadata("design:paramtypes", [Array, Array]), __metadata("design:returntype", void 0) ], TableChartStyleService.prototype, "sortColByConfigCol", null); __decorate([ bind, __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", void 0) ], TableChartStyleService.prototype, "initDefaultColumn", null); __decorate([ bind, action, __metadata("design:type", Function), __metadata("design:paramtypes", [Boolean]), __metadata("design:returntype", void 0) ], TableChartStyleService.prototype, "setPagination", null); __decorate([ bind, action, __metadata("design:type", Function), __metadata("design:paramtypes", [Number]), __metadata("design:returntype", void 0) ], TableChartStyleService.prototype, "setTablePageSize", null); __decorate([ bind, action, __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", void 0) ], TableChartStyleService.prototype, "setTextDisplayMode", null); __decorate([ bind, action, __metadata("design:type", Function), __metadata("design:paramtypes", [Array]), __metadata("design:returntype", void 0) ], TableChartStyleService.prototype, "setFilterColumns", null); __decorate([ bind, action, __metadata("design:type", Function), __metadata("design:paramtypes", [Array]), __metadata("design:returntype", void 0) ], TableChartStyleService.prototype, "setColumns", null); __decorate([ bind, action, __metadata("design:type", Function), __metadata("design:paramtypes", [Array]), __metadata("design:returntype", void 0) ], TableChartStyleService.prototype, "setDataSource", null); __decorate([ bind, action, __metadata("design:type", Function), __metadata("design:paramtypes", [Boolean]), __metadata("design:returntype", void 0) ], TableChartStyleService.prototype, "setBordered", null); __decorate([ bind, action, __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", void 0) ], TableChartStyleService.prototype, "setTableTitleFont", null); __decorate([ bind, action, __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", void 0) ], TableChartStyleService.prototype, "setTableTitleBgColor", null); __decorate([ bind, action, __metadata("design:type", Function), __metadata("design:paramtypes", [Boolean]), __metadata("design:returntype", void 0) ], TableChartStyleService.prototype, "setScroll", null); __decorate([ bind, action, __metadata("design:type", Function), __metadata("design:paramtypes", [Number]), __metadata("design:returntype", void 0) ], TableChartStyleService.prototype, "setAutoplaySpeed", null); __decorate([ action, __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object]), __metadata("design:returntype", void 0) ], TableChartStyleService.prototype, "set", null); return TableChartStyleService; }(ChartStyleService)); export default TableChartStyleService;