Skip to content

Commit

Permalink
plot: add some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
gucio321 committed Sep 19, 2021
1 parent 16e485e commit 0058b8c
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions Plot.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ func (p *PlotCanvasWidget) Build() {
}
}

// PlotBarWidget adds bar plot (column chart) to the canvas
type PlotBarWidget struct {
title string
data []float64
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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
Expand Down

0 comments on commit 0058b8c

Please sign in to comment.