Skip to content

Commit

Permalink
Add optional property XLim to Lines plot (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
mlange-42 authored May 23, 2024
1 parent 4d1c6f4 commit 4700f2a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [[unpublished]](https://github.com/mlange-42/arche-pixel/compare/v0.9.0...main)

### Features

* Adds optional property `XLim` to `Lines` plot (#54)

## [[v0.9.0]](https://github.com/mlange-42/arche-pixel/compare/v0.8.1...v0.9.0)

### Features
Expand Down
6 changes: 6 additions & 0 deletions plot/lines.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type Lines struct {
Observer observer.Table // Observer providing a data series for lines.
X string // X column name. Optional. Defaults to row index.
Y []string // Y column names. Optional. Defaults to all but X column.
XLim [2]float64 // X axis limits. Optional, default auto.
YLim [2]float64 // Y axis limits. Optional, default auto.
Labels Labels // Labels for plot and axes. Optional.

Expand Down Expand Up @@ -101,6 +102,11 @@ func (l *Lines) Draw(w *ecs.World, win *opengl.Window) {
p.Y.Max = l.YLim[1]
}

if l.XLim[0] != 0 || l.XLim[1] != 0 {
p.X.Min = l.XLim[0]
p.Y.Max = l.XLim[1]
}

p.Legend = plot.NewLegend()
p.Legend.TextStyle.Font.Variant = "Mono"

Expand Down
1 change: 1 addition & 0 deletions plot/lines_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func TestLines(t *testing.T) {
m.AddUISystem((&window.Window{}).
With(&plot.Lines{
Observer: &TableObserver{},
XLim: [2]float64{0, 30},
YLim: [2]float64{0.5, 0.6},
}))

Expand Down

0 comments on commit 4700f2a

Please sign in to comment.