Browse Source

Fix width for data label

pull/300/head
Masayuki Tanaka 11 years ago
parent
commit
ed534fc53a
  1. 16
      c3.js
  2. 4
      c3.min.js

16
c3.js

@ -1234,7 +1234,7 @@
} }
// add padding for data label // add padding for data label
if (showHorizontalDataLabel) { if (showHorizontalDataLabel) {
widths = getDataLabelWidth(yDomainMin, yDomainMax); widths = getDataLabelWidth(yDomainMin, yDomainMax, axisId);
diff = diffDomain(y.range()); diff = diffDomain(y.range());
ratio = [widths[0] / diff, widths[1] / diff]; ratio = [widths[0] / diff, widths[1] / diff];
padding_top += domainLength * (ratio[1] / (1 - ratio[0] - ratio[1])); padding_top += domainLength * (ratio[1] / (1 - ratio[0] - ratio[1]));
@ -1806,13 +1806,15 @@
} }
return false; return false;
} }
function getDataLabelWidth(min, max) { function getDataLabelWidth(min, max, axisId) {
var widths = [], paddingCoef = 1.3; var widths = [], paddingCoef = 1.3;
selectChart.select('svg').selectAll('.dummy') selectChart.select('svg').selectAll('.dummy')
.data([min, max]) .data([min, max])
.enter().append('text') .enter().append('text')
.text(function (d) { return formatByAxisId(d.id)(d.value, d.id); }) .text(function (d) { return formatByAxisId(axisId)(d); })
.each(function (d, i) { widths[i] = this.getBoundingClientRect().width * paddingCoef; }) .each(function (d, i) {
widths[i] = this.getBoundingClientRect().width * paddingCoef;
})
.remove(); .remove();
return widths; return widths;
} }
@ -1838,8 +1840,8 @@
function defaultArcValueFormat(v, ratio) { function defaultArcValueFormat(v, ratio) {
return (ratio * 100).toFixed(1) + '%'; return (ratio * 100).toFixed(1) + '%';
} }
function formatByAxisId(id) { function formatByAxisId(axisId) {
var defaultFormat = function (v) { return isValue(v) ? +v : ""; }, axisId = getAxisId(id), format = defaultFormat; var format = function (v) { return isValue(v) ? +v : ""; };
// find format according to axis id // find format according to axis id
if (typeof __data_labels.format === 'function') { if (typeof __data_labels.format === 'function') {
format = __data_labels.format; format = __data_labels.format;
@ -3710,7 +3712,7 @@
.style("fill", color) .style("fill", color)
.style("fill-opacity", 0); .style("fill-opacity", 0);
mainText mainText
.text(function (d) { return formatByAxisId(d.id)(d.value, d.id); }) .text(function (d) { return formatByAxisId(getAxisId(d.id))(d.value, d.id); })
.style("fill-opacity", initialOpacityForText); .style("fill-opacity", initialOpacityForText);
mainText.exit() mainText.exit()
.transition().duration(durationForExit) .transition().duration(durationForExit)

4
c3.min.js vendored

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save