Skip to content

Commit

Permalink
Replace bbx with getComputedTextLength
Browse files Browse the repository at this point in the history
  • Loading branch information
ulfschneider committed Aug 11, 2019
1 parent 91f83ba commit 0bf1222
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
20 changes: 10 additions & 10 deletions cfd.js
Original file line number Diff line number Diff line change
Expand Up @@ -498,19 +498,19 @@ function drawTextWithBackground({
.text(text);

try {
let bbx = txt.node().getBBox();
let length = txt.node().getComputedTextLength()
if (textAnchor == 'middle') {
bkg.attr('x', x - bbx.width / 2);
bkg.attr('x', x - length / 2);
} else if (textAnchor == 'end') {
bkg.attr('x', x - bbx.width);
bkg.attr('x', x - length);
} else {
bkg.attr('x', x);
}
bkg.attr('y', y - settings.style.fontSize / 2)
.attr('width', bbx.width)
.attr('width', length)
.attr('height', settings.style.fontSize);
} catch (e) {
//JSDOM is not able to operate with bbox
//JSDOM is not able to operate with getComputedTextLength
//therefore this code is not going to run in the tests
}
}
Expand Down Expand Up @@ -1010,10 +1010,10 @@ function drawLegend(settings) {
//and use progress because it has the most length of
//To Do, In Progress and Done
try {
let bbox = progress.node().getBBox();
background.attr('width', bbox.width + 2.6 * lineHeight);
let length = progress.node().getComputedTextLength();
background.attr('width', length + 2.6 * lineHeight);
} catch (e) {
//JSDOM is not able to operate with bbox
//JSDOM is not able to operate with getComputedTextLength
//therefore this code is not going to run in the tests
}

Expand Down Expand Up @@ -1078,8 +1078,8 @@ function drawFocus(settings) {
.style('display', null)
.text(key == 'date' ? getMoment(dataSet[key]).format(DATE_FORMAT) : round(dataSet[key]) + ' ' + key)
try {
let bbx = focusItems[count].node().getBBox();
width = Math.max(width, bbx.width + 2 * LEGEND_PAD);
let length = focusItems[count].node().getComputedTextLength();
width = Math.max(width, length + 2 * LEGEND_PAD);
} catch (e) { }
row++;
count++;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cumulative-flow",
"version": "1.20.1",
"version": "1.20.2",
"description": "Draw SVG Cumulative Flow Diagrams",
"keywords": [
"cumulative",
Expand Down
20 changes: 10 additions & 10 deletions test/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -20806,19 +20806,19 @@ function drawTextWithBackground({
.text(text);

try {
let bbx = txt.node().getBBox();
let length = txt.node().getComputedTextLength()
if (textAnchor == 'middle') {
bkg.attr('x', x - bbx.width / 2);
bkg.attr('x', x - length / 2);
} else if (textAnchor == 'end') {
bkg.attr('x', x - bbx.width);
bkg.attr('x', x - length);
} else {
bkg.attr('x', x);
}
bkg.attr('y', y - settings.style.fontSize / 2)
.attr('width', bbx.width)
.attr('width', length)
.attr('height', settings.style.fontSize);
} catch (e) {
//JSDOM is not able to operate with bbox
//JSDOM is not able to operate with getComputedTextLength
//therefore this code is not going to run in the tests
}
}
Expand Down Expand Up @@ -21318,10 +21318,10 @@ function drawLegend(settings) {
//and use progress because it has the most length of
//To Do, In Progress and Done
try {
let bbox = progress.node().getBBox();
background.attr('width', bbox.width + 2.6 * lineHeight);
let length = progress.node().getComputedTextLength();
background.attr('width', length + 2.6 * lineHeight);
} catch (e) {
//JSDOM is not able to operate with bbox
//JSDOM is not able to operate with getComputedTextLength
//therefore this code is not going to run in the tests
}

Expand Down Expand Up @@ -21386,8 +21386,8 @@ function drawFocus(settings) {
.style('display', null)
.text(key == 'date' ? getMoment(dataSet[key]).format(DATE_FORMAT) : round(dataSet[key]) + ' ' + key)
try {
let bbx = focusItems[count].node().getBBox();
width = Math.max(width, bbx.width + 2 * LEGEND_PAD);
let length = focusItems[count].node().getComputedTextLength();
width = Math.max(width, length + 2 * LEGEND_PAD);
} catch (e) { }
row++;
count++;
Expand Down

0 comments on commit 0bf1222

Please sign in to comment.