MCPcopy
hub / github.com/pterm/pterm / Srender

Method Srender

heatmap_printer.go:239–299  ·  view source on GitHub ↗

Srender renders the HeatmapPrinter as a string.

()

Source from the content-addressed store, hash-verified

237
238// Srender renders the HeatmapPrinter as a string.
239func (p HeatmapPrinter) Srender() (string, error) {
240 if err := p.errCheck(); err != nil {
241 return "", err
242 }
243
244 if p.SeparatorStyle == nil {
245 p.SeparatorStyle = DefaultHeatmap.SeparatorStyle
246 }
247 if p.AxisStyle == nil {
248 p.AxisStyle = DefaultHeatmap.AxisStyle
249 }
250
251 if RawOutput {
252 p.Legend = false
253 }
254
255 buffer := bytes.NewBufferString("")
256 xAmount := len(p.Data[0]) - 1
257 yAmount := len(p.Data) - 1
258 p.minValue, p.maxValue = minMaxFloat32(p.Data)
259
260 var data string
261 for _, datum := range p.Data {
262 for _, f := range datum {
263 data += Sprintf("%v\n", f)
264 }
265 }
266
267 if p.HasHeader {
268 data, xAmount, yAmount = p.computeAxisData(data, xAmount, yAmount)
269 }
270
271 colWidth := internal.GetStringMaxWidth(data)
272 legendColWidth := colWidth + 2
273
274 if p.OnlyColoredCells && (p.CellSize > colWidth || !p.HasHeader) {
275 colWidth = p.CellSize
276 }
277
278 if p.Boxed {
279 p.renderSeparatorRow(buffer, colWidth, xAmount, true)
280 }
281
282 p.renderData(buffer, colWidth, xAmount, yAmount)
283
284 if p.HasHeader {
285 p.renderHeader(buffer, colWidth, xAmount)
286 }
287
288 if p.Boxed {
289 p.renderSeparatorRow(buffer, colWidth, xAmount, false)
290 }
291
292 if p.Legend {
293 p.renderLegend(buffer, legendColWidth)
294 }
295
296 buffer.WriteString("\n")

Callers 1

RenderMethod · 0.95

Calls 10

errCheckMethod · 0.95
computeAxisDataMethod · 0.95
renderSeparatorRowMethod · 0.95
renderDataMethod · 0.95
renderHeaderMethod · 0.95
renderLegendMethod · 0.95
GetStringMaxWidthFunction · 0.92
minMaxFloat32Function · 0.85
SprintfFunction · 0.85
StringMethod · 0.45

Tested by

no test coverage detected