MCPcopy Index your code
hub / github.com/gonum/plot / Ticks

Method Ticks

axis.go:493–566  ·  view source on GitHub ↗

Ticks returns Ticks in the specified range.

(min, max float64)

Source from the content-addressed store, hash-verified

491
492// Ticks returns Ticks in the specified range.
493func (DefaultTicks) Ticks(min, max float64) []Tick {
494 if max <= min {
495 panic("illegal range")
496 }
497
498 const suggestedTicks = 3
499
500 labels, step, q, mag := talbotLinHanrahan(min, max, suggestedTicks, withinData, nil, nil, nil)
501 majorDelta := step * math.Pow10(mag)
502 if q == 0 {
503 // Simple fall back was chosen, so
504 // majorDelta is the label distance.
505 majorDelta = labels[1] - labels[0]
506 }
507
508 // Choose a reasonable, but ad
509 // hoc formatting for labels.
510 fc := byte('f')
511 var off int
512 if mag < -1 || 6 < mag {
513 off = 1
514 fc = 'g'
515 }
516 if math.Trunc(q) != q {
517 off += 2
518 }
519 prec := minInt(6, maxInt(off, -mag))
520 ticks := make([]Tick, len(labels))
521 for i, v := range labels {
522 ticks[i] = Tick{Value: v, Label: strconv.FormatFloat(v, fc, prec, 64)}
523 }
524
525 var minorDelta float64
526 // See talbotLinHanrahan for the values used here.
527 switch step {
528 case 1, 2.5:
529 minorDelta = majorDelta / 5
530 case 2, 3, 4, 5:
531 minorDelta = majorDelta / step
532 default:
533 if majorDelta/2 < dlamchP {
534 return ticks
535 }
536 minorDelta = majorDelta / 2
537 }
538
539 // Find the first minor tick not greater
540 // than the lowest data value.
541 var i float64
542 for labels[0]+(i-1)*minorDelta > min {
543 i--
544 }
545 // Add ticks at minorDelta intervals when
546 // they are not within minorDelta/2 of a
547 // labelled tick.
548 for {
549 val := labels[0] + i*minorDelta
550 if val > max {

Callers 1

TestAxisSmallTickFunction · 0.95

Calls 3

talbotLinHanrahanFunction · 0.85
minIntFunction · 0.85
maxIntFunction · 0.85

Tested by 1

TestAxisSmallTickFunction · 0.76