introduces the Range interface (instead of a concrete type).
This commit is contained in:
parent
8af50213c3
commit
b0934ee2e3
27 changed files with 331 additions and 172 deletions
32
concat_series.go
Normal file
32
concat_series.go
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
package chart
|
||||
|
||||
// ConcatSeries is a special type of series that concatenates its `InnerSeries`.
|
||||
type ConcatSeries []Series
|
||||
|
||||
// Len returns the length of the concatenated set of series.
|
||||
func (cs ConcatSeries) Len() int {
|
||||
total := 0
|
||||
for _, s := range cs {
|
||||
if typed, isValueProvider := s.(ValueProvider); isValueProvider {
|
||||
total += typed.Len()
|
||||
}
|
||||
}
|
||||
|
||||
return total
|
||||
}
|
||||
|
||||
// GetValue returns the value at the (meta) index (i.e 0 => totalLen-1)
|
||||
func (cs ConcatSeries) GetValue(index int) (x, y float64) {
|
||||
cursor := 0
|
||||
for _, s := range cs {
|
||||
if typed, isValueProvider := s.(ValueProvider); isValueProvider {
|
||||
len := typed.Len()
|
||||
if index < cursor+len {
|
||||
x, y = typed.GetValue(index - cursor) //FENCEPOSTS.
|
||||
return
|
||||
}
|
||||
cursor += typed.Len()
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue