| [`hoverBorderWidth`](#interactions) | `number` | Yes | Yes | `1`
| [`hoverBorderRadius`](#interactions) | `number` | Yes | Yes | `0`
| [`indexAxis`](#general) | `string` | - | - | `'x'`
+| [`inflateAmount`](#inflateamount) | `number`\|`'auto'` | Yes | Yes | `'auto'`
| [`maxBarThickness`](#maxbarthickness) | `number` | - | - | |
| [`minBarLength`](#styling) | `number` | - | - | |
| [`label`](#general) | `string` | - | - | `''`
When the border radius is supplied as a number and the chart is stacked, the radius will only be applied to the bars that are at the edges of the stack or where the bar is floating. The object syntax can be used to override this behavior.
:::
+#### inflateAmount
+
+This option can be used to inflate the rects that are used to draw the bars. This can be used to hide artifacts between bars when `barPercentage`(#barpercentage) * `categoryPercentage`(#categorypercentage) is 1. The default value `'auto'` should work in most cases.
+
### Interactions
The interaction with each bar can be controlled with the following properties:
| `borderColor` | [`Color`](/general/colors.md) | `Chart.defaults.borderColor` | Bar stroke color.
| `borderSkipped` | `string` | `'start'` | Skipped (excluded) border: `'start'`, `'end'`, `'middle'`, `'bottom'`, `'left'`, `'top'`, `'right'` or `false`.
| `borderRadius` | `number`\|`object` | `0` | The bar border radius (in pixels).
+| `inflateAmount` | `number`\|`'auto'` | `'auto'` | The amount of pixels to inflate the bar rectangle(s) when drawing.
| [`pointStyle`](#point-styles) | `string`\|`Image`\|`HTMLCanvasElement` | `'circle'` | Style of the point for legend.
## Arc Configuration
return v === 'start' ? start : v === 'end' ? end : v;
}
+function setInflateAmount(properties, {inflateAmount}, ratio) {
+ properties.inflateAmount = inflateAmount === 'auto'
+ ? ratio === 1 ? 0.33 : 0
+ : inflateAmount;
+}
+
export default class BarController extends DatasetController {
/**
if (includeOptions) {
properties.options = sharedOptions || this.resolveDataElementOptions(i, bars[i].active ? 'active' : mode);
}
- setBorderSkipped(properties, properties.options || bars[i].options, stack, index);
+ const options = properties.options || bars[i].options;
+ setBorderSkipped(properties, options, stack, index);
+ setInflateAmount(properties, options, ruler.ratio);
this.updateElement(bars[i], i, properties, mode);
}
}
this.base = undefined;
this.width = undefined;
this.height = undefined;
+ this.inflateAmount = undefined;
if (cfg) {
Object.assign(this, cfg);
}
draw(ctx) {
- const options = this.options;
+ const {inflateAmount, options: {borderColor, backgroundColor}} = this;
const {inner, outer} = boundingRects(this);
const addRectPath = hasRadius(outer.radius) ? addRoundedRectPath : addNormalRectPath;
- const inflateAmount = 0.33;
ctx.save();
addRectPath(ctx, inflateRect(outer, inflateAmount, inner));
ctx.clip();
addRectPath(ctx, inflateRect(inner, -inflateAmount, outer));
- ctx.fillStyle = options.borderColor;
+ ctx.fillStyle = borderColor;
ctx.fill('evenodd');
}
ctx.beginPath();
- addRectPath(ctx, inflateRect(inner, inflateAmount, outer));
- ctx.fillStyle = options.backgroundColor;
+ addRectPath(ctx, inflateRect(inner, inflateAmount));
+ ctx.fillStyle = backgroundColor;
ctx.fill();
ctx.restore();
borderSkipped: 'start',
borderWidth: 0,
borderRadius: 0,
- enableBorderRadius: true,
+ inflateAmount: 'auto',
pointStyle: undefined
};
base: number;
/**
- * Skipped (excluded) border: 'start', 'end', 'left', 'right', 'bottom', 'top' or false (none).
+ * Skipped (excluded) border: 'start', 'end', 'left', 'right', 'bottom', 'top' or false (none).
* @default 'start'
*/
borderSkipped: 'start' | 'end' | 'left' | 'right' | 'bottom' | 'top' | false;
* @default 0
*/
borderRadius: number | BorderRadius;
+
+ /**
+ * Amount to inflate the rectangle(s). This can be used to hide artifacts between bars.
+ * Unit is pixels. 'auto' translates to 0.33 pixels when barPercentage * categoryPercentage is 1, else 0.
+ * @default 'auto'
+ */
+ inflateAmount: number | 'auto';
}
export interface BorderRadius {