12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- 'use strict';
- /*
- *+------------------------------------------------------------------------+
- *| Licensed Materials - Property of IBM
- *| IBM Cognos Products: Dashboard
- *| (C) Copyright IBM Corp. 2017, 2019
- *|
- *| US Government Users Restricted Rights - Use, duplication or disclosure
- *| restricted by GSA ADP Schedule Contract with IBM Corp.
- *+------------------------------------------------------------------------+
- */
- define(['../lib/@waca/core-client/js/core-client/i18n/Formatter', '../widgets/livewidget/nls/StringResources'], function (Formatter, StringResources) {
- 'use strict';
- var DashboardFormatter = function DashboardFormatter() {
- return {
- /**
- * Invert the given color by inverting the brightness of the color
- * @param value
- * @param format
- */
- format: function format(value, _format) {
- if (_format) {
- _format = _format.validFormatSpec || _format.formatSpec || _format;
- }
- if (value === undefined || value === null || value === '') {
- // If value is null or undefined or empty
- // and defaultValue is defined in spec,
- // return defaultValue
- if (_format && _format.defaultValue) {
- return _format.defaultValue;
- }
- return StringResources.get('nullValueContent');
- }
- if (value === 'ERROR') {
- return StringResources.get('value_is_not_available');
- }
- if (!_format || value === StringResources.get('value_is_not_available')) {
- return value;
- }
- return Formatter.format(value, _format);
- },
- /**
- * Format null value as '(null)'
- * @param value
- * @param format
- */
- formatNull: function formatNull(value, format) {
- if (format) {
- format = format.validFormatSpec || format.formatSpec || format;
- }
- // Per OM decision re: Story 280739, we'll start with option 1 '(null)' and add localization later if necessary.
- if (value === null) {
- // If value is null,
- // and defaultValue is defined in spec,
- // return defaultValue
- if (format && format.defaultValue) {
- return format.defaultValue;
- }
- return '(null)';
- } else {
- return this.format(value, format);
- }
- },
- /**
- * @description Returns a Number from a formatted string
- * @param {String} formattedValue - A number that was formatted by calling the format method
- * @returns {Number} - Returns a number or NaN
- */
- getNumberFromFormattedValue: function getNumberFromFormattedValue(formattedValue) {
- var groupingSeperator = Formatter.formatNumber(1000).substring(1, 2);
- var decimalSeperator = Formatter.formatNumber(0.1).substring(1, 2);
- var patternGrp = new RegExp('\\' + groupingSeperator, 'g');
- var patternDecimal = new RegExp('\\' + decimalSeperator, 'g');
- var valueString = formattedValue + '';
- return Number(valueString.replace(patternGrp, '').replace(patternDecimal, '.'));
- }
- };
- };
- return new DashboardFormatter();
- });
- //# sourceMappingURL=DashboardFormatter.js.map
|