@qn-pandora/pandora-visualization
Version:
Pandora 通用可视化库
125 lines (124 loc) • 5.61 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);
};
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 __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var lodash_1 = require("lodash");
var bind_1 = __importDefault(require("../../../../utils/bind"));
var utils_1 = require("../../../../base-pandora-visualization/services/chart-style/utils");
var chart_drill_down_1 = require("../../../../services/chart-drill-down");
var chart_common_action_1 = require("../../../../services/chart-common-action");
var store_1 = __importDefault(require("../store"));
var transform_1 = require("../transform");
var GridTableStore = /** @class */ (function (_super) {
__extends(GridTableStore, _super);
function GridTableStore() {
return _super !== null && _super.apply(this, arguments) || this;
}
GridTableStore.prototype.getInitTableData = function (dataset) {
var _a = transform_1.filterBuiltInFields(dataset), fields = _a.fields, rows = _a.rows;
var columnRange = [];
var columns = fields.map(function (field) {
var columnMax = lodash_1.max(utils_1.getDataOfField(field.key, dataset)) || 0;
var columnSum = lodash_1.sum(utils_1.getDataOfField(field.key, dataset)) || 0;
columnRange.push([columnMax, columnSum]);
return {
key: field.key,
title: field.name || field.key,
dataIndex: field.key,
type: field.type || '',
fieldType: field.fieldType || ''
};
});
var dataSource = rows.map(function (line) {
var newRow = {};
fields.forEach(function (field, i) {
var _a = __read(columnRange[i], 2), columnMax = _a[0], columnSum = _a[1];
var current = line[i][0];
if (lodash_1.isNil(current)) {
newRow[field.key] = {
current: current
};
}
else {
var compare = line[i][1] || 0;
var metricValue = {
current: current,
compare: compare,
curMaxProcess: current / columnMax,
curSumProcess: current / columnSum
};
// TODO 添加compareKey
newRow[field.key] = metricValue;
}
});
return newRow;
});
return { columns: columns, dataSource: dataSource };
};
GridTableStore.prototype.handleTableCellClick = function (record, clickField, clickValue, event) {
var position = {
clientX: lodash_1.get(event, ['clientX']),
clientY: lodash_1.get(event, ['clientY'])
};
this.onAction({
record: record,
clickField: clickField,
clickValue: clickValue,
fields: this.fields,
position: position
}, chart_drill_down_1.GridTableDrillDownService, chart_common_action_1.GridTableActionService);
};
__decorate([
bind_1.default,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], GridTableStore.prototype, "getInitTableData", null);
__decorate([
bind_1.default,
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object, Object, Object, Object]),
__metadata("design:returntype", void 0)
], GridTableStore.prototype, "handleTableCellClick", null);
return GridTableStore;
}(store_1.default));
exports.default = GridTableStore;