Tick culling: depend on tick width

parent 4caef74d
...@@ -8401,7 +8401,9 @@ ...@@ -8401,7 +8401,9 @@
var start = domain[0], stop = domain[domain.length - 1]; var start = domain[0], stop = domain[domain.length - 1];
return start < stop ? [ start, stop ] : [ stop, start ]; return start < stop ? [ start, stop ] : [ stop, start ];
} }
function shouldDrawTickText(id){ function shouldDrawTickText(id, m){
// Multiplier to handle long tick texts
m = m || 1;
var heightLimits = [ var heightLimits = [
// Left is width, right is n // Left is width, right is n
// Every nth tick will be shown // Every nth tick will be shown
...@@ -8415,8 +8417,8 @@ ...@@ -8415,8 +8417,8 @@
// Left is width, right is n // Left is width, right is n
// Every nth tick will be show // Every nth tick will be show
[-Infinity], [-Infinity],
[100, 6], [70, 6],
[200, 4], [140, 4],
[300, 2], [300, 2],
[Infinity, 1] [Infinity, 1]
]; ];
...@@ -8424,7 +8426,7 @@ ...@@ -8424,7 +8426,7 @@
var size = $$.config.axis_rotated ? $$.currentWidth : $$.currentHeight; var size = $$.config.axis_rotated ? $$.currentWidth : $$.currentHeight;
var sizeLimits = $$.config.axis_rotated ? widthLimits : heightLimits; var sizeLimits = $$.config.axis_rotated ? widthLimits : heightLimits;
for(var i = sizeLimits.length-1; i--; ){ for(var i = sizeLimits.length-1; i--; ){
if(size > sizeLimits[i][0]) { if(size > sizeLimits[i][0] * m) {
divisor = sizeLimits[i+1][1]; divisor = sizeLimits[i+1][1];
break; break;
} }
...@@ -8575,21 +8577,24 @@ ...@@ -8575,21 +8577,24 @@
text = tick.select("text"); text = tick.select("text");
text.style('display', function(d, i){ var maxTickLength = 1;
return shouldDrawTickText(i - indexOfZero) ? 'block' : 'none';
});
tspan = text.selectAll('tspan') tspan = text.selectAll('tspan')
.data(function (d, i) { .data(function (d, i) {
var splitted = params.tickMultiline ? splitTickText(d, params.tickWidth) : [].concat(textFormatted(d)); var splitted = params.tickMultiline ? splitTickText(d, params.tickWidth) : [].concat(textFormatted(d));
counts[i] = splitted.length; counts[i] = splitted.length;
return splitted.map(function (s) { return splitted.map(function (s) {
maxTickLength = Math.max(maxTickLength, s.length);
return { index: i, splitted: String(s) }; return { index: i, splitted: String(s) };
}); });
}); });
tspan.enter().append('tspan'); tspan.enter().append('tspan');
tspan.exit().remove(); tspan.exit().remove();
text.style('display', function(d, i){
return shouldDrawTickText(i - indexOfZero, $$.config.axis_rotated ? maxTickLength : 1) ? 'block' : 'none';
});
var fontSize = parseFloat(getStyleValue($$, '.c3-axis-y .tick', 'font-size')); var fontSize = parseFloat(getStyleValue($$, '.c3-axis-y .tick', 'font-size'));
var axisId = $$.isXAxis(orient) ? 'x' : 'y'; var axisId = $$.isXAxis(orient) ? 'x' : 'y';
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -34,7 +34,9 @@ function c3_axis(d3, params, $$) { ...@@ -34,7 +34,9 @@ function c3_axis(d3, params, $$) {
var start = domain[0], stop = domain[domain.length - 1]; var start = domain[0], stop = domain[domain.length - 1];
return start < stop ? [ start, stop ] : [ stop, start ]; return start < stop ? [ start, stop ] : [ stop, start ];
} }
function shouldDrawTickText(id){ function shouldDrawTickText(id, m){
// Multiplier to handle long tick texts
m = m || 1;
var heightLimits = [ var heightLimits = [
// Left is width, right is n // Left is width, right is n
// Every nth tick will be shown // Every nth tick will be shown
...@@ -48,8 +50,8 @@ function c3_axis(d3, params, $$) { ...@@ -48,8 +50,8 @@ function c3_axis(d3, params, $$) {
// Left is width, right is n // Left is width, right is n
// Every nth tick will be show // Every nth tick will be show
[-Infinity], [-Infinity],
[100, 6], [70, 6],
[200, 4], [140, 4],
[300, 2], [300, 2],
[Infinity, 1] [Infinity, 1]
]; ];
...@@ -57,7 +59,7 @@ function c3_axis(d3, params, $$) { ...@@ -57,7 +59,7 @@ function c3_axis(d3, params, $$) {
var size = $$.config.axis_rotated ? $$.currentWidth : $$.currentHeight; var size = $$.config.axis_rotated ? $$.currentWidth : $$.currentHeight;
var sizeLimits = $$.config.axis_rotated ? widthLimits : heightLimits; var sizeLimits = $$.config.axis_rotated ? widthLimits : heightLimits;
for(var i = sizeLimits.length-1; i--; ){ for(var i = sizeLimits.length-1; i--; ){
if(size > sizeLimits[i][0]) { if(size > sizeLimits[i][0] * m) {
divisor = sizeLimits[i+1][1]; divisor = sizeLimits[i+1][1];
break; break;
} }
...@@ -208,21 +210,24 @@ function c3_axis(d3, params, $$) { ...@@ -208,21 +210,24 @@ function c3_axis(d3, params, $$) {
text = tick.select("text"); text = tick.select("text");
text.style('display', function(d, i){ var maxTickLength = 1;
return shouldDrawTickText(i - indexOfZero) ? 'block' : 'none';
});
tspan = text.selectAll('tspan') tspan = text.selectAll('tspan')
.data(function (d, i) { .data(function (d, i) {
var splitted = params.tickMultiline ? splitTickText(d, params.tickWidth) : [].concat(textFormatted(d)); var splitted = params.tickMultiline ? splitTickText(d, params.tickWidth) : [].concat(textFormatted(d));
counts[i] = splitted.length; counts[i] = splitted.length;
return splitted.map(function (s) { return splitted.map(function (s) {
maxTickLength = Math.max(maxTickLength, s.length);
return { index: i, splitted: String(s) }; return { index: i, splitted: String(s) };
}); });
}); });
tspan.enter().append('tspan'); tspan.enter().append('tspan');
tspan.exit().remove(); tspan.exit().remove();
text.style('display', function(d, i){
return shouldDrawTickText(i - indexOfZero, $$.config.axis_rotated ? maxTickLength : 1) ? 'block' : 'none';
});
var fontSize = parseFloat(getStyleValue($$, '.c3-axis-y .tick', 'font-size')); var fontSize = parseFloat(getStyleValue($$, '.c3-axis-y .tick', 'font-size'));
var axisId = $$.isXAxis(orient) ? 'x' : 'y'; var axisId = $$.isXAxis(orient) ? 'x' : 'y';
......
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