-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathoptions.go
193 lines (161 loc) · 5.11 KB
/
options.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
// Copyright (c) 2019, 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 netview
import (
"log"
"reflect"
"strconv"
"cogentcore.org/core/core"
"cogentcore.org/core/math32/minmax"
)
// NVarCols is the default number of variable columns in the NetView
var NVarCols = 2
// RasterOptions holds parameters controlling the raster plot view
type RasterOptions struct { //types:add
// if true, show a raster plot over time, otherwise units
On bool
// if true, the raster counter (time) is plotted across the X axis -- otherwise the Z depth axis
XAxis bool
// maximum count for the counter defining the raster plot
Max int
// size of a single unit, where 1 = full width and no space.. 1 default
UnitSize float32 `min:"0.1" max:"1" step:"0.1" default:"1"`
// height multiplier for units, where 1 = full height.. 0.2 default
UnitHeight float32 `min:"0.1" max:"1" step:"0.1" default:"0.2"`
}
func (nv *RasterOptions) Defaults() {
if nv.Max == 0 {
nv.Max = 200
}
if nv.UnitSize == 0 {
nv.UnitSize = 1
}
if nv.UnitHeight == 0 {
nv.UnitHeight = .2
}
}
// Options holds parameters controlling how the view is rendered
type Options struct { //types:add
// whether to display the pathways between layers as arrows
Paths bool
// PathType has name(s) to display (space separated), for path arrows,
// and when there are multiple pathways from the same layer.
// Uses the parameter Class names in addition to type,
// and case insensitive "contains" logic for each name.
PathType string
// width of the path arrows, in normalized units
PathWidth float32 `min:"0.0001" max:".05" step:"0.001" default:"0.002"`
// raster plot parameters
Raster RasterOptions `display:"inline"`
// do not record synapse level data -- turn this on for very large networks where recording the entire synaptic state would be prohibitive
NoSynData bool
// maximum number of records to store to enable rewinding through prior states
MaxRecs int `min:"1"`
// number of variable columns
NVarCols int
// size of a single unit, where 1 = full width and no space.. .9 default
UnitSize float32 `min:"0.1" max:"1" step:"0.1" default:"0.9"`
// size of the layer name labels -- entire network view is unit sized
LayerNameSize float32 `min:"0.01" max:".1" step:"0.01" default:"0.05"`
// name of color map to use
ColorMap core.ColorMapName
// opacity (0-1) of zero values -- greater magnitude values become increasingly opaque on either side of this minimum
ZeroAlpha float32 `min:"0" max:"1" step:"0.1" default:"0.5"`
// the number of records to jump for fast forward/backward
NFastSteps int
}
func (nv *Options) Defaults() {
nv.Raster.Defaults()
if nv.NVarCols == 0 {
nv.NVarCols = NVarCols
nv.Paths = true
nv.PathWidth = 0.002
}
if nv.MaxRecs == 0 {
nv.MaxRecs = 210 // 200 cycles + 8 phase updates max + 2 extra..
}
if nv.UnitSize == 0 {
nv.UnitSize = .9
}
if nv.LayerNameSize == 0 {
nv.LayerNameSize = .05
}
if nv.ZeroAlpha == 0 {
nv.ZeroAlpha = 0.5
}
if nv.ColorMap == "" {
nv.ColorMap = core.ColorMapName("ColdHot")
}
if nv.NFastSteps == 0 {
nv.NFastSteps = 10
}
}
// VarOptions holds parameters for display of each variable
type VarOptions struct { //types:add
// name of the variable
Var string
// keep Min - Max centered around 0, and use negative heights for units -- else use full min-max range for height (no negative heights)
ZeroCtr bool
// range to display
Range minmax.Range32 `display:"inline"`
// if not using fixed range, this is the actual range of data
MinMax minmax.F32 `display:"inline"`
}
// Defaults sets default values if otherwise not set
func (vp *VarOptions) Defaults() {
if vp.Range.Max == 0 && vp.Range.Min == 0 {
vp.ZeroCtr = true
vp.Range.SetMin(-1)
vp.Range.SetMax(1)
}
}
// SetProps parses Go struct-tag style properties for variable and sets values accordingly
// for customized defaults
func (vp *VarOptions) SetProps(pstr string) {
rstr := reflect.StructTag(pstr)
if tv, ok := rstr.Lookup("range"); ok {
rg, err := strconv.ParseFloat(tv, 32)
if err != nil {
log.Printf("NetView.VarOptions.SetProps for Var: %v 'range:' err: %v on val: %v\n", vp.Var, err, tv)
} else {
vp.Range.Max = float32(rg)
vp.Range.Min = -float32(rg)
vp.ZeroCtr = true
}
}
if tv, ok := rstr.Lookup("min"); ok {
rg, err := strconv.ParseFloat(tv, 32)
if err != nil {
log.Printf("NetView.VarOptions.SetProps for Var: %v 'min:' err: %v on val: %v\n", vp.Var, err, tv)
} else {
vp.Range.Min = float32(rg)
vp.ZeroCtr = false
}
}
if tv, ok := rstr.Lookup("max"); ok {
rg, err := strconv.ParseFloat(tv, 32)
if err != nil {
log.Printf("NetView.VarOptions.SetProps for Var: %v 'max:' err: %v on val: %v\n", vp.Var, err, tv)
} else {
vp.Range.Max = float32(rg)
vp.ZeroCtr = false
}
}
if tv, ok := rstr.Lookup("auto-scale"); ok {
if tv == "+" {
vp.Range.FixMin = false
vp.Range.FixMax = false
} else {
vp.Range.FixMin = true
vp.Range.FixMax = true
}
}
if tv, ok := rstr.Lookup("zeroctr"); ok {
if tv == "+" {
vp.ZeroCtr = true
} else {
vp.ZeroCtr = false
}
}
}