import Element from '../core/core.element';
-import {isObject} from '../helpers';
+import {isObject, _limitValue} from '../helpers';
import {addRoundedRectPath} from '../helpers/helpers.canvas';
import {toTRBL, toTRBLCorners} from '../helpers/helpers.options';
}
function skipOrLimit(skip, value, min, max) {
- return skip ? 0 : Math.max(Math.min(value, max), min);
+ return skip ? 0 : _limitValue(value, min, max);
}
function parseBorderWidth(bar, maxW, maxH) {
ctx.rect(rect.x, rect.y, rect.w, rect.h);
}
+function inflateRect(rect, amount, refRect = {}) {
+ const x = rect.x !== refRect.x ? -amount : 0;
+ const y = rect.y !== refRect.y ? -amount : 0;
+ const w = (rect.x + rect.w !== refRect.x + refRect.w ? amount : 0) - x;
+ const h = (rect.y + rect.h !== refRect.y + refRect.h ? amount : 0) - y;
+ return {
+ x: rect.x + x,
+ y: rect.y + y,
+ w: rect.w + w,
+ h: rect.h + h,
+ radius: rect.radius
+ };
+}
+
export default class BarElement extends Element {
constructor(cfg) {
const options = this.options;
const {inner, outer} = boundingRects(this);
const addRectPath = hasRadius(outer.radius) ? addRoundedRectPath : addNormalRectPath;
+ const inflateAmount = 0.33;
ctx.save();
if (outer.w !== inner.w || outer.h !== inner.h) {
ctx.beginPath();
- addRectPath(ctx, outer);
+ addRectPath(ctx, inflateRect(outer, inflateAmount, inner));
ctx.clip();
- addRectPath(ctx, inner);
+ addRectPath(ctx, inflateRect(inner, -inflateAmount, outer));
ctx.fillStyle = options.borderColor;
ctx.fill('evenodd');
}
ctx.beginPath();
- addRectPath(ctx, inner);
+ addRectPath(ctx, inflateRect(inner, inflateAmount, outer));
ctx.fillStyle = options.backgroundColor;
ctx.fill();
--- /dev/null
+module.exports = {
+ threshold: 0,
+ tolerance: 0,
+ config: {
+ type: 'bar',
+ data: {
+ labels: [0, 1, 2, 3, 4, 5, 6],
+ datasets: [
+ {
+ // option in dataset
+ data: [5, 4, 3, 2, 3, 4, 5],
+ },
+ ]
+ },
+ options: {
+ events: [],
+ devicePixelRatio: 1.5,
+ barPercentage: 1,
+ categoryPercentage: 1,
+ backgroundColor: 'black',
+ borderColor: 'black',
+ borderWidth: 8,
+ scales: {
+ x: {display: false},
+ y: {display: false}
+ }
+ }
+ },
+ options: {
+ canvas: {
+ height: 256,
+ width: 501
+ }
+ }
+};
--- /dev/null
+module.exports = {
+ threshold: 0.01,
+ config: {
+ type: 'bar',
+ data: {
+ labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
+ datasets: [
+ {
+ data: [9, 25, 13, 17, 12, 21, 20, 19, 6, 12, 14, 20],
+ categoryPercentage: 1,
+ barPercentage: 1,
+ backgroundColor: '#2E5C76',
+ borderWidth: 2,
+ borderColor: '#377395',
+ borderRadius: 5,
+ },
+ ]
+ },
+ options: {
+ devicePixelRatio: 1.25,
+ scales: {
+ x: {display: false},
+ y: {display: false}
+ }
+ }
+ },
+ options: {
+ canvas: {
+ height: 256,
+ width: 512
+ }
+ }
+};
type: 'bar',
data: {
datasets: [{
- data: [10, 5, 0, 25, 78]
+ data: [10, 5, 0, 25, 78],
+ backgroundColor: 'transparent'
}],
labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick5']
},
options: {
indexAxis: 'y',
- elements: {
- bar: {
- backgroundColor: '#AAAAAA80',
- borderColor: '#80808080',
- borderWidth: {bottom: 6, left: 15, top: 6, right: 15}
- }
- },
scales: {
x: {display: false},
y: {display: true}
}
},
options: {
- spriteText: true
+ spriteText: true,
+ canvas: {
+ width: 128,
+ height: 256
+ }
}
};