lab

package
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 19, 2026 License: BSD-3-Clause Imports: 31 Imported by: 1

README

lab

The lab package provides GUI elements for data exploration and visualization, and a simple Browser implementation that combines these elements.

See the Cogent Lab Docs for full documentation.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// LabBrowser is the current Lab Browser, for yaegi / Go consistent access.
	LabBrowser *Browser

	// RunScript is set if labscripts is imported.
	// Runs given script name on browser's interpreter.
	RunScript func(br *Browser, scriptName string) error

	// RunScriptCode is set if labscripts is imported.
	// Runs given code on browser's interpreter.
	RunScriptCode func(br *Browser, code string) error
)

Functions

func DirAndFileNoSlash added in v0.1.1

func DirAndFileNoSlash(fpath string) string

DirAndFileNoSlash returns fsx.DirAndFile with slashes replaced with spaces. Slashes are also used in core Widget paths, so spaces are safer.

func FirstComment

func FirstComment(sc string) string

FirstComment returns the first comment lines from given .goal file, which is used to set the tooltip for scripts.

func IsTableFile

func IsTableFile(fname string) bool

func NewDiffBrowserDirs

func NewDiffBrowserDirs(pathA, pathB string)

NewDiffBrowserDirs returns a new diff browser for files that differ within the two given directories. Excludes Job and .tsv data files.

func NewPlot

func NewPlot(parent ...tree.Node) *plot.Plot

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. See also NewPlotFrom.

func NewPlotFrom

func NewPlotFrom(from *plot.Plot, parent ...tree.Node) *plot.Plot

NewPlotFrom is a version of NewPlot that copies plot data from the given starting plot.

func NewPlotWidget

func NewPlotWidget(parent ...tree.Node) (*plot.Plot, *plotcore.Plot)

NewPlotWidget is a simple helper function that does plot.New and plotcore.NewPlot, returning both the plot.Plot and plotcore.Plot for convenient use in lab plots. See NewPlot for a version that only returns the more commonly useful plot.Plot.

func NewTab

func NewTab[T any](tb Tabber, label string, mkfun func(tab *core.Frame) T) T

NewTab recycles a tab with given label, or returns the existing one with given type of widget within it. The existing that is returned is the last one in the frame, allowing for there to be a toolbar at the top. mkfun function is called to create and configure a new widget if not already existing.

func PromptOKCancel

func PromptOKCancel(ctx core.Widget, prompt string, fun func())

PromptOKCancel prompts the user for whether to do something, calling the given function if the user clicks OK.

func PromptString

func PromptString(ctx core.Widget, str string, prompt string, fun func(s string))

PromptString prompts the user for a string value (initial value given), calling the given function if the user clicks OK.

func PromptStruct

func PromptStruct(ctx core.Widget, str any, prompt string, fun func())

PromptStruct prompts the user for the values in given struct (pass a pointer), calling the given function if the user clicks OK.

func TabAt

func TabAt[T any](tb Tabber, label string) T

TabAt returns widget of given type at tab of given name, nil if tab not found.

func TensorFS

func TensorFS(fn *filetree.Node) *tensorfs.Node

TensorFS returns the tensorfs representation of this item. returns nil if not a dataFS item.

func TrimOrderPrefix

func TrimOrderPrefix(s string) string

TrimOrderPrefix trims any optional #- prefix from given string, used for ordering items by name.

Types

type Basic

type Basic struct {
	core.Frame
	Browser
}

Basic is a basic data browser with the files as the left panel, and the Tabber as the right panel.

func NewBasic

func NewBasic(parent ...tree.Node) *Basic

NewBasic returns a new Basic with the given optional parent: Basic is a basic data browser with the files as the left panel, and the Tabber as the right panel.

func NewBasicWindow

func NewBasicWindow(fsys fs.FS, dataDir string) (*core.Body, *Basic)

NewBasicWindow returns a new Lab Browser window for given file system (nil for os files) and data directory. do RunWindow on resulting core.Body to open the window.

func (*Basic) Init

func (br *Basic) Init()

Init initializes with the data and script directories

type Browser

type Browser struct {
	// FS is the filesystem, if browsing an FS.
	FS fs.FS

	// DataRoot is the path to the root of the data to browse.
	DataRoot string

	// StartDir is the starting directory, where the app was originally started.
	StartDir string

	// ScriptsDir is the directory containing scripts for toolbar actions.
	// It defaults to DataRoot/dbscripts
	ScriptsDir string

	// Scripts are interpreted goal scripts (via yaegi) to automate
	// routine tasks.
	Scripts map[string]string `set:"-"`

	// Interpreter is the interpreter to use for running Browser scripts.
	// is of type: *goal/interpreter.Interpreter but can't use that directly
	// to avoid importing goal unless needed. Import [labscripts] if needed.
	Interpreter any `set:"-"`

	// Files is the [DataTree] tree browser of the tensorfs or files.
	Files *DataTree

	// Tabs is the [Tabs] element managing tabs of data views.
	Tabs *Tabs

	// Toolbar is the top-level toolbar for the browser, if used.
	Toolbar *core.Toolbar

	// Splits is the overall [core.Splits] for the browser.
	Splits *core.Splits
}

