Commit 0bc9ce15 authored by Yordis Prieto's avatar Yordis Prieto

Fix data label position when all the data set is Zero

When all the data set is zero the label should be in the above of the y axis
parent a6241ca2
......@@ -2036,6 +2036,8 @@
var $$ = this, config = $$.config,
ids = $$.d3.keys(data[0]).filter($$.isNotX, $$),
xs = $$.d3.keys(data[0]).filter($$.isX, $$),
zeroUnderYAxis = true,
allZero = true,
targets;
$$.allDataIsNegative = true;
......@@ -2095,8 +2097,12 @@
x = undefined;
}
if(value !== null && value !== 0) {
allZero = false;
}
if(value > 0) {
$$.allDataIsNegative = false;
zeroUnderYAxis = false;
}
return {x: x, value: value, id: convertedId};
......@@ -2126,6 +2132,12 @@
});
});
if(allZero) {
zeroUnderYAxis = false;
}
$$.zeroUnderYAxis = zeroUnderYAxis;
// set target types
if (config.data_type) {
$$.setTargetType($$.mapToIds(targets).filter(function (id) { return ! (id in config.data_types); }), config.data_type);
......@@ -3361,7 +3373,7 @@
yPos = (points[0][0] + points[2][0] + box.height * 0.6) / 2;
} else {
yPos = points[2][1];
if (d.value < 0 || (d.value === 0 && $$.allDataIsNegative)) {
if (d.value < 0 || (d.value === 0 && $$.zeroUnderYAxis)) {
yPos += box.height;
if ($$.isBarType(d) && $$.isSafari()) {
yPos -= 3;
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -96,6 +96,8 @@ c3_chart_internal_fn.convertDataToTargets = function (data, appendXs) {
var $$ = this, config = $$.config,
ids = $$.d3.keys(data[0]).filter($$.isNotX, $$),
xs = $$.d3.keys(data[0]).filter($$.isX, $$),
zeroUnderYAxis = true,
allZero = true,
targets;
$$.allDataIsNegative = true;
......@@ -155,8 +157,12 @@ c3_chart_internal_fn.convertDataToTargets = function (data, appendXs) {
x = undefined;
}
if(value !== null && value !== 0) {
allZero = false;
}
if(value > 0) {
$$.allDataIsNegative = false;
zeroUnderYAxis = false;
}
return {x: x, value: value, id: convertedId};
......@@ -186,6 +192,12 @@ c3_chart_internal_fn.convertDataToTargets = function (data, appendXs) {
});
});
if(allZero) {
zeroUnderYAxis = false;
}
$$.zeroUnderYAxis = zeroUnderYAxis;
// set target types
if (config.data_type) {
$$.setTargetType($$.mapToIds(targets).filter(function (id) { return ! (id in config.data_types); }), config.data_type);
......
......@@ -98,7 +98,7 @@ c3_chart_internal_fn.getYForText = function (points, d, textElement) {
yPos = (points[0][0] + points[2][0] + box.height * 0.6) / 2;
} else {
yPos = points[2][1];
if (d.value < 0 || (d.value === 0 && $$.allDataIsNegative)) {
if (d.value < 0 || (d.value === 0 && $$.zeroUnderYAxis)) {
yPos += box.height;
if ($$.isBarType(d) && $$.isSafari()) {
yPos -= 3;
......
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