-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
60 lines (50 loc) · 1.37 KB
/
options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// ntcharts - Copyright (c) 2024 Neomantra Corp.
package sparkline
import (
"github.com/NimbleMarkets/ntcharts/canvas"
"github.com/charmbracelet/lipgloss"
)
// Option is used to set options when initializing a sparkline. Example:
//
// sl := New(width, height, WithMaxValue(someValue), WithNoAuto())
type Option func(*Model)
// WithStyle sets the default column style.
func WithStyle(s lipgloss.Style) Option {
return func(m *Model) {
m.Style = s
}
}
// WithKeyMap sets the canvas KeyMap used
// when processing keyboard event messages in Update().
func WithKeyMap(k canvas.KeyMap) Option {
return func(m *Model) {
m.Canvas.KeyMap = k
}
}
// WithUpdateHandler sets the canvas UpdateHandler used
// when processing bubbletea Msg events in Update().
func WithUpdateHandler(h canvas.UpdateHandler) Option {
return func(m *Model) {
m.Canvas.UpdateHandler = h
}
}
// WithNoAutoMaxValue disables automatically setting the max value
// if new data greater than the current max is added.
func WithNoAutoMaxValue() Option {
return func(m *Model) {
m.AutoMaxValue = false
}
}
// WithMaxValue sets the expected maximum data value
// to given float64.
func WithMaxValue(f float64) Option {
return func(m *Model) {
m.SetMax(f)
}
}
// WithData adds all data values in []float64 to sparkline data buffer.
func WithData(d []float64) Option {
return func(m *Model) {
m.PushAll(d)
}
}