Merge pull request #72 from euerla/main

fix: Label position of the pie chart
This commit is contained in:
Tree Xie 2024-03-23 10:33:19 +08:00 committed by GitHub
commit 5a69c3e5a3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 142 additions and 3 deletions

View file

@ -94,7 +94,7 @@ func NewSector(cx int, cy int, radius float64, labelRadius float64, value float6
s.cy = cy s.cy = cy
s.rx = radius s.rx = radius
s.ry = radius s.ry = radius
p := currentValue / totalValue p := (currentValue + value/2) / totalValue
if p < 0.25 { if p < 0.25 {
s.quadrant = 1 s.quadrant = 1
} else if p < 0.5 { } else if p < 0.5 {
@ -104,7 +104,7 @@ func NewSector(cx int, cy int, radius float64, labelRadius float64, value float6
} else { } else {
s.quadrant = 2 s.quadrant = 2
} }
s.start = chart.PercentToRadians(currentValue/totalValue) - math.Pi/2 // Bogenmaß s.start = chart.PercentToRadians(currentValue/totalValue) - math.Pi/2
s.delta = chart.PercentToRadians(value / totalValue) s.delta = chart.PercentToRadians(value / totalValue)
angle := s.start + s.delta/2 angle := s.start + s.delta/2
s.lineStartX = cx + int(radius*math.Cos(angle)) s.lineStartX = cx + int(radius*math.Cos(angle))

File diff suppressed because one or more lines are too long