UNPKG

@gooddata/react-components

Version:

GoodData.UI - A powerful JavaScript library for building analytical applications

66 lines 3 kB
"use strict"; 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); }; Object.defineProperty(exports, "__esModule", { value: true }); // (C) 2007-2019 GoodData Corporation var classNames = require("classnames"); var numberjs_1 = require("@gooddata/numberjs"); var variables_1 = require("../components/visualizations/styles/variables"); var MappingHeader_1 = require("../interfaces/MappingHeader"); var Table_1 = require("../interfaces/Table"); function getFormattedNumber(cellContent, format, separators) { var parsedNumber = cellContent === null ? "" : typeof cellContent === "string" ? parseFloat(cellContent) : cellContent; return numberjs_1.numberFormat(parsedNumber, format, undefined, separators); } function getCellClassNames(rowIndex, columnIndex, isDrillable) { return classNames({ "gd-cell-drillable": isDrillable, }, "gd-cell", "s-cell-" + rowIndex + "-" + columnIndex, "s-table-cell"); } exports.getCellClassNames = getCellClassNames; function getMeasureCellFormattedValue(cellContent, format, separators) { var formattedNumber = getFormattedNumber(cellContent, format, separators); var label = numberjs_1.colors2Object(formattedNumber).label; return label === "" ? "–" : label; } exports.getMeasureCellFormattedValue = getMeasureCellFormattedValue; function getMeasureCellStyle(cellContent, format, separators, applyColor) { var formattedNumber = getFormattedNumber(cellContent, format, separators); var _a = numberjs_1.colors2Object(formattedNumber), backgroundColor = _a.backgroundColor, color = _a.color, label = _a.label; if (label === "") { return { color: variables_1.styleVariables.gdColorStateBlank, fontWeight: "bold", }; } if (!applyColor) { return {}; } return __assign({}, (color && { color: color }), (backgroundColor && { backgroundColor: backgroundColor })); } exports.getMeasureCellStyle = getMeasureCellStyle; function getCellStyleAndFormattedValue(header, cellContent, applyColor, separators) { if (applyColor === void 0) { applyColor = true; } if (Table_1.isAttributeCell(cellContent)) { return { style: {}, formattedValue: cellContent.name, }; } var measureFormat = MappingHeader_1.isMappingHeaderMeasureItem(header) ? header.measureHeaderItem.format : ""; return { style: getMeasureCellStyle(cellContent, measureFormat, separators, applyColor), formattedValue: getMeasureCellFormattedValue(cellContent, measureFormat, separators), }; } exports.getCellStyleAndFormattedValue = getCellStyleAndFormattedValue; //# sourceMappingURL=tableCell.js.map