UNPKG

@qn-pandora/pandora-visualization

Version:

Pandora 通用可视化库

188 lines (187 loc) 7.05 kB
"use strict"; 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 __values = (this && this.__values) || function(o) { var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; if (m) return m.call(o); if (o && typeof o.length === "number") return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getColumnColor = exports.columnIsFixedRight = exports.columnIsFixedLeft = exports.getColumnIsFixed = exports.getColumnsFixedIndexes = exports.getColumnPositionStyle = exports.hasChildren = exports.getLeafColumns = void 0; var lodash_1 = require("lodash"); var transform_1 = require("../../Charts/TableChart/transform"); var table_style_1 = require("../../../constants/table-style"); var constant_1 = require("./constant"); function getLeafColumns(columns) { var leafColumns = []; columns.forEach(function (column) { if (!hasChildren(column)) { leafColumns.push(column); } else { leafColumns.push.apply(leafColumns, __spread(getLeafColumns(column.children))); } }); return leafColumns; } exports.getLeafColumns = getLeafColumns; function hasChildren(data) { return data.children && Array.isArray(data.children); } exports.hasChildren = hasChildren; function getColumnPositionStyle(columns, dataIndex, position) { var e_1, _a, e_2, _b; var width = 0; if (position === constant_1.ColumnPosition.Left) { try { for (var columns_1 = __values(columns), columns_1_1 = columns_1.next(); !columns_1_1.done; columns_1_1 = columns_1.next()) { var col = columns_1_1.value; if (col.dataIndex === dataIndex) { break; } width += lodash_1.isNumber(col.width) ? col.width : table_style_1.NORMAL_COLUMN_WIDTH; } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (columns_1_1 && !columns_1_1.done && (_a = columns_1.return)) _a.call(columns_1); } finally { if (e_1) throw e_1.error; } } return { left: width }; } else if (constant_1.ColumnPosition.Right) { try { for (var _c = __values(__spread(columns).reverse()), _d = _c.next(); !_d.done; _d = _c.next()) { var col = _d.value; if (col.dataIndex === dataIndex) { break; } width += lodash_1.isNumber(col.width) ? col.width : table_style_1.NORMAL_COLUMN_WIDTH; } } catch (e_2_1) { e_2 = { error: e_2_1 }; } finally { try { if (_d && !_d.done && (_b = _c.return)) _b.call(_c); } finally { if (e_2) throw e_2.error; } } return { right: width }; } else { return {}; } } exports.getColumnPositionStyle = getColumnPositionStyle; function getColumnsFixedIndexes(columns) { var indexes = []; columns.forEach(function (col, index) { if (col.fixed) { indexes.push(index); } }); var leftIndexes = []; var rightIndexes = []; if (indexes.length) { if (indexes[0] === 0) { leftIndexes.push(0); for (var i = 1; i < indexes.length; i++) { if (indexes[i] - 1 === indexes[i - 1]) { leftIndexes.push(i); } else { break; } } } indexes.reverse(); if (indexes[0] === columns.length - 1) { rightIndexes.push(columns.length - 1); for (var i = 1; i < indexes.length; i++) { if (indexes[i] + 1 === indexes[i - 1]) { rightIndexes.push(indexes[i]); } else { break; } } } } return { left: leftIndexes, right: rightIndexes.reverse() }; } exports.getColumnsFixedIndexes = getColumnsFixedIndexes; function getColumnIsFixed(fixedIndexes, col, colIndex) { var isLast = false; var isFixed = false; var position = constant_1.ColumnPosition.None; if (col.fixed) { var leftLength = fixedIndexes.left.length; var rightLength = fixedIndexes.right.length; var leftIndex = leftLength && fixedIndexes.left.findIndex(function (index) { return index === colIndex; }) !== -1 ? fixedIndexes.left.findIndex(function (index) { return index === colIndex; }) : -1; var rightIndex = rightLength && fixedIndexes.right.findIndex(function (index) { return index === colIndex; }) !== -1 ? fixedIndexes.right.findIndex(function (index) { return index === colIndex; }) : -1; if (leftIndex !== -1 || rightIndex !== -1) { isFixed = true; position = leftIndex !== -1 ? constant_1.ColumnPosition.Left : constant_1.ColumnPosition.Right; if ((leftLength && fixedIndexes.left[leftLength - 1] === colIndex) || (rightLength && fixedIndexes.right[0] === colIndex)) { isLast = true; } } } return { isFixed: isFixed, isLast: isLast, position: position }; } exports.getColumnIsFixed = getColumnIsFixed; function columnIsFixedLeft(columnIsFixed) { return (columnIsFixed.isFixed && columnIsFixed.isLast && columnIsFixed.position === constant_1.ColumnPosition.Left); } exports.columnIsFixedLeft = columnIsFixedLeft; function columnIsFixedRight(columnIsFixed) { return (columnIsFixed.isFixed && columnIsFixed.isLast && columnIsFixed.position === constant_1.ColumnPosition.Right); } exports.columnIsFixedRight = columnIsFixedRight; function getColumnColor(col, value) { if (!col || !col.showColor || (col.thresholdColorScope && col.thresholdColorScope !== table_style_1.ThresholdColorScope.CellBg)) { return 'inherit'; } return transform_1.getColor(col.thresholdType, 'inherit', col.isNumeric, col.splitter, value); } exports.getColumnColor = getColumnColor;