Skip to content

Commit dcaff3d

Browse files
authored
Merge pull request #58 from cogentcore/plotminmax
plotminmax: a fixed min or max value also limits values plotted to that range
2 parents c3c9541 + c2bd7d6 commit dcaff3d

21 files changed

Lines changed: 550 additions & 129 deletions

File tree

docs/content/plot.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,21 @@ plt := lab.NewPlot(b)
8282
plots.NewLine(plt, data)
8383
```
8484

85+
## Out-of-Range data
86+
87+
You can set fixed Min / Max ranges to plot, for either axis. By default, the out-of-range data will show up as a break in the plot line, with red X's marking the out-of-range points. This behavior can be adjusted by changing the `OutOfRange` property in the [[doc:plot.PlotStyle]].
88+
89+
```Goal
90+
data := #rand(10)#
91+
plot.SetStyler(data, func(s *plot.Style) {
92+
s.Range.SetMin(0.2) // sets a FixMin flag to indicate a fixed min has been set.
93+
s.Range.SetMax(0.8)
94+
s.Plot.OutOfRange = plot.BreakMark // default
95+
})
96+
plt := lab.NewPlot(b)
97+
plots.NewLine(plt, data)
98+
```
99+
85100
## Plot Types
86101

87102
The following are the builtin standard plot types, in the `plots` package:

go.mod

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ go 1.25.6
88
// https://github.com/googleapis/go-genproto/issues/1015
99

1010
require (
11-
cogentcore.org/core v0.3.25
11+
cogentcore.org/core v0.3.28
1212
github.com/cogentcore/readline v0.1.3
1313
github.com/cogentcore/yaegi v0.0.0-20260116172027-700fbf8949f3
1414
github.com/mitchellh/go-homedir v1.1.0
@@ -38,10 +38,10 @@ require (
3838
github.com/ericchiang/css v1.4.0 // indirect
3939
github.com/fsnotify/fsnotify v1.9.0 // indirect
4040
github.com/go-fonts/latin-modern v0.3.3 // indirect
41-
github.com/go-gl/glfw/v3.4/glfw v0.1.0-pre.1 // indirect
41+
github.com/go-gl/glfw/v3.4/glfw v0.1.0-pre.1.0.20260406072232-3ac4aa2bb164 // indirect
4242
github.com/go-text/typesetting v0.3.5-0.20260418130854-c41d02a44bec // indirect
4343
github.com/gobwas/glob v0.2.3 // indirect
44-
github.com/gomarkdown/markdown v0.0.0-20250810172220-2e2c11897d1a // indirect
44+
github.com/gomarkdown/markdown v0.0.0-20260417124207-7d523f7318df // indirect
4545
github.com/gorilla/css v1.0.1 // indirect
4646
github.com/h2non/filetype v1.1.3 // indirect
4747
github.com/hack-pad/go-indexeddb v0.3.2 // indirect
@@ -66,8 +66,8 @@ require (
6666
golang.org/x/sync v0.20.0 // indirect
6767
golang.org/x/sys v0.42.0 // indirect
6868
golang.org/x/text v0.36.0 // indirect
69-
google.golang.org/genproto v0.0.0-20260420184626-e10c466a9529 // indirect
70-
google.golang.org/genproto/googleapis/rpc v0.0.0-20260414002931-afd174a4e478 // indirect
69+
google.golang.org/genproto v0.0.0-20260511170946-3700d4141b60 // indirect
70+
google.golang.org/genproto/googleapis/rpc v0.0.0-20260504160031-60b97b32f348 // indirect
7171
gopkg.in/yaml.v3 v3.0.1 // indirect
7272
modernc.org/knuth v0.5.4 // indirect
7373
modernc.org/token v1.1.0 // indirect

go.sum

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
codeberg.org/go-pdf/fpdf v0.11.0 h1:n3I8WISQ1cr0S2rvx9DOlE/GypbcimMWqLpel3slHmY=
22
codeberg.org/go-pdf/fpdf v0.11.0/go.mod h1:Y0DGRAdZ0OmnZPvjbMp/1bYxmIPxm0ws4tfoPOc4LjU=
3-
cogentcore.org/core v0.3.25 h1:nrECnVQIl/JvyGFae5c/KystUAlLwSmIsjW1MkpkpiU=
4-
cogentcore.org/core v0.3.25/go.mod h1:+5R2kihBnWrFmRlYd8yJ8JmRuLsGgCXXgvcgLk/YDEI=
3+
cogentcore.org/core v0.3.28 h1:4sE28se7PLtDrYESg9W1hirOYY9Pddkle0cLxCLPZyw=
4+
cogentcore.org/core v0.3.28/go.mod h1:IuX9mO4iQAMACI3yJbRfPmCN+PM+Z+mbJrFXa9fc7sg=
55
git.sr.ht/~sbinet/cmpimg v0.1.0 h1:E0zPRk2muWuCqSKSVZIWsgtU9pjsw3eKHi8VmQeScxo=
66
git.sr.ht/~sbinet/cmpimg v0.1.0/go.mod h1:FU12psLbF4TfNXkKH2ZZQ29crIqoiqTZmeQ7dkp/pxE=
77
github.com/Bios-Marcel/wastebasket/v2 v2.0.3 h1:TkoDPcSqluhLGE+EssHu7UGmLgUEkWg7kNyHyyJ3Q9g=
@@ -47,8 +47,8 @@ github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S
4747
github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
4848
github.com/go-fonts/latin-modern v0.3.3 h1:g2xNgI8yzdNzIVm+qvbMryB6yGPe0pSMss8QT3QwlJ0=
4949
github.com/go-fonts/latin-modern v0.3.3/go.mod h1:tHaiWDGze4EPB0Go4cLT5M3QzRY3peya09Z/8KSCrpY=
50-
github.com/go-gl/glfw/v3.4/glfw v0.1.0-pre.1 h1:nIVzcwqIaO1mK8LFr0fGkKpgQD4wJDDHRyv4t5k40Ps=
51-
github.com/go-gl/glfw/v3.4/glfw v0.1.0-pre.1/go.mod h1:T5Dn0JwIJOX1euPZ/iT4tq6nFYtmukjcYa7937HuYK8=
50+
github.com/go-gl/glfw/v3.4/glfw v0.1.0-pre.1.0.20260406072232-3ac4aa2bb164 h1:c87Nyz3ox3QbCl0yozQPeVPW4mmgFOSKY4yyc1TrS0w=
51+
github.com/go-gl/glfw/v3.4/glfw v0.1.0-pre.1.0.20260406072232-3ac4aa2bb164/go.mod h1:T5Dn0JwIJOX1euPZ/iT4tq6nFYtmukjcYa7937HuYK8=
5252
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
5353
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
5454
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
@@ -61,8 +61,8 @@ github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
6161
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
6262
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
6363
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
64-
github.com/gomarkdown/markdown v0.0.0-20250810172220-2e2c11897d1a h1:l7A0loSszR5zHd/qK53ZIHMO8b3bBSmENnQ6eKnUT0A=
65-
github.com/gomarkdown/markdown v0.0.0-20250810172220-2e2c11897d1a/go.mod h1:JDGcbDT52eL4fju3sZ4TeHGsQwhG9nbDV21aMyhwPoA=
64+
github.com/gomarkdown/markdown v0.0.0-20260417124207-7d523f7318df h1:Mwihr/o+v4L5h56rwHLOE20+hh7Okhwno5BHz3zDuao=
65+
github.com/gomarkdown/markdown v0.0.0-20260417124207-7d523f7318df/go.mod h1:JDGcbDT52eL4fju3sZ4TeHGsQwhG9nbDV21aMyhwPoA=
6666
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
6767
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
6868
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
@@ -167,10 +167,10 @@ golang.org/x/tools v0.43.0/go.mod h1:uHkMso649BX2cZK6+RpuIPXS3ho2hZo4FVwfoy1vIk0
167167
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
168168
gonum.org/v1/gonum v0.17.0 h1:VbpOemQlsSMrYmn7T2OUvQ4dqxQXU+ouZFQsZOx50z4=
169169
gonum.org/v1/gonum v0.17.0/go.mod h1:El3tOrEuMpv2UdMrbNlKEh9vd86bmQ6vqIcDwxEOc1E=
170-
google.golang.org/genproto v0.0.0-20260420184626-e10c466a9529 h1:QoMBg0moLIlB/eucPzc+ID5SgPZWuirtjAn3l8nW2Dg=
171-
google.golang.org/genproto v0.0.0-20260420184626-e10c466a9529/go.mod h1:EjLmDZ8liSLBrCTK5vP+bGIxRQHE3ovGvOI0CzGk1PI=
172-
google.golang.org/genproto/googleapis/rpc v0.0.0-20260414002931-afd174a4e478 h1:RmoJA1ujG+/lRGNfUnOMfhCy5EipVMyvUE+KNbPbTlw=
173-
google.golang.org/genproto/googleapis/rpc v0.0.0-20260414002931-afd174a4e478/go.mod h1:4Hqkh8ycfw05ld/3BWL7rJOSfebL2Q+DVDeRgYgxUU8=
170+
google.golang.org/genproto v0.0.0-20260511170946-3700d4141b60 h1:rhBdfmsOlOZIvz3Y5/BdUzPg2CkO8L7QQPKj96B8554=
171+
google.golang.org/genproto v0.0.0-20260511170946-3700d4141b60/go.mod h1:8xo2Pj1b20ZOCpzlU3B9qieMwVIAXx1QVZWLMlPL6sM=
172+
google.golang.org/genproto/googleapis/rpc v0.0.0-20260504160031-60b97b32f348 h1:pfIbyB44sWzHiCpRqIen67ZQnVXSfIxWrqUMk1qwODE=
173+
google.golang.org/genproto/googleapis/rpc v0.0.0-20260504160031-60b97b32f348/go.mod h1:4Hqkh8ycfw05ld/3BWL7rJOSfebL2Q+DVDeRgYgxUU8=
174174
google.golang.org/grpc v1.80.0 h1:Xr6m2WmWZLETvUNvIUmeD5OAagMw3FiKmMlTdViWsHM=
175175
google.golang.org/grpc v1.80.0/go.mod h1:ho/dLnxwi3EDJA4Zghp7k2Ec1+c2jqup0bFkw07bwF4=
176176
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=

gosl/gotosl/config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ type Config struct {
4141
// and must fit in a uint32 number.
4242
// The default is 32 byte aligned down version of 2147483647 max for nvidia
4343
MaxBufferSize uint32 `default:"2147483616"`
44+
45+
// MaxStorageBuffersPerShaderStage is used to flag shaders that use more
46+
// than this maximum number, which is the default max for web-based apps
47+
// based on all the various backends. Specific backends may have more
48+
// but using more will affect portability.
49+
MaxStorageBuffersPerShaderStage int `default:"16"`
4450
}
4551

4652
//cli:cmd -root

gosl/gotosl/translate.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ func (st *State) TranslateDir(pf string) error {
137137
kn.Atomics, kn.VarsUsed, nvars = st.VarsUsed(st.KernelFuncs)
138138
maxVarsUsed = max(maxVarsUsed, nvars)
139139
fmt.Printf("###################################\nTranslating Kernel file: %s NVars: %d (atomic: %d)\n", kn.Name, nvars, len(kn.Atomics))
140-
if nvars > 10 { // todo: change when limit is raised to 16
141-
fmt.Println("WARNING: NVars exceeds maxStorageBuffersPerShaderStage min of 10")
140+
if nvars > st.Config.MaxStorageBuffersPerShaderStage {
141+
fmt.Println("WARNING: NVars exceeds maxStorageBuffersPerShaderStage min of:", st.Config.MaxStorageBuffersPerShaderStage)
142142
nOverBase++
143143
}
144144
hdr := st.GenKernelHeader(sy, kn)
@@ -193,7 +193,7 @@ func (st *State) TranslateDir(pf string) error {
193193
}
194194
fmt.Println("\n###################################\nMaximum number of variables used per shader:", maxVarsUsed)
195195
if nOverBase > 0 {
196-
fmt.Printf("WARNING: %d shaders exceed maxStorageBuffersPerShaderStage min of 10\n", nOverBase)
196+
fmt.Printf("WARNING: %d shaders exceed maxStorageBuffersPerShaderStage min of: %d\n", nOverBase, st.Config.MaxStorageBuffersPerShaderStage)
197197
}
198198

199199
//////// check types

gosl/gotosl/typegen.go

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plot/README.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,3 @@ Here is the copyright notice for that package:
4545
// license that can be found in the LICENSE file.
4646
```
4747

