diff --git a/_examples/pie_chart/main.go b/_examples/pie_chart/main.go index d928c41..9d1098d 100644 --- a/_examples/pie_chart/main.go +++ b/_examples/pie_chart/main.go @@ -30,7 +30,26 @@ func drawChart(res http.ResponseWriter, req *http.Request) { } } +func drawChartRegression(res http.ResponseWriter, req *http.Request) { + pie := chart.PieChart{ + Width: 512, + Height: 512, + Values: []chart.Value{ + {Value: 5, Label: "Blue"}, + {Value: 2, Label: "Two"}, + {Value: 1, Label: "One"}, + }, + } + + res.Header().Set("Content-Type", chart.ContentTypeSVG) + err := pie.Render(chart.SVG, res) + if err != nil { + fmt.Printf("Error rendering pie chart: %v\n", err) + } +} + func main() { http.HandleFunc("/", drawChart) + http.HandleFunc("/reg", drawChartRegression) log.Fatal(http.ListenAndServe(":8080", nil)) } diff --git a/_examples/pie_chart/reg.svg b/_examples/pie_chart/reg.svg new file mode 100644 index 0000000..6b8d2ff --- /dev/null +++ b/_examples/pie_chart/reg.svg @@ -0,0 +1,17 @@ + + + + + \ No newline at end of file diff --git a/pie_chart.go b/pie_chart.go index d0f1260..6d5d75e 100644 --- a/pie_chart.go +++ b/pie_chart.go @@ -11,6 +11,7 @@ import ( ) const ( + _pi = math.Pi _pi2 = math.Pi / 2.0 _pi4 = math.Pi / 4.0 ) diff --git a/vector_renderer.go b/vector_renderer.go index 17d7b73..6996fe8 100644 --- a/vector_renderer.go +++ b/vector_renderer.go @@ -107,7 +107,12 @@ func (vr *vectorRenderer) ArcTo(cx, cy int, rx, ry, startAngle, delta float64) { dd := util.Math.RadiansToDegrees(delta) - vr.p = append(vr.p, fmt.Sprintf("A %d %d %0.2f 0 1 %d %d", int(rx), int(ry), dd, endx, endy)) + largeArcFlag := 0 + if delta > _pi { + largeArcFlag = 1 + } + + vr.p = append(vr.p, fmt.Sprintf("A %d %d %0.2f %d 1 %d %d", int(rx), int(ry), dd, largeArcFlag, endx, endy)) } // Close closes a shape.