Skip to content

Commit

Permalink
Allow to limit the number of entries in time series plots (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
mlange-42 authored May 9, 2024
1 parent c062687 commit 4d1c6f4
Show file tree
Hide file tree
Showing 3 changed files with 11 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

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

### Features

* Allows to limit the number of entries in time series plots (#53)

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

### Features
Expand Down
4 changes: 4 additions & 0 deletions plot/time_series.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type TimeSeries struct {
Columns []string // Columns to show, by name. Optional, default all.
UpdateInterval int // Interval for getting data from the the observer, in model ticks. Optional.
Labels Labels // Labels for plot and axes. Optional.
MaxRows int // Maximum number of rows to keep. Zero means unlimited. Optional.

indices []int
headers []string
Expand All @@ -36,6 +37,9 @@ type TimeSeries struct {
func (t *TimeSeries) append(x float64, values []float64) {
for i := 0; i < len(t.series); i++ {
t.series[i] = append(t.series[i], plotter.XY{X: x, Y: values[i]})
if t.MaxRows > 0 && len(t.series[i]) > t.MaxRows {
t.series[i] = t.series[i][len(t.series[i])-t.MaxRows:]
}
}
}

Expand Down
1 change: 1 addition & 0 deletions plot/time_series_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func TestTimeSeries_Columns(t *testing.T) {
With(&plot.TimeSeries{
Observer: &RowObserver{},
Columns: []string{"A", "C"},
MaxRows: 50,
}))

m.AddSystem(&system.FixedTermination{
Expand Down

0 comments on commit 4d1c6f4

Please sign in to comment.