• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mlange-42 / ark-pixel / 13720015176

07 Mar 2025 11:46AM CUT coverage: 34.646% (+5.5%) from 29.148%
13720015176

push

github

web-flow
Add resource inspector (#5)

69 of 93 new or added lines in 1 file covered. (74.19%)

264 of 762 relevant lines covered (34.65%)

67.62 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

74.07
/plot/util.go
1
package plot
2

3
import (
4
        "math"
5

6
        "github.com/gopxl/pixel/v2/ext/text"
7
        "golang.org/x/image/font/basicfont"
8
        "gonum.org/v1/plot/vg/vgimg"
9
)
10

11
var defaultFont = text.NewAtlas(basicfont.Face7x13, text.ASCII)
12

13
var preferredTicks = []float64{1, 2, 5, 10}
14
var preferredTps = []float64{0, 1, 2, 3, 4, 5, 7, 10, 15, 20, 30, 40, 50, 60, 80, 100, 120, 150, 200, 250, 500, 750, 1000, 2000, 5000, 10000}
15

16
/*
17
var defaultColors = []color.Color{
18
        colornames.Blue,
19
        colornames.Orange,
20
        colornames.Green,
21
        colornames.Purple,
22
        colornames.Red,
23
        colornames.Turquoise,
24
}
25
*/
26

27
// Labels for plots.
28
type Labels struct {
29
        Title string // Plot title
30
        X     string // X axis label
31
        Y     string // Y axis label
32
}
33

34
// Get the index of an element in a slice.
35
func find[T comparable](sl []T, value T) (int, bool) {
2✔
36
        for i, v := range sl {
7✔
37
                if v == value {
6✔
38
                        return i, true
1✔
39
                }
1✔
40
        }
41
        return -1, false
1✔
42
}
43

44
// Calculate scale correction for scaled monitors.
45
func calcScaleCorrection() float64 {
×
46
        return 72.0 / vgimg.DefaultDPI
×
47
}
×
48

49
// Calculate the optimal step size for axis ticks.
50
func calcTicksStep(max float64, desired int) float64 {
×
51
        steps := float64(desired)
×
52
        approxStep := float64(max) / (steps - 1)
×
53
        stepPower := math.Pow(10, -math.Floor(math.Log10(approxStep)))
×
54
        normalizedStep := approxStep * stepPower
×
55
        for _, s := range preferredTicks {
×
56
                if s >= normalizedStep {
×
57
                        normalizedStep = s
×
58
                        break
×
59
                }
60
        }
61
        return normalizedStep / stepPower
×
62
}
63

64
// Calculate TPS when increasing/decreasing it.
65
func calcTps(curr float64, increase bool) float64 {
7✔
66
        ln := len(preferredTps)
7✔
67
        if increase {
11✔
68
                for i := 0; i < ln; i++ {
66✔
69
                        if preferredTps[i] > curr {
65✔
70
                                return preferredTps[i]
3✔
71
                        }
3✔
72
                }
73
                return curr
1✔
74
        }
75
        for i := 1; i < ln; i++ {
34✔
76
                if preferredTps[i] >= curr {
34✔
77
                        return preferredTps[i-1]
3✔
78
                }
3✔
79
        }
80
        return 0
×
81
}
82

83
/*
84
func setLabels(p *plot.Plot, l Labels) {
85
        p.Title.Text = l.Title
86
        p.Title.TextStyle.Font.Size = 16
87
        p.Title.TextStyle.Font.Variant = "Mono"
88

89
        p.X.Label.Text = l.X
90
        p.X.Label.TextStyle.Font.Size = 14
91
        p.X.Label.TextStyle.Font.Variant = "Mono"
92

93
        p.X.Tick.Label.Font.Size = 12
94
        p.X.Tick.Label.Font.Variant = "Mono"
95

96
        p.Y.Label.Text = l.Y
97
        p.Y.Label.TextStyle.Font.Size = 14
98
        p.Y.Label.TextStyle.Font.Variant = "Mono"
99

100
        p.Y.Tick.Label.Font.Size = 12
101
        p.Y.Tick.Label.Font.Variant = "Mono"
102

103
        p.Y.Tick.Marker = paddedTicks{}
104
}
105

106
// Left-pads tick labels to avoid jumping Y axis.
107
type paddedTicks struct {
108
        plot.DefaultTicks
109
}
110

111
func (t paddedTicks) Ticks(min, max float64) []plot.Tick {
112
        ticks := t.DefaultTicks.Ticks(min, max)
113
        for i := 0; i < len(ticks); i++ {
114
                ticks[i].Label = fmt.Sprintf("%*s", 10, ticks[i].Label)
115
        }
116
        return ticks
117
}
118

119
// Removes the last tick label to avoid jumping X axis.
120
type removeLastTicks struct {
121
        plot.DefaultTicks
122
}
123

124
func (t removeLastTicks) Ticks(min, max float64) []plot.Tick {
125
        ticks := t.DefaultTicks.Ticks(min, max)
126
        for i := 0; i < len(ticks); i++ {
127
                tick := &ticks[i]
128
                if tick.IsMinor() {
129
                        continue
130
                }
131
                if tick.Value > max-(0.05*(max-min)) {
132
                        tick.Label = ""
133
                }
134
        }
135
        return ticks
136
}
137

138
type plotGrid struct {
139
        observer.Grid
140
        Values []float64
141
}
142

143
func (g *plotGrid) Z(c, r int) float64 {
144
        w, _ := g.Dims()
145
        return g.Values[r*w+c]
146
}
147
*/
148

149
type ringBuffer[T any] struct {
150
        data  []T
151
        start int
152
}
153

154
func newRingBuffer[T any](cap int) ringBuffer[T] {
1✔
155
        return ringBuffer[T]{
1✔
156
                data:  make([]T, 0, cap),
1✔
157
                start: 0,
1✔
158
        }
1✔
159
}
1✔
160

161
func (r *ringBuffer[T]) Len() int {
20✔
162
        return len(r.data)
20✔
163
}
20✔
164

165
func (r *ringBuffer[T]) Cap() int {
40✔
166
        return cap(r.data)
40✔
167
}
40✔
168

169
func (r *ringBuffer[T]) Get(idx int) T {
30✔
170
        return r.data[(r.start+idx)%r.Cap()]
30✔
171
}
30✔
172

173
func (r *ringBuffer[T]) Add(elem T) {
20✔
174
        if cap(r.data) > len(r.data) {
30✔
175
                r.data = append(r.data, elem)
10✔
176
                return
10✔
177
        }
10✔
178
        r.data[r.start] = elem
10✔
179
        r.start = (r.start + 1) % r.Cap()
10✔
180
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc