Skip to content

Commit

Permalink
Display data labels for horizontal bar chart
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre Clavequin committed Dec 29, 2017
1 parent 6fd2a24 commit 1f388f3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/morris.bar.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,11 @@ class Morris.Bar extends Morris.Grid
lastTop -= size
@seriesBars[idx][sidx] = @drawBar(top, left, size, barWidth, @colorFor(row, sidx, 'bar'),
@options.barOpacity, @options.barRadius)

if @options.dataLabels
if @options.stacked || @options.dataLabelsPosition=='inside'
@drawDataLabel(top + size / 2, left + barWidth / 2,@yLabelFormat(row.y[sidx]))
else
@drawDataLabel(top + size + 5, left + barWidth / 2,@yLabelFormat(row.y[sidx]))
if @options.inBarValue and
barWidth > @options.gridTextSize + 2*@options.inBarValueMinTopMargin
barMiddle = left + 0.5 * barWidth
Expand Down
7 changes: 7 additions & 0 deletions morris.js
Original file line number Diff line number Diff line change
Expand Up @@ -1874,6 +1874,13 @@ Licensed under the BSD-2-Clause License.
} else {
lastTop -= size;
this.seriesBars[idx][sidx] = this.drawBar(top, left, size, barWidth, this.colorFor(row, sidx, 'bar'), this.options.barOpacity, this.options.barRadius);
if (this.options.dataLabels) {
if (this.options.stacked || this.options.dataLabelsPosition === 'inside') {
this.drawDataLabel(top + size / 2, left + barWidth / 2, this.yLabelFormat(row.y[sidx]));
} else {
this.drawDataLabel(top + size + 5, left + barWidth / 2, this.yLabelFormat(row.y[sidx]));
}
}
if (this.options.inBarValue && barWidth > this.options.gridTextSize + 2 * this.options.inBarValueMinTopMargin) {
barMiddle = left + 0.5 * barWidth;
_results1.push(this.raphael.text(bottom - this.options.inBarValueRightMargin, barMiddle, this.yLabelFormat(row.y[sidx], sidx)).attr('font-size', this.options.gridTextSize).attr('font-family', this.options.gridTextFamily).attr('font-weight', this.options.gridTextWeight).attr('fill', this.options.inBarValueTextColor).attr('text-anchor', 'end'));
Expand Down
Loading

0 comments on commit 1f388f3

Please sign in to comment.