Skip to content

Commit

Permalink
Merge pull request #18 from fusioncharts/develop
Browse files Browse the repository at this point in the history
Release 2.1.0
  • Loading branch information
priyanjitdey94 authored Aug 16, 2019
2 parents 02d60c9 + c28e30a commit 965c0a1
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 30 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.MD
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Directory | Summary
----------------|---------------------------------------------
`dist` | A UMD bundle is built and kept here. This can be included without the need for any build system
`example` | Example usage of the component. Github page gets generated from here.
`lib` | Contains a transpiled CommonJS version (generated with Babel) of the code for use with node.js
`es` | Contains a transpiled CommonJS version (generated with Babel) of the code for use with node.js
`script` | CI script
`src` | Component source modules
`test` | Component test cases
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ To get the size of a given text
* }
* If detailedCalculationFlag is set to false the returned object wont have the detailObj prop.
*/
size = sl.getOriSize(text, detailedCalculationFlag);
size = sl.getSize(text, detailedCalculationFlag);
```

To dispose the components
Expand Down
4 changes: 2 additions & 2 deletions dist/fusioncharts-smartlabel.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/fusioncharts-smartlabel.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion es/SmartlabelManager.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion es/lib.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fusioncharts-smartlabel",
"version": "2.0.1",
"version": "2.1.0",
"description": "SmartLabel component to measure and restrict text in svg / canvas",
"main": "dist/fusioncharts-smartlabel.min.js",
"module": "es/SmartlabelManager.js",
Expand Down
49 changes: 30 additions & 19 deletions src/SmartlabelManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ SmartLabelManager.prototype.getSmartText = function (text, maxWidth, maxHeight,
isTruncated : false
};

hasHTMLTag = slLib.xmlTagRegEx.test(text);
hasHTMLTag = slLib.xmlTagRegEx.test(text) || slLib.nbspRegex.test(text);
hasOnlyBrTag = slLib._hasOnlyBRTag(text);

this.requireDiv = (hasHTMLTag && !hasOnlyBrTag);
Expand Down Expand Up @@ -466,7 +466,7 @@ SmartLabelManager.prototype.getSmartText = function (text, maxWidth, maxHeight,
tmpText = text = text.replace(slLib.ltgtRegex, function (match) {
return match === '&lt;' ? '<' : '>';
});
getOriSizeImproveObj = this.getOriSize(tmpText, true, {
getOriSizeImproveObj = this.getSize(tmpText, true, {
hasHTMLTag: hasHTMLTag,
hasOnlyBrTag: hasOnlyBrTag,
cleanText: true
Expand Down Expand Up @@ -913,7 +913,7 @@ SmartLabelManager.prototype.getSmartText = function (text, maxWidth, maxHeight,
* }
* If detailedCalculationFlag is set to false the returned object wont have the detailObj prop.
*/
SmartLabelManager.prototype.getOriSize = function (text = '', detailedCalculationFlag = true, config = {}) {
SmartLabelManager.prototype.getSize = function (text = '', detailedCalculationFlag = true, config = {}) {
if (!this._init) {
return false;
}
Expand All @@ -937,7 +937,7 @@ SmartLabelManager.prototype.getOriSize = function (text = '', detailedCalculatio
hasOnlyBrTag = config.hasOnlyBrTag;

if (typeof hasHTMLTag === 'undefined') {
hasHTMLTag = slLib.xmlTagRegEx.test(text);
hasHTMLTag = slLib.xmlTagRegEx.test(text) || slLib.nbspRegex.test(text);
}
if (typeof hasOnlyBrTag === 'undefined') {
hasOnlyBrTag = slLib._hasOnlyBRTag(text);
Expand All @@ -951,42 +951,53 @@ SmartLabelManager.prototype.getOriSize = function (text = '', detailedCalculatio
}
this._updateStyle();
container = this._container;
// If text has br tag, return the width and height with proper calculations
if (hasOnlyBrTag) {
return slLib._getDimentionOfMultiLineText(text, this);
}

// When text is normal text
if (!detailedCalculationFlag) {
return this._calCharDimWithCache(text);
} else {
// Calculate the width of every letter with an approximation
textArr = text.split('');
for (i = 0, l = textArr.length; i < l; i++) {
letter = textArr[i];
lSize = this._calCharDimWithCache(letter, false, textArr.length);
height = max(height, lSize.height);
cumulativeSize += lSize.width;
indiSizeStore[letter] = lSize.width;
}
}
// If text has br tag, return the width and height with proper calculations
if (hasOnlyBrTag) {
return {
...slLib._getDimentionOfMultiLineText(text, this),
detailObj: indiSizeStore
};
}

// text contains html tags other than br
if (hasHTMLTag) {
container.innerHTML = text;
return {
width: container.offsetWidth,
height: container.offsetHeight
height: container.offsetHeight,
detailObj: indiSizeStore
};
}

// Calculate the width of every letter with an approximation
textArr = text.split('');
for (i = 0, l = textArr.length; i < l; i++) {
letter = textArr[i];
lSize = this._calCharDimWithCache(letter, false, textArr.length);
height = max(height, lSize.height);
cumulativeSize += lSize.width;
indiSizeStore[letter] = lSize.width;
}

return {
width: round(cumulativeSize),
height: height,
detailObj: indiSizeStore
};
};

/**
* getOriSize API will eventually be deprecated and will be renamed to getSize API. For the next two versions,
* both getOriSize and getSize API will be supported.
*/
SmartLabelManager.prototype.getOriSize = function (text = '', detailedCalculationFlag = true, config = {}) {
return this.getSize(text, detailedCalculationFlag, config);
};
/*
* Dispose the container and object allocated by the smartlabel
*/
Expand Down
2 changes: 2 additions & 0 deletions src/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ var lib = {

ltgtRegex: /&lt;|&gt;/g,

nbspRegex: /&nbsp;|&#160;|&#xA0;/g,

htmlSpecialEntityRegex: /&amp;|&quot;|&lt;|&gt;/g,

brReplaceRegex: /<br\/>/ig,
Expand Down
Loading

0 comments on commit 965c0a1

Please sign in to comment.