UNPKG

@qn-pandora/pandora-visualization

Version:

Pandora 通用可视化库

431 lines (430 loc) 18.3 kB
"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 __spread = (this && this.__spread) || function () { for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); return ar; }; 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 app_sdk_1 = require("@qn-pandora/app-sdk"); var bind_1 = __importDefault(require("../../../../../utils/bind")); var table_style_1 = require("../../../../../constants/table-style"); var sparkline_1 = require("../../../../../constants/sparkline"); var compare_1 = __importDefault(require("../../../chart-style/components/compare")); var sparkline_2 = __importDefault(require("../../../chart-style/components/sparkline")); var base_1 = __importStar(require("../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 = table_style_1.InitTitleFont; _this.tableTitleBgColor = ''; _this.scroll = false; _this.autoplaySpeed = table_style_1.DEFAULT_AUTO_PLAY_SPEED; _this.textDisplayMode = option.textDisplayMode || "omit" /* Omit */; _this._filterColumns = option.filterColumns || []; _this.pagination = lodash_1.isUndefined(option.pagination) ? true : option.pagination; _this.tablePageSize = option.tablePageSize || 10; _this.compare = new compare_1.default(option.compare || { method: "none" /* None */ }); _this.columns = option.columns || []; _this.dataSource = option.dataSource || []; _this.sparkline = new sparkline_2.default(option.sparkline || { type: sparkline_1.SparkLineChartType.Line }); _this.bordered = option.bordered; _this.tableTitleFont = option.tableTitleFont || table_style_1.InitTitleFont; _this.tableTitleBgColor = option.tableTitleBgColor; _this.scroll = lodash_1.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 === app_sdk_1.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 = lodash_1.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) { table_style_1.FilterColumnKeys.forEach(function (key) { _this.setColumnConfig(column, columnConfig, key); }); } }); return columns; }, enumerable: false, configurable: true }); TableChartStyleService.prototype.setColumnConfig = function (columnItem, confItem, key) { if (!lodash_1.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 lodash_1.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 (lodash_1.isNil(col.isNumeric)) { col.isNumeric = col.type === 'metric'; } lodash_1.keys(table_style_1.DefaultColumnSuffix).map(function (key) { if (lodash_1.isNil(lodash_1.get(col, key))) { lodash_1.set(col, key, lodash_1.get(table_style_1.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([ mobx_1.observable.ref, __metadata("design:type", Array) ], TableChartStyleService.prototype, "_filterColumns", void 0); __decorate([ base_1.styleOption(), __metadata("design:type", String) ], TableChartStyleService.prototype, "textDisplayMode", void 0); __decorate([ base_1.styleOption(), __metadata("design:type", Boolean) ], TableChartStyleService.prototype, "pagination", void 0); __decorate([ base_1.styleOption(), __metadata("design:type", Number) ], TableChartStyleService.prototype, "tablePageSize", void 0); __decorate([ base_1.styleOption(), __metadata("design:type", Array) ], TableChartStyleService.prototype, "columns", void 0); __decorate([ base_1.styleOption(), __metadata("design:type", Array) ], TableChartStyleService.prototype, "dataSource", void 0); __decorate([ base_1.styleOption(), __metadata("design:type", Boolean) ], TableChartStyleService.prototype, "bordered", void 0); __decorate([ base_1.styleOption(), __metadata("design:type", Object) ], TableChartStyleService.prototype, "tableTitleFont", void 0); __decorate([ base_1.styleOption(), __metadata("design:type", String) ], TableChartStyleService.prototype, "tableTitleBgColor", void 0); __decorate([ base_1.styleOption(), __metadata("design:type", Boolean) ], TableChartStyleService.prototype, "scroll", void 0); __decorate([ base_1.styleOption(), __metadata("design:type", Number) ], TableChartStyleService.prototype, "autoplaySpeed", void 0); __decorate([ mobx_1.computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], TableChartStyleService.prototype, "hasSparkline", null); __decorate([ mobx_1.computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], TableChartStyleService.prototype, "hasColumnsConfig", null); __decorate([ mobx_1.computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], TableChartStyleService.prototype, "filterColumns", null); __decorate([ bind_1.default, __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object, String]), __metadata("design:returntype", void 0) ], TableChartStyleService.prototype, "setColumnConfig", null); __decorate([ mobx_1.computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], TableChartStyleService.prototype, "contextOption", null); __decorate([ bind_1.default, __metadata("design:type", Function), __metadata("design:paramtypes", [Array, Array]), __metadata("design:returntype", void 0) ], TableChartStyleService.prototype, "sortColByConfigCol", null); __decorate([ bind_1.default, __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", void 0) ], TableChartStyleService.prototype, "initDefaultColumn", null); __decorate([ bind_1.default, mobx_1.action, __metadata("design:type", Function), __metadata("design:paramtypes", [Boolean]), __metadata("design:returntype", void 0) ], TableChartStyleService.prototype, "setPagination", null); __decorate([ bind_1.default, mobx_1.action, __metadata("design:type", Function), __metadata("design:paramtypes", [Number]), __metadata("design:returntype", void 0) ], TableChartStyleService.prototype, "setTablePageSize", null); __decorate([ bind_1.default, mobx_1.action, __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", void 0) ], TableChartStyleService.prototype, "setTextDisplayMode", null); __decorate([ bind_1.default, mobx_1.action, __metadata("design:type", Function), __metadata("design:paramtypes", [Array]), __metadata("design:returntype", void 0) ], TableChartStyleService.prototype, "setFilterColumns", null); __decorate([ bind_1.default, mobx_1.action, __metadata("design:type", Function), __metadata("design:paramtypes", [Array]), __metadata("design:returntype", void 0) ], TableChartStyleService.prototype, "setColumns", null); __decorate([ bind_1.default, mobx_1.action, __metadata("design:type", Function), __metadata("design:paramtypes", [Array]), __metadata("design:returntype", void 0) ], TableChartStyleService.prototype, "setDataSource", null); __decorate([ bind_1.default, mobx_1.action, __metadata("design:type", Function), __metadata("design:paramtypes", [Boolean]), __metadata("design:returntype", void 0) ], TableChartStyleService.prototype, "setBordered", null); __decorate([ bind_1.default, mobx_1.action, __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", void 0) ], TableChartStyleService.prototype, "setTableTitleFont", null); __decorate([ bind_1.default, mobx_1.action, __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", void 0) ], TableChartStyleService.prototype, "setTableTitleBgColor", null); __decorate([ bind_1.default, mobx_1.action, __metadata("design:type", Function), __metadata("design:paramtypes", [Boolean]), __metadata("design:returntype", void 0) ], TableChartStyleService.prototype, "setScroll", null); __decorate([ bind_1.default, mobx_1.action, __metadata("design:type", Function), __metadata("design:paramtypes", [Number]), __metadata("design:returntype", void 0) ], TableChartStyleService.prototype, "setAutoplaySpeed", null); __decorate([ mobx_1.action, __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object]), __metadata("design:returntype", void 0) ], TableChartStyleService.prototype, "set", null); return TableChartStyleService; }(base_1.default)); exports.default = TableChartStyleService;