Skip to content

Commit

Permalink
Introduce the 'minSize' dataset property for bar controller
Browse files Browse the repository at this point in the history
  • Loading branch information
adube committed Sep 19, 2018
1 parent 7a65546 commit c7a8fd0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/charts/bar.md
Expand Up @@ -77,6 +77,7 @@ Some properties can be specified as an array. If these are set to an array value
| `hoverBackgroundColor` | `Color/Color[]` | The fill colour of the bars when hovered.
| `hoverBorderColor` | `Color/Color[]` | The stroke colour of the bars when hovered.
| `hoverBorderWidth` | `Number/Number[]` | The stroke width of the bars when hovered.
| `minSize` | `Number` | The minimum size (height for vertical, width for horizontal) in pixels bars should be rendered.

### borderSkipped
This setting is used to avoid drawing the bar stroke at the base of the fill. In general, this does not need to be changed except when creating chart types that derive from a bar chart.
Expand Down
11 changes: 11 additions & 0 deletions src/controllers/controller.bar.js
Expand Up @@ -382,8 +382,10 @@ module.exports = function(Chart) {
var chart = me.chart;
var meta = me.getMeta();
var scale = me.getValueScale();
var isHorizontal = scale.isHorizontal();
var datasets = chart.data.datasets;
var value = scale.getRightValue(datasets[datasetIndex].data[index]);
var minSize = datasets[datasetIndex].minSize;
var stacked = scale.options.stacked;
var stack = meta.stack;
var start = 0;
Expand All @@ -410,6 +412,15 @@ module.exports = function(Chart) {
head = scale.getPixelForValue(start + value);
size = (head - base) / 2;

if (minSize !== undefined && Math.abs(size) < minSize) {
size = minSize;
if (value >= 0 && !isHorizontal || value < 0 && isHorizontal) {
head = base - minSize;
} else {
head = base + minSize;
}
}

return {
size: size,
base: base,
Expand Down

0 comments on commit c7a8fd0

Please sign in to comment.