feat: support radius for pie chart
This commit is contained in:
parent
e07cb90607
commit
524eb79a8e
12 changed files with 376 additions and 66 deletions
13
range.go
13
range.go
|
|
@ -24,6 +24,8 @@ package charts
|
|||
|
||||
import (
|
||||
"math"
|
||||
|
||||
"github.com/dustin/go-humanize"
|
||||
)
|
||||
|
||||
type Range struct {
|
||||
|
|
@ -62,6 +64,17 @@ func NewRange(min, max float64, divideCount int) Range {
|
|||
}
|
||||
}
|
||||
|
||||
func (r Range) Values() []string {
|
||||
offset := (r.Max - r.Min) / float64(r.divideCount)
|
||||
values := make([]string, 0)
|
||||
for i := 0; i <= r.divideCount; i++ {
|
||||
v := r.Min + float64(i)*offset
|
||||
value := humanize.CommafWithDigits(v, 2)
|
||||
values = append(values, value)
|
||||
}
|
||||
return values
|
||||
}
|
||||
|
||||
func (r *Range) getHeight(value float64) int {
|
||||
v := (value - r.Min) / (r.Max - r.Min)
|
||||
return int(v * float64(r.Size))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue