Documentation ¶
Index ¶
- Constants
- Variables
- func MetaMapLower(meta map[string]string, key string) (string, bool)
- type ColumnParams
- type Plot
- func (pt *Plot) HandleEvents()
- func (t *Plot) New() tree.Node
- func (t *Plot) NodeType() *types.Type
- func (pt *Plot) OnInit()
- func (pt *Plot) Render()
- func (pt *Plot) SavePNG(filename core.Filename) error
- func (pt *Plot) SavePlot(filename core.Filename) error
- func (pt *Plot) SetPlot(pl *plot.Plot)
- func (t *Plot) SetScale(v float32) *Plot
- func (pt *Plot) SetStyles()
- func (t *Plot) SetTooltip(v string) *Plot
- func (pt *Plot) SizeFinal()
- func (pt *Plot) UpdatePlot()
- func (pt *Plot) WidgetTooltip() (string, image.Point)
- type PlotParams
- type PlotTypes
- func (i PlotTypes) Desc() string
- func (i PlotTypes) Int64() int64
- func (i PlotTypes) MarshalText() ([]byte, error)
- func (i *PlotTypes) SetInt64(in int64)
- func (i *PlotTypes) SetString(s string) error
- func (i PlotTypes) String() string
- func (i *PlotTypes) UnmarshalText(text []byte) error
- func (i PlotTypes) Values() []enums.Enum
- type PlotView
- func (pl *PlotView) ColParamsTry(colNm string) (*ColumnParams, error)
- func (pl *PlotView) ColumnParams(colNm string) *ColumnParams
- func (pl *PlotView) ColumnsConfig()
- func (pl *PlotView) ColumnsFromMetaMap(meta map[string]string)
- func (pl *PlotView) ColumnsLay() *core.Frame
- func (pl *PlotView) ColumnsListUpdate()
- func (pl *PlotView) ColumnsUpdate()
- func (pl *PlotView) Config()
- func (pl *PlotView) ConfigPlot(plt *plot.Plot)
- func (pl *PlotView) ConfigPlotView()
- func (pl *PlotView) ConfigToolbar(tb *core.Toolbar)
- func (pl *PlotView) CopyFieldsFrom(frm tree.Node)
- func (pl *PlotView) DeleteColumns()
- func (pl *PlotView) GenPlot()
- func (pl *PlotView) GenPlotBar()
- func (pl *PlotView) GenPlotXY()
- func (pl *PlotView) GoUpdatePlot()
- func (t *PlotView) New() tree.Node
- func (t *PlotView) NodeType() *types.Type
- func (pl *PlotView) OnAdd()
- func (pl *PlotView) OnInit()
- func (pl *PlotView) OpenCSV(filename core.Filename, delim table.Delims)
- func (pl *PlotView) OpenFS(fsys fs.FS, filename core.Filename, delim table.Delims)
- func (pl *PlotView) PlotChild() *Plot
- func (pl *PlotView) PlotXAxis(plt *plot.Plot, ixvw *table.IndexView) (xi int, xview *table.IndexView, err error)
- func (pl *PlotView) SaveAll(fname core.Filename)
- func (pl *PlotView) SaveCSV(fname core.Filename, delim table.Delims)
- func (pl *PlotView) SavePNG(fname core.Filename)
- func (pl *PlotView) SaveSVG(fname core.Filename)
- func (pl *PlotView) SetAllColumns(on bool)
- func (pl *PlotView) SetColParams(colNm string, on bool, fixMin bool, min float32, fixMax bool, max float32) *ColumnParams
- func (pl *PlotView) SetColumnsByName(nameContains string, on bool)
- func (t *PlotView) SetConfigPlotFunc(v func()) *PlotView
- func (t *PlotView) SetDataFile(v core.Filename) *PlotView
- func (t *PlotView) SetParams(v PlotParams) *PlotView
- func (t *PlotView) SetSVGFile(v core.Filename) *PlotView
- func (pl *PlotView) SetTable(tab *table.Table) *PlotView
- func (pl *PlotView) SetTableView(tab *table.IndexView) *PlotView
- func (t *PlotView) SetTooltip(v string) *PlotView
- func (pt *PlotView) SizeFinal()
- func (pl *PlotView) UpdatePlot()
- func (pl *PlotView) XLabel() string
- func (pl *PlotView) YLabel() string
- type TableXY
- func (txy *TableXY) FilterValues()
- func (txy *TableXY) Label(row int) string
- func (txy *TableXY) Len() int
- func (txy *TableXY) TRowValue(row int) float32
- func (txy *TableXY) TRowXValue(row int) float32
- func (txy *TableXY) Validate() error
- func (txy *TableXY) Value(row int) float32
- func (txy *TableXY) XValue(row int) float32
- func (txy *TableXY) XY(row int) (x, y float32)
- func (txy *TableXY) YError(row int) (float32, float32)
Constants ¶
const ( On bool = true Off = false FixMin = true FloatMin = false FixMax = true FloatMax = false )
use these for SetColParams args
const PlotColumnsHeaderN = 2
Variables ¶
var PlotType = types.AddType(&types.Type{Name: "cogentcore.org/core/plot/plotview.Plot", IDName: "plot", Doc: "Plot is a Widget that renders a [plot.Plot] object.\nIf it is not [states.ReadOnly], the user can pan and zoom the display.\nBy default, it is [states.ReadOnly]. See [ConfigPlotToolbar] for a\ntoolbar with panning, selecting, and I/O buttons,\nand PlotView for an interactive interface for selecting columns to view.", Methods: []types.Method{{Name: "SavePlot", Doc: "SaveSVG saves the current Plot to an SVG file", Directives: []types.Directive{{Tool: "types", Directive: "add"}}, Args: []string{"filename"}, Returns: []string{"error"}}, {Name: "SavePNG", Doc: "SavePNG saves the current rendered Plot image to an PNG image file.", Directives: []types.Directive{{Tool: "types", Directive: "add"}}, Args: []string{"filename"}, Returns: []string{"error"}}}, Embeds: []types.Field{{Name: "WidgetBase"}}, Fields: []types.Field{{Name: "Scale", Doc: "Scale multiplies the plot DPI value, to change the overall scale\nof the rendered plot. Larger numbers produce larger scaling.\nTypically use larger numbers when generating plots for inclusion in\ndocuments or other cases where the overall plot size will be small."}, {Name: "Plot", Doc: "Plot is the Plot to display in this widget"}}, Instance: &Plot{}})
PlotType is the types.Type for Plot
var PlotViewType = types.AddType(&types.Type{Name: "cogentcore.org/core/plot/plotview.PlotView", IDName: "plot-view", Doc: "PlotView is a Cogent Core Widget that provides an interactive 2D plot\nof selected columns of Tabular data, represented by an IndexView into\na table.Table. Other types of tabular data can be converted into this format.", Directives: []types.Directive{{Tool: "types", Directive: "add"}}, Methods: []types.Method{{Name: "SaveSVG", Doc: "SaveSVG saves the plot to an svg -- first updates to ensure that plot is current", Directives: []types.Directive{{Tool: "types", Directive: "add"}}, Args: []string{"fname"}}, {Name: "SavePNG", Doc: "SavePNG saves the current plot to a png, capturing current render", Directives: []types.Directive{{Tool: "types", Directive: "add"}}, Args: []string{"fname"}}, {Name: "SaveCSV", Doc: "SaveCSV saves the Table data to a csv (comma-separated values) file with headers (any delim)", Directives: []types.Directive{{Tool: "types", Directive: "add"}}, Args: []string{"fname", "delim"}}, {Name: "SaveAll", Doc: "SaveAll saves the current plot to a png, svg, and the data to a tsv -- full save\nAny extension is removed and appropriate extensions are added", Directives: []types.Directive{{Tool: "types", Directive: "add"}}, Args: []string{"fname"}}, {Name: "OpenCSV", Doc: "OpenCSV opens the Table data from a csv (comma-separated values) file (or any delim)", Directives: []types.Directive{{Tool: "types", Directive: "add"}}, Args: []string{"filename", "delim"}}, {Name: "SetColumnsByName", Doc: "SetColumnsByName turns cols On or Off if their name contains given string", Directives: []types.Directive{{Tool: "types", Directive: "add"}}, Args: []string{"nameContains", "on"}}}, Embeds: []types.Field{{Name: "Layout"}}, Fields: []types.Field{{Name: "Table", Doc: "the table of data being plotted"}, {Name: "Params", Doc: "the overall plot parameters"}, {Name: "Columns", Doc: "the parameters for each column of the table"}, {Name: "Plot", Doc: "the plot object"}, {Name: "ConfigPlotFunc", Doc: "ConfigPlotFunc is a function to call to configure [PlotView.Plot], the plot.Plot that\nactually does the plotting. It is called after [Plot] is generated, and properties\nof [Plot] can be modified in it. Properties of [Plot] should not be modified outside\nof this function, as doing so will have no effect."}, {Name: "SVGFile", Doc: "current svg file"}, {Name: "DataFile", Doc: "current csv data file"}, {Name: "InPlot", Doc: "currently doing a plot"}}, Instance: &PlotView{}})
PlotViewType is the types.Type for PlotView
Functions ¶
Types ¶
type ColumnParams ¶
type ColumnParams struct { // whether to plot this column On bool // name of column we're plotting Column string // whether to plot lines; uses the overall plot option if unset Lines option.Option[bool] // whether to plot points with symbols; uses the overall plot option if unset Points option.Option[bool] // the width of lines; uses the overall plot option if unset LineWidth option.Option[float32] // the size of points; uses the overall plot option if unset PointSize option.Option[float32] // the shape used to draw points; uses the overall plot option if unset PointShape option.Option[plots.Shapes] // effective range of data to plot -- either end can be fixed Range minmax.Range32 `view:"inline"` // full actual range of data -- only valid if specifically computed FullRange minmax.F32 `view:"inline"` // color to use when plotting the line / column Color color.Color // desired number of ticks NTicks int // if non-empty, this is an alternative label to use in plotting Lbl string `label:"Label"` // if column has n-dimensional tensor cells in each row, this is the index within each cell to plot -- use -1 to plot *all* indexes as separate lines TensorIndex int // specifies a column containing error bars for this column ErrColumn string // if true this is a string column -- plots as labels IsString bool `edit:"-"` // our plot, for update method Plot *PlotView `copier:"-" json:"-" xml:"-" view:"-"` }
ColumnParams are parameters for plotting one column of data
func (*ColumnParams) CopyFrom ¶
func (cp *ColumnParams) CopyFrom(fr *ColumnParams)
CopyFrom copies from other col params
func (*ColumnParams) Defaults ¶
func (cp *ColumnParams) Defaults()
Defaults sets defaults if nil vals present
func (*ColumnParams) FromMetaMap ¶
func (cp *ColumnParams) FromMetaMap(meta map[string]string)
FromMetaMap sets plot params from meta data map
func (*ColumnParams) Label ¶
func (cp *ColumnParams) Label() string
func (*ColumnParams) Update ¶
func (cp *ColumnParams) Update()
Update satisfies the core.Updater interface and will trigger display update on edits
type Plot ¶
type Plot struct { core.WidgetBase // Scale multiplies the plot DPI value, to change the overall scale // of the rendered plot. Larger numbers produce larger scaling. // Typically use larger numbers when generating plots for inclusion in // documents or other cases where the overall plot size will be small. Scale float32 // Plot is the Plot to display in this widget Plot *plot.Plot `set:"-"` }
Plot is a Widget that renders a plot.Plot object. If it is not states.ReadOnly, the user can pan and zoom the graph. See [ConfigPlotToolbar] for a toolbar with panning, selecting, and I/O buttons, and PlotView for an interactive interface for selecting columns to view.
func NewPlot ¶
NewPlot adds a new Plot with the given name to the given parent: Plot is a Widget that renders a plot.Plot object. If it is not states.ReadOnly, the user can pan and zoom the display. By default, it is states.ReadOnly. See [ConfigPlotToolbar] for a toolbar with panning, selecting, and I/O buttons, and PlotView for an interactive interface for selecting columns to view.
func (*Plot) HandleEvents ¶
func (pt *Plot) HandleEvents()
func (*Plot) NodeType ¶
NodeType returns the *types.Type of Plot
func (*Plot) SetPlot ¶
SetPlot sets the plot to given Plot, and calls UpdatePlot to ensure it is drawn at the current size of this widget
func (*Plot) SetScale ¶
SetScale sets the [Plot.Scale]: Scale multiplies the plot DPI value, to change the overall scale of the rendered plot. Larger numbers produce larger scaling. Typically use larger numbers when generating plots for inclusion in documents or other cases where the overall plot size will be small.
func (*Plot) SetTooltip ¶
SetTooltip sets the [Plot.Tooltip]
func (*Plot) UpdatePlot ¶
func (pt *Plot) UpdatePlot()
UpdatePlot draws the current plot at the size of the current widget, and triggers a Render so the widget will be rendered.
type PlotParams ¶
type PlotParams struct { // optional title at top of plot Title string // type of plot to generate. For a Bar plot, items are plotted ordinally by row and the XAxis is optional Type PlotTypes // whether to plot lines Lines bool `default:"true"` // whether to plot points with symbols Points bool // width of lines LineWidth float32 `default:"1"` // size of points PointSize float32 `default:"3"` // the shape used to draw points PointShape plots.Shapes // width of bars for bar plot, as fraction of available space (1 = no gaps) BarWidth float32 `min:"0.01" max:"1" default:"0.8"` // if true, draw lines that connect points with a negative X-axis direction; // otherwise there is a break in the line. // default is false, so that repeated series of data across the X axis // are plotted separately. NegativeXDraw bool // Scale multiplies the plot DPI value, to change the overall scale // of the rendered plot. Larger numbers produce larger scaling. // Typically use larger numbers when generating plots for inclusion in // documents or other cases where the overall plot size will be small. Scale float32 `default:"1,2"` // what column to use for the common X axis. if empty or not found, // the row number is used. This optional for Bar plots, if present and // LegendColumn is also present, then an extra space will be put between X values. XAxisColumn string // optional column for adding a separate colored / styled line or bar // according to this value, and acts just like a separate Y variable, // crossed with Y variables. LegendColumn string // position of the Legend LegendPosition plot.LegendPosition `view:"inline"` // rotation of the X Axis labels, in degrees XAxisRotation float32 // optional label to use for XAxis instead of column name XAxisLabel string // optional label to use for YAxis -- if empty, first column name is used YAxisLabel string // our plot, for update method Plot *PlotView `copier:"-" json:"-" xml:"-" view:"-"` }
PlotParams are parameters for overall plot
func (*PlotParams) CopyFrom ¶
func (pp *PlotParams) CopyFrom(fr *PlotParams)
CopyFrom copies from other col params
func (*PlotParams) Defaults ¶
func (pp *PlotParams) Defaults()
Defaults sets defaults if nil vals present
func (*PlotParams) FromMeta ¶
func (pp *PlotParams) FromMeta(dt *table.Table)
FromMeta sets plot params from meta data
func (*PlotParams) FromMetaMap ¶
func (pp *PlotParams) FromMetaMap(meta map[string]string)
FromMetaMap sets plot params from meta data map
func (*PlotParams) Update ¶
func (pp *PlotParams) Update()
Update satisfies the core.Updater interface and will trigger display update on edits
type PlotTypes ¶
type PlotTypes int32 //enums:enum
PlotTypes are different types of plots
const PlotTypesN PlotTypes = 2
PlotTypesN is the highest valid value for type PlotTypes, plus one.
func PlotTypesValues ¶
func PlotTypesValues() []PlotTypes
PlotTypesValues returns all possible values for the type PlotTypes.
func (PlotTypes) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (*PlotTypes) SetString ¶
SetString sets the PlotTypes value from its string representation, and returns an error if the string is invalid.
func (*PlotTypes) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.
type PlotView ¶
type PlotView struct { core.Layout // the table of data being plotted Table *table.IndexView `set:"-"` // the overall plot parameters Params PlotParams // the parameters for each column of the table Columns []*ColumnParams `set:"-"` // the plot object Plot *plot.Plot `set:"-" edit:"-" json:"-" xml:"-"` // ConfigPlotFunc is a function to call to configure [PlotView.Plot], the plot.Plot that // actually does the plotting. It is called after [Plot] is generated, and properties // of [Plot] can be modified in it. Properties of [Plot] should not be modified outside // of this function, as doing so will have no effect. ConfigPlotFunc func() `json:"-" xml:"-"` // current svg file SVGFile core.Filename // current csv data file DataFile core.Filename // currently doing a plot InPlot bool `set:"-" edit:"-" json:"-" xml:"-"` }
PlotView is a Cogent Core Widget that provides an interactive 2D plot of selected columns of Tabular data, represented by an IndexView into a table.Table. Other types of tabular data can be converted into this format.
func NewPlotView ¶
NewPlotView adds a new PlotView with the given name to the given parent: PlotView is a Cogent Core Widget that provides an interactive 2D plot of selected columns of Tabular data, represented by an IndexView into a table.Table. Other types of tabular data can be converted into this format.
func NewSubPlot ¶
NewSubPlot returns a PlotView with its own separate Toolbar, suitable for a tab or other element that is not the main plot.
func (*PlotView) ColParamsTry ¶
func (pl *PlotView) ColParamsTry(colNm string) (*ColumnParams, error)
ColParamsTry returns the current column parameters by name (to access by index, just use Columns directly) Try version returns error message if not found.
func (*PlotView) ColumnParams ¶
func (pl *PlotView) ColumnParams(colNm string) *ColumnParams
ColParams returns the current column parameters by name (to access by index, just use Columns directly) returns nil if not found
func (*PlotView) ColumnsConfig ¶
func (pl *PlotView) ColumnsConfig()
ColumnsConfig configures the column gui buttons
func (*PlotView) ColumnsFromMetaMap ¶
ColumnsFromMetaMap updates all the column settings from given meta map
func (*PlotView) ColumnsLay ¶
func (*PlotView) ColumnsListUpdate ¶
func (pl *PlotView) ColumnsListUpdate()
ColumnsListUpdate updates the list of columns
func (*PlotView) ColumnsUpdate ¶
func (pl *PlotView) ColumnsUpdate()
ColumnsUpdate updates the display toggles for all the cols
func (*PlotView) ConfigPlot ¶
ConfigPlot configures the plot with params
func (*PlotView) ConfigPlotView ¶
func (pl *PlotView) ConfigPlotView()
ConfigPlotView configures the overall view widget
func (*PlotView) ConfigToolbar ¶
func (*PlotView) CopyFieldsFrom ¶
func (*PlotView) DeleteColumns ¶
func (pl *PlotView) DeleteColumns()
DeleteColumns deletes any existing cols, to ensure an update to new table
func (*PlotView) GenPlot ¶
func (pl *PlotView) GenPlot()
GenPlot generates the plot and renders it to SVG It surrounds operation with InPlot true / false to prevent multiple updates
func (*PlotView) GenPlotBar ¶
func (pl *PlotView) GenPlotBar()
GenPlotBar generates a Bar plot, setting GPlot variable
func (*PlotView) GenPlotXY ¶
func (pl *PlotView) GenPlotXY()
GenPlotXY generates an XY (lines, points) plot, setting Plot variable
func (*PlotView) GoUpdatePlot ¶
func (pl *PlotView) GoUpdatePlot()
GoUpdatePlot updates the display based on current IndexView into table. this version can be called from go routines.
func (*PlotView) NodeType ¶
NodeType returns the *types.Type of PlotView
func (*PlotView) OpenCSV ¶
OpenCSV opens the Table data from a csv (comma-separated values) file (or any delim)
func (*PlotView) OpenFS ¶
OpenFS opens the Table data from a csv (comma-separated values) file (or any delim) from the given filesystem.
func (*PlotView) PlotXAxis ¶
func (pl *PlotView) PlotXAxis(plt *plot.Plot, ixvw *table.IndexView) (xi int, xview *table.IndexView, err error)
PlotXAxis processes the XAxis and returns its index
func (*PlotView) SaveAll ¶
SaveAll saves the current plot to a png, svg, and the data to a tsv -- full save Any extension is removed and appropriate extensions are added
func (*PlotView) SaveCSV ¶
SaveCSV saves the Table data to a csv (comma-separated values) file with headers (any delim)
func (*PlotView) SaveSVG ¶
SaveSVG saves the plot to an svg -- first updates to ensure that plot is current
func (*PlotView) SetAllColumns ¶
SetAllColumns turns all Columns on or off (except X axis)
func (*PlotView) SetColParams ¶
func (pl *PlotView) SetColParams(colNm string, on bool, fixMin bool, min float32, fixMax bool, max float32) *ColumnParams
SetColParams sets main parameters for one column
func (*PlotView) SetColumnsByName ¶
SetColumnsByName turns cols On or Off if their name contains given string
func (*PlotView) SetConfigPlotFunc ¶
SetConfigPlotFunc sets the [PlotView.ConfigPlotFunc]: ConfigPlotFunc is a function to call to configure [PlotView.Plot], the plot.Plot that actually does the plotting. It is called after Plot is generated, and properties of Plot can be modified in it. Properties of Plot should not be modified outside of this function, as doing so will have no effect.
func (*PlotView) SetDataFile ¶
SetDataFile sets the [PlotView.DataFile]: current csv data file
func (*PlotView) SetParams ¶
func (t *PlotView) SetParams(v PlotParams) *PlotView
SetParams sets the [PlotView.Params]: the overall plot parameters
func (*PlotView) SetSVGFile ¶
SetSVGFile sets the [PlotView.SVGFile]: current svg file
func (*PlotView) SetTableView ¶
SetTableView sets the table to view and updates view
func (*PlotView) SetTooltip ¶
SetTooltip sets the [PlotView.Tooltip]
func (*PlotView) UpdatePlot ¶
func (pl *PlotView) UpdatePlot()
UpdatePlot updates the display based on current IndexView into table. This version can only be called within main goroutine for window eventloop -- use GoUpdateUplot for other-goroutine updates.
type TableXY ¶
type TableXY struct { // the index view of data table to plot from Table *table.IndexView // the indexes of the tensor columns to use for the X and Y data, respectively XColumn, YColumn int // numer of elements in each row of data -- 1 for scalar, > 1 for multi-dimensional XRowSz, YRowSz int // the indexes of the element within each tensor cell if cells are n-dimensional, respectively XIndex, YIndex int // the column to use for returning a label using Label interface -- for string cols LabelColumn int // the column to use for returning errorbars (+/- given value) -- if YColumn is tensor then this must also be a tensor and given YIndex used ErrColumn int // range constraints on Y values YRange minmax.Range32 }
TableXY selects two columns from a table.Table data table to plot in a gonum plot, satisfying the plot/plots.XYer and .Valuer interfaces (for bar charts). For Tensor-valued cells, Index's specify tensor cell. Also satisfies the plot/plots.Labeler interface for labels attached to a line, and plot/plots.YErrorer for error bars.
func NewTableXY ¶
func NewTableXY(dt *table.IndexView, xcol, xtsrIndex, ycol, ytsrIndex int, yrng minmax.Range32) (*TableXY, error)
NewTableXY returns a new XY plot view onto the given IndexView of table.Table (makes a copy), from given column indexes, and tensor indexes within each cell. Column indexes are enforced to be valid, with an error message if they are not.
func NewTableXYName ¶
func NewTableXYName(dt *table.IndexView, xi, xtsrIndex int, ycol string, ytsrIndex int, yrng minmax.Range32) (*TableXY, error)
NewTableXYName returns a new XY plot view onto the given IndexView of table.Table (makes a copy), from given column name and tensor indexes within each cell. Column indexes are enforced to be valid, with an error message if they are not.
func (*TableXY) FilterValues ¶
func (txy *TableXY) FilterValues()
FilterValues removes items with NaN values, and out of Y range
func (*TableXY) Label ¶
Label returns a label for given row in table, using plot/plots.Labeler interface
func (*TableXY) TRowXValue ¶
TRowXValue returns an x value at given actual row in table
func (*TableXY) Validate ¶
Validate returns error message if column indexes are invalid, else nil it also sets column indexes to 0 so nothing crashes.