UNPKG

@qn-pandora/pandora-visualization

Version:

Pandora 通用可视化库

147 lines (146 loc) 6.96 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); }; import * as React from 'react'; import classnames from 'classnames'; import { observer } from 'mobx-react'; import { computed } from 'mobx'; import { get } from 'lodash'; import { ChartType } from '../../../../constants'; import { FIRST_CELL_PADDING_LEFT_GAP } from '../constant'; import { getColumnPositionStyle, getColumnsFixedIndexes, getColumnIsFixed, columnIsFixedLeft, columnIsFixedRight, getColumnColor } from '../columnManager'; import Cell from './Cell'; import * as styles from '../style.mless'; var TableRow = /** @class */ (function (_super) { __extends(TableRow, _super); function TableRow() { return _super !== null && _super.apply(this, arguments) || this; } Object.defineProperty(TableRow.prototype, "fixedIndexes", { get: function () { return getColumnsFixedIndexes(this.props.columns); }, enumerable: false, configurable: true }); Object.defineProperty(TableRow.prototype, "color", { get: function () { return get(this.props.tableOption, 'color'); }, enumerable: false, configurable: true }); TableRow.prototype.getRealColumnColor = function (columnColor, rowColor) { if (rowColor && this.props.chartType !== ChartType.TreeTable) { if (columnColor !== 'inherit') { if (rowColor !== 'rgba(0,0,0,0)' && rowColor !== get(this.props.tableOption, 'backgroundColor') && rowColor !== get(this.props.tableOption, 'rowBackgroundColor')) { columnColor = rowColor; } } else { if (rowColor !== 'rgba(0,0,0,0)') { columnColor = rowColor; } } } if (columnColor === 'inherit') { columnColor = get(this.props.tableOption, 'backgroundColor'); } return columnColor; }; TableRow.prototype.render = function () { var _this = this; var _a = this.props, columns = _a.columns, rowData = _a.rowData, rowIndex = _a.rowIndex, rowStyle = _a.rowStyle, _b = _a.level, level = _b === void 0 ? 0 : _b, bordered = _a.bordered, handleCellResize = _a.handleCellResize; return (React.createElement("div", { className: styles.tr }, columns.map(function (col, colIndex) { var _a, _b, _c; var text = get(rowData, col.dataIndex); var current = get(rowData, [col.dataIndex, 'current']); var cellDom = (React.createElement("div", { style: { paddingLeft: colIndex === 0 ? level * FIRST_CELL_PADDING_LEFT_GAP : 0, textAlign: col.align || 'center', color: _this.color } }, col.render ? col.render(text, rowData, rowIndex, colIndex) : text)); var columnColor = getColumnColor(col, current); if (rowStyle) { var background = rowStyle(rowIndex).background; columnColor = _this.getRealColumnColor(columnColor, background); } else { columnColor = _this.getRealColumnColor(columnColor); } var columnIsFixed = getColumnIsFixed(_this.fixedIndexes, col, colIndex); var style = columnIsFixed.isFixed ? getColumnPositionStyle(columns, col.dataIndex, columnIsFixed.position) : {}; var borderOpts = get(_this.props.tableOption, 'border'); var borderStyle = (bordered === undefined ? borderOpts.show : _this.props.bordered) ? { borderBottom: borderOpts.width + "px " + borderOpts.type + " " + borderOpts.color } : {}; var cellWidth = undefined; if (colIndex === columns.length - 1 && col.fixed !== true && _this.props.textDisplayMode !== "newline" /* NewLine */) { cellWidth = 'auto'; } return (React.createElement("div", { className: classnames(styles.tdContainer, col.className, (_a = {}, _a[styles.columnFixed] = columnIsFixed.isFixed, _a), (_b = {}, _b[styles.columnFixedLeftLast] = columnIsFixedLeft(columnIsFixed), _b), (_c = {}, _c[styles.columnFixedRightLast] = columnIsFixedRight(columnIsFixed), _c)), key: colIndex, style: __assign(__assign({ background: columnColor }, style), borderStyle) }, React.createElement(Cell, { col: col, renderDom: cellDom, handleCellResize: handleCellResize, width: cellWidth }))); }))); }; __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], TableRow.prototype, "fixedIndexes", null); __decorate([ computed, __metadata("design:type", Object), __metadata("design:paramtypes", []) ], TableRow.prototype, "color", null); TableRow = __decorate([ observer ], TableRow); return TableRow; }(React.Component)); export default TableRow;