MCPcopy Create free account
hub / github.com/microsoft/SandDance / updateGradient

Function updateGradient

docs/tests/v2/es6/js/sanddance.js:101800–101843  ·  view source on GitHub ↗
(el, grad, index)

Source from the content-addressed store, hash-verified

101798};
101799
101800function updateGradient(el, grad, index) {
101801 var i, n, stop;
101802
101803 if (grad.gradient === 'radial') {
101804 // SVG radial gradients automatically transform to normalized bbox
101805 // coordinates, in a way that is cumbersome to replicate in canvas.
101806 // So we wrap the radial gradient in a pattern element, allowing us
101807 // to mantain a circular gradient that matches what canvas provides.
101808 var pt = (0, _dom.domChild)(el, index++, 'pattern', ns);
101809 pt.setAttribute('id', _Gradient.patternPrefix + grad.id);
101810 pt.setAttribute('viewBox', '0,0,1,1');
101811 pt.setAttribute('width', '100%');
101812 pt.setAttribute('height', '100%');
101813 pt.setAttribute('preserveAspectRatio', 'xMidYMid slice');
101814 pt = (0, _dom.domChild)(pt, 0, 'rect', ns);
101815 pt.setAttribute('width', '1');
101816 pt.setAttribute('height', '1');
101817 pt.setAttribute('fill', 'url(' + href() + '#' + grad.id + ')');
101818 el = (0, _dom.domChild)(el, index++, 'radialGradient', ns);
101819 el.setAttribute('id', grad.id);
101820 el.setAttribute('fx', grad.x1);
101821 el.setAttribute('fy', grad.y1);
101822 el.setAttribute('fr', grad.r1);
101823 el.setAttribute('cx', grad.x2);
101824 el.setAttribute('cy', grad.y2);
101825 el.setAttribute('r', grad.r2);
101826 } else {
101827 el = (0, _dom.domChild)(el, index++, 'linearGradient', ns);
101828 el.setAttribute('id', grad.id);
101829 el.setAttribute('x1', grad.x1);
101830 el.setAttribute('x2', grad.x2);
101831 el.setAttribute('y1', grad.y1);
101832 el.setAttribute('y2', grad.y2);
101833 }
101834
101835 for (i = 0, n = grad.stops.length; i < n; ++i) {
101836 stop = (0, _dom.domChild)(el, i, 'stop', ns);
101837 stop.setAttribute('offset', grad.stops[i].offset);
101838 stop.setAttribute('stop-color', grad.stops[i].color);
101839 }
101840
101841 (0, _dom.domClear)(el, i);
101842 return index;
101843}
101844
101845function updateClipping(el, clip, index) {
101846 var mask;

Callers 1

sanddance.jsFile · 0.70

Calls 1

hrefFunction · 0.70

Tested by

no test coverage detected