Skip to content

Commit 08fe62c

Browse files
Merge pull request #21 from fusioncharts/release-2.1.1
Release 2.1.1
2 parents 8deb9e7 + 941379e commit 08fe62c

6 files changed

+24
-14
lines changed

dist/fusioncharts-smartlabel.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/fusioncharts-smartlabel.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

es/SmartlabelManager.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fusioncharts-smartlabel",
3-
"version": "2.1.1",
3+
"version": "2.1.2",
44
"description": "SmartLabel component to measure and restrict text in svg / canvas",
55
"main": "dist/fusioncharts-smartlabel.min.js",
66
"module": "es/SmartlabelManager.js",

src/SmartlabelManager.js

+13-10
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function SmartLabelManager(container, useEllipses, options) {
5757

5858
// Get a context of canvas
5959
this.ctx = canvas && canvas.getContext && canvas.getContext('2d');
60-
60+
6161
this._containerManager = new ContainerManager(wrapper, isBrowserLess, 10);
6262
this._showNoEllipses = !useEllipses;
6363
this._init = true;
@@ -223,7 +223,7 @@ SmartLabelManager.prototype._isSameStyle = function () {
223223
};
224224
/**
225225
* Sets font property of canvas context based on which the width of text is calculated.
226-
*
226+
*
227227
* @param {any} style style configuration which affects the text size
228228
* {
229229
* fontSize / 'font-size' : MUST BE FOLLOWED BY PX (10px, 11px)
@@ -448,8 +448,8 @@ SmartLabelManager.prototype.getSmartText = function (text, maxWidth, maxHeight,
448448
/**
449449
* For canvas lineHeight is directly used. In some cases, lineHeight can be 0.x pixels greater than
450450
* maxHeight. Previously, div was used to calculate lineHeight and it used to return a rounded number.
451-
*
452-
* Adding a buffer of 1px, maxheight will be increased by a factor of 1.2 only when
451+
*
452+
* Adding a buffer of 1px, maxheight will be increased by a factor of 1.2 only when
453453
* 0 <= (lineHeight - maxHeight) <= 1
454454
*/
455455
if ((lineHeight - maxHeight <= 1) && (lineHeight - maxHeight >= 0)) {
@@ -503,7 +503,7 @@ SmartLabelManager.prototype.getSmartText = function (text, maxWidth, maxHeight,
503503
text = fastTrim(text).replace(/(\s+)/g, ' ');
504504
maxWidthWithEll = this._showNoEllipses ? maxWidth : (maxWidth - ellipsesWidth);
505505

506-
// Checks if any html tag is present. This if block is executed for all normal texts and
506+
// Checks if any html tag is present. This if block is executed for all normal texts and
507507
// all texts containing only <br /> tag.
508508
if (!hasHTMLTag || hasOnlyBrTag) {
509509
// Gets splitted array
@@ -557,7 +557,7 @@ SmartLabelManager.prototype.getSmartText = function (text, maxWidth, maxHeight,
557557
if (tempArr[i] === '<br />') {
558558
strHeight += this._lineHeight;
559559
lastIndexBroken = i;
560-
560+
561561
maxStrWidth = max(maxStrWidth, strWidth);
562562
strWidth = 0;
563563
trimStr = null;
@@ -585,7 +585,8 @@ SmartLabelManager.prototype.getSmartText = function (text, maxWidth, maxHeight,
585585
smartLabel.text = fastTrim(trimStr) + ellipsesStr;
586586
smartLabel.tooltext = smartLabel.oriText;
587587
smartLabel.width = max(maxStrWidth, strWidth);
588-
smartLabel.height = strHeight;
588+
smartLabel.height = strHeight;
589+
smartLabel.isTruncated = true;
589590
return smartLabel;
590591
}
591592
}
@@ -619,7 +620,8 @@ SmartLabelManager.prototype.getSmartText = function (text, maxWidth, maxHeight,
619620
smartLabel.text = fastTrim(trimStr) + ellipsesStr;
620621
smartLabel.tooltext = toolText;
621622
smartLabel.width = maxStrWidth;
622-
smartLabel.height = strHeight - this._lineHeight;
623+
smartLabel.height = strHeight - this._lineHeight;
624+
smartLabel.isTruncated = true;
623625
return smartLabel;
624626
}
625627
}
@@ -681,7 +683,8 @@ SmartLabelManager.prototype.getSmartText = function (text, maxWidth, maxHeight,
681683
smartLabel.tooltext = smartLabel.oriText;
682684
// The max width among all the lines will be the width of the string.
683685
smartLabel.width = maxWidth;
684-
smartLabel.height = (strHeight - this._lineHeight);
686+
smartLabel.height = (strHeight - this._lineHeight);
687+
smartLabel.isTruncated = true;
685688
return smartLabel;
686689
} else {
687690
maxStrWidth = max(maxStrWidth, strWidth);
@@ -1023,4 +1026,4 @@ SmartLabelManager.prototype.dispose = function () {
10231026
return this;
10241027
};
10251028

1026-
export default SmartLabelManager;
1029+
export default SmartLabelManager;

test/smartlabel-manager.js

+7
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,13 @@ describe('SmartLabel', function () {
118118
expect(smartlabel.text).to.equal('a quick<br />brown f');
119119
});
120120

121+
it('checks if isTruncated is set correctly',
122+
function () {
123+
var smartlabel = sl.getSmartText('a quick brown fox over the lazy dog', 80, 50);
124+
125+
expect(smartlabel.isTruncated).to.equal(true);
126+
});
127+
121128

122129
it('truncates the text correctly without wrapping',
123130
function () {

0 commit comments

Comments
 (0)