Commit ecd5728a authored by Masayuki Tanaka's avatar Masayuki Tanaka

Avoid setting c3 class to body - #1014

parent 97998e29
...@@ -3302,8 +3302,8 @@ ...@@ -3302,8 +3302,8 @@
]; ];
}; };
c3_chart_internal_fn.getTextRect = function (text, cls) { c3_chart_internal_fn.getTextRect = function (text, cls) {
var body = this.d3.select('body').classed('c3', true), var dummy = this.d3.select('body').append('div').classed('c3', true),
svg = body.append("svg").style('visibility', 'hidden').style('position', 'fixed').style('top', 0).style('left', 0), svg = dummy.append("svg").style('visibility', 'hidden').style('position', 'fixed').style('top', 0).style('left', 0),
rect; rect;
svg.selectAll('.dummy') svg.selectAll('.dummy')
.data([text]) .data([text])
...@@ -3311,8 +3311,7 @@ ...@@ -3311,8 +3311,7 @@
.classed(cls ? cls : "", true) .classed(cls ? cls : "", true)
.text(text) .text(text)
.each(function () { rect = this.getBoundingClientRect(); }); .each(function () { rect = this.getBoundingClientRect(); });
svg.remove(); dummy.remove();
body.classed('c3', false);
return rect; return rect;
}; };
c3_chart_internal_fn.generateXYForText = function (areaIndices, barIndices, lineIndices, forX) { c3_chart_internal_fn.generateXYForText = function (areaIndices, barIndices, lineIndices, forX) {
...@@ -4401,7 +4400,7 @@ ...@@ -4401,7 +4400,7 @@
}; };
Axis.prototype.getMaxTickWidth = function getMaxTickWidth(id, withoutRecompute) { Axis.prototype.getMaxTickWidth = function getMaxTickWidth(id, withoutRecompute) {
var $$ = this.owner, config = $$.config, var $$ = this.owner, config = $$.config,
maxWidth = 0, targetsToShow, scale, axis, body, svg; maxWidth = 0, targetsToShow, scale, axis, dummy, svg;
if (withoutRecompute && $$.currentMaxTickWidths[id]) { if (withoutRecompute && $$.currentMaxTickWidths[id]) {
return $$.currentMaxTickWidths[id]; return $$.currentMaxTickWidths[id];
} }
...@@ -4418,16 +4417,15 @@ ...@@ -4418,16 +4417,15 @@
axis = this.getXAxis(scale, $$.xOrient, $$.xAxisTickFormat, $$.xAxisTickValues, false, true, true); axis = this.getXAxis(scale, $$.xOrient, $$.xAxisTickFormat, $$.xAxisTickValues, false, true, true);
this.updateXAxisTickValues(targetsToShow, axis); this.updateXAxisTickValues(targetsToShow, axis);
} }
body = $$.d3.select('body').classed('c3', true); dummy = $$.d3.select('body').append('div').classed('c3', true);
svg = body.append("svg").style('visibility', 'hidden').style('position', 'fixed').style('top', 0).style('left', 0), svg = dummy.append("svg").style('visibility', 'hidden').style('position', 'fixed').style('top', 0).style('left', 0),
svg.append('g').call(axis).each(function () { svg.append('g').call(axis).each(function () {
$$.d3.select(this).selectAll('text').each(function () { $$.d3.select(this).selectAll('text').each(function () {
var box = this.getBoundingClientRect(); var box = this.getBoundingClientRect();
if (maxWidth < box.width) { maxWidth = box.width; } if (maxWidth < box.width) { maxWidth = box.width; }
}); });
svg.remove(); dummy.remove();
}); });
body.classed('c3', false);
} }
$$.currentMaxTickWidths[id] = maxWidth <= 0 ? $$.currentMaxTickWidths[id] : maxWidth; $$.currentMaxTickWidths[id] = maxWidth <= 0 ? $$.currentMaxTickWidths[id] : maxWidth;
return $$.currentMaxTickWidths[id]; return $$.currentMaxTickWidths[id];
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -265,7 +265,7 @@ Axis.prototype.textAnchorForY2AxisLabel = function textAnchorForY2AxisLabel() { ...@@ -265,7 +265,7 @@ Axis.prototype.textAnchorForY2AxisLabel = function textAnchorForY2AxisLabel() {
}; };
Axis.prototype.getMaxTickWidth = function getMaxTickWidth(id, withoutRecompute) { Axis.prototype.getMaxTickWidth = function getMaxTickWidth(id, withoutRecompute) {
var $$ = this.owner, config = $$.config, var $$ = this.owner, config = $$.config,
maxWidth = 0, targetsToShow, scale, axis, body, svg; maxWidth = 0, targetsToShow, scale, axis, dummy, svg;
if (withoutRecompute && $$.currentMaxTickWidths[id]) { if (withoutRecompute && $$.currentMaxTickWidths[id]) {
return $$.currentMaxTickWidths[id]; return $$.currentMaxTickWidths[id];
} }
...@@ -282,16 +282,15 @@ Axis.prototype.getMaxTickWidth = function getMaxTickWidth(id, withoutRecompute) ...@@ -282,16 +282,15 @@ Axis.prototype.getMaxTickWidth = function getMaxTickWidth(id, withoutRecompute)
axis = this.getXAxis(scale, $$.xOrient, $$.xAxisTickFormat, $$.xAxisTickValues, false, true, true); axis = this.getXAxis(scale, $$.xOrient, $$.xAxisTickFormat, $$.xAxisTickValues, false, true, true);
this.updateXAxisTickValues(targetsToShow, axis); this.updateXAxisTickValues(targetsToShow, axis);
} }
body = $$.d3.select('body').classed('c3', true); dummy = $$.d3.select('body').append('div').classed('c3', true);
svg = body.append("svg").style('visibility', 'hidden').style('position', 'fixed').style('top', 0).style('left', 0), svg = dummy.append("svg").style('visibility', 'hidden').style('position', 'fixed').style('top', 0).style('left', 0),
svg.append('g').call(axis).each(function () { svg.append('g').call(axis).each(function () {
$$.d3.select(this).selectAll('text').each(function () { $$.d3.select(this).selectAll('text').each(function () {
var box = this.getBoundingClientRect(); var box = this.getBoundingClientRect();
if (maxWidth < box.width) { maxWidth = box.width; } if (maxWidth < box.width) { maxWidth = box.width; }
}); });
svg.remove(); dummy.remove();
}); });
body.classed('c3', false);
} }
$$.currentMaxTickWidths[id] = maxWidth <= 0 ? $$.currentMaxTickWidths[id] : maxWidth; $$.currentMaxTickWidths[id] = maxWidth <= 0 ? $$.currentMaxTickWidths[id] : maxWidth;
return $$.currentMaxTickWidths[id]; return $$.currentMaxTickWidths[id];
......
...@@ -48,8 +48,8 @@ c3_chart_internal_fn.redrawText = function (xForText, yForText, forFlow, withTra ...@@ -48,8 +48,8 @@ c3_chart_internal_fn.redrawText = function (xForText, yForText, forFlow, withTra
]; ];
}; };
c3_chart_internal_fn.getTextRect = function (text, cls) { c3_chart_internal_fn.getTextRect = function (text, cls) {
var body = this.d3.select('body').classed('c3', true), var dummy = this.d3.select('body').append('div').classed('c3', true),
svg = body.append("svg").style('visibility', 'hidden').style('position', 'fixed').style('top', 0).style('left', 0), svg = dummy.append("svg").style('visibility', 'hidden').style('position', 'fixed').style('top', 0).style('left', 0),
rect; rect;
svg.selectAll('.dummy') svg.selectAll('.dummy')
.data([text]) .data([text])
...@@ -57,8 +57,7 @@ c3_chart_internal_fn.getTextRect = function (text, cls) { ...@@ -57,8 +57,7 @@ c3_chart_internal_fn.getTextRect = function (text, cls) {
.classed(cls ? cls : "", true) .classed(cls ? cls : "", true)
.text(text) .text(text)
.each(function () { rect = this.getBoundingClientRect(); }); .each(function () { rect = this.getBoundingClientRect(); });
svg.remove(); dummy.remove();
body.classed('c3', false);
return rect; return rect;
}; };
c3_chart_internal_fn.generateXYForText = function (areaIndices, barIndices, lineIndices, forX) { c3_chart_internal_fn.generateXYForText = function (areaIndices, barIndices, lineIndices, forX) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment