Skip to content

Commit

Permalink
fix: 修复group背景色绘制不正确
Browse files Browse the repository at this point in the history
  • Loading branch information
zengyue committed May 7, 2021
1 parent e7fb3f4 commit 8f38df1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
22 changes: 10 additions & 12 deletions src/graphic/engine/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,18 +168,16 @@ class Element {

resetContext(context) {
const elAttrs = this._attrs.attrs;
if (!this._attrs.isGroup) {
for (const k in elAttrs) {
if (SHAPE_ATTRS.indexOf(k) > -1) {
let v = elAttrs[k];
if ((k === 'fillStyle' || k === 'strokeStyle') && v) {
v = parseStyle(v, this, context);
}
if (k === 'lineDash' && context.setLineDash && isArray(v)) {
context.setLineDash(v);
} else {
context[k] = v;
}
for (const k in elAttrs) {
if (SHAPE_ATTRS.indexOf(k) > -1) {
let v = elAttrs[k];
if ((k === 'fillStyle' || k === 'strokeStyle') && v) {
v = parseStyle(v, this, context);
}
if (k === 'lineDash' && context.setLineDash && isArray(v)) {
context.setLineDash(v);
} else {
context[k] = v;
}
}
}
Expand Down
16 changes: 13 additions & 3 deletions test/unit/graphic/group-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ document.body.appendChild(dom);
const canvas = new Canvas({
el: 'canvas-group',
width: 500,
height: 500
height: 500,
pixelRatio: 1
});

describe('Group', function() {
Expand Down Expand Up @@ -380,7 +381,7 @@ describe('Group', function() {
width: 40,
height: 40,
radius: 4,
fill: 'gray'
fill: '#0000FF'
}
});
group1.addShape('circle', {
Expand Down Expand Up @@ -410,8 +411,17 @@ describe('Group', function() {
expect(group2._attrs.attrs.width).to.equal(40);
expect(group2._attrs.attrs.height).to.equal(40);
expect(group2._attrs.attrs.radius).to.equal(4);
expect(group2._attrs.attrs.fill).to.equal('gray');
expect(group2._attrs.attrs.fill).to.equal('#0000FF');

canvas.set('animateHandler', false);
canvas.draw();

// 检测背景是否绘制正确
const context = canvas.get('context');
const imageData = context.getImageData(34, 34, 1, 1).data;
expect(imageData[0]).to.equal(0);
expect(imageData[1]).to.equal(0);
expect(imageData[2]).to.equal(255);
expect(imageData[3]).to.equal(255);
});
});

0 comments on commit 8f38df1

Please sign in to comment.