48-
# TODO
49-
50-
* Min / Max not just for extending but also _limiting_ the range -- currently doesn't do
51-
52-
* tensor index
53-
* Grid? in styling.
54-

plot/axis.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,15 @@ func (ax *AxisStyle) Defaults() {
104104
// This is the "internal" data structure and should not be used for styling.
105105
type Axis struct {
106106

107-
// Range has the Min, Max range of values for the axis (in raw data units.)
107+
// Range has the full Min, Max range of values for the axis
108+
// (in raw data units). This includes extra space needed for plotting.
108109
Range minmax.F64
109110

111+
// DataRange has the Min, Max range for the actual data values
112+
// for the axis (in raw data units), *exclusive* of extra plotting space.
113+
// This is used for OutOfRange clipping.
114+
DataRange minmax.F64
115+
110116
// specifies which axis this is: X, Y or Z.
111117
Axis math32.Dims
112118

plot/data.go

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,49 @@ func Range(data Valuer, rng *minmax.F64) {
150150
}
151151
}
152152

153+
// RangeLogic processes the OutOfRange setting to set the given axis range
154+
// based on style range settings (i.e., dealing with Stretch vs. other cases).
155+
// Returns true if the range of the data fits entirely within the styleRng
156+
// min / max values (according to axisRng which must already be updated from data).
157+
func RangeLogic(oor OutOfRange, axisRng *minmax.F64, styleRng *minmax.Range64) bool {
158+
if oor == Stretch {
159+
RangeClamp(axisRng, styleRng)
160+
return true // by definition
161+
}
162+
return RangeSet(axisRng, styleRng)
163+
}
164+
153165
// RangeClamp updates the given axis Min, Max range values based
154-
// on the range of values in the given [Data], and the given style range.
155-
func RangeClamp(data Valuer, axisRng *minmax.F64, styleRng *minmax.Range64) {
156-
Range(data, axisRng)
166+
// on the axis range (from data values), and the given style range.
167+
// The style can only stretch the range, not shrink it.
168+
func RangeClamp(axisRng *minmax.F64, styleRng *minmax.Range64) {
157169
axisRng.Min, axisRng.Max = styleRng.Clamp(axisRng.Min, axisRng.Max)
158170
}
159171

172+
// RangeSet sets the axis range based on the given style range,
173+
// where styleRng flags for Min or Max are set, and otherwise gets the range
174+
// from the axis range (based on actual data).
175+
// This is for the case where the flags indicate a hard,
176+
// non-stretchable extreme, whereas RangeClamp is the stretch case.
177+
// Returns true if the range of the data fits entirely within the styleRng
178+
// min / max values.
179+
func RangeSet(axisRng *minmax.F64, styleRng *minmax.Range64) bool {
180+
fits := true
181+
if styleRng.FixMin {
182+
if axisRng.Min < styleRng.Min {
183+
fits = false
184+
}
185+
axisRng.Min = styleRng.Min
186+
}
187+
if styleRng.FixMax {
188+
if axisRng.Max > styleRng.Max {
189+
fits = false
190+
}
191+
axisRng.Max = styleRng.Max
192+
}
193+
return fits
194+
}
195+
160196
// CheckLengths checks that all the data elements have the same length.
161197
// Logs and returns an error if not.
162198
func (dt Data) CheckLengths() error {

0 commit comments

Comments
 (0)