snapshot
This commit is contained in:
parent
3cb33d48d3
commit
26eaa1d898
76 changed files with 1076 additions and 1717 deletions
26
pie_chart.go
26
pie_chart.go
|
|
@ -4,16 +4,8 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
|
||||
"github.com/golang/freetype/truetype"
|
||||
"github.com/wcharczuk/go-chart/util"
|
||||
)
|
||||
|
||||
const (
|
||||
_pi = math.Pi
|
||||
_pi2 = math.Pi / 2.0
|
||||
_pi4 = math.Pi / 4.0
|
||||
)
|
||||
|
||||
// PieChart is a chart that draws sections of a circle based on percentages.
|
||||
|
|
@ -131,7 +123,7 @@ func (pc PieChart) drawTitle(r Renderer) {
|
|||
|
||||
func (pc PieChart) drawSlices(r Renderer, canvasBox Box, values []Value) {
|
||||
cx, cy := canvasBox.Center()
|
||||
diameter := util.Math.MinInt(canvasBox.Width(), canvasBox.Height())
|
||||
diameter := MinInt(canvasBox.Width(), canvasBox.Height())
|
||||
radius := float64(diameter >> 1)
|
||||
labelRadius := (radius * 2.0) / 3.0
|
||||
|
||||
|
|
@ -148,8 +140,8 @@ func (pc PieChart) drawSlices(r Renderer, canvasBox Box, values []Value) {
|
|||
v.Style.InheritFrom(pc.stylePieChartValue(index)).WriteToRenderer(r)
|
||||
|
||||
r.MoveTo(cx, cy)
|
||||
rads = util.Math.PercentToRadians(total)
|
||||
delta = util.Math.PercentToRadians(v.Value)
|
||||
rads = PercentToRadians(total)
|
||||
delta = PercentToRadians(v.Value)
|
||||
|
||||
r.ArcTo(cx, cy, radius, radius, rads, delta)
|
||||
|
||||
|
|
@ -165,9 +157,9 @@ func (pc PieChart) drawSlices(r Renderer, canvasBox Box, values []Value) {
|
|||
for index, v := range values {
|
||||
v.Style.InheritFrom(pc.stylePieChartValue(index)).WriteToRenderer(r)
|
||||
if len(v.Label) > 0 {
|
||||
delta2 = util.Math.PercentToRadians(total + (v.Value / 2.0))
|
||||
delta2 = util.Math.RadianAdd(delta2, _pi2)
|
||||
lx, ly = util.Math.CirclePoint(cx, cy, labelRadius, delta2)
|
||||
delta2 = PercentToRadians(total + (v.Value / 2.0))
|
||||
delta2 = RadianAdd(delta2, _pi2)
|
||||
lx, ly = CirclePoint(cx, cy, labelRadius, delta2)
|
||||
|
||||
tb := r.MeasureText(v.Label)
|
||||
lx = lx - (tb.Width() >> 1)
|
||||
|
|
@ -199,7 +191,7 @@ func (pc PieChart) getDefaultCanvasBox() Box {
|
|||
}
|
||||
|
||||
func (pc PieChart) getCircleAdjustedCanvasBox(canvasBox Box) Box {
|
||||
circleDiameter := util.Math.MinInt(canvasBox.Width(), canvasBox.Height())
|
||||
circleDiameter := MinInt(canvasBox.Width(), canvasBox.Height())
|
||||
|
||||
square := Box{
|
||||
Right: circleDiameter,
|
||||
|
|
@ -245,7 +237,7 @@ func (pc PieChart) stylePieChartValue(index int) Style {
|
|||
}
|
||||
|
||||
func (pc PieChart) getScaledFontSize() float64 {
|
||||
effectiveDimension := util.Math.MinInt(pc.GetWidth(), pc.GetHeight())
|
||||
effectiveDimension := MinInt(pc.GetWidth(), pc.GetHeight())
|
||||
if effectiveDimension >= 2048 {
|
||||
return 48.0
|
||||
} else if effectiveDimension >= 1024 {
|
||||
|
|
@ -284,7 +276,7 @@ func (pc PieChart) styleDefaultsTitle() Style {
|
|||
}
|
||||
|
||||
func (pc PieChart) getTitleFontSize() float64 {
|
||||
effectiveDimension := util.Math.MinInt(pc.GetWidth(), pc.GetHeight())
|
||||
effectiveDimension := MinInt(pc.GetWidth(), pc.GetHeight())
|
||||
if effectiveDimension >= 2048 {
|
||||
return 48
|
||||
} else if effectiveDimension >= 1024 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue