Commit 3c5f1452 authored by Evgeny's avatar Evgeny

Fix ticks and grid filtering. Now filtering values from 0 to negative and from 0…

Fix ticks and grid filtering. Now filtering values from 0 to negative and from 0 to positive, rather than from negative to positive
parent caca8119
...@@ -3877,8 +3877,9 @@ ...@@ -3877,8 +3877,9 @@
var thinOutCoef = $$.getXThinOutCoef; var thinOutCoef = $$.getXThinOutCoef;
if(thinOutCoef > 1){ if(thinOutCoef > 1){
var indexOfZero = xgridData.indexOf(0);
xgridData = xgridData.filter(function(v, i){ xgridData = xgridData.filter(function(v, i){
return i % thinOutCoef == 0; return (i - indexOfZero)%thinOutCoef == 0;
}); });
} }
...@@ -3911,8 +3912,9 @@ ...@@ -3911,8 +3912,9 @@
var thinOutCoef = $$.getYThinOutCoef() var thinOutCoef = $$.getYThinOutCoef()
if(thinOutCoef > 1){ if(thinOutCoef > 1){
var indexOfZero = gridValues.indexOf(0);
gridValues = gridValues.filter(function(v, i){ gridValues = gridValues.filter(function(v, i){
return i%thinOutCoef == 0; return (i - indexOfZero)%thinOutCoef == 0;
}); });
} }
...@@ -6608,6 +6610,40 @@ ...@@ -6608,6 +6610,40 @@
value.value = Math.abs(value.value); value.value = Math.abs(value.value);
}); });
}); });
},
isXAxis = c3_chart_internal_fn.isXAxis = function(orient){
var $$ = this, config = $$.config;
if(config.axis_rotated){
if(orient === 'left' || orient === 'right'){
return true;
} else {
return false;
}
} else {
if(orient === 'top' || orient === 'bottom'){
return true;
} else {
return false;
}
}
},
isYAxis = c3_chart_internal_fn.isYAxis = function(orient){
var $$ = this, config = $$.config;
if(config.axis_rotated){
if(orient === 'top' || orient === 'bottom'){
return true;
} else {
return false;
}
} else {
if(orient === 'left' || orient === 'right'){
return true;
} else {
return false;
}
}
}; };
...@@ -8207,27 +8243,26 @@ ...@@ -8207,27 +8243,26 @@
var tickLength = Math.max(innerTickSize, 0) + tickPadding, var tickLength = Math.max(innerTickSize, 0) + tickPadding,
isVertical = orient === 'left' || orient === 'right'; isVertical = orient === 'left' || orient === 'right';
var indexOfZero = ticks.indexOf(0);
// If we have 'broken' axis
if(indexOfZero === -1){
indexOfZero = 0;
}
// this should be called only when category axis // this should be called only when category axis
function splitTickText(d, maxWidth) { function splitTickText(d, maxWidth) {
var tickText = textFormatted(d), var tickText = textFormatted(d),
subtext, spaceIndex, textWidth, thinOutCoef, splitted = []; subtext, spaceIndex, textWidth, thinOutCoef, splitted = [];
switch(orient){ if($$.isXAxis(orient)){
case "top":
case "bottom":
{
thinOutCoef = $$.getXThinOutCoef(); thinOutCoef = $$.getXThinOutCoef();
break; } else {
}
case "left":
case "right":
{
thinOutCoef = $$.getYThinOutCoef(); thinOutCoef = $$.getYThinOutCoef();
break;
}
} }
if(d % thinOutCoef !== 0){ if((d-indexOfZero) % thinOutCoef !== 0){
return [""]; return [""];
} }
...@@ -8281,7 +8316,7 @@ ...@@ -8281,7 +8316,7 @@
text = tick.select("text"); text = tick.select("text");
text.style('display', function(d, i){ text.style('display', function(d, i){
return shouldDrawTickText(i) ? 'block' : 'none'; return shouldDrawTickText(i - indexOfZero) ? 'block' : 'none';
}); });
tspan = text.selectAll('tspan') tspan = text.selectAll('tspan')
...@@ -8309,31 +8344,22 @@ ...@@ -8309,31 +8344,22 @@
var line = tick.select("line"); var line = tick.select("line");
switch(orient){ if($$.isXAxis(orient)){
case "bottom":
case "top":
{
if($$.config.grid_x_show){ if($$.config.grid_x_show){
var coef = $$.getXThinOutCoef(); var coef = $$.getXThinOutCoef();
line.style('display', function(d, i){ line.style('display', function(d, i){
return i%coef == 0 ? 'block' : 'none'; return (i-indexOfZero)%coef == 0 ? 'block' : 'none';
}); });
} }
break; } else {
}
case "left":
case "right":
{
if($$.config.grid_y_show){ if($$.config.grid_y_show){
var coef = $$.getYThinOutCoef(); var coef = $$.getYThinOutCoef();
line.style('display', function(d, i){ line.style('display', function(d, i){
return i%coef == 0 ? 'block' : 'none'; return (i-indexOfZero)%coef == 0 ? 'block' : 'none';
}); });
} }
break;
}
} }
switch (orient) { switch (orient) {
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -138,27 +138,26 @@ function c3_axis(d3, params, $$) { ...@@ -138,27 +138,26 @@ function c3_axis(d3, params, $$) {
var tickLength = Math.max(innerTickSize, 0) + tickPadding, var tickLength = Math.max(innerTickSize, 0) + tickPadding,
isVertical = orient === 'left' || orient === 'right'; isVertical = orient === 'left' || orient === 'right';
var indexOfZero = ticks.indexOf(0);
// If we have 'broken' axis
if(indexOfZero === -1){
indexOfZero = 0;
}
// this should be called only when category axis // this should be called only when category axis
function splitTickText(d, maxWidth) { function splitTickText(d, maxWidth) {
var tickText = textFormatted(d), var tickText = textFormatted(d),
subtext, spaceIndex, textWidth, thinOutCoef, splitted = []; subtext, spaceIndex, textWidth, thinOutCoef, splitted = [];
switch(orient){ if($$.isXAxis(orient)){
case "top":
case "bottom":
{
thinOutCoef = $$.getXThinOutCoef(); thinOutCoef = $$.getXThinOutCoef();
break; } else {
}
case "left":
case "right":
{
thinOutCoef = $$.getYThinOutCoef(); thinOutCoef = $$.getYThinOutCoef();
break;
}
} }
if(d % thinOutCoef !== 0){ if((d-indexOfZero) % thinOutCoef !== 0){
return [""]; return [""];
} }
...@@ -212,7 +211,7 @@ function c3_axis(d3, params, $$) { ...@@ -212,7 +211,7 @@ function c3_axis(d3, params, $$) {
text = tick.select("text"); text = tick.select("text");
text.style('display', function(d, i){ text.style('display', function(d, i){
return shouldDrawTickText(i) ? 'block' : 'none'; return shouldDrawTickText(i - indexOfZero) ? 'block' : 'none';
}); });
tspan = text.selectAll('tspan') tspan = text.selectAll('tspan')
...@@ -240,31 +239,22 @@ function c3_axis(d3, params, $$) { ...@@ -240,31 +239,22 @@ function c3_axis(d3, params, $$) {
var line = tick.select("line"); var line = tick.select("line");
switch(orient){ if($$.isXAxis(orient)){
case "bottom":
case "top":
{
if($$.config.grid_x_show){ if($$.config.grid_x_show){
var coef = $$.getXThinOutCoef(); var coef = $$.getXThinOutCoef();
line.style('display', function(d, i){ line.style('display', function(d, i){
return i%coef == 0 ? 'block' : 'none'; return (i-indexOfZero)%coef == 0 ? 'block' : 'none';
}); });
} }
break; } else {
}
case "left":
case "right":
{
if($$.config.grid_y_show){ if($$.config.grid_y_show){
var coef = $$.getYThinOutCoef(); var coef = $$.getYThinOutCoef();
line.style('display', function(d, i){ line.style('display', function(d, i){
return i%coef == 0 ? 'block' : 'none'; return (i-indexOfZero)%coef == 0 ? 'block' : 'none';
}); });
} }
break;
}
} }
switch (orient) { switch (orient) {
......
...@@ -35,8 +35,9 @@ c3_chart_internal_fn.updateXGrid = function (withoutUpdate) { ...@@ -35,8 +35,9 @@ c3_chart_internal_fn.updateXGrid = function (withoutUpdate) {
var thinOutCoef = $$.getXThinOutCoef; var thinOutCoef = $$.getXThinOutCoef;
if(thinOutCoef > 1){ if(thinOutCoef > 1){
var indexOfZero = xgridData.indexOf(0);
xgridData = xgridData.filter(function(v, i){ xgridData = xgridData.filter(function(v, i){
return i % thinOutCoef == 0; return (i - indexOfZero)%thinOutCoef == 0;
}); });
} }
...@@ -69,8 +70,9 @@ c3_chart_internal_fn.updateYGrid = function () { ...@@ -69,8 +70,9 @@ c3_chart_internal_fn.updateYGrid = function () {
var thinOutCoef = $$.getYThinOutCoef() var thinOutCoef = $$.getYThinOutCoef()
if(thinOutCoef > 1){ if(thinOutCoef > 1){
var indexOfZero = gridValues.indexOf(0);
gridValues = gridValues.filter(function(v, i){ gridValues = gridValues.filter(function(v, i){
return i%thinOutCoef == 0; return (i - indexOfZero)%thinOutCoef == 0;
}); });
} }
......
...@@ -120,5 +120,39 @@ var isValue = c3_chart_internal_fn.isValue = function (v) { ...@@ -120,5 +120,39 @@ var isValue = c3_chart_internal_fn.isValue = function (v) {
value.value = Math.abs(value.value); value.value = Math.abs(value.value);
}); });
}); });
},
isXAxis = c3_chart_internal_fn.isXAxis = function(orient){
var $$ = this, config = $$.config;
if(config.axis_rotated){
if(orient === 'left' || orient === 'right'){
return true;
} else {
return false;
}
} else {
if(orient === 'top' || orient === 'bottom'){
return true;
} else {
return false;
}
}
},
isYAxis = c3_chart_internal_fn.isYAxis = function(orient){
var $$ = this, config = $$.config;
if(config.axis_rotated){
if(orient === 'top' || orient === 'bottom'){
return true;
} else {
return false;
}
} else {
if(orient === 'left' || orient === 'right'){
return true;
} else {
return false;
}
}
}; };
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