MCPcopy Create free account
hub / github.com/tensorflow/tensorboard / getGradient

Function getGradient

tensorboard/plugins/graph/tf_graph_common/node.ts:732–769  ·  view source on GitHub ↗
(
  id: string,
  colors: Array<{
    color: string;
    proportion: number;
  }>,
  svgRoot?: SVGElement
)

Source from the content-addressed store, hash-verified

730}
731
732function getGradient(
733 id: string,
734 colors: Array<{
735 color: string;
736 proportion: number;
737 }>,
738 svgRoot?: SVGElement
739): string {
740 let escapedId = tf_graph_util.escapeQuerySelector(id);
741 if (!svgRoot) return `url(#${escapedId})`;
742 let $svgRoot = d3.select(svgRoot);
743 let gradientDefs = $svgRoot.select('defs#_graph-gradients');
744 if (gradientDefs.empty()) {
745 gradientDefs = $svgRoot.append('defs').attr('id', '_graph-gradients');
746 }
747 let linearGradient = gradientDefs.select('linearGradient#' + escapedId);
748 // If the linear gradient is not there yet, create it.
749 if (linearGradient.empty()) {
750 linearGradient = gradientDefs.append('linearGradient').attr('id', id);
751 // Re-create the stops of the linear gradient.
752 linearGradient.selectAll('*').remove();
753 let cumulativeProportion = 0;
754 // For each color, create a stop using the proportion of that device.
755 _.each(colors, (d) => {
756 let color = d.color;
757 linearGradient
758 .append('stop')
759 .attr('offset', cumulativeProportion)
760 .attr('stop-color', color);
761 linearGradient
762 .append('stop')
763 .attr('offset', cumulativeProportion + d.proportion)
764 .attr('stop-color', color);
765 cumulativeProportion += d.proportion;
766 });
767 }
768 return `url(#${escapedId})`;
769}
770export function removeGradientDefinitions(svgRoot: SVGElement) {
771 d3.select(svgRoot).select('defs#_graph-gradients').remove();
772}

Callers 1

getFillForNodeFunction · 0.85

Calls 2

emptyMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…