diff --git a/bar_chart.go b/bar_chart.go index 0ac9f47..26f8da5 100644 --- a/bar_chart.go +++ b/bar_chart.go @@ -32,6 +32,7 @@ type barChart struct { opt *BarChartOption } +// NewBarChart returns a bar chart renderer func NewBarChart(p *Painter, opt BarChartOption) *barChart { if opt.Theme == nil { opt.Theme = defaultTheme @@ -43,6 +44,7 @@ func NewBarChart(p *Painter, opt BarChartOption) *barChart { } type BarChartOption struct { + // The theme Theme ColorPalette // The font size Font *truetype.Font @@ -155,7 +157,7 @@ func (b *barChart) render(result *defaultRenderResult, seriesList SeriesList) (B if distance == 0 { distance = 5 } - text := NewValueLabelFormater(seriesNames, series.Label.Formatter)(index, item.Value, -1) + text := NewValueLabelFormatter(seriesNames, series.Label.Formatter)(index, item.Value, -1) labelStyle := Style{ FontColor: theme.GetTextColor(), FontSize: labelFontSize, diff --git a/charts.go b/charts.go index a2e0ec0..6c1c92b 100644 --- a/charts.go +++ b/charts.go @@ -35,11 +35,14 @@ const defaultStrokeWidth = 2.0 var defaultChartWidth = 600 var defaultChartHeight = 400 +// SetDefaultWidth sets default width of chart func SetDefaultWidth(width int) { if width > 0 { defaultChartWidth = width } } + +// SetDefaultHeight sets default height of chart func SetDefaultHeight(height int) { if height > 0 { defaultChartHeight = height diff --git a/funnel_chart.go b/funnel_chart.go index 7c04bfe..719853a 100644 --- a/funnel_chart.go +++ b/funnel_chart.go @@ -34,6 +34,7 @@ type funnelChart struct { opt *FunnelChartOption } +// NewFunnelSeriesList returns a series list for funnel func NewFunnelSeriesList(values []float64) SeriesList { seriesList := make(SeriesList, len(values)) for index, value := range values { @@ -44,6 +45,7 @@ func NewFunnelSeriesList(values []float64) SeriesList { return seriesList } +// NewFunnelChart returns a funnel chart renderer func NewFunnelChart(p *Painter, opt FunnelChartOption) *funnelChart { if opt.Theme == nil { opt.Theme = defaultTheme @@ -55,6 +57,7 @@ func NewFunnelChart(p *Painter, opt FunnelChartOption) *funnelChart { } type FunnelChartOption struct { + // The theme Theme ColorPalette // The font size Font *truetype.Font diff --git a/grid.go b/grid.go index 252fe2e..fb5dad6 100644 --- a/grid.go +++ b/grid.go @@ -28,16 +28,25 @@ type gridPainter struct { } type GridPainterOption struct { - StrokeWidth float64 - StrokeColor Color - Column int - Row int - IgnoreFirstRow bool - IgnoreLastRow bool + // The stroke width + StrokeWidth float64 + // The stroke color + StrokeColor Color + // The column of grid + Column int + // The row of grid + Row int + // Ignore first row + IgnoreFirstRow bool + // Ignore last row + IgnoreLastRow bool + // Ignore first column IgnoreFirstColumn bool - IgnoreLastColumn bool + // Ignore last column + IgnoreLastColumn bool } +// NewGridPainter returns new a grid renderer func NewGridPainter(p *Painter, opt GridPainterOption) *gridPainter { return &gridPainter{ p: p, diff --git a/horizontal_bar_chart.go b/horizontal_bar_chart.go index fb23734..30a9b7d 100644 --- a/horizontal_bar_chart.go +++ b/horizontal_bar_chart.go @@ -33,6 +33,7 @@ type horizontalBarChart struct { } type HorizontalBarChartOption struct { + // The theme Theme ColorPalette // The font size Font *truetype.Font @@ -50,6 +51,7 @@ type HorizontalBarChartOption struct { Legend LegendOption } +// NewHorizontalBarChart returns a horizontal bar chart renderer func NewHorizontalBarChart(p *Painter, opt HorizontalBarChartOption) *horizontalBarChart { if opt.Theme == nil { opt.Theme = defaultTheme diff --git a/legend.go b/legend.go index 65db102..2acd35b 100644 --- a/legend.go +++ b/legend.go @@ -36,6 +36,7 @@ const IconRect = "rect" const IconLineDot = "lineDot" type LegendOption struct { + // The theme Theme ColorPalette // Text array of legend Data []string @@ -60,6 +61,7 @@ type LegendOption struct { Show *bool } +// NewLegendOption returns a legend option func NewLegendOption(labels []string, left ...string) LegendOption { opt := LegendOption{ Data: labels, @@ -70,6 +72,7 @@ func NewLegendOption(labels []string, left ...string) LegendOption { return opt } +// IsEmpty checks legend is empty func (opt *LegendOption) IsEmpty() bool { isEmpty := true for _, v := range opt.Data { @@ -81,6 +84,7 @@ func (opt *LegendOption) IsEmpty() bool { return isEmpty } +// NewLegendPainter returns a legend renderer func NewLegendPainter(p *Painter, opt LegendOption) *legendPainter { return &legendPainter{ p: p, diff --git a/line_chart.go b/line_chart.go index f171813..0770447 100644 --- a/line_chart.go +++ b/line_chart.go @@ -32,6 +32,7 @@ type lineChart struct { opt *LineChartOption } +// NewLineChart returns a line chart render func NewLineChart(p *Painter, opt LineChartOption) *lineChart { if opt.Theme == nil { opt.Theme = defaultTheme @@ -43,6 +44,7 @@ func NewLineChart(p *Painter, opt LineChartOption) *lineChart { } type LineChartOption struct { + // The theme Theme ColorPalette // The font size Font *truetype.Font diff --git a/mark_line.go b/mark_line.go index a0efcfb..af1062d 100644 --- a/mark_line.go +++ b/mark_line.go @@ -27,6 +27,7 @@ import ( "github.com/wcharczuk/go-chart/v2" ) +// NewMarkLine returns a series mark line func NewMarkLine(markLineTypes ...string) SeriesMarkLine { data := make([]SeriesMarkData, len(markLineTypes)) for index, t := range markLineTypes { @@ -48,6 +49,7 @@ func (m *markLinePainter) Add(opt markLineRenderOption) { m.options = append(m.options, opt) } +// NewMarkLinePainter returns a mark line renderer func NewMarkLinePainter(p *Painter) *markLinePainter { return &markLinePainter{ p: p, diff --git a/mark_point.go b/mark_point.go index 014b17f..f6c93f3 100644 --- a/mark_point.go +++ b/mark_point.go @@ -27,6 +27,7 @@ import ( "github.com/wcharczuk/go-chart/v2/drawing" ) +// NewMarkPoint returns a series mark point func NewMarkPoint(markPointTypes ...string) SeriesMarkPoint { data := make([]SeriesMarkData, len(markPointTypes)) for index, t := range markPointTypes { @@ -55,6 +56,7 @@ type markPointRenderOption struct { Points []Point } +// NewMarkPointPainter returns a mark point renderer func NewMarkPointPainter(p *Painter) *markPointPainter { return &markPointPainter{ p: p, diff --git a/painter.go b/painter.go index da07007..c250369 100644 --- a/painter.go +++ b/painter.go @@ -136,7 +136,7 @@ func PainterWidthHeightOption(width, height int) PainterOption { } } -// NewPainter creates a new painter +// NewPainter creates a painter func NewPainter(opts PainterOptions, opt ...PainterOption) (*Painter, error) { if opts.Width <= 0 || opts.Height <= 0 { return nil, errors.New("width/height can not be nil") diff --git a/pie_chart.go b/pie_chart.go index 972b4c1..6382140 100644 --- a/pie_chart.go +++ b/pie_chart.go @@ -36,6 +36,7 @@ type pieChart struct { } type PieChartOption struct { + // The theme Theme ColorPalette // The font size Font *truetype.Font @@ -51,6 +52,7 @@ type PieChartOption struct { backgroundIsFilled bool } +// NewPieChart returns a pie chart renderer func NewPieChart(p *Painter, opt PieChartOption) *pieChart { if opt.Theme == nil { opt.Theme = defaultTheme diff --git a/radar_chart.go b/radar_chart.go index 5b8aa85..eab70d5 100644 --- a/radar_chart.go +++ b/radar_chart.go @@ -45,6 +45,7 @@ type RadarIndicator struct { } type RadarChartOption struct { + // The theme Theme ColorPalette // The font size Font *truetype.Font @@ -62,6 +63,7 @@ type RadarChartOption struct { backgroundIsFilled bool } +// NewRadarIndicators returns a radar indicator list func NewRadarIndicators(names []string, values []float64) []RadarIndicator { if len(names) != len(values) { return nil @@ -76,6 +78,7 @@ func NewRadarIndicators(names []string, values []float64) []RadarIndicator { return indicators } +// NewRadarChart returns a radar chart renderer func NewRadarChart(p *Painter, opt RadarChartOption) *radarChart { if opt.Theme == nil { opt.Theme = defaultTheme diff --git a/range.go b/range.go index d5a9ef7..579a77f 100644 --- a/range.go +++ b/range.go @@ -37,13 +37,19 @@ type axisRange struct { } type AxisRangeOption struct { - Min float64 - Max float64 - Size int - Boundary bool + // The min value of axis + Min float64 + // The max value of axis + Max float64 + // The size of axis + Size int + // Boundary gap + Boundary bool + // The count of divide DivideCount int } +// NewRange returns a axis range func NewRange(opt AxisRangeOption) axisRange { max := opt.Max min := opt.Min @@ -88,6 +94,7 @@ func NewRange(opt AxisRangeOption) axisRange { } } +// Values returns values of range func (r axisRange) Values() []string { offset := (r.max - r.min) / float64(r.divideCount) values := make([]string, 0) @@ -108,10 +115,13 @@ func (r *axisRange) getRestHeight(value float64) int { return r.size - r.getHeight(value) } +// GetRange returns a range of index func (r *axisRange) GetRange(index int) (float64, float64) { unit := float64(r.size) / float64(r.divideCount) return unit * float64(index), unit * float64(index+1) } + +// AutoDivide divides the axis func (r *axisRange) AutoDivide() []int { return autoDivide(r.size, r.divideCount) } diff --git a/series.go b/series.go index 44c4749..87a719f 100644 --- a/series.go +++ b/series.go @@ -36,6 +36,7 @@ type SeriesData struct { Style Style } +// NewSeriesListDataFromValues returns a series list func NewSeriesListDataFromValues(values [][]float64, chartType ...string) SeriesList { seriesList := make(SeriesList, len(values)) for index, value := range values { @@ -44,6 +45,7 @@ func NewSeriesListDataFromValues(values [][]float64, chartType ...string) Series return seriesList } +// NewSeriesFromValues returns a series func NewSeriesFromValues(values []float64, chartType ...string) Series { s := Series{ Data: NewSeriesDataFromValues(values), @@ -54,6 +56,7 @@ func NewSeriesFromValues(values []float64, chartType ...string) Series { return s } +// NewSeriesDataFromValues return a series data func NewSeriesDataFromValues(values []float64) []SeriesData { data := make([]SeriesData, len(values)) for index, value := range values { @@ -204,13 +207,19 @@ func NewPieSeriesList(values []float64, opts ...PieSeriesOption) SeriesList { } type seriesSummary struct { - MaxIndex int - MaxValue float64 - MinIndex int - MinValue float64 + // The index of max value + MaxIndex int + // The max value + MaxValue float64 + // The index of min value + MinIndex int + // The min value + MinValue float64 + // THe average value AverageValue float64 } +// Summary get summary of series func (s *Series) Summary() seriesSummary { minIndex := -1 maxIndex := -1 @@ -237,6 +246,7 @@ func (s *Series) Summary() seriesSummary { } } +// Names returns the names of series list func (sl SeriesList) Names() []string { names := make([]string, len(sl)) for index, s := range sl { @@ -245,8 +255,10 @@ func (sl SeriesList) Names() []string { return names } +// LabelFormatter label formatter type LabelFormatter func(index int, value float64, percent float64) string +// NewPieLabelFormatter returns a pie label formatter func NewPieLabelFormatter(seriesNames []string, layout string) LabelFormatter { if len(layout) == 0 { layout = "{b}: {d}" @@ -254,13 +266,15 @@ func NewPieLabelFormatter(seriesNames []string, layout string) LabelFormatter { return NewLabelFormatter(seriesNames, layout) } -func NewValueLabelFormater(seriesNames []string, layout string) LabelFormatter { +// NewValueLabelFormatter returns a value formatter +func NewValueLabelFormatter(seriesNames []string, layout string) LabelFormatter { if len(layout) == 0 { layout = "{c}" } return NewLabelFormatter(seriesNames, layout) } +// NewLabelFormatter returns a label formaatter func NewLabelFormatter(seriesNames []string, layout string) LabelFormatter { return func(index int, value, percent float64) string { // 如果无percent的则设置为<0 diff --git a/theme.go b/theme.go index 26786b9..31c3bf8 100644 --- a/theme.go +++ b/theme.go @@ -220,6 +220,7 @@ func init() { SetDefaultTheme(ThemeLight) } +// SetDefaultTheme sets default theme func SetDefaultTheme(name string) { defaultTheme = NewTheme(name) } diff --git a/title.go b/title.go index a805c55..5af4c39 100644 --- a/title.go +++ b/title.go @@ -84,6 +84,7 @@ type titlePainter struct { opt *TitleOption } +// NewTitlePainter returns a title renderer func NewTitlePainter(p *Painter, opt TitleOption) *titlePainter { return &titlePainter{ p: p, diff --git a/xaxis.go b/xaxis.go index bfb57cb..00636a5 100644 --- a/xaxis.go +++ b/xaxis.go @@ -53,6 +53,7 @@ type XAxisOption struct { const defaultXAxisHeight = 30 +// NewXAxisOption returns a x axis option func NewXAxisOption(data []string, boundaryGap ...*bool) XAxisOption { opt := XAxisOption{ Data: data, @@ -89,6 +90,7 @@ func (opt *XAxisOption) ToAxisOption() AxisOption { return axisOpt } +// NewBottomXAxis returns a bottom x axis renderer func NewBottomXAxis(p *Painter, opt XAxisOption) *axisPainter { return NewAxisPainter(p, opt.ToAxisOption()) } diff --git a/yaxis.go b/yaxis.go index 265ac59..b0bfa86 100644 --- a/yaxis.go +++ b/yaxis.go @@ -50,6 +50,7 @@ type YAxisOption struct { isCategoryAxis bool } +// NewYAxisOptions returns a y axis option func NewYAxisOptions(data []string, others ...[]string) []YAxisOption { arr := [][]string{ data, @@ -95,6 +96,7 @@ func (opt *YAxisOption) ToAxisOption() AxisOption { return axisOpt } +// NewLeftYAxis returns a left y axis renderer func NewLeftYAxis(p *Painter, opt YAxisOption) *axisPainter { p = p.Child(PainterPaddingOption(Box{ Bottom: defaultXAxisHeight, @@ -102,6 +104,7 @@ func NewLeftYAxis(p *Painter, opt YAxisOption) *axisPainter { return NewAxisPainter(p, opt.ToAxisOption()) } +// NewRightYAxis returns a right y axis renderer func NewRightYAxis(p *Painter, opt YAxisOption) *axisPainter { p = p.Child(PainterPaddingOption(Box{ Bottom: defaultXAxisHeight,