Commit ed534fc5 authored by Masayuki Tanaka's avatar Masayuki Tanaka

Fix width for data label

parent abfc67ff
...@@ -1234,7 +1234,7 @@ ...@@ -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 @@ ...@@ -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 @@ ...@@ -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 @@ ...@@ -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)
......
This source diff could not be displayed because it is too large. You can view the blob instead.
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