Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions src/elements/element.bar.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
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';

Expand Down Expand Up @@ -67,7 +67,7 @@ function startEnd(v, start, end) {
}

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) {
Expand Down Expand Up @@ -156,6 +156,20 @@ function addNormalRectPath(ctx, rect) {
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) {
Expand All @@ -176,20 +190,21 @@ export default class BarElement extends Element {
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();

Expand Down
Binary file modified test/fixtures/controller.bar/bar-base-value.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/fixtures/controller.bar/baseLine/bottom.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/fixtures/controller.bar/baseLine/left.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/fixtures/controller.bar/baseLine/mid-x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/fixtures/controller.bar/baseLine/mid-y.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/fixtures/controller.bar/baseLine/right.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/fixtures/controller.bar/baseLine/top.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/fixtures/controller.bar/baseLine/value-x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/fixtures/controller.bar/baseLine/value-y.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions test/fixtures/controller.bar/borderColor/border+dpr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
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
}
}
};
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/fixtures/controller.bar/borderRadius/border-radius.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions test/fixtures/controller.bar/borderRadius/no-spacing.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
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
}
}
};
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/fixtures/controller.bar/borderWidth/indexable.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/fixtures/controller.bar/borderWidth/object.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/fixtures/controller.bar/borderWidth/value.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/fixtures/controller.bar/horizontal-borders.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 7 additions & 9 deletions test/fixtures/scale.category/ticks-from-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,24 @@ module.exports = {
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
}
}
};
Binary file modified test/fixtures/scale.category/ticks-from-data.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.