1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- /**
- * Licensed Materials - Property of IBM IBM Cognos Products: Modeling UI (C) Copyright IBM Corp. 2016, 2019
- * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP
- * Schedule Contract with IBM Corp.
- */
- define([], function() {
- //offset value attached to the label shortener if filter icon is present
- var MAX_DIAGRAM_LABEL_LENGTH = 20;
- //offset value attached to the label shortener if filter icon is present
- var MAX_DIAGRAM_LABEL_LENGTH_FILTER = 16;
- //offset value attached to the label shortener if capitalized letters are present
- var MAX_DIAGRAM_LABEL_LENGTH_CAPTALIZED = 15;
- //offset value attached to the label shortener if capitalized letters are and a filter is present
- var MAX_DIAGRAM_LABEL_LENGTH_CAPTALIZED_FILTER = 12;
- var StringUtils = {
- /**
- * Return the max length of a text string for the diagram
- *
- * @param isFiter
- * Boolean value for if a filter is applied to the diagram
- * node (ie. filter icon visible)
- * @param label
- * Label of the diagram node
- */
- getMaxDiagramLabelLength : function(isFilter, label) {
- if (isFilter) {
- if ((label.match(/[A-Z]/g) || []).length >= 12) {
- return MAX_DIAGRAM_LABEL_LENGTH_CAPTALIZED_FILTER;
- }
- return MAX_DIAGRAM_LABEL_LENGTH_FILTER;
- }
- if ((label.match(/[A-Z]/g) || []).length > 15) {
- return MAX_DIAGRAM_LABEL_LENGTH_CAPTALIZED;
- }
- return MAX_DIAGRAM_LABEL_LENGTH;
- },
- /**
- * Shorten a passed string that will be formatted with
- * the ellipsis in the middle of the string eg:
- * Hollywood Movies Csv -> Hollywo...ies Csv
- *
- * @param text
- * The text item that is to be shortened
- * @param maxSize
- * Max size allowed (number of characters)
- */
- shortenTextMidEllipsis : function(text, maxSize) {
- var shortenedText = text;
- var length = text.length;
- // subtract 2 so we don't exceed the max val (adding
- // in 3 chars with the ...)
- var subLength = maxSize / 2 - 2;
- if (length > maxSize) {
- shortenedText = text.substring(0, subLength);
- shortenedText += '...';
- shortenedText += text.substring(length - subLength, length);
- }
- return shortenedText;
- }
- };
- return StringUtils;
- });
|