MCPcopy
hub / github.com/g3n/engine / updateLabelsY

Method updateLabelsY

gui/chart.go:343–369  ·  view source on GitHub ↗

updateLabelsY updates the Y scale labels text and positions

()

Source from the content-addressed store, hash-verified

341
342// updateLabelsY updates the Y scale labels text and positions
343func (ch *Chart) updateLabelsY() {
344
345 if ch.scaleY == nil {
346 return
347 }
348
349 th := float32(0)
350 if ch.title != nil {
351 th = ch.title.height
352 }
353
354 nlines := ch.scaleY.lines
355 vstep := (ch.maxY - ch.minY) / float32(nlines-1)
356 pstep := (ch.ContentHeight() - th - ch.top - ch.bottom) / float32(nlines-1)
357 value := ch.minY
358 for i := 0; i < nlines; i++ {
359 label := ch.labelsY[i]
360 label.SetText(fmt.Sprintf(ch.formatY, value))
361 px := ch.left - 4 - label.Width()
362 if px < 0 {
363 px = 0
364 }
365 py := ch.ContentHeight() - ch.bottom - float32(i)*pstep
366 label.SetPosition(px, py-label.Height()/2)
367 value += vstep
368 }
369}
370
371// calcRangeY calculates the minimum and maximum y values for all graphs
372func (ch *Chart) calcRangeY() {

Callers 3

SetFormatYMethod · 0.95
updateGraphsMethod · 0.95
recalcMethod · 0.95

Calls 5

ContentHeightMethod · 0.80
WidthMethod · 0.65
SetPositionMethod · 0.65
HeightMethod · 0.65
SetTextMethod · 0.45

Tested by

no test coverage detected