Skip to content

Commit

Permalink
added detailObj to return value of getSize API
Browse files Browse the repository at this point in the history
  • Loading branch information
priyanjitdey94 committed Jul 11, 2019
1 parent 4963f0b commit 5b85fb9
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 22 deletions.
2 changes: 1 addition & 1 deletion 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.

38 changes: 19 additions & 19 deletions src/SmartlabelManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -951,35 +951,39 @@ SmartLabelManager.prototype.getSize = function (text = '', detailedCalculationFl
}
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,
Expand All @@ -992,10 +996,6 @@ SmartLabelManager.prototype.getSize = function (text = '', detailedCalculationFl
* both getOriSize and getSize API will be supported.
*/
SmartLabelManager.prototype.getOriSize = function (text = '', detailedCalculationFlag = true, config = {}) {
if (!this._init) {
return false;
}

return this.getSize(text, detailedCalculationFlag, config);
};
/*
Expand Down
11 changes: 11 additions & 0 deletions test/smartlabel-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,17 @@ describe('SmartLabel', function () {
expect(smarttext.lines.length).to.equal(6);
});

it('getSize API should always return detailObj', function () {
var smarttext,
present;

smarttext = sl.getSize('AAAA');
expect(smarttext.hasOwnProperty('detailObj')).to.equal(true);
smarttext = sl.getSize('AAA <br> AAA');
expect(smarttext.hasOwnProperty('detailObj')).to.equal(true);
smarttext = sl.getSize('AAA <div></div> AAA');
expect(smarttext.hasOwnProperty('detailObj')).to.equal(true);
})

it('removes the div when disposed',
function () {
Expand Down

0 comments on commit 5b85fb9

Please sign in to comment.