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

Function gradient

docs/app/js/sanddance-app.js:122255–122275  ·  view source on GitHub ↗
(context26, spec, bounds2)

Source from the content-addressed store, hash-verified

122253 return gradient2;
122254}
122255function gradient(context26, spec, bounds2) {
122256 const w5 = bounds2.width(), h10 = bounds2.height();
122257 let gradient3;
122258 if (spec.gradient === "radial") gradient3 = context26.createRadialGradient(bounds2.x1 + value(spec.x1, 0.5) * w5, bounds2.y1 + value(spec.y1, 0.5) * h10, Math.max(w5, h10) * value(spec.r1, 0), bounds2.x1 + value(spec.x2, 0.5) * w5, bounds2.y1 + value(spec.y2, 0.5) * h10, Math.max(w5, h10) * value(spec.r2, 0.5));
122259 else {
122260 // linear gradient
122261 const x1 = value(spec.x1, 0), y1 = value(spec.y1, 0), x2 = value(spec.x2, 1), y2 = value(spec.y2, 0);
122262 if (x1 === x2 || y1 === y2 || w5 === h10) // axis aligned: use normal gradient
122263 gradient3 = context26.createLinearGradient(bounds2.x1 + x1 * w5, bounds2.y1 + y1 * h10, bounds2.x1 + x2 * w5, bounds2.y1 + y2 * h10);
122264 else {
122265 // not axis aligned: render gradient into a pattern (#2365)
122266 // this allows us to use normalized bounding box coordinates
122267 const image1 = (0, _vegaCanvas.canvas)(Math.ceil(w5), Math.ceil(h10)), ictx = image1.getContext("2d");
122268 ictx.scale(w5, h10);
122269 ictx.fillStyle = addStops(ictx.createLinearGradient(x1, y1, x2, y2), spec.stops);
122270 ictx.fillRect(0, 0, w5, h10);
122271 return context26.createPattern(image1, "no-repeat");
122272 }
122273 }
122274 return addStops(gradient3, spec.stops);
122275}
122276function color(context27, item, value5) {
122277 return isGradient(value5) ? gradient(context27, value5, item.bounds) : value5;
122278}

Callers 2

colorFunction · 0.70
entry$1Function · 0.70

Calls 5

valueFunction · 0.70
addStopsFunction · 0.70
scaleRefFunction · 0.70
maxMethod · 0.45
scaleMethod · 0.45

Tested by

no test coverage detected