Browse Source

Fixing firefox issue (mozilla bugzilla: #612118) for title rendering.

pull/1285/head
upphiminn 10 years ago
parent
commit
95b6180d87
  1. 30
      src/title.js

30
src/title.js

@ -11,19 +11,39 @@ c3_chart_internal_fn.redrawTitle = function () {
.attr("y", $$.yForTitle.bind($$)); .attr("y", $$.yForTitle.bind($$));
}; };
c3_chart_internal_fn.xForTitle = function () { c3_chart_internal_fn.xForTitle = function () {
var $$ = this, config = $$.config, position = config.title_position || 'left', x; var $$ = this, config = $$.config, position = config.title_position || 'left', x, textWidth;
try {
textWidth = $$.title.node().getBBox().width;
} catch (e) {
//FF bug https://bugzilla.mozilla.org/show_bug.cgi?id=612118
if (e.name === 'NS_ERROR_FAILURE') {
textWidth = $$.title.node().getComputedTextLength();
} else {
throw(e);
}
}
if (position.indexOf('right') >= 0) { if (position.indexOf('right') >= 0) {
x = $$.currentWidth - $$.title.node().getBBox().width - config.title_padding.right; x = $$.currentWidth - textWidth - config.title_padding.right;
} else if (position.indexOf('center') >= 0) { } else if (position.indexOf('center') >= 0) {
x = ($$.currentWidth - $$.title.node().getBBox().width) / 2; x = ($$.currentWidth - textWidth) / 2;
} else { // left } else { // left
x = config.title_padding.left; x = config.title_padding.left;
} }
return x; return x;
}; };
c3_chart_internal_fn.yForTitle = function () { c3_chart_internal_fn.yForTitle = function () {
var $$ = this; var $$ = this, textHeight;
return $$.config.title_padding.top + $$.title.node().getBBox().height; try {
textHeight = $$.title.node().getBBox().height;
} catch (e) {
//FF bug https://bugzilla.mozilla.org/show_bug.cgi?id=612118
if (e.name === 'NS_ERROR_FAILURE') {
textHeight = 0;
} else {
throw(e);
}
}
return $$.config.title_padding.top + textHeight;
}; };
c3_chart_internal_fn.getTitlePadding = function() { c3_chart_internal_fn.getTitlePadding = function() {
var $$ = this; var $$ = this;

Loading…
Cancel
Save