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

Method getRGB

tensorboard/components/tensor_widget/colormap.ts:160–197  ·  view source on GitHub ↗
(value: number)

Source from the content-addressed store, hash-verified

158
159export class JetColorMap extends ColorMap {
160 getRGB(value: number): [number, number, number] {
161 if (isNaN(value)) {
162 // NaN.
163 return [MAX_RGB * 0.25, MAX_RGB * 0.25, MAX_RGB * 0.25];
164 } else if (!isFinite(value)) {
165 if (value < 0) {
166 // -Infinity.
167 return [MAX_RGB * 0.5, MAX_RGB * 0.5, MAX_RGB * 0.5];
168 } else {
169 // +Infinity.
170 return [MAX_RGB * 0.75, MAX_RGB * 0.75, MAX_RGB * 0.75];
171 }
172 }
173
174 let relR = 0;
175 let relG = 0;
176 let relB = 0;
177 const lim0 = 0.35;
178 const lim1 = 0.65;
179
180 let relValue =
181 this.config.min === this.config.max
182 ? 0.5
183 : (value - this.config.min) / (this.config.max - this.config.min);
184 relValue = Math.max(Math.min(relValue, 1), 0);
185 if (relValue <= lim0) {
186 relG = relValue / lim0;
187 relB = 1;
188 } else if (relValue > lim0 && relValue <= lim1) {
189 relR = (relValue - lim0) / (lim1 - lim0);
190 relG = 1;
191 relB = (lim1 - relValue) / (lim1 - lim0);
192 } else if (relValue > lim1) {
193 relR = 1;
194 relG = (1 - relValue) / (1 - lim1);
195 }
196 return [relR * MAX_RGB, relG * MAX_RGB, relB * MAX_RGB];
197 }
198}

Callers 3

colormap-test.tsFile · 0.45
renderValueDivsMethod · 0.45
renderFunction · 0.45

Calls 3

isFiniteFunction · 0.85
maxMethod · 0.80
minMethod · 0.80

Tested by

no test coverage detected