Skip to content

Commit

Permalink
Made a fix to calcApproxTextWidth, to fix bug on IE9.
Browse files Browse the repository at this point in the history
  • Loading branch information
robinfhu committed Dec 16, 2013
1 parent 3dd43d6 commit b8b06c7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
11 changes: 6 additions & 5 deletions nv.d3.js
Original file line number Diff line number Diff line change
Expand Up @@ -971,24 +971,25 @@ nv.utils.pjax = function(links, content) {
}

/* For situations where we want to approximate the width in pixels for an SVG:text element.
Most common instance is when the element is in a display:none; container.
Most common instance is when the element is in a display:none; container.
Forumla is : text.length * font-size * constant_factor
*/
nv.utils.calcApproxTextWidth = function (svgTextElem) {
if (svgTextElem instanceof d3.selection) {
if (typeof svgTextElem.style === 'function'
&& typeof svgTextElem.text === 'function') {
var fontSize = parseInt(svgTextElem.style("font-size").replace("px",""));
var textLength = svgTextElem.text().length;

return textLength * fontSize * 0.5;
return textLength * fontSize * 0.5;
}
return 0;
};

/* Numbers that are undefined, null or NaN, convert them to zeros.
*/
nv.utils.NaNtoZero = function(n) {
if (typeof n !== 'number'
|| isNaN(n)
if (typeof n !== 'number'
|| isNaN(n)
|| n === null
|| n === Infinity) return 0;

Expand Down
11 changes: 6 additions & 5 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,24 +105,25 @@ nv.utils.pjax = function(links, content) {
}

/* For situations where we want to approximate the width in pixels for an SVG:text element.
Most common instance is when the element is in a display:none; container.
Most common instance is when the element is in a display:none; container.
Forumla is : text.length * font-size * constant_factor
*/
nv.utils.calcApproxTextWidth = function (svgTextElem) {
if (svgTextElem instanceof d3.selection) {
if (typeof svgTextElem.style === 'function'
&& typeof svgTextElem.text === 'function') {
var fontSize = parseInt(svgTextElem.style("font-size").replace("px",""));
var textLength = svgTextElem.text().length;

return textLength * fontSize * 0.5;
return textLength * fontSize * 0.5;
}
return 0;
};

/* Numbers that are undefined, null or NaN, convert them to zeros.
*/
nv.utils.NaNtoZero = function(n) {
if (typeof n !== 'number'
|| isNaN(n)
if (typeof n !== 'number'
|| isNaN(n)
|| n === null
|| n === Infinity) return 0;

Expand Down

0 comments on commit b8b06c7

Please sign in to comment.