-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathplots.go
250 lines (224 loc) · 7.25 KB
/
plots.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
// Copyright (c) 2022, The Emergent Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package egui
/*
// AddPlots adds plots based on the unique tables we have,
// currently assumes they should always be plotted
func (gui *GUI) AddPlots(title string, lg *elog.Logs) {
gui.Plots = make(map[etime.ScopeKey]*plotcore.Editor)
// for key, table := range Log.Tables {
for _, key := range lg.TableOrder {
modes, times := key.ModesAndTimes()
time := times[0]
mode := modes[0]
lt := lg.Tables[key] // LogTable struct
if doplot, has := lt.Meta["Plot"]; has {
if doplot == "false" {
continue
}
}
plt := gui.NewPlotTab(key, mode+" "+time+" Plot")
plt.SetTable(lt.Table)
plt.Options.FromMetaMap(lt.Meta)
ConfigPlotFromLog(title, plt, lg, key)
}
}
*/
// // AddMiscPlotTab adds a misc (non log-generated) plot with a new
// // tab and plot of given name.
// func (gui *GUI) AddMiscPlotTab(name string) *plotcore.Editor {
// tab, _ := gui.Tabs.NewTab(name)
// plt := plotcore.NewSubPlot(tab)
// gui.SetPlotByName(name, plt)
// return plt
// }
/*
func ConfigPlotFromLog(title string, plt *plotcore.Editor, lg *elog.Logs, key etime.ScopeKey) {
_, times := key.ModesAndTimes()
time := times[0]
lt := lg.Tables[key] // LogTable struct
for _, item := range lg.Items {
_, ok := item.Write[key]
if !ok {
continue
}
cp := plt.SetColumnOptions(item.Name, item.Plot, item.FixMin, item.Range.Min, item.FixMax, item.Range.Max)
if item.Color != "" {
cp.Color = errors.Log1(gradient.FromString(item.Color, nil))
}
cp.TensorIndex = item.TensorIndex
cp.ErrColumn = item.ErrCol
plt.Options.Title = title + " " + time + " Plot"
plt.Options.XAxis = time
if xaxis, has := lt.Meta["XAxis"]; has {
plt.Options.XAxis = xaxis
}
if legend, has := lt.Meta["Legend"]; has {
plt.Options.Legend = legend
}
}
plt.ColumnsFromMetaMap(lt.Table.MetaData)
plt.ColumnsFromMetaMap(lt.Meta)
}
*/
/*
// Plot returns plot for mode, time scope
func (gui *GUI) Plot(mode etime.Modes, time etime.Times) *plotcore.Editor {
return gui.PlotScope(etime.Scope(mode, time))
}
// PlotScope returns plot for given scope
func (gui *GUI) PlotScope(scope etime.ScopeKey) *plotcore.Editor {
if !gui.Active {
return nil
}
plot, ok := gui.Plots[scope]
if !ok {
// fmt.Printf("egui Plot not found for scope: %s\n", scope)
return nil
}
return plot
}
// PlotByName returns a misc plot by name (instead of scope key).
func (gui *GUI) PlotByName(name string) *plotcore.Editor {
return gui.PlotScope(etime.ScopeKey(name))
}
// SetPlot stores given plot in Plots map.
func (gui *GUI) SetPlot(scope etime.ScopeKey, plt *plotcore.Editor) {
if gui.Plots == nil {
gui.Plots = make(map[etime.ScopeKey]*plotcore.Editor)
}
gui.Plots[scope] = plt
}
// SetPlotByName stores given misc plot by name (instead of scope key) in Plots map.
func (gui *GUI) SetPlotByName(name string, plt *plotcore.Editor) {
gui.SetPlot(etime.ScopeKey(name), plt)
}
// UpdatePlot updates plot for given mode, time scope.
// This version should be called in the GUI event loop, e.g., for direct
// updating in a toolbar action. Use [GoUpdatePlot] if being called from
// a separate goroutine, when the sim is running.
func (gui *GUI) UpdatePlot(mode etime.Modes, tm etime.Times) *plotcore.Editor {
plot := gui.Plot(mode, tm)
if plot != nil {
plot.UpdatePlot()
}
return plot
}
// GoUpdatePlot updates plot for given mode, time scope.
// This version is for use in a running simulation, in a separate goroutine.
// It will cause the GUI to hang if called from within the GUI event loop:
// use [UpdatePlot] for that case.
func (gui *GUI) GoUpdatePlot(mode etime.Modes, tm etime.Times) *plotcore.Editor {
plot := gui.Plot(mode, tm)
if plot != nil {
plot.GoUpdatePlot()
}
return plot
}
// UpdatePlotScope updates plot at given scope.
// This version should be called in the GUI event loop, e.g., for direct
// updating in a toolbar action. Use [GoUpdatePlot] if being called from
// a separate goroutine, when the sim is running.
func (gui *GUI) UpdatePlotScope(scope etime.ScopeKey) *plotcore.Editor {
plot := gui.PlotScope(scope)
if plot != nil {
plot.UpdatePlot()
}
return plot
}
// GoUpdatePlotScope updates plot at given scope.
// This version is for use in a running simulation, in a separate goroutine.
// It will cause the GUI to hang if called from within the GUI event loop:
// use [UpdatePlotScope] for that case.
func (gui *GUI) GoUpdatePlotScope(scope etime.ScopeKey) *plotcore.Editor {
plot := gui.PlotScope(scope)
if plot != nil {
plot.GoUpdatePlot()
}
return plot
}
// UpdateCyclePlot updates cycle plot for given mode.
// only updates every CycleUpdateInterval.
// This version should be called in the GUI event loop, e.g., for direct
// updating in a toolbar action. Use [GoUpdateCyclePlot] if being called from
// a separate goroutine, when the sim is running.
func (gui *GUI) UpdateCyclePlot(mode etime.Modes, cycle int) *plotcore.Editor {
plot := gui.Plot(mode, etime.Cycle)
if plot == nil {
return plot
}
if (gui.CycleUpdateInterval > 0) && (cycle%gui.CycleUpdateInterval == 0) {
plot.UpdatePlot()
}
return plot
}
// GoUpdateCyclePlot updates cycle plot for given mode.
// only updates every CycleUpdateInterval.
// This version is for use in a running simulation, in a separate goroutine.
// It will cause the GUI to hang if called from within the GUI event loop:
// use [UpdateCyclePlot] for that case.
func (gui *GUI) GoUpdateCyclePlot(mode etime.Modes, cycle int) *plotcore.Editor {
plot := gui.Plot(mode, etime.Cycle)
if plot == nil {
return plot
}
if (gui.CycleUpdateInterval > 0) && (cycle%gui.CycleUpdateInterval == 0) {
plot.GoUpdatePlot()
}
return plot
}
// NewPlotTab adds a new plot with given key for Plots lookup
// and using given tab label. For ad-hoc plots, you can
// construct a ScopeKey from any two strings using etime.ScopeStr.
func (gui *GUI) NewPlotTab(key etime.ScopeKey, tabLabel string) *plotcore.Editor {
tab, _ := gui.Tabs.NewTab(tabLabel)
plt := plotcore.NewSubPlot(tab)
gui.Plots[key] = plt
return plt
}
*/
/*
// AddTableView adds a table view of given log,
// typically particularly useful for Debug logs.
func (gui *GUI) AddTableView(lg *elog.Logs, mode etime.Modes, time etime.Times) *tensorcore.Table {
if gui.TableViews == nil {
gui.TableViews = make(map[etime.ScopeKey]*tensorcore.Table)
}
key := etime.Scope(mode, time)
lt, ok := lg.Tables[key]
if !ok {
log.Printf("ERROR: in egui.AddTableView, log: %s not found\n", key)
return nil
}
tt, _ := gui.Tabs.NewTab(mode.String() + " " + time.String() + " ")
tv := tensorcore.NewTable(tt)
gui.TableViews[key] = tv
tv.SetReadOnly(true)
tv.SetTable(lt.Table)
return tv
}
*/
/*
// TableView returns TableView for mode, time scope
func (gui *GUI) TableView(mode etime.Modes, time etime.Times) *tensorcore.Table {
if !gui.Active {
return nil
}
scope := etime.Scope(mode, time)
tv, ok := gui.TableViews[scope]
if !ok {
fmt.Printf("egui TableView not found for scope: %s\n", scope)
return nil
}
return tv
}
// UpdateTableView updates TableView for given mode, time scope
func (gui *GUI) UpdateTableView(mode etime.Modes, time etime.Times) *tensorcore.Table {
tv := gui.TableView(mode, time)
if tv != nil {
tv.AsyncUpdateTable()
}
return tv
}
*/