|
|
|
@ -30,13 +30,14 @@ c3_chart_internal_fn.initAxis = function () {
|
|
|
|
|
.attr("transform", config.axis_rotated ? "" : "rotate(-90)") |
|
|
|
|
.style("text-anchor", $$.textAnchorForY2AxisLabel.bind($$)); |
|
|
|
|
}; |
|
|
|
|
c3_chart_internal_fn.getXAxis = function (scale, orient, tickFormat, tickValues, withOuterTick) { |
|
|
|
|
c3_chart_internal_fn.getXAxis = function (scale, orient, tickFormat, tickValues, withOuterTick, withoutTransition) { |
|
|
|
|
var $$ = this, config = $$.config, |
|
|
|
|
axisParams = { |
|
|
|
|
isCategory: $$.isCategorized(), |
|
|
|
|
withOuterTick: withOuterTick, |
|
|
|
|
tickMultiline: config.axis_x_tick_multiline, |
|
|
|
|
tickWidth: config.axis_x_tick_width |
|
|
|
|
tickWidth: config.axis_x_tick_width, |
|
|
|
|
withoutTransition: withoutTransition, |
|
|
|
|
}, |
|
|
|
|
axis = c3_axis($$.d3, axisParams).scale(scale).orient(orient); |
|
|
|
|
|
|
|
|
@ -63,6 +64,19 @@ c3_chart_internal_fn.getXAxis = function (scale, orient, tickFormat, tickValues,
|
|
|
|
|
|
|
|
|
|
return axis; |
|
|
|
|
}; |
|
|
|
|
c3_chart_internal_fn.updateXAxisTickValues = function (targets, axis) { |
|
|
|
|
var $$ = this, config = $$.config, tickValues; |
|
|
|
|
if (config.axis_x_tick_fit || config.axis_x_tick_count) { |
|
|
|
|
tickValues = $$.generateTickValues($$.mapTargetsToUniqueXs(targets), config.axis_x_tick_count, $$.isTimeSeries()); |
|
|
|
|
} |
|
|
|
|
if (axis) { |
|
|
|
|
axis.tickValues(tickValues); |
|
|
|
|
} else { |
|
|
|
|
$$.xAxis.tickValues(tickValues); |
|
|
|
|
$$.subXAxis.tickValues(tickValues); |
|
|
|
|
} |
|
|
|
|
return tickValues; |
|
|
|
|
}; |
|
|
|
|
c3_chart_internal_fn.getYAxis = function (scale, orient, tickFormat, tickValues, withOuterTick) { |
|
|
|
|
var axisParams = {withOuterTick: withOuterTick}, |
|
|
|
|
axis = c3_axis(this.d3, axisParams).scale(scale).orient(orient).tickFormat(tickFormat); |
|
|
|
@ -266,7 +280,7 @@ c3_chart_internal_fn.rotateTickText = function (axis, transition, rotate) {
|
|
|
|
|
|
|
|
|
|
c3_chart_internal_fn.getMaxTickWidth = function (id, withoutRecompute) { |
|
|
|
|
var $$ = this, config = $$.config, |
|
|
|
|
maxWidth = 0, targetsToShow, scale, axis; |
|
|
|
|
maxWidth = 0, targetsToShow, scale, axis, body, svg; |
|
|
|
|
if (withoutRecompute && $$.currentMaxTickWidths[id]) { |
|
|
|
|
return $$.currentMaxTickWidths[id]; |
|
|
|
|
} |
|
|
|
@ -281,13 +295,21 @@ c3_chart_internal_fn.getMaxTickWidth = function (id, withoutRecompute) {
|
|
|
|
|
} else { |
|
|
|
|
scale = $$.x.copy().domain($$.getXDomain(targetsToShow)); |
|
|
|
|
axis = $$.getXAxis(scale, $$.xOrient, $$.xAxisTickFormat, $$.xAxisTickValues); |
|
|
|
|
$$.updateXAxisTickValues(targetsToShow, axis); |
|
|
|
|
} |
|
|
|
|
$$.d3.select('body').append("g").style('visibility', 'hidden').call(axis).each(function () { |
|
|
|
|
body = this.d3.select('body').classed('c3', true); |
|
|
|
|
svg = body.append('svg').style('visibility', 'hidden'); |
|
|
|
|
svg.append('g').call(axis).each(function () { |
|
|
|
|
$$.d3.select(this).selectAll('text tspan').each(function () { |
|
|
|
|
var box = this.getBoundingClientRect(); |
|
|
|
|
if (box.left > 0 && maxWidth < box.width) { maxWidth = box.width; } |
|
|
|
|
if (box.left >= 0 && maxWidth < box.width) { maxWidth = box.width; } |
|
|
|
|
}); |
|
|
|
|
}).remove(); |
|
|
|
|
}); |
|
|
|
|
// TODO: time lag to get maxWidth
|
|
|
|
|
window.setTimeout(function () { |
|
|
|
|
svg.remove(); |
|
|
|
|
}, 100); |
|
|
|
|
body.classed('c3', false); |
|
|
|
|
} |
|
|
|
|
$$.currentMaxTickWidths[id] = maxWidth <= 0 ? $$.currentMaxTickWidths[id] : maxWidth; |
|
|
|
|
return $$.currentMaxTickWidths[id]; |
|
|
|
|