|
|
|
@ -1804,7 +1804,8 @@
|
|
|
|
|
c3_chart_internal_fn.mapTargetsToUniqueXs = function (targets) { |
|
|
|
|
var $$ = this; |
|
|
|
|
var xs = $$.d3.set($$.d3.merge(targets.map(function (t) { return t.values.map(function (v) { return +v.x; }); }))).values(); |
|
|
|
|
return $$.isTimeSeries() ? xs.map(function (x) { return new Date(+x); }) : xs.map(function (x) { return +x; }); |
|
|
|
|
xs = $$.isTimeSeries() ? xs.map(function (x) { return new Date(+x); }) : xs.map(function (x) { return +x; }); |
|
|
|
|
return xs.sort(function (a, b) { return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN; }); |
|
|
|
|
}; |
|
|
|
|
c3_chart_internal_fn.addHiddenTargetIds = function (targetIds) { |
|
|
|
|
this.hiddenTargetIds = this.hiddenTargetIds.concat(targetIds); |
|
|
|
@ -3371,14 +3372,16 @@
|
|
|
|
|
.style("fill-opacity", forFlow ? 0 : this.opacityForText.bind(this)) |
|
|
|
|
]; |
|
|
|
|
}; |
|
|
|
|
c3_chart_internal_fn.getTextRect = function (text, cls) { |
|
|
|
|
c3_chart_internal_fn.getTextRect = function (text, cls, element) { |
|
|
|
|
var dummy = this.d3.select('body').append('div').classed('c3', true), |
|
|
|
|
svg = dummy.append("svg").style('visibility', 'hidden').style('position', 'fixed').style('top', 0).style('left', 0), |
|
|
|
|
font = this.d3.select(element).style('font'), |
|
|
|
|
rect; |
|
|
|
|
svg.selectAll('.dummy') |
|
|
|
|
.data([text]) |
|
|
|
|
.enter().append('text') |
|
|
|
|
.classed(cls ? cls : "", true) |
|
|
|
|
.style('font', font) |
|
|
|
|
.text(text) |
|
|
|
|
.each(function () { rect = this.getBoundingClientRect(); }); |
|
|
|
|
dummy.remove(); |
|
|
|
@ -4026,7 +4029,7 @@
|
|
|
|
|
|
|
|
|
|
function getTextBox(textElement, id) { |
|
|
|
|
if (!$$.legendItemTextBox[id]) { |
|
|
|
|
$$.legendItemTextBox[id] = $$.getTextRect(textElement.textContent, CLASS.legendItem); |
|
|
|
|
$$.legendItemTextBox[id] = $$.getTextRect(textElement.textContent, CLASS.legendItem, textElement); |
|
|
|
|
} |
|
|
|
|
return $$.legendItemTextBox[id]; |
|
|
|
|
} |
|
|
|
@ -4238,9 +4241,9 @@
|
|
|
|
|
c3_chart_internal_fn.xForTitle = function () { |
|
|
|
|
var $$ = this, config = $$.config, position = config.title_position || 'left', x; |
|
|
|
|
if (position.indexOf('right') >= 0) { |
|
|
|
|
x = $$.currentWidth - $$.title.node().getBBox().width - config.title_padding.right; |
|
|
|
|
x = $$.currentWidth - $$.getTextRect($$.title.node().textContent, $$.CLASS.title, $$.title.node()).width - config.title_padding.right; |
|
|
|
|
} else if (position.indexOf('center') >= 0) { |
|
|
|
|
x = ($$.currentWidth - $$.title.node().getBBox().width) / 2; |
|
|
|
|
x = ($$.currentWidth - $$.getTextRect($$.title.node().textContent, $$.CLASS.title, $$.title.node()).width) / 2; |
|
|
|
|
} else { // left
|
|
|
|
|
x = config.title_padding.left; |
|
|
|
|
} |
|
|
|
@ -4248,7 +4251,7 @@
|
|
|
|
|
}; |
|
|
|
|
c3_chart_internal_fn.yForTitle = function () { |
|
|
|
|
var $$ = this; |
|
|
|
|
return $$.config.title_padding.top + $$.title.node().getBBox().height; |
|
|
|
|
return $$.config.title_padding.top + $$.getTextRect($$.title.node().textContent, $$.CLASS.title, $$.title.node()).height; |
|
|
|
|
}; |
|
|
|
|
c3_chart_internal_fn.getTitlePadding = function() { |
|
|
|
|
var $$ = this; |
|
|
|
|