Commit 13d543f0 authored by Evgeny's avatar Evgeny

Make grid thing out more flexible

parent 6cea1c00
...@@ -3864,10 +3864,11 @@ ...@@ -3864,10 +3864,11 @@
xgridData = $$.generateGridData(config.grid_x_type, $$.x), xgridData = $$.generateGridData(config.grid_x_type, $$.x),
tickOffset = $$.isCategorized() ? $$.xAxis.tickOffset() : 0; tickOffset = $$.isCategorized() ? $$.xAxis.tickOffset() : 0;
var thinOutCoef = $$.getXThinOutCoef;
if($$.shouldThinOutXGrid()){ if(thinOutCoef > 1){
xgridData = xgridData.filter(function(v, i){ xgridData = xgridData.filter(function(v, i){
return i % 2 == 0; return i % thinOutCoef == 0;
}); });
} }
...@@ -3897,9 +3898,11 @@ ...@@ -3897,9 +3898,11 @@
var $$ = this, config = $$.config, var $$ = this, config = $$.config,
gridValues = $$.yAxis.tickValues() || $$.y.ticks(config.grid_y_ticks); gridValues = $$.yAxis.tickValues() || $$.y.ticks(config.grid_y_ticks);
if($$.shouldThinOutYGrid()){ var thinOutCoef = $$.getYThinOutCoef()
if(thinOutCoef > 1){
gridValues = gridValues.filter(function(v, i){ gridValues = gridValues.filter(function(v, i){
return i%2 == 0; return i%thinOutCoef == 0;
}); });
} }
...@@ -4074,24 +4077,46 @@ ...@@ -4074,24 +4077,46 @@
} }
} }
c3_chart_internal_fn.shouldThinOutXGrid = function(){ c3_chart_internal_fn.getXThinOutCoef = function(){
var $$ = this, config = $$.config; var $$ = this, config = $$.config;
var cv;
if(config.axis_rotated){ if(config.axis_rotated){
return $$.getCurrentHeight() <= 300; cv = $$.getCurrentHeight();
} else { } else {
return $$.getCurrentWidth() <= 300; cv = $$.getCurrentWidth();
} }
if(cv <= 150){
return 3;
} else if(cv <= 300){
return 2;
} else {
return 1;
}
};; };;
c3_chart_internal_fn.shouldThinOutYGrid = function(){ c3_chart_internal_fn.getYThinOutCoef = function(){
var $$ = this, config = $$.config; var $$ = this, config = $$.config;
var cv;
if(config.axis_rotated){ if(config.axis_rotated){
return $$.getCurrentWidth() <= 300; cv = $$.getCurrentWidth();
} else { } else {
return $$.getCurrentHeight() <= 300; cv = $$.getCurrentHeight();
} }
if(cv <= 150){
return 3;
} else if(cv <= 300){
return 2;
} else {
return 1;
}
}; };
c3_chart_internal_fn.initTooltip = function () { c3_chart_internal_fn.initTooltip = function () {
...@@ -8254,16 +8279,20 @@ ...@@ -8254,16 +8279,20 @@
switch(orient){ switch(orient){
case "bottom": case "bottom":
case "top": case "top":
if($$.shouldThinOutXGrid()){ if($$.config.grid_x_show){
var coef = $$.getXThinOutCoef();
line.style('display', function(d, i){ line.style('display', function(d, i){
return i%2 == 0 ? 'block' : 'none'; return i%coef == 0 ? 'block' : 'none';
}); });
} }
case "left": case "left":
case "right": case "right":
if($$.shouldThinOutYGrid()){ if($$.config.grid_y_show){
var coef = $$.getYThinOutCoef();
line.style('display', function(d, i){ line.style('display', function(d, i){
return i%2 == 0 ? 'block' : 'none'; return i%coef == 0 ? 'block' : 'none';
}); });
} }
} }
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -222,16 +222,20 @@ function c3_axis(d3, params, $$) { ...@@ -222,16 +222,20 @@ function c3_axis(d3, params, $$) {
switch(orient){ switch(orient){
case "bottom": case "bottom":
case "top": case "top":
if($$.shouldThinOutXGrid()){ if($$.config.grid_x_show){
var coef = $$.getXThinOutCoef();
line.style('display', function(d, i){ line.style('display', function(d, i){
return i%2 == 0 ? 'block' : 'none'; return i%coef == 0 ? 'block' : 'none';
}); });
} }
case "left": case "left":
case "right": case "right":
if($$.shouldThinOutYGrid()){ if($$.config.grid_y_show){
var coef = $$.getYThinOutCoef();
line.style('display', function(d, i){ line.style('display', function(d, i){
return i%2 == 0 ? 'block' : 'none'; return i%coef == 0 ? 'block' : 'none';
}); });
} }
} }
......
...@@ -32,10 +32,11 @@ c3_chart_internal_fn.updateXGrid = function (withoutUpdate) { ...@@ -32,10 +32,11 @@ c3_chart_internal_fn.updateXGrid = function (withoutUpdate) {
xgridData = $$.generateGridData(config.grid_x_type, $$.x), xgridData = $$.generateGridData(config.grid_x_type, $$.x),
tickOffset = $$.isCategorized() ? $$.xAxis.tickOffset() : 0; tickOffset = $$.isCategorized() ? $$.xAxis.tickOffset() : 0;
var thinOutCoef = $$.getXThinOutCoef;
if($$.shouldThinOutXGrid()){ if(thinOutCoef > 1){
xgridData = xgridData.filter(function(v, i){ xgridData = xgridData.filter(function(v, i){
return i % 2 == 0; return i % thinOutCoef == 0;
}); });
} }
...@@ -65,9 +66,11 @@ c3_chart_internal_fn.updateYGrid = function () { ...@@ -65,9 +66,11 @@ c3_chart_internal_fn.updateYGrid = function () {
var $$ = this, config = $$.config, var $$ = this, config = $$.config,
gridValues = $$.yAxis.tickValues() || $$.y.ticks(config.grid_y_ticks); gridValues = $$.yAxis.tickValues() || $$.y.ticks(config.grid_y_ticks);
if($$.shouldThinOutYGrid()){ var thinOutCoef = $$.getYThinOutCoef()
if(thinOutCoef > 1){
gridValues = gridValues.filter(function(v, i){ gridValues = gridValues.filter(function(v, i){
return i%2 == 0; return i%thinOutCoef == 0;
}); });
} }
...@@ -242,22 +245,44 @@ c3_chart_internal_fn.removeGridLines = function (params, forX) { ...@@ -242,22 +245,44 @@ c3_chart_internal_fn.removeGridLines = function (params, forX) {
} }
} }
c3_chart_internal_fn.shouldThinOutXGrid = function(){ c3_chart_internal_fn.getXThinOutCoef = function(){
var $$ = this, config = $$.config; var $$ = this, config = $$.config;
var cv;
if(config.axis_rotated){ if(config.axis_rotated){
return $$.getCurrentHeight() <= 300; cv = $$.getCurrentHeight();
} else {
cv = $$.getCurrentWidth();
}
if(cv <= 150){
return 3;
} else if(cv <= 300){
return 2;
} else { } else {
return $$.getCurrentWidth() <= 300; return 1;
} }
};; };;
c3_chart_internal_fn.shouldThinOutYGrid = function(){ c3_chart_internal_fn.getYThinOutCoef = function(){
var $$ = this, config = $$.config; var $$ = this, config = $$.config;
var cv;
if(config.axis_rotated){ if(config.axis_rotated){
return $$.getCurrentWidth() <= 300; cv = $$.getCurrentWidth();
} else { } else {
return $$.getCurrentHeight() <= 300; cv = $$.getCurrentHeight();
} }
if(cv <= 150){
return 3;
} else if(cv <= 300){
return 2;
} else {
return 1;
}
}; };
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