MCPcopy Index your code
hub / github.com/microsoft/SandDance / updateGradient

Function updateGradient

docs/app/js/sanddance-app.js:124342–124390  ·  view source on GitHub ↗
(el, grad, index)

Source from the content-addressed store, hash-verified

124340 }
124341} // update gradient definitions
124342function updateGradient(el, grad, index) {
124343 let i, n, stop;
124344 if (grad.gradient === "radial") {
124345 // SVG radial gradients automatically transform to normalized bbox
124346 // coordinates, in a way that is cumbersome to replicate in canvas.
124347 // We wrap the radial gradient in a pattern element, allowing us to
124348 // maintain a circular gradient that matches what canvas provides.
124349 let pt = domChild(el, index++, "pattern", svgns);
124350 setAttributes(pt, {
124351 id: patternPrefix + grad.id,
124352 viewBox: "0,0,1,1",
124353 width: "100%",
124354 height: "100%",
124355 preserveAspectRatio: "xMidYMid slice"
124356 });
124357 pt = domChild(pt, 0, "rect", svgns);
124358 setAttributes(pt, {
124359 width: 1,
124360 height: 1,
124361 fill: `url(${href()}#${grad.id})`
124362 });
124363 el = domChild(el, index++, "radialGradient", svgns);
124364 setAttributes(el, {
124365 id: grad.id,
124366 fx: grad.x1,
124367 fy: grad.y1,
124368 fr: grad.r1,
124369 cx: grad.x2,
124370 cy: grad.y2,
124371 r: grad.r2
124372 });
124373 } else {
124374 el = domChild(el, index++, "linearGradient", svgns);
124375 setAttributes(el, {
124376 id: grad.id,
124377 x1: grad.x1,
124378 x2: grad.x2,
124379 y1: grad.y1,
124380 y2: grad.y2
124381 });
124382 }
124383 for(i = 0, n = grad.stops.length; i < n; ++i){
124384 stop = domChild(el, i, "stop", svgns);
124385 stop.setAttribute("offset", grad.stops[i].offset);
124386 stop.setAttribute("stop-color", grad.stops[i].color);
124387 }
124388 domClear(el, i);
124389 return index;
124390} // update clipping path definitions
124391function updateClipping(el, clip3, index) {
124392 let mask;
124393 el = domChild(el, index, "clipPath", svgns);

Callers 1

defsFunction · 0.70

Calls 4

domChildFunction · 0.70
setAttributesFunction · 0.70
hrefFunction · 0.70
domClearFunction · 0.70

Tested by

no test coverage detected