Skip to content

Commit

Permalink
draw the score graph with different colors to indicate the score per …
Browse files Browse the repository at this point in the history
…band
  • Loading branch information
ftl committed May 17, 2023
1 parent 9736abc commit e1be8ab
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 36 deletions.
31 changes: 31 additions & 0 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,37 @@ func (s Score) Result() BandScore {
return result
}

func (s Score) StackedGraphPerBand() []BandGraph {
result := make([]BandGraph, 0, len(Bands))
var lastDataPoints []BandScore
for _, band := range Bands {
graph, ok := s.GraphPerBand[band]
if !ok {
continue
}
stackedGraph := BandGraph{
Band: graph.Band,
DataPoints: make([]BandScore, len(graph.DataPoints)),
startTime: graph.startTime,
binSeconds: graph.binSeconds,
}

for i, dataPoint := range graph.DataPoints {
stackedGraph.DataPoints[i] = dataPoint
if lastDataPoints != nil {
stackedGraph.DataPoints[i].QSOs += lastDataPoints[i].QSOs
stackedGraph.DataPoints[i].Duplicates += lastDataPoints[i].Duplicates
stackedGraph.DataPoints[i].Points += lastDataPoints[i].Points
stackedGraph.DataPoints[i].Multis += lastDataPoints[i].Multis
}
}

result = append(result, stackedGraph)
lastDataPoints = stackedGraph.DataPoints
}
return result
}

type BandGraph struct {
Band Band
DataPoints []BandScore
Expand Down
24 changes: 24 additions & 0 deletions core/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,30 @@ func TestBandGraph_Bindex(t *testing.T) {
}
}

func TestScore_StackedGraphPerBand(t *testing.T) {
score := NewScore()
score.GraphPerBand[Band160m] = BandGraph{
Band: Band160m,
DataPoints: []BandScore{{16, 16, 16, 16}, {15, 15, 15, 15}, {14, 14, 14, 14}},
}
score.GraphPerBand[Band80m] = BandGraph{
Band: Band80m,
DataPoints: []BandScore{{8, 8, 8, 8}, {7, 7, 7, 7}, {6, 6, 6, 6}},
}
score.GraphPerBand[Band40m] = BandGraph{
Band: Band40m,
DataPoints: []BandScore{{4, 4, 4, 4}, {3, 3, 3, 3}, {2, 2, 2, 2}},
}

stackedGraphs := score.StackedGraphPerBand()

assert.Equal(t, 3, len(stackedGraphs))

assert.Equal(t, 16, stackedGraphs[0].DataPoints[0].QSOs)
assert.Equal(t, 24, stackedGraphs[1].DataPoints[0].QSOs)
assert.Equal(t, 28, stackedGraphs[2].DataPoints[0].QSOs)
}

