MCPcopy Index your code
hub / github.com/plotly/plotly.js / gradientWithBounds

Function gradientWithBounds

src/components/drawing/index.js:462–530  ·  view source on GitHub ↗

* gradient_with_bounds: create and apply a gradient fill for defined start and stop positions * * @param {object} sel: d3 selection to apply this gradient to * You can use `selection.call(Drawing.gradient, ...)` * @param {DOM element} gd: the graph div `sel` is part of * @param {string} gra

(sel, gd, gradientID, type, colorscale, prop, start, stop, inUserSpace, reversed)

Source from the content-addressed store, hash-verified

460 * to center for radial gradients.
461 */
462function gradientWithBounds(sel, gd, gradientID, type, colorscale, prop, start, stop, inUserSpace, reversed) {
463 var len = colorscale.length;
464
465 var info;
466 if (type === 'linear') {
467 info = {
468 node: 'linearGradient',
469 attrs: {
470 x1: start.x,
471 y1: start.y,
472 x2: stop.x,
473 y2: stop.y,
474 gradientUnits: inUserSpace ? 'userSpaceOnUse' : 'objectBoundingBox'
475 },
476 reversed: reversed
477 };
478 } else if (type === 'radial') {
479 info = {
480 node: 'radialGradient',
481 reversed: reversed
482 };
483 }
484
485 var colorStops = new Array(len);
486 for (var i = 0; i < len; i++) {
487 if (info.reversed) {
488 colorStops[len - 1 - i] = [stopFormatter((1 - colorscale[i][0]) * 100), colorscale[i][1]];
489 } else {
490 colorStops[i] = [stopFormatter(colorscale[i][0] * 100), colorscale[i][1]];
491 }
492 }
493
494 var fullLayout = gd._fullLayout;
495 var fullID = 'g' + fullLayout._uid + '-' + gradientID;
496
497 var gradient = fullLayout._defs
498 .select('.gradients')
499 .selectAll('#' + fullID)
500 .data([type + colorStops.join(';')], Lib.identity);
501
502 gradient.exit().remove();
503
504 gradient
505 .enter()
506 .append(info.node)
507 .each(function () {
508 var el = d3.select(this);
509 if (info.attrs) el.attr(info.attrs);
510
511 el.attr('id', fullID);
512
513 var stops = el.selectAll('stop').data(colorStops);
514 stops.exit().remove();
515 stops.enter().append('stop');
516
517 stops.each(function (d) {
518 var tc = tinycolor(d[1]);
519 d3.select(this).attr({

Callers 1

index.jsFile · 0.85

Calls 1

getFullUrlFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…