forked from wcharczuk/go-chart
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Will Charczuk
committed
Sep 7, 2018
1 parent
1144b80
commit 1555902
Showing
13 changed files
with
207 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package chart | ||
|
||
import "fmt" | ||
|
||
// FirstValueAnnotation returns an annotation series of just the first value of a value provider as an annotation. | ||
func FirstValueAnnotation(innerSeries ValuesProvider, vfs ...ValueFormatter) AnnotationSeries { | ||
var vf ValueFormatter | ||
if len(vfs) > 0 { | ||
vf = vfs[0] | ||
} else if typed, isTyped := innerSeries.(ValueFormatterProvider); isTyped { | ||
_, vf = typed.GetValueFormatters() | ||
} else { | ||
vf = FloatValueFormatter | ||
} | ||
|
||
var firstValue Value2 | ||
if typed, isTyped := innerSeries.(FirstValuesProvider); isTyped { | ||
firstValue.XValue, firstValue.YValue = typed.GetFirstValues() | ||
firstValue.Label = vf(firstValue.YValue) | ||
} else { | ||
firstValue.XValue, firstValue.YValue = innerSeries.GetValues(0) | ||
firstValue.Label = vf(firstValue.YValue) | ||
} | ||
|
||
var seriesName string | ||
var seriesStyle Style | ||
if typed, isTyped := innerSeries.(Series); isTyped { | ||
seriesName = fmt.Sprintf("%s - First Value", typed.GetName()) | ||
seriesStyle = typed.GetStyle() | ||
} | ||
|
||
return AnnotationSeries{ | ||
Name: seriesName, | ||
Style: seriesStyle, | ||
Annotations: []Value2{firstValue}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package chart | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/blend/go-sdk/assert" | ||
) | ||
|
||
func TestFirstValueAnnotation(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
series := ContinuousSeries{ | ||
XValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0}, | ||
YValues: []float64{5.0, 3.0, 3.0, 2.0, 1.0}, | ||
} | ||
|
||
fva := FirstValueAnnotation(series) | ||
assert.NotEmpty(fva.Annotations) | ||
fvaa := fva.Annotations[0] | ||
assert.Equal(1, fvaa.XValue) | ||
assert.Equal(5, fvaa.YValue) | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package chart | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/blend/go-sdk/assert" | ||
) | ||
|
||
func TestLastValueAnnotation(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
series := ContinuousSeries{ | ||
XValues: []float64{1.0, 2.0, 3.0, 4.0, 5.0}, | ||
YValues: []float64{5.0, 3.0, 3.0, 2.0, 1.0}, | ||
} | ||
|
||
lva := LastValueAnnotation(series) | ||
assert.NotEmpty(lva.Annotations) | ||
lvaa := lva.Annotations[0] | ||
assert.Equal(5, lvaa.XValue) | ||
assert.Equal(1, lvaa.YValue) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters