From 0058b8cb7a05749f1ba2a1ffae38893cd1bcf318 Mon Sep 17 00:00:00 2001 From: gucio321 Date: Sun, 19 Sep 2021 11:47:51 +0200 Subject: [PATCH] plot: add some comments --- Plot.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Plot.go b/Plot.go index 5b78a3ae..ea492759 100644 --- a/Plot.go +++ b/Plot.go @@ -184,6 +184,7 @@ func (p *PlotCanvasWidget) Build() { } } +// PlotBarWidget adds bar plot (column chart) to the canvas type PlotBarWidget struct { title string data []float64 @@ -192,6 +193,7 @@ type PlotBarWidget struct { offset int } +// PlotBar adds a plot bar (column chart) func PlotBar(title string, data []float64) *PlotBarWidget { return &PlotBarWidget{ title: title, @@ -202,25 +204,30 @@ func PlotBar(title string, data []float64) *PlotBarWidget { } } +// Width sets bar width func (p *PlotBarWidget) Width(width float64) *PlotBarWidget { p.width = width return p } +// Shift sets shift of the bar func (p *PlotBarWidget) Shift(shift float64) *PlotBarWidget { p.shift = shift return p } +// Offset sets bar's offset func (p *PlotBarWidget) Offset(offset int) *PlotBarWidget { p.offset = offset return p } +// Plot implements Plot interface func (p *PlotBarWidget) Plot() { imgui.ImPlotBars(p.title, p.data, p.width, p.shift, p.offset) } +// PlotBarHWidget represents a column chart on Y axis type PlotBarHWidget struct { title string data []float64 @@ -229,6 +236,7 @@ type PlotBarHWidget struct { offset int } +// PlotBarH adds plot bars on y axis func PlotBarH(title string, data []float64) *PlotBarHWidget { return &PlotBarHWidget{ title: title, @@ -239,25 +247,30 @@ func PlotBarH(title string, data []float64) *PlotBarHWidget { } } +// Height sets bar height (in fact bars' width) func (p *PlotBarHWidget) Height(height float64) *PlotBarHWidget { p.height = height return p } +// Shift sets shift func (p *PlotBarHWidget) Shift(shift float64) *PlotBarHWidget { p.shift = shift return p } +// Offset sets offset func (p *PlotBarHWidget) Offset(offset int) *PlotBarHWidget { p.offset = offset return p } +// Plot implements plot interface func (p *PlotBarHWidget) Plot() { imgui.ImPlotBarsH(tStr(p.title), p.data, p.height, p.shift, p.offset) } +// PlotLineWidget represents a plot line (linear chart) type PlotLineWidget struct { title string values []float64 @@ -266,6 +279,7 @@ type PlotLineWidget struct { yAxis ImPlotYAxis } +// PlotLine adds a new plot line to the canvas func PlotLine(title string, values []float64) *PlotLineWidget { return &PlotLineWidget{ title: title, @@ -276,37 +290,44 @@ func PlotLine(title string, values []float64) *PlotLineWidget { } } +// SetPlotYAxis sets yAxis parameters func (p *PlotLineWidget) SetPlotYAxis(yAxis ImPlotYAxis) *PlotLineWidget { p.yAxis = yAxis return p } +// XScale sets x-axis-scale func (p *PlotLineWidget) XScale(scale float64) *PlotLineWidget { p.xScale = scale return p } +// X0 sets a start position on x axis func (p *PlotLineWidget) X0(x0 float64) *PlotLineWidget { p.x0 = x0 return p } +// Offset sets chart offset func (p *PlotLineWidget) Offset(offset int) *PlotLineWidget { p.offset = offset return p } +// Plot implements Plot interface func (p *PlotLineWidget) Plot() { imgui.ImPlotSetPlotYAxis(imgui.ImPlotYAxis(p.yAxis)) imgui.ImPlotLine(tStr(p.title), p.values, p.xScale, p.x0, p.offset) } +// PlotLineXYWidget adds XY plot line type PlotLineXYWidget struct { title string xs, ys []float64 offset int } +// PlotLineXY adds XY plot line to canvas func PlotLineXY(title string, xvalues, yvalues []float64) *PlotLineXYWidget { return &PlotLineXYWidget{ title: title, @@ -316,15 +337,18 @@ func PlotLineXY(title string, xvalues, yvalues []float64) *PlotLineXYWidget { } } +// Offset sets chart's offset func (p *PlotLineXYWidget) Offset(offset int) *PlotLineXYWidget { p.offset = offset return p } +// Plot implements Plot interface func (p *PlotLineXYWidget) Plot() { imgui.ImPlotLineXY(tStr(p.title), p.xs, p.ys, p.offset) } +// PlotPieChartWidget represents a pie chart type PlotPieChartWidget struct { labels []string values []float64 @@ -334,6 +358,7 @@ type PlotPieChartWidget struct { angle0 float64 } +// PlotPieChart adds pie chart to the canvas func PlotPieChart(labels []string, values []float64, x, y, radius float64) *PlotPieChartWidget { return &PlotPieChartWidget{ labels: labels, @@ -352,6 +377,7 @@ func (p *PlotPieChartWidget) Normalize(n bool) *PlotPieChartWidget { return p } +// LabelFormat sets format of labels func (p *PlotPieChartWidget) LabelFormat(fmtStr string) *PlotPieChartWidget { p.labelFormat = fmtStr return p