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

mlange-42 / ark-pixel / 13727326526

07 Mar 2025 06:52PM CUT coverage: 28.089% (-19.3%) from 47.374%
13727326526

push

github

web-flow
Add first plot drawers (#8)

7 of 677 new or added lines in 11 files covered. (1.03%)

457 of 1627 relevant lines covered (28.09%)

55.34 hits per line

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

12.0
/plot/util.go
1
package plot
2

3
import (
4
        "fmt"
5
        "image/color"
6

7
        "github.com/mlange-42/ark-tools/observer"
8
        "golang.org/x/image/colornames"
9
        "gonum.org/v1/plot"
10
        "gonum.org/v1/plot/vg/vgimg"
11
)
12

13
var defaultColors = []color.Color{
14
        colornames.Blue,
15
        colornames.Orange,
16
        colornames.Green,
17
        colornames.Purple,
18
        colornames.Red,
19
        colornames.Turquoise,
20
}
21

22
// Labels for plots.
23
type Labels struct {
24
        Title string // Plot title
25
        X     string // X axis label
26
        Y     string // Y axis label
27
}
28

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

39
// Calculate scale correction for scaled monitors.
NEW
40
func calcScaleCorrection() float64 {
×
NEW
41
        return 72.0 / vgimg.DefaultDPI
×
NEW
42
}
×
43

NEW
44
func setLabels(p *plot.Plot, l Labels) {
×
NEW
45
        p.Title.Text = l.Title
×
NEW
46
        p.Title.TextStyle.Font.Size = 16
×
NEW
47
        p.Title.TextStyle.Font.Variant = "Mono"
×
NEW
48

×
NEW
49
        p.X.Label.Text = l.X
×
NEW
50
        p.X.Label.TextStyle.Font.Size = 14
×
NEW
51
        p.X.Label.TextStyle.Font.Variant = "Mono"
×
NEW
52

×
NEW
53
        p.X.Tick.Label.Font.Size = 12
×
NEW
54
        p.X.Tick.Label.Font.Variant = "Mono"
×
NEW
55

×
NEW
56
        p.Y.Label.Text = l.Y
×
NEW
57
        p.Y.Label.TextStyle.Font.Size = 14
×
NEW
58
        p.Y.Label.TextStyle.Font.Variant = "Mono"
×
NEW
59

×
NEW
60
        p.Y.Tick.Label.Font.Size = 12
×
NEW
61
        p.Y.Tick.Label.Font.Variant = "Mono"
×
NEW
62

×
NEW
63
        p.Y.Tick.Marker = paddedTicks{}
×
NEW
64
}
×
65

66
// Left-pads tick labels to avoid jumping Y axis.
67
type paddedTicks struct {
68
        plot.DefaultTicks
69
}
70

NEW
71
func (t paddedTicks) Ticks(min, max float64) []plot.Tick {
×
NEW
72
        ticks := t.DefaultTicks.Ticks(min, max)
×
NEW
73
        for i := 0; i < len(ticks); i++ {
×
NEW
74
                ticks[i].Label = fmt.Sprintf("%*s", 10, ticks[i].Label)
×
NEW
75
        }
×
NEW
76
        return ticks
×
77
}
78

79
// Removes the last tick label to avoid jumping X axis.
80
type removeLastTicks struct {
81
        plot.DefaultTicks
82
}
83

NEW
84
func (t removeLastTicks) Ticks(min, max float64) []plot.Tick {
×
NEW
85
        ticks := t.DefaultTicks.Ticks(min, max)
×
NEW
86
        for i := 0; i < len(ticks); i++ {
×
NEW
87
                tick := &ticks[i]
×
NEW
88
                if tick.IsMinor() {
×
NEW
89
                        continue
×
90
                }
NEW
91
                if tick.Value > max-(0.05*(max-min)) {
×
NEW
92
                        tick.Label = ""
×
NEW
93
                }
×
94
        }
NEW
95
        return ticks
×
96
}
97

98
type plotGrid struct {
99
        observer.Grid
100
        Values []float64
101
}
102

NEW
103
func (g *plotGrid) Z(c, r int) float64 {
×
NEW
104
        w, _ := g.Dims()
×
NEW
105
        return g.Values[r*w+c]
×
NEW
106
}
×
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