|
1 | 1 | import {Element} from 'chart.js'; |
2 | | -import {isObject} from 'chart.js/helpers'; |
| 2 | +import {isObject, addRoundedRectPath, toTRBLCorners} from 'chart.js/helpers'; |
3 | 3 |
|
4 | 4 | /** |
5 | 5 | * Helper function to get the bounds of the rect |
@@ -86,21 +86,23 @@ export default class MatrixElement extends Element { |
86 | 86 | draw(ctx) { |
87 | 87 | const options = this.options; |
88 | 88 | const {inner, outer} = boundingRects(this); |
| 89 | + const radius = toTRBLCorners(options.borderRadius); |
89 | 90 |
|
90 | 91 | ctx.save(); |
91 | 92 |
|
92 | 93 | if (outer.w !== inner.w || outer.h !== inner.h) { |
93 | 94 | ctx.beginPath(); |
94 | | - ctx.rect(outer.x, outer.y, outer.w, outer.h); |
95 | | - ctx.clip(); |
96 | | - ctx.rect(inner.x, inner.y, inner.w, inner.h); |
| 95 | + addRoundedRectPath(ctx, {x: outer.x, y: outer.y, w: outer.w, h: outer.h, radius}); |
| 96 | + addRoundedRectPath(ctx, {x: inner.x, y: inner.y, w: inner.w, h: inner.h, radius}); |
97 | 97 | ctx.fillStyle = options.backgroundColor; |
98 | 98 | ctx.fill(); |
99 | 99 | ctx.fillStyle = options.borderColor; |
100 | 100 | ctx.fill('evenodd'); |
101 | 101 | } else { |
| 102 | + ctx.beginPath(); |
| 103 | + addRoundedRectPath(ctx, {x: inner.x, y: inner.y, w: inner.w, h: inner.h, radius}); |
102 | 104 | ctx.fillStyle = options.backgroundColor; |
103 | | - ctx.fillRect(inner.x, inner.y, inner.w, inner.h); |
| 105 | + ctx.fill(); |
104 | 106 | } |
105 | 107 |
|
106 | 108 | ctx.restore(); |
@@ -140,6 +142,7 @@ MatrixElement.defaults = { |
140 | 142 | backgroundColor: undefined, |
141 | 143 | borderColor: undefined, |
142 | 144 | borderWidth: undefined, |
| 145 | + borderRadius: 0, |
143 | 146 | anchorX: undefined, |
144 | 147 | anchorY: undefined, |
145 | 148 | width: 20, |
|
0 commit comments