func TestBandmapEntry_ProximityFactor(t *testing.T) {
const frequency Frequency = 7035000
tt := []struct {
Expand Down
57 changes: 33 additions & 24 deletions ui/rateIndicator.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,40 @@ var timeColors = colorMap{
const angleRotation = (3.0 / 2.0) * math.Pi

var rateStyle = struct {
backgroundColor color
fontColor color
fontSize float64
axisColor color
axisMargin float64
lowZoneColor color
areaAlpha float64
borderAlpha float64
timeIndicatorWidth float64
timeFrameColor color
timeFrameAlpha float64
scoreGraphColor color
backgroundColor color
fontColor color
fontSize float64
axisColor color
axisMargin float64
lowZoneColor color
areaAlpha float64
borderAlpha float64
timeIndicatorWidth float64
timeFrameColor color
timeFrameAlpha float64
defaultScoreGraphColor color
scoreGraphColors map[core.Band]color
}{
backgroundColor: color{1, 1, 1},
fontColor: color{0.4, 0.4, 0.4},
fontSize: 15,
axisColor: color{0.4, 0.4, 0.4},
axisMargin: 15,
lowZoneColor: color{0.8, 0.8, 0.8},
areaAlpha: 0.4,
borderAlpha: 0.8,
timeIndicatorWidth: 10,
timeFrameColor: color{1, 0.73, 0.2},
timeFrameAlpha: 1,
scoreGraphColor: color{0.2, 0.47, 1},
backgroundColor: color{1, 1, 1},
fontColor: color{0.4, 0.4, 0.4},
fontSize: 15,
axisColor: color{0.4, 0.4, 0.4},
axisMargin: 15,
lowZoneColor: color{0.8, 0.8, 0.8},
areaAlpha: 0.4,
borderAlpha: 0.8,
timeIndicatorWidth: 10,
timeFrameColor: color{1, 0.73, 0.2},
timeFrameAlpha: 1,
defaultScoreGraphColor: color{0.4, 0.4, 0.4},
scoreGraphColors: map[core.Band]color{
core.Band160m: {0.5, 0, 0.5},
core.Band80m: {0, 0, 0.5},
core.Band40m: {0, 1.0, 0},
core.Band20m: {1, 1, 0},
core.Band15m: {1, 0.5, 0},
core.Band10m: {1, 0, 0},
},
}

type rateIndicator struct {
Expand Down
41 changes: 30 additions & 11 deletions ui/scoreGraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

type scoreGraph struct {
graph core.BandGraph
graphs []core.BandGraph
pointsGoal int
multisGoal int
timeFrameIndex int
Expand All @@ -21,16 +21,16 @@ type scoreGraph struct {

func newScoreGraph() *scoreGraph {
result := &scoreGraph{
graph: core.BandGraph{},
graphs: nil,
pointsGoal: 60,
multisGoal: 60,
}
result.updateBinGoals()
return result
}

func (g *scoreGraph) SetGraph(graph core.BandGraph) {
g.graph = graph
func (g *scoreGraph) SetGraphs(graphs []core.BandGraph) {
g.graphs = graphs
g.updateBinGoals()
g.UpdateTimeFrame()
}
Expand All @@ -42,12 +42,21 @@ func (g *scoreGraph) SetGoals(points int, multis int) {
}

func (g *scoreGraph) updateBinGoals() {
g.pointsBinGoal = g.graph.ScaleHourlyGoalToBin(g.pointsGoal)
g.multisBinGoal = g.graph.ScaleHourlyGoalToBin(g.multisGoal)
if len(g.graphs) == 0 {
g.pointsBinGoal = float64(g.pointsGoal)
g.multisBinGoal = float64(g.multisGoal)
return
}
g.pointsBinGoal = g.graphs[0].ScaleHourlyGoalToBin(g.pointsGoal)
g.multisBinGoal = g.graphs[0].ScaleHourlyGoalToBin(g.multisGoal)
}

func (g *scoreGraph) UpdateTimeFrame() {
g.timeFrameIndex = g.graph.Bindex(time.Now())
if len(g.graphs) == 0 {
g.timeFrameIndex = -1
return
}
g.timeFrameIndex = g.graphs[0].Bindex(time.Now()) // TODO: use the central clock!!!
}

type graphLayout struct {
Expand All @@ -66,7 +75,10 @@ func (g *scoreGraph) Draw(da *gtk.DrawingArea, cr *cairo.Context) {

// preparations

valueCount := len(g.graph.DataPoints)
valueCount := 0
if len(g.graphs) > 0 {
valueCount = len(g.graphs[0].DataPoints)
}
layout := g.calculateLayout(da, valueCount)

// the background
Expand All @@ -90,8 +102,16 @@ func (g *scoreGraph) Draw(da *gtk.DrawingArea, cr *cairo.Context) {
cr.Stroke()

// the graph
// TODO: draw the stacked band graph
g.drawDataPoints(cr, layout, g.graph.DataPoints)
for i := len(g.graphs) - 1; i >= 0; i-- {
graph := g.graphs[i]
color, ok := rateStyle.scoreGraphColors[graph.Band]
if !ok {
color = rateStyle.defaultScoreGraphColor
}
cr.SetSourceRGB(color.toRGB())

g.drawDataPoints(cr, layout, graph.DataPoints)
}

// the time frame
if g.timeFrameIndex >= 0 && valueCount > 1 {
Expand Down Expand Up @@ -139,7 +159,6 @@ func (g *scoreGraph) fillBackground(cr *cairo.Context) {
func (g *scoreGraph) drawDataPoints(cr *cairo.Context, layout graphLayout, datapoints []core.BandScore) {
valueCount := len(datapoints)

cr.SetSourceRGB(rateStyle.scoreGraphColor.toRGB())
cr.MoveTo(0, layout.zeroY)

valueScaling := layout.lowZoneHeight / g.pointsBinGoal
Expand Down
2 changes: 1 addition & 1 deletion ui/scoreView.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (v *scoreView) ShowScore(score core.Score) {
if v == nil {
return
}
v.graph.SetGraph(score.GraphPerBand[core.NoBand])
v.graph.SetGraphs(score.StackedGraphPerBand())

if v.tableLabel != nil {
renderedScore := fmt.Sprintf("<span allow_breaks='true' font_family='monospace'>%s</span>", score)
Expand Down

0 comments on commit e1be8ab

Please sign in to comment.