MCPcopy Create free account
hub / github.com/google/pprof / dotColor

Function dotColor

internal/graph/dotgraph.go:330–382  ·  view source on GitHub ↗

dotColor returns a color for the given score (between -1.0 and 1.0), with -1.0 colored green, 0.0 colored grey, and 1.0 colored red. If isBackground is true, then a light (low-saturation) color is returned (suitable for use as a background color); otherwise, a darker color is returned (suitable for

(score float64, isBackground bool)

Source from the content-addressed store, hash-verified

328// otherwise, a darker color is returned (suitable for use as a
329// foreground color).
330func dotColor(score float64, isBackground bool) string {
331 // A float between 0.0 and 1.0, indicating the extent to which
332 // colors should be shifted away from grey (to make positive and
333 // negative values easier to distinguish, and to make more use of
334 // the color range.)
335 const shift = 0.7
336
337 // Saturation and value (in hsv colorspace) for background colors.
338 const bgSaturation = 0.1
339 const bgValue = 0.93
340
341 // Saturation and value (in hsv colorspace) for foreground colors.
342 const fgSaturation = 1.0
343 const fgValue = 0.7
344
345 // Choose saturation and value based on isBackground.
346 var saturation float64
347 var value float64
348 if isBackground {
349 saturation = bgSaturation
350 value = bgValue
351 } else {
352 saturation = fgSaturation
353 value = fgValue
354 }
355
356 // Limit the score values to the range [-1.0, 1.0].
357 score = math.Max(-1.0, math.Min(1.0, score))
358
359 // Reduce saturation near score=0 (so it is colored grey, rather than yellow).
360 if math.Abs(score) < 0.2 {
361 saturation *= math.Abs(score) / 0.2
362 }
363
364 // Apply 'shift' to move scores away from 0.0 (grey).
365 if score > 0.0 {
366 score = math.Pow(score, (1.0 - shift))
367 }
368 if score < 0.0 {
369 score = -math.Pow(-score, (1.0 - shift))
370 }
371
372 var r, g, b float64 // red, green, blue
373 if score < 0.0 {
374 g = value
375 r = value * (1 + saturation*score)
376 } else {
377 r = value
378 g = value * (1 - saturation*score)
379 }
380 b = value * (1 - saturation)
381 return fmt.Sprintf("#%02x%02x%02x", uint8(r*255.0), uint8(g*255.0), uint8(b*255.0))
382}
383
384func multilinePrintableName(info *NodeInfo) string {
385 infoCopy := *info

Callers 2

addNodeMethod · 0.85
addEdgeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…