Browser holds all the elements of a data browser, for browsing data either on an OS filesystem or as a tensorfs virtual data filesystem. It supports the automatic loading of [goal] scripts as toolbar actions to perform pre-programmed tasks on the data, to create app-like functionality. Scripts are ordered alphabetically and any leading #- prefix is automatically removed from the label, so you can use numbers to specify a custom order. It is not a core.Widget itself, and is intended to be incorporated into a core.Frame widget, potentially along with other custom elements. See Basic for a basic implementation.

func (*Browser) MakeScriptsToolbar

func (br *Browser) MakeScriptsToolbar(p *tree.Plan)

MakeScriptsToolbar is a maker for adding buttons for each uppercase script to the toolbar.

func (*Browser) MakeToolbar

func (br *Browser) MakeToolbar(p *tree.Plan)

MakeToolbar makes a default toolbar for the browser, with update files and update scripts buttons, followed by MakeScriptsToolbar for the scripts.

func (*Browser) SetDataRoot

func (t *Browser) SetDataRoot(v string) *Browser

SetDataRoot sets the [Browser.DataRoot]: DataRoot is the path to the root of the data to browse.

func (*Browser) SetFS

func (t *Browser) SetFS(v fs.FS) *Browser

SetFS sets the [Browser.FS]: FS is the filesystem, if browsing an FS.

func (*Browser) SetFiles

func (t *Browser) SetFiles(v *DataTree) *Browser

SetFiles sets the [Browser.Files]: Files is the DataTree tree browser of the tensorfs or files.

func (*Browser) SetScriptsDir

func (t *Browser) SetScriptsDir(v string) *Browser

SetScriptsDir sets the [Browser.ScriptsDir]: ScriptsDir is the directory containing scripts for toolbar actions. It defaults to DataRoot/dbscripts

func (*Browser) SetSplits

func (t *Browser) SetSplits(v *core.Splits) *Browser

SetSplits sets the [Browser.Splits]: Splits is the overall core.Splits for the browser.

func (*Browser) SetStartDir

func (t *Browser) SetStartDir(v string) *Browser

SetStartDir sets the [Browser.StartDir]: StartDir is the starting directory, where the app was originally started.

func (*Browser) SetTabs

func (t *Browser) SetTabs(v *Tabs) *Browser

SetTabs sets the [Browser.Tabs]: Tabs is the Tabs element managing tabs of data views.

func (*Browser) SetToolbar

func (t *Browser) SetToolbar(v *core.Toolbar) *Browser

SetToolbar sets the [Browser.Toolbar]: Toolbar is the top-level toolbar for the browser, if used.

func (*Browser) UpdateFiles

func (br *Browser) UpdateFiles()

UpdateFiles Updates the files list.

func (*Browser) UpdateScripts

func (br *Browser) UpdateScripts()

UpdateScripts updates the Scripts and updates the toolbar.

type DataTree

type DataTree struct {
	filetree.Tree

	// Tabber is the [Tabber] for this tree.
	Tabber Tabber
}

DataTree is the databrowser version of filetree.Tree, which provides the Tabber to show data editors.

func AsDataTree

func AsDataTree(n tree.Node) *DataTree

AsDataTree returns the given value as a DataTree if it has an AsDataTree() method, or nil otherwise.

func NewDataTree

func NewDataTree(parent ...tree.Node) *DataTree

NewDataTree returns a new DataTree with the given optional parent: DataTree is the databrowser version of filetree.Tree, which provides the Tabber to show data editors.

func (*DataTree) AsDataTree

func (ft *DataTree) AsDataTree() *DataTree

func (*DataTree) Init

func (ft *DataTree) Init()

func (*DataTree) SetTabber

func (t *DataTree) SetTabber(v Tabber) *DataTree

SetTabber sets the [DataTree.Tabber]: Tabber is the Tabber for this tree.

type FileNode

type FileNode struct {
	filetree.Node
}

FileNode is databrowser version of FileNode for FileTree

func NewFileNode

func NewFileNode(parent ...tree.Node) *FileNode

NewFileNode returns a new FileNode with the given optional parent: FileNode is databrowser version of FileNode for FileTree

func (*FileNode) ContextMenu

func (fn *FileNode) ContextMenu(m *core.Scene)

func (*FileNode) DiffDirs

func (fn *FileNode) DiffDirs()

DiffDirs displays a browser with differences between two selected directories

func (*FileNode) EditFile

func (fn *FileNode) EditFile()

EditFile pulls up this file in a texteditor

func (*FileNode) EditFiles

func (fn *FileNode) EditFiles()

EditFiles calls EditFile on selected files

func (*FileNode) GetFileInfo

func (fn *FileNode) GetFileInfo() error

