in tensorboard/plugins/graph/tf_graph_common/node.ts [779:866]
export function getFillForNode(
templateIndex: (name: string) => number | null,
colorBy: ColorBy,
renderInfo: render.RenderNodeInfo,
isExpanded: boolean,
svgRoot?: SVGElement
): string {
let colorParams = render.MetanodeColors;
templateIndex = templateIndex || (() => 0);
switch (colorBy) {
// The 'none' mode still colors nodes, just ignores the template structural
// colors.
case ColorBy.NONE:
case ColorBy.STRUCTURE:
if (renderInfo.node.type === NodeType.META) {
let tid = (<Metanode>renderInfo.node).templateId;
return colorBy === ColorBy.STRUCTURE && tid !== null
? colorParams.STRUCTURE_PALETTE(templateIndex(tid), isExpanded)
: colorParams.UNKNOWN;
} else if (renderInfo.node.type === NodeType.SERIES) {
// If expanded, we're showing the background rect, which we want to
// appear gray. Otherwise we're showing a stack of ellipses which we
// want to show white.
return isExpanded ? colorParams.EXPANDED_COLOR : 'white';
} else if (renderInfo.node.type === NodeType.BRIDGE) {
return renderInfo.structural
? '#f0e'
: (<BridgeNode>renderInfo.node).inbound
? '#0ef'
: '#fe0';
} else if (_.isNumber((renderInfo.node as OpNode).functionInputIndex)) {
// This is an input of a TensorFlow function.
return '#795548';
} else if (_.isNumber((renderInfo.node as OpNode).functionOutputIndex)) {
// This is an output of a TensorFlow function.
return '#009688';
} else {
// Op nodes are white.
return 'white';
}
case ColorBy.DEVICE:
if (renderInfo.deviceColors == null) {
// Return the hue for unknown device.
return colorParams.UNKNOWN;
}
return isExpanded
? colorParams.EXPANDED_COLOR
: getGradient(
'device-' + renderInfo.node.name,
renderInfo.deviceColors,
svgRoot
);
case ColorBy.XLA_CLUSTER:
if (renderInfo.xlaClusterColors == null) {
// Return the hue for unknown xlaCluster.
return colorParams.UNKNOWN;
}
return isExpanded
? colorParams.EXPANDED_COLOR
: getGradient(
'xla-' + renderInfo.node.name,
renderInfo.xlaClusterColors,
svgRoot
);
case ColorBy.COMPUTE_TIME:
return isExpanded
? colorParams.EXPANDED_COLOR
: renderInfo.computeTimeColor || colorParams.UNKNOWN;
case ColorBy.MEMORY:
return isExpanded
? colorParams.EXPANDED_COLOR
: renderInfo.memoryColor || colorParams.UNKNOWN;
case ColorBy.OP_COMPATIBILITY:
if (renderInfo.compatibilityColors == null) {
// Return the hue for unknown compatibility info.
return colorParams.UNKNOWN;
}
return isExpanded
? colorParams.EXPANDED_COLOR
: getGradient(
'op-compat-' + renderInfo.node.name,
renderInfo.compatibilityColors,
svgRoot
);
default:
throw new Error('Unknown case to color nodes by');
}
}