Skip to content

Commit c7a8fd0

Browse files
committed
Introduce the 'minSize' dataset property for bar controller
1 parent 7a65546 commit c7a8fd0

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

docs/charts/bar.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ Some properties can be specified as an array. If these are set to an array value
7777
| `hoverBackgroundColor` | `Color/Color[]` | The fill colour of the bars when hovered.
7878
| `hoverBorderColor` | `Color/Color[]` | The stroke colour of the bars when hovered.
7979
| `hoverBorderWidth` | `Number/Number[]` | The stroke width of the bars when hovered.
80+
| `minSize` | `Number` | The minimum size (height for vertical, width for horizontal) in pixels bars should be rendered.
8081

8182
### borderSkipped
8283
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.

src/controllers/controller.bar.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,10 @@ module.exports = function(Chart) {
382382
var chart = me.chart;
383383
var meta = me.getMeta();
384384
var scale = me.getValueScale();
385+
var isHorizontal = scale.isHorizontal();
385386
var datasets = chart.data.datasets;
386387
var value = scale.getRightValue(datasets[datasetIndex].data[index]);
388+
var minSize = datasets[datasetIndex].minSize;
387389
var stacked = scale.options.stacked;
388390
var stack = meta.stack;
389391
var start = 0;
@@ -410,6 +412,15 @@ module.exports = function(Chart) {
410412
head = scale.getPixelForValue(start + value);
411413
size = (head - base) / 2;
412414

415+
if (minSize !== undefined && Math.abs(size) < minSize) {
416+
size = minSize;
417+
if (value >= 0 && !isHorizontal || value < 0 && isHorizontal) {
418+
head = base - minSize;
419+
} else {
420+
head = base + minSize;
421+
}
422+
}
423+
413424
return {
414425
size: size,
415426
base: base,

0 commit comments

Comments
 (0)