Browse Source

Fix data label position for cero value when all the data set is negative

When all the data set is negative the label position of cero value will
be above the the y axis line then you will not see the label.
pull/1086/head
Yordis Prieto 10 years ago
parent
commit
a6241ca232
  1. 4
      c3.css
  2. 15
      c3.js
  3. 13
      c3.min.js
  4. 13
      src/data.convert.js
  5. 2
      src/text.js

4
c3.css

@ -70,11 +70,11 @@
/*-- Region --*/
.c3-region {
fill: steelblue;
fill-opacity: 0.1; }
fill-opacity: .1; }
/*-- Brush --*/
.c3-brush .extent {
fill-opacity: 0.1; }
fill-opacity: .1; }
/*-- Select - Drag --*/
/*-- Legend --*/

15
c3.js

@ -2038,6 +2038,8 @@
xs = $$.d3.keys(data[0]).filter($$.isX, $$),
targets;
$$.allDataIsNegative = true;
// save x for update data by load when custom x and c3.x API
ids.forEach(function (id) {
var xKey = $$.getXKey(id);
@ -2080,7 +2082,9 @@
id: convertedId,
id_org: id,
values: data.map(function (d, i) {
var xKey = $$.getXKey(id), rawX = d[xKey], x = $$.generateTargetX(rawX, id, i);
var xKey = $$.getXKey(id), rawX = d[xKey],
x = $$.generateTargetX(rawX, id, i),
value = d[id] !== null && !isNaN(d[id]) ? +d[id] : null;
// use x as categories if custom x and categorized
if ($$.isCustomX() && $$.isCategorized() && index === 0 && rawX) {
if (i === 0) { config.axis_x_categories = []; }
@ -2090,7 +2094,12 @@
if (isUndefined(d[id]) || $$.data.xs[id].length <= i) {
x = undefined;
}
return {x: x, value: d[id] !== null && !isNaN(d[id]) ? +d[id] : null, id: convertedId};
if(value > 0) {
$$.allDataIsNegative = false;
}
return {x: x, value: value, id: convertedId};
}).filter(function (v) { return isDefined(v.x); })
};
});
@ -3352,7 +3361,7 @@
yPos = (points[0][0] + points[2][0] + box.height * 0.6) / 2;
} else {
yPos = points[2][1];
if (d.value < 0) {
if (d.value < 0 || (d.value === 0 && $$.allDataIsNegative)) {
yPos += box.height;
if ($$.isBarType(d) && $$.isSafari()) {
yPos -= 3;

13
c3.min.js vendored

File diff suppressed because one or more lines are too long

13
src/data.convert.js

@ -98,6 +98,8 @@ c3_chart_internal_fn.convertDataToTargets = function (data, appendXs) {
xs = $$.d3.keys(data[0]).filter($$.isX, $$),
targets;
$$.allDataIsNegative = true;
// save x for update data by load when custom x and c3.x API
ids.forEach(function (id) {
var xKey = $$.getXKey(id);
@ -140,7 +142,9 @@ c3_chart_internal_fn.convertDataToTargets = function (data, appendXs) {
id: convertedId,
id_org: id,
values: data.map(function (d, i) {
var xKey = $$.getXKey(id), rawX = d[xKey], x = $$.generateTargetX(rawX, id, i);
var xKey = $$.getXKey(id), rawX = d[xKey],
x = $$.generateTargetX(rawX, id, i),
value = d[id] !== null && !isNaN(d[id]) ? +d[id] : null;
// use x as categories if custom x and categorized
if ($$.isCustomX() && $$.isCategorized() && index === 0 && rawX) {
if (i === 0) { config.axis_x_categories = []; }
@ -150,7 +154,12 @@ c3_chart_internal_fn.convertDataToTargets = function (data, appendXs) {
if (isUndefined(d[id]) || $$.data.xs[id].length <= i) {
x = undefined;
}
return {x: x, value: d[id] !== null && !isNaN(d[id]) ? +d[id] : null, id: convertedId};
if(value > 0) {
$$.allDataIsNegative = false;
}
return {x: x, value: value, id: convertedId};
}).filter(function (v) { return isDefined(v.x); })
};
});

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) {
if (d.value < 0 || (d.value === 0 && $$.allDataIsNegative)) {
yPos += box.height;
if ($$.isBarType(d) && $$.isSafari()) {
yPos -= 3;

Loading…
Cancel
Save