MCPcopy Index your code
hub / github.com/pterm/pterm / renderData

Method renderData

heatmap_printer.go:410–492  ·  view source on GitHub ↗
(buffer *bytes.Buffer, colWidth int, xAmount int, yAmount int)

Source from the content-addressed store, hash-verified

408}
409
410func (p HeatmapPrinter) renderData(buffer *bytes.Buffer, colWidth int, xAmount int, yAmount int) {
411 for i, datum := range p.Data {
412 if p.Boxed {
413 buffer.WriteString(p.SeparatorStyle.Sprint(p.VerticalSeparator))
414 }
415 for j, f := range datum {
416 if j == 0 && p.HasHeader {
417 ct := internal.CenterText(p.Axis.YAxis[i], colWidth)
418 if len(ct) < colWidth {
419 ct += strings.Repeat(" ", colWidth-len(ct))
420 }
421 buffer.WriteString(p.AxisStyle.Sprint(ct))
422 if p.Grid {
423 buffer.WriteString(p.SeparatorStyle.Sprint(p.VerticalSeparator))
424 }
425 }
426 var ct string
427 if p.OnlyColoredCells {
428 ct = internal.CenterText(" ", colWidth)
429 } else {
430 ct = internal.CenterText(Sprintf("%v", f), colWidth)
431 }
432 if len(ct) < colWidth {
433 if len(Sprintf("%v", f)) == 1 {
434 ct += strings.Repeat(" ", colWidth-len(ct))
435 } else {
436 ct = strings.Repeat(" ", colWidth-len(ct)) + ct
437 }
438 }
439 if p.EnableRGB {
440 rgb := p.RGBRange[0].Fade(p.minValue, p.maxValue, f, p.RGBRange[1:]...)
441 rgbStyle := NewRGBStyle(p.TextRGB, rgb)
442 if p.EnableComplementaryColor {
443 complimentary := NewRGB(internal.Complementary(rgb.R, rgb.G, rgb.B))
444 rgbStyle = NewRGBStyle(complimentary, rgb)
445 }
446 buffer.WriteString(rgbStyle.Sprint(ct))
447 } else {
448 color := getColor(p.minValue, p.maxValue, f, p.Colors...)
449 fgColor := p.TextColor
450 if p.EnableComplementaryColor {
451 fgColor = complementaryColors[color]
452 }
453 buffer.WriteString(fgColor.Sprint(color.Sprintf("%s", ct)))
454 }
455 if j < xAmount {
456 if !p.Boxed && p.HasHeader && j == xAmount-1 {
457 continue
458 }
459 if p.Grid {
460 buffer.WriteString(p.SeparatorStyle.Sprint(p.VerticalSeparator))
461 }
462 }
463 if p.Boxed && !p.HasHeader && j == xAmount {
464 buffer.WriteString(p.SeparatorStyle.Sprint(p.VerticalSeparator))
465 }
466 }
467

Callers 1

SrenderMethod · 0.95

Calls 10

SprintMethod · 0.95
CenterTextFunction · 0.92
ComplementaryFunction · 0.92
SprintfFunction · 0.85
NewRGBStyleFunction · 0.85
NewRGBFunction · 0.85
getColorFunction · 0.85
FadeMethod · 0.80
SprintMethod · 0.65
SprintfMethod · 0.65

Tested by

no test coverage detected