func (*FileNode) GridFile

func (fn *FileNode) GridFile()

GridFile creates a grid view of data.

func (*FileNode) GridFiles

func (fn *FileNode) GridFiles()

GridFiles calls GridFile on selected files

func (*FileNode) Init

func (fn *FileNode) Init()

func (*FileNode) OpenFile

func (fn *FileNode) OpenFile() error

func (*FileNode) PlotFile

func (fn *FileNode) PlotFile()

PlotFile creates a plot of data.

func (*FileNode) PlotFiles

func (fn *FileNode) PlotFiles()

PlotFiles calls PlotFile on selected files

func (*FileNode) Tabber

func (fn *FileNode) Tabber() Tabber

Tabber returns the Tabber for this filenode, from root tree.

func (*FileNode) WidgetTooltip

func (fn *FileNode) WidgetTooltip(pos image.Point) (string, image.Point)

type Tabber

type Tabber interface {
	core.Tabber

	// AsLab returns the [lab.Tabs] widget with all the tabs methods.
	AsLab() *Tabs
}

Tabber is a core.Tabs based widget that has support for opening tabs for plotcore.Editor and tensorcore.Table editors, among others.

type Tabs

type Tabs struct {
	core.Tabs
}

Tabs implements the Tabber interface.

var Lab *Tabs

Lab is the current Tabs, for yaegi / Go consistent access.

func NewTabs

func NewTabs(parent ...tree.Node) *Tabs

NewTabs returns a new Tabs with the given optional parent: Tabs implements the Tabber interface.

func (*Tabs) AsLab

func (ts *Tabs) AsLab() *Tabs

func (*Tabs) EditorFile

func (ts *Tabs) EditorFile(label, filename string) *textcore.Editor

EditorFile opens an editor tab for given file.

func (*Tabs) EditorString

func (ts *Tabs) EditorString(label, content string) *textcore.Editor

EditorString recycles a textcore.Editor tab, displaying given string.

func (*Tabs) GoUpdatePlot

func (ts *Tabs) GoUpdatePlot(label string) *plotcore.Editor

GoUpdatePlot calls GoUpdatePlot on plot at tab with given name. Does nothing if tab name doesn't exist (returns nil).

func (*Tabs) GridTensorFS

func (ts *Tabs) GridTensorFS(dfs *tensorfs.Node) *tensorcore.TensorGrid

GridTensorFS recycles a tab with a Grid of given tensorfs.Node.

func (*Tabs) Init

func (ts *Tabs) Init()

func (*Tabs) NewPlot added in v0.1.3

func (ts *Tabs) NewPlot(label string) *plotcore.Editor

NewPlot recycles a tab with a plotcore.Editor.

func (*Tabs) Plot

func (ts *Tabs) Plot(label string, plt *plot.Plot) *plotcore.Plot

Plot recycles a tab with given Plot using given label.

func (*Tabs) PlotTable

func (ts *Tabs) PlotTable(label string, dt *table.Table) *plotcore.Editor

PlotTable recycles a tab with a Plot of given table.Table.

func (*Tabs) PlotTensorFS

func (ts *Tabs) PlotTensorFS(dfs *tensorfs.Node) *plotcore.Editor

PlotTensorFS recycles a tab with a Plot of given tensorfs.Node.

func (*Tabs) SliceTable

func (ts *Tabs) SliceTable(label string, slc any) *core.Table

SliceTable recycles a tab with a core.Table widget to view the given slice of structs.

func (*Tabs) TabUpdateRender added in v0.1.3

func (ts *Tabs) TabUpdateRender(label string) core.Widget

TabUpdateRender calls UpdateRender on content of given tab. This is the best way to update display widgets during running an ongoing computation.

func (*Tabs) TensorEditor

func (ts *Tabs) TensorEditor(label string, tsr tensor.Tensor) *tensorcore.TensorEditor

TensorEditor recycles a tab with a tensorcore.TensorEditor widget to view given Tensor.

func (*Tabs) TensorGrid

func (ts *Tabs) TensorGrid(label string, tsr tensor.Tensor) *tensorcore.TensorGrid

TensorGrid recycles a tab with a tensorcore.TensorGrid widget to view given Tensor.

func (*Tabs) TensorTable

func (ts *Tabs) TensorTable(label string, dt *table.Table) *tensorcore.Table

TensorTable recycles a tab with a tensorcore.Table widget to view given table.Table, using its own table.Table as tv.Table. Use tv.Table.Table to get the underlying *table.Table Use tv.Table.Sequential to update the Indexed to view all of the rows when done updating the Table, and then call br.Update()

func (*Tabs) UpdatePlot

func (ts *Tabs) UpdatePlot(label string) *plotcore.Editor

UpdatePlot calls UpdatePlot on plot at tab with given name. Does nothing if tab name doesn't exist (returns nil).

type Treer

type Treer interface {
	AsDataTree() *DataTree
}

Treer is an interface for getting the Root node as a DataTree struct.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL