Browse Source

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
pull/1086/head
Yordis Prieto 10 years ago
parent
commit
0bc9ce1577
  1. 16
      c3.js
  2. 4
      c3.min.js
  3. 14
      src/data.convert.js
  4. 2
      src/text.js

16
c3.js

@ -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;

4
c3.min.js vendored

File diff suppressed because one or more lines are too long

14
src/data.convert.js

@ -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);

2
src/text.js

@ -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;

Loading…
Cancel
Save