Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(shadow): specify the shadow filter units as userSpaceOnUse. #792

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/svg/helper/ShadowManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export default class ShadowManager extends Definable {
if (!shadowDom) {
shadowDom = this.createElement('filter') as SVGFilterElement;
shadowDom.setAttribute('id', 'zr' + this._zrId + '-shadow-' + this.nextId++);
shadowDom.setAttribute('filterUnits', 'userSpaceOnUse');
const domChild = this.createElement('feDropShadow');
shadowDom.appendChild(domChild);
this.addDom(shadowDom);
Expand Down Expand Up @@ -118,6 +119,7 @@ export default class ShadowManager extends Definable {
shadowDom.setAttribute('y', '-100%');
shadowDom.setAttribute('width', '300%');
shadowDom.setAttribute('height', '300%');
shadowDom.setAttribute('filterUnits', 'userSpaceOnUse');

// Store dom element in shadow, to avoid creating multiple
// dom instances for the same shadow element
Expand Down
24 changes: 23 additions & 1 deletion test/svg-shadow.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body>
<h4>Canvas</h4>
<div id="main-canvas" style="width:1000px;height:200px;"></div>
<h4>SVG</h4>
<div id="main-svg" style="width:1000px;height:200px;"></div>
<div style="position: absolute; left: 10px; top: 10px">
<div style="position: absolute; right: 10px; top: 10px">
<button onclick="toggleShadow()">Toggle Shadow</button>
</div>
<script type="text/javascript">
Expand Down Expand Up @@ -46,6 +48,26 @@
rects.push(rect);
(k ? zrSvg : zrCanvas).add(rect);
}

const line = new zrender.Line({
shape: {
x1: 60,
y1: 160,
x2: 310,
y2: 160
},
style: {
stroke: 'red',
lineWidth: 3,
shadowBlur: 10,
shadowColor: 'blue',
shadowOffsetX: 10,
shadowOffsetY: 10
}
});
line.__shadowBlur = 10;
rects.push(line);
(k ? zrSvg : zrCanvas).add(line);
}

function toggleShadow() {
Expand Down