Skip to content

Commit 532f37e

Browse files
committed
Bring back NewPainter and Child functionality
The multiple chart examples show this API may still be useful. For that reason I don't think we should remove it yet.
1 parent f27272c commit 532f37e

25 files changed

+78
-98
lines changed

axis.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func (a *axisPainter) Render() (Box, error) {
138138
padding.Top = top.Height() - defaultXAxisHeight
139139
}
140140

141-
p := top.child(PainterPaddingOption(padding))
141+
p := top.Child(painterPaddingOption(padding))
142142

143143
x0 := 0
144144
y0 := 0
@@ -228,7 +228,7 @@ func (a *axisPainter) Render() (Box, error) {
228228
}
229229

230230
if strokeWidth > 0 {
231-
p.child(PainterPaddingOption(Box{
231+
p.Child(painterPaddingOption(Box{
232232
Top: ticksPaddingTop,
233233
Left: ticksPaddingLeft,
234234
IsSet: true,
@@ -246,7 +246,7 @@ func (a *axisPainter) Render() (Box, error) {
246246
})
247247
}
248248

249-
p.child(PainterPaddingOption(Box{
249+
p.Child(painterPaddingOption(Box{
250250
Left: labelPaddingLeft,
251251
Top: labelPaddingTop,
252252
Right: labelPaddingRight,

axis_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func TestAxis(t *testing.T) {
170170
})
171171
for i, tt := range tests {
172172
t.Run(strconv.Itoa(i)+"-"+tt.name, func(t *testing.T) {
173-
p, err := newPainter(PainterOptions{
173+
p, err := NewPainter(PainterOptions{
174174
OutputFormat: ChartOutputSVG,
175175
Width: 600,
176176
Height: 400,

bar_chart_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,20 +117,20 @@ func TestBarChart(t *testing.T) {
117117
}
118118
if tt.defaultTheme {
119119
t.Run(strconv.Itoa(i)+"-"+tt.name, func(t *testing.T) {
120-
p, err := newPainter(painterOptions)
120+
p, err := NewPainter(painterOptions)
121121
require.NoError(t, err)
122122

123123
validateBarChartRender(t, p, tt.makeOptions(), tt.result)
124124
})
125125
} else {
126126
t.Run(strconv.Itoa(i)+"-"+tt.name+"-painter", func(t *testing.T) {
127-
p, err := newPainter(painterOptions, PainterThemeOption(GetTheme(ThemeVividDark)))
127+
p, err := NewPainter(painterOptions, PainterThemeOption(GetTheme(ThemeVividDark)))
128128
require.NoError(t, err)
129129

130130
validateBarChartRender(t, p, tt.makeOptions(), tt.result)
131131
})
132132
t.Run(strconv.Itoa(i)+"-"+tt.name+"-options", func(t *testing.T) {
133-
p, err := newPainter(painterOptions)
133+
p, err := NewPainter(painterOptions)
134134
require.NoError(t, err)
135135
opt := tt.makeOptions()
136136
opt.Theme = GetTheme(ThemeVividDark)

chart_option.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ type ChartOption struct {
4747
BarWidth int
4848
// BarHeight is the height of the bars for horizontal bar charts.
4949
BarHeight int
50-
// Children are child charts to render together.
50+
// Children are Child charts to render together.
5151
Children []ChartOption
5252
parent *Painter
5353
// ValueFormatter to format numeric values into labels.
@@ -187,7 +187,7 @@ func PieSeriesShowLabel() OptionFunc {
187187
}
188188

189189
// TODO - add testing and examples
190-
// ChildOptionFunc add child chart
190+
// ChildOptionFunc add Child chart
191191
func ChildOptionFunc(child ...ChartOption) OptionFunc {
192192
return func(opt *ChartOption) {
193193
if opt.Children == nil {
@@ -379,7 +379,7 @@ func TableOptionRender(opt TableChartOption) (*Painter, error) {
379379
opt.Width = defaultChartWidth
380380
}
381381

382-
p, err := newPainter(PainterOptions{
382+
p, err := NewPainter(PainterOptions{
383383
OutputFormat: opt.OutputFormat,
384384
Width: opt.Width,
385385
Height: 100, // is only used to calculate the height of the table
@@ -393,7 +393,7 @@ func TableOptionRender(opt TableChartOption) (*Painter, error) {
393393
return nil, err
394394
}
395395

396-
p, err = newPainter(PainterOptions{
396+
p, err = NewPainter(PainterOptions{
397397
OutputFormat: opt.OutputFormat,
398398
Width: info.width,
399399
Height: info.height,

chart_option_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ func TestChildRender(t *testing.T) {
422422
{150, 232, 201, 154, 190, 330, 410},
423423
{320, 332, 301, 334, 390, 330, 320},
424424
},
425-
SVGOutputOption(),
425+
SVGOutputOptionFunc(),
426426
XAxisDataOptionFunc([]string{
427427
"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun",
428428
}),

charts.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func defaultRender(p *Painter, opt defaultRenderOption) (*defaultRenderResult, e
104104
}
105105

106106
if !opt.Padding.IsZero() {
107-
p = p.child(PainterPaddingOption(opt.Padding))
107+
p = p.Child(painterPaddingOption(opt.Padding))
108108
}
109109

110110
const legendTitlePadding = 15
@@ -120,7 +120,7 @@ func defaultRender(p *Painter, opt defaultRenderOption) (*defaultRenderResult, e
120120
legendTopSpacing = legendHeight + legendTitlePadding
121121
} else {
122122
// horizontal legend at the bottom, raise the chart above it
123-
p = p.child(PainterPaddingOption(Box{
123+
p = p.Child(painterPaddingOption(Box{
124124
Bottom: legendHeight + legendTitlePadding,
125125
IsSet: true,
126126
}))
@@ -141,13 +141,13 @@ func defaultRender(p *Painter, opt defaultRenderOption) (*defaultRenderResult, e
141141
top = legendTopSpacing // the legend may still need space on the top, set to whatever the legend requested
142142
}
143143

144-
p = p.child(PainterPaddingOption(Box{
144+
p = p.Child(painterPaddingOption(Box{
145145
Top: top,
146146
Bottom: bottom,
147147
IsSet: true,
148148
}))
149149
} else if legendTopSpacing > 0 { // apply chart spacing below legend
150-
p = p.child(PainterPaddingOption(Box{
150+
p = p.Child(painterPaddingOption(Box{
151151
Top: legendTopSpacing,
152152
IsSet: true,
153153
}))
@@ -252,7 +252,7 @@ func defaultRender(p *Painter, opt defaultRenderOption) (*defaultRenderResult, e
252252
opt.XAxis.isValueAxis = true
253253
}
254254
reverseStringSlice(yAxisOption.Data)
255-
child := p.child(PainterPaddingOption(Box{
255+
child := p.Child(painterPaddingOption(Box{
256256
Left: rangeWidthLeft,
257257
Right: rangeWidthRight,
258258
IsSet: true,
@@ -272,7 +272,7 @@ func defaultRender(p *Painter, opt defaultRenderOption) (*defaultRenderResult, e
272272
}
273273
}
274274

275-
xAxis := newBottomXAxis(p.child(PainterPaddingOption(Box{
275+
xAxis := newBottomXAxis(p.Child(painterPaddingOption(Box{
276276
Left: rangeWidthLeft,
277277
Right: rangeWidthRight,
278278
IsSet: true,
@@ -281,7 +281,7 @@ func defaultRender(p *Painter, opt defaultRenderOption) (*defaultRenderResult, e
281281
return nil, err
282282
}
283283

284-
result.seriesPainter = p.child(PainterPaddingOption(Box{
284+
result.seriesPainter = p.Child(painterPaddingOption(Box{
285285
Left: rangeWidthLeft,
286286
Right: rangeWidthRight,
287287
Bottom: defaultXAxisHeight,
@@ -309,7 +309,7 @@ func Render(opt ChartOption, opts ...OptionFunc) (*Painter, error) {
309309

310310
isChild := opt.parent != nil
311311
if !isChild {
312-
p, err := newPainter(PainterOptions{
312+
p, err := NewPainter(PainterOptions{
313313
OutputFormat: opt.OutputFormat,
314314
Width: opt.Width,
315315
Height: opt.Height,
@@ -325,7 +325,7 @@ func Render(opt ChartOption, opts ...OptionFunc) (*Painter, error) {
325325
p.valueFormatter = opt.ValueFormatter
326326
}
327327
if !opt.Box.IsZero() {
328-
p = p.child(PainterBoxOption(opt.Box))
328+
p = p.Child(PainterBoxOption(opt.Box))
329329
}
330330
if !isChild {
331331
p.SetBackground(p.Width(), p.Height(), opt.Theme.GetBackgroundColor())

font_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func TestGetPreferredFont(t *testing.T) {
3131
func TestCustomFontSizeRender(t *testing.T) {
3232
t.Parallel()
3333

34-
p, err := newPainter(PainterOptions{
34+
p, err := NewPainter(PainterOptions{
3535
OutputFormat: ChartOutputSVG,
3636
Width: 600,
3737
Height: 400,

funnel_chart_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,20 @@ func TestFunnelChart(t *testing.T) {
6262
}
6363
if tt.defaultTheme {
6464
t.Run(strconv.Itoa(i)+"-"+tt.name, func(t *testing.T) {
65-
p, err := newPainter(painterOptions)
65+
p, err := NewPainter(painterOptions)
6666
require.NoError(t, err)
6767

6868
validateFunnelChartRender(t, p, tt.makeOptions(), tt.result)
6969
})
7070
} else {
7171
t.Run(strconv.Itoa(i)+"-"+tt.name+"-painter", func(t *testing.T) {
72-
p, err := newPainter(painterOptions, PainterThemeOption(GetTheme(ThemeVividDark)))
72+
p, err := NewPainter(painterOptions, PainterThemeOption(GetTheme(ThemeVividDark)))
7373
require.NoError(t, err)
7474

7575
validateFunnelChartRender(t, p, tt.makeOptions(), tt.result)
7676
})
7777
t.Run(strconv.Itoa(i)+"-"+tt.name+"-options", func(t *testing.T) {
78-
p, err := newPainter(painterOptions)
78+
p, err := NewPainter(painterOptions)
7979
require.NoError(t, err)
8080
opt := tt.makeOptions()
8181
opt.Theme = GetTheme(ThemeVividDark)

horizontal_bar_chart_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,20 +119,20 @@ func TestHorizontalBarChart(t *testing.T) {
119119
}
120120
if tt.defaultTheme {
121121
t.Run(strconv.Itoa(i)+"-"+tt.name, func(t *testing.T) {
122-
p, err := newPainter(painterOptions)
122+
p, err := NewPainter(painterOptions)
123123
require.NoError(t, err)
124124

125125
validateHorizontalBarChartRender(t, p, tt.makeOptions(), tt.result)
126126
})
127127
} else {
128128
t.Run(strconv.Itoa(i)+"-"+tt.name+"-painter", func(t *testing.T) {
129-
p, err := newPainter(painterOptions, PainterThemeOption(GetTheme(ThemeVividDark)))
129+
p, err := NewPainter(painterOptions, PainterThemeOption(GetTheme(ThemeVividDark)))
130130
require.NoError(t, err)
131131

132132
validateHorizontalBarChartRender(t, p, tt.makeOptions(), tt.result)
133133
})
134134
t.Run(strconv.Itoa(i)+"-"+tt.name+"-options", func(t *testing.T) {
135-
p, err := newPainter(painterOptions)
135+
p, err := NewPainter(painterOptions)
136136
require.NoError(t, err)
137137
opt := tt.makeOptions()
138138
opt.Theme = GetTheme(ThemeVividDark)

legend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func (l *legendPainter) Render() (Box, error) {
9090
if padding.IsZero() {
9191
padding.Top = 5
9292
}
93-
p := l.p.child(PainterPaddingOption(padding))
93+
p := l.p.Child(painterPaddingOption(padding))
9494
p.SetFontStyle(fontStyle)
9595

9696
// calculate the width and height of the display

0 commit comments

Comments
 (0)