Add adds data points to the SparkLine. Each data point is represented by one bar on the SparkLine. Zero value data points are valid and are represented by an empty space on the SparkLine (i.e. a missing bar). At least one data point must be provided. All data points must be positive integers. The
(data []int, opts ...Option)
| 223 | // |
| 224 | // Provided options override values set when New() was called. |
| 225 | func (sl *SparkLine) Add(data []int, opts ...Option) error { |
| 226 | sl.mu.Lock() |
| 227 | defer sl.mu.Unlock() |
| 228 | |
| 229 | for _, opt := range opts { |
| 230 | opt.set(sl.opts) |
| 231 | } |
| 232 | |
| 233 | for i, d := range data { |
| 234 | if d < 0 { |
| 235 | return fmt.Errorf("data point[%d]: %v must be a positive integer", i, d) |
| 236 | } |
| 237 | } |
| 238 | sl.data = append(sl.data, data...) |
| 239 | return nil |
| 240 | } |
| 241 | |
| 242 | // Clear removes all the data points in the SparkLine, effectively returning to |
| 243 | // an empty graph. |