MCPcopy Create free account
hub / github.com/cogentcore/core / genPlotBar

Method genPlotBar

plot/plotcore/barplot.go:24–202  ·  view source on GitHub ↗

bar plot is on integer positions, with different Y values and / or legend values interleaved genPlotBar generates a Bar plot, setting GPlot variable

()

Source from the content-addressed store, hash-verified

22
23// genPlotBar generates a Bar plot, setting GPlot variable
24func (pl *PlotEditor) genPlotBar() {
25 plt := plot.New() // note: not clear how to re-use, due to newtablexynames
26 if pl.Options.BarWidth > 1 {
27 pl.Options.BarWidth = .8
28 }
29
30 // process xaxis first
31 xi, xview, err := pl.plotXAxis(plt, pl.table)
32 if err != nil {
33 return
34 }
35 xp := pl.Columns[xi]
36
37 var lsplit *table.Splits
38 nleg := 1
39 if pl.Options.Legend != "" {
40 _, err = pl.table.Table.ColumnIndexTry(pl.Options.Legend)
41 if err != nil {
42 log.Println("plot.Legend: " + err.Error())
43 } else {
44 xview.SortColumnNames([]string{pl.Options.Legend, xp.Column}, table.Ascending) // make it fit!
45 lsplit = split.GroupBy(xview, pl.Options.Legend)
46 nleg = max(lsplit.Len(), 1)
47 }
48 }
49
50 var firstXY *tableXY
51 var strCols []*ColumnOptions
52 nys := 0
53 for _, cp := range pl.Columns {
54 if !cp.On {
55 continue
56 }
57 if cp.IsString {
58 strCols = append(strCols, cp)
59 continue
60 }
61 if cp.TensorIndex < 0 {
62 yc := pl.table.Table.ColumnByName(cp.Column)
63 _, sz := yc.RowCellSize()
64 nys += sz
65 } else {
66 nys++
67 }
68 }
69
70 if nys == 0 {
71 return
72 }
73
74 stride := nys * nleg
75 if stride > 1 {
76 stride += 1 // extra gap
77 }
78
79 yoff := 0
80 yidx := 0
81 maxx := 0 // max number of x values

Callers 1

genPlotMethod · 0.95

Calls 15

plotXAxisMethod · 0.95
LenMethod · 0.95
ValueMethod · 0.95
configPlotMethod · 0.95
NewFunction · 0.92
GroupByFunction · 0.92
UniformFunction · 0.92
SpacedFunction · 0.92
NewBarChartFunction · 0.92
Vec2Function · 0.92
NewLabelsFunction · 0.92
newTableXYNameFunction · 0.85

Tested by

no test coverage detected