Skip to content

Commit

Permalink
add lab.NewPlotFrom helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoreilly committed Jan 15, 2025
1 parent e052b95 commit fff0012
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
3 changes: 1 addition & 2 deletions docs/content/compression-tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ From **a2**, we can compute and plot **x2**, the approximation of **x** based on

```Goal
# x2 := U @ a2
plt := lab.NewPlot(b)
*plt = *fig1
plt := lab.NewPlotFrom(fig1, b)
plt.Add(plots.NewLine(plot.NewY(x2)))
```
9 changes: 8 additions & 1 deletion lab/plot.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

// NewPlot is a simple helper function that does [plot.New] and [plotcore.NewPlot],
// only returning the [plot.Plot] for convenient use in lab plots. See [NewPlotWidget]
// for a version that also returns the [plotcore.Plot].
// for a version that also returns the [plotcore.Plot]. See also [NewPlotFrom].
func NewPlot(parent ...tree.Node) *plot.Plot {
plt, _ := NewPlotWidget(parent...)
return plt
Expand All @@ -26,3 +26,10 @@ func NewPlotWidget(parent ...tree.Node) (*plot.Plot, *plotcore.Plot) {
pw := plotcore.NewPlot(parent...).SetPlot(plt)
return plt, pw
}

// NewPlotFrom is a version of [NewPlot] that copies plot data from the given starting plot.
func NewPlotFrom(from *plot.Plot, parent ...tree.Node) *plot.Plot {
plt := NewPlot(parent...)
*plt = *from
return plt
}
1 change: 1 addition & 0 deletions yaegilab/gui/cogentcore_org-lab-lab.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions yaegilab/gui/cogentcore_org-lab-plot.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fff0012

Please sign in to comment.