Compare commits
No commits in common. "main" and "v2.6.4" have entirely different histories.
45 changed files with 171 additions and 874 deletions
18
README.md
18
README.md
|
|
@ -1,7 +1,5 @@
|
||||||
# go-charts
|
# go-charts
|
||||||
|
|
||||||
Clone from https://github.com/vicanso/go-charts
|
|
||||||
|
|
||||||
[](https://github.com/vicanso/go-charts/blob/master/LICENSE)
|
[](https://github.com/vicanso/go-charts/blob/master/LICENSE)
|
||||||
[](https://github.com/vicanso/go-charts/actions)
|
[](https://github.com/vicanso/go-charts/actions)
|
||||||
|
|
||||||
|
|
@ -35,7 +33,7 @@ More examples can be found in the [./examples/](./examples/) directory.
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
charts "git.smarteching.com/zeni/go-charts/v2"
|
charts "github.com/vicanso/go-charts/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
@ -101,7 +99,7 @@ func main() {
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.smarteching.com/zeni/go-charts/v2"
|
"github.com/vicanso/go-charts/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
@ -176,7 +174,7 @@ func main() {
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.smarteching.com/zeni/go-charts/v2"
|
"github.com/vicanso/go-charts/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
@ -233,7 +231,7 @@ func main() {
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.smarteching.com/zeni/go-charts/v2"
|
"github.com/vicanso/go-charts/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
@ -288,7 +286,7 @@ func main() {
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.smarteching.com/zeni/go-charts/v2"
|
"github.com/vicanso/go-charts/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
@ -346,7 +344,7 @@ func main() {
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.smarteching.com/zeni/go-charts/v2"
|
"github.com/vicanso/go-charts/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
@ -386,7 +384,7 @@ func main() {
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.smarteching.com/zeni/go-charts/v2"
|
"github.com/vicanso/go-charts/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
@ -451,7 +449,7 @@ func main() {
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.smarteching.com/zeni/go-charts/v2"
|
"github.com/vicanso/go-charts/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
||||||
16
README_zh.md
16
README_zh.md
|
|
@ -32,7 +32,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
charts "git.smarteching.com/zeni/go-charts/v2"
|
charts "github.com/vicanso/go-charts/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
@ -98,7 +98,7 @@ func main() {
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.smarteching.com/zeni/go-charts/v2"
|
"github.com/vicanso/go-charts/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
@ -173,7 +173,7 @@ func main() {
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.smarteching.com/zeni/go-charts/v2"
|
"github.com/vicanso/go-charts/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
@ -230,7 +230,7 @@ func main() {
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.smarteching.com/zeni/go-charts/v2"
|
"github.com/vicanso/go-charts/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
@ -285,7 +285,7 @@ func main() {
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.smarteching.com/zeni/go-charts/v2"
|
"github.com/vicanso/go-charts/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
@ -343,7 +343,7 @@ func main() {
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.smarteching.com/zeni/go-charts/v2"
|
"github.com/vicanso/go-charts/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
@ -383,7 +383,7 @@ func main() {
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.smarteching.com/zeni/go-charts/v2"
|
"github.com/vicanso/go-charts/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
@ -447,7 +447,7 @@ func main() {
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.smarteching.com/zeni/go-charts/v2"
|
"github.com/vicanso/go-charts/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
||||||
4
alias.go
4
alias.go
|
|
@ -23,8 +23,8 @@
|
||||||
package charts
|
package charts
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.smarteching.com/zeni/go-chart/v2"
|
"github.com/wcharczuk/go-chart/v2"
|
||||||
"git.smarteching.com/zeni/go-chart/v2/drawing"
|
"github.com/wcharczuk/go-chart/v2/drawing"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Box = chart.Box
|
type Box = chart.Box
|
||||||
|
|
|
||||||
2
axis.go
2
axis.go
|
|
@ -26,7 +26,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/golang/freetype/truetype"
|
"github.com/golang/freetype/truetype"
|
||||||
"git.smarteching.com/zeni/go-chart/v2"
|
"github.com/wcharczuk/go-chart/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type axisPainter struct {
|
type axisPainter struct {
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"git.smarteching.com/zeni/go-chart/v2/drawing"
|
"github.com/wcharczuk/go-chart/v2/drawing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAxis(t *testing.T) {
|
func TestAxis(t *testing.T) {
|
||||||
|
|
|
||||||
18
bar_chart.go
18
bar_chart.go
|
|
@ -26,7 +26,7 @@ import (
|
||||||
"math"
|
"math"
|
||||||
|
|
||||||
"github.com/golang/freetype/truetype"
|
"github.com/golang/freetype/truetype"
|
||||||
"git.smarteching.com/zeni/go-chart/v2"
|
"github.com/wcharczuk/go-chart/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type barChart struct {
|
type barChart struct {
|
||||||
|
|
@ -63,8 +63,6 @@ type BarChartOption struct {
|
||||||
// The legend option
|
// The legend option
|
||||||
Legend LegendOption
|
Legend LegendOption
|
||||||
BarWidth int
|
BarWidth int
|
||||||
// Margin of bar
|
|
||||||
BarMargin int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *barChart) render(result *defaultRenderResult, seriesList SeriesList) (Box, error) {
|
func (b *barChart) render(result *defaultRenderResult, seriesList SeriesList) (Box, error) {
|
||||||
|
|
@ -90,9 +88,6 @@ func (b *barChart) render(result *defaultRenderResult, seriesList SeriesList) (B
|
||||||
margin = 5
|
margin = 5
|
||||||
barMargin = 3
|
barMargin = 3
|
||||||
}
|
}
|
||||||
if opt.BarMargin > 0 {
|
|
||||||
barMargin = opt.BarMargin
|
|
||||||
}
|
|
||||||
seriesCount := len(seriesList)
|
seriesCount := len(seriesList)
|
||||||
// 总的宽度-两个margin-(总数-1)的barMargin
|
// 总的宽度-两个margin-(总数-1)的barMargin
|
||||||
barWidth := (width - 2*margin - barMargin*(seriesCount-1)) / seriesCount
|
barWidth := (width - 2*margin - barMargin*(seriesCount-1)) / seriesCount
|
||||||
|
|
@ -147,7 +142,6 @@ func (b *barChart) render(result *defaultRenderResult, seriesList SeriesList) (B
|
||||||
}
|
}
|
||||||
top := barMaxHeight - h
|
top := barMaxHeight - h
|
||||||
|
|
||||||
if series.RoundRadius <= 0 {
|
|
||||||
seriesPainter.OverrideDrawingStyle(Style{
|
seriesPainter.OverrideDrawingStyle(Style{
|
||||||
FillColor: fillColor,
|
FillColor: fillColor,
|
||||||
}).Rect(chart.Box{
|
}).Rect(chart.Box{
|
||||||
|
|
@ -156,16 +150,6 @@ func (b *barChart) render(result *defaultRenderResult, seriesList SeriesList) (B
|
||||||
Right: x + barWidth,
|
Right: x + barWidth,
|
||||||
Bottom: barMaxHeight - 1,
|
Bottom: barMaxHeight - 1,
|
||||||
})
|
})
|
||||||
} else {
|
|
||||||
seriesPainter.OverrideDrawingStyle(Style{
|
|
||||||
FillColor: fillColor,
|
|
||||||
}).RoundedRect(chart.Box{
|
|
||||||
Top: top,
|
|
||||||
Left: x,
|
|
||||||
Right: x + barWidth,
|
|
||||||
Bottom: barMaxHeight - 1,
|
|
||||||
}, series.RoundRadius)
|
|
||||||
}
|
|
||||||
// 用于生成marker point
|
// 用于生成marker point
|
||||||
points[j] = Point{
|
points[j] = Point{
|
||||||
// 居中的位置
|
// 居中的位置
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -67,8 +67,6 @@ type ChartOption struct {
|
||||||
LineStrokeWidth float64
|
LineStrokeWidth float64
|
||||||
// The bar with of bar chart
|
// The bar with of bar chart
|
||||||
BarWidth int
|
BarWidth int
|
||||||
// The margin of each bar
|
|
||||||
BarMargin int
|
|
||||||
// The bar height of horizontal bar chart
|
// The bar height of horizontal bar chart
|
||||||
BarHeight int
|
BarHeight int
|
||||||
// Fill the area of line chart
|
// Fill the area of line chart
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"git.smarteching.com/zeni/go-chart/v2/drawing"
|
"github.com/wcharczuk/go-chart/v2/drawing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestChartOption(t *testing.T) {
|
func TestChartOption(t *testing.T) {
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ import (
|
||||||
"math"
|
"math"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"git.smarteching.com/zeni/go-chart/v2"
|
"github.com/wcharczuk/go-chart/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
const labelFontSize = 10
|
const labelFontSize = 10
|
||||||
|
|
@ -379,7 +379,6 @@ func Render(opt ChartOption, opts ...OptionFunc) (*Painter, error) {
|
||||||
Font: opt.font,
|
Font: opt.font,
|
||||||
XAxis: opt.XAxis,
|
XAxis: opt.XAxis,
|
||||||
BarWidth: opt.BarWidth,
|
BarWidth: opt.BarWidth,
|
||||||
BarMargin: opt.BarMargin,
|
|
||||||
}).render(renderResult, barSeriesList)
|
}).render(renderResult, barSeriesList)
|
||||||
return err
|
return err
|
||||||
})
|
})
|
||||||
|
|
@ -392,7 +391,6 @@ func Render(opt ChartOption, opts ...OptionFunc) (*Painter, error) {
|
||||||
Theme: opt.theme,
|
Theme: opt.theme,
|
||||||
Font: opt.font,
|
Font: opt.font,
|
||||||
BarHeight: opt.BarHeight,
|
BarHeight: opt.BarHeight,
|
||||||
BarMargin: opt.BarMargin,
|
|
||||||
YAxisOptions: opt.YAxisOptions,
|
YAxisOptions: opt.YAxisOptions,
|
||||||
}).render(renderResult, horizontalBarSeriesList)
|
}).render(renderResult, horizontalBarSeriesList)
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.smarteching.com/zeni/go-chart/v2"
|
"github.com/wcharczuk/go-chart/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func BenchmarkMultiChartPNGRender(b *testing.B) {
|
func BenchmarkMultiChartPNGRender(b *testing.B) {
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ import (
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"git.smarteching.com/zeni/go-chart/v2"
|
"github.com/wcharczuk/go-chart/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func convertToArray(data []byte) []byte {
|
func convertToArray(data []byte) []byte {
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"git.smarteching.com/zeni/go-chart/v2/drawing"
|
"github.com/wcharczuk/go-chart/v2/drawing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestConvertToArray(t *testing.T) {
|
func TestConvertToArray(t *testing.T) {
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"git.smarteching.com/zeni/go-charts/v2"
|
"github.com/vicanso/go-charts/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func writeFile(buf []byte) error {
|
func writeFile(buf []byte) error {
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"git.smarteching.com/zeni/go-charts/v2"
|
"github.com/vicanso/go-charts/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func writeFile(buf []byte) error {
|
func writeFile(buf []byte) error {
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
charts "git.smarteching.com/zeni/go-charts/v2"
|
charts "github.com/vicanso/go-charts/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var html = `<!DOCTYPE html>
|
var html = `<!DOCTYPE html>
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"git.smarteching.com/zeni/go-charts/v2"
|
"github.com/vicanso/go-charts/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func writeFile(buf []byte) error {
|
func writeFile(buf []byte) error {
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"git.smarteching.com/zeni/go-charts/v2"
|
"github.com/vicanso/go-charts/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func writeFile(buf []byte) error {
|
func writeFile(buf []byte) error {
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"git.smarteching.com/zeni/go-charts/v2"
|
"github.com/vicanso/go-charts/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func writeFile(buf []byte) error {
|
func writeFile(buf []byte) error {
|
||||||
|
|
@ -65,9 +65,6 @@ func main() {
|
||||||
"China",
|
"China",
|
||||||
"World",
|
"World",
|
||||||
}),
|
}),
|
||||||
func(opt *charts.ChartOption) {
|
|
||||||
opt.SeriesList[0].RoundRadius = 5
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"git.smarteching.com/zeni/go-charts/v2"
|
"github.com/vicanso/go-charts/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func writeFile(buf []byte) error {
|
func writeFile(buf []byte) error {
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,8 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
charts "git.smarteching.com/zeni/go-charts/v2"
|
charts "github.com/vicanso/go-charts/v2"
|
||||||
"git.smarteching.com/zeni/go-chart/v2/drawing"
|
"github.com/wcharczuk/go-chart/v2/drawing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func writeFile(buf []byte) error {
|
func writeFile(buf []byte) error {
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"git.smarteching.com/zeni/go-charts/v2"
|
"github.com/vicanso/go-charts/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func writeFile(buf []byte) error {
|
func writeFile(buf []byte) error {
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"git.smarteching.com/zeni/go-charts/v2"
|
"github.com/vicanso/go-charts/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func writeFile(buf []byte) error {
|
func writeFile(buf []byte) error {
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,8 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"git.smarteching.com/zeni/go-charts/v2"
|
"github.com/vicanso/go-charts/v2"
|
||||||
"git.smarteching.com/zeni/go-chart/v2/drawing"
|
"github.com/wcharczuk/go-chart/v2/drawing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func writeFile(buf []byte, filename string) error {
|
func writeFile(buf []byte, filename string) error {
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.smarteching.com/zeni/go-charts/v2"
|
"github.com/vicanso/go-charts/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func writeFile(buf []byte) error {
|
func writeFile(buf []byte) error {
|
||||||
|
|
|
||||||
2
font.go
2
font.go
|
|
@ -27,7 +27,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/golang/freetype/truetype"
|
"github.com/golang/freetype/truetype"
|
||||||
"git.smarteching.com/zeni/go-chart/v2/roboto"
|
"github.com/wcharczuk/go-chart/v2/roboto"
|
||||||
)
|
)
|
||||||
|
|
||||||
var fonts = sync.Map{}
|
var fonts = sync.Map{}
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"git.smarteching.com/zeni/go-chart/v2/roboto"
|
"github.com/wcharczuk/go-chart/v2/roboto"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestInstallFont(t *testing.T) {
|
func TestInstallFont(t *testing.T) {
|
||||||
|
|
|
||||||
10
go.mod
10
go.mod
|
|
@ -1,17 +1,17 @@
|
||||||
module git.smarteching.com/zeni/go-charts/v2
|
module github.com/vicanso/go-charts/v2
|
||||||
|
|
||||||
go 1.24.1
|
go 1.17
|
||||||
|
|
||||||
require (
|
require (
|
||||||
git.smarteching.com/zeni/go-chart/v2 v2.1.4
|
|
||||||
github.com/dustin/go-humanize v1.0.1
|
github.com/dustin/go-humanize v1.0.1
|
||||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0
|
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0
|
||||||
github.com/stretchr/testify v1.10.0
|
github.com/stretchr/testify v1.8.2
|
||||||
|
github.com/wcharczuk/go-chart/v2 v2.1.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
golang.org/x/image v0.21.0 // indirect
|
golang.org/x/image v0.0.0-20200927104501-e162460cd6b5 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
|
|
||||||
20
go.sum
20
go.sum
|
|
@ -1,5 +1,4 @@
|
||||||
git.smarteching.com/zeni/go-chart/v2 v2.1.4 h1:pF06+F6eqJLIG8uMiTVPR5TygPGMjM/FHMzTxmu5V/Q=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
git.smarteching.com/zeni/go-chart/v2 v2.1.4/go.mod h1:b3ueW9h3pGGXyhkormZAvilHaG4+mQti+bMNPdQBeOQ=
|
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
|
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
|
||||||
|
|
@ -8,11 +7,20 @@ github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF0
|
||||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
|
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||||
golang.org/x/image v0.21.0 h1:c5qV36ajHpdj4Qi0GnE0jUc/yuo33OLFaa0d+crTD5s=
|
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||||
golang.org/x/image v0.21.0/go.mod h1:vUbsLavqK/W303ZroQQVKQ+Af3Yl6Uz1Ppu5J/cLz78=
|
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
|
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||||
|
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
|
||||||
|
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||||
|
github.com/wcharczuk/go-chart/v2 v2.1.0 h1:tY2slqVQ6bN+yHSnDYwZebLQFkphK4WNrVwnt7CJZ2I=
|
||||||
|
github.com/wcharczuk/go-chart/v2 v2.1.0/go.mod h1:yx7MvAVNcP/kN9lKXM/NTce4au4DFN99j6i1OwDclNA=
|
||||||
|
golang.org/x/image v0.0.0-20200927104501-e162460cd6b5 h1:QelT11PB4FXiDEXucrfNckHoFxwt8USGY1ajP1ZF5lM=
|
||||||
|
golang.org/x/image v0.0.0-20200927104501-e162460cd6b5/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||||
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"git.smarteching.com/zeni/go-chart/v2/drawing"
|
"github.com/wcharczuk/go-chart/v2/drawing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGrid(t *testing.T) {
|
func TestGrid(t *testing.T) {
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ package charts
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/golang/freetype/truetype"
|
"github.com/golang/freetype/truetype"
|
||||||
"git.smarteching.com/zeni/go-chart/v2"
|
"github.com/wcharczuk/go-chart/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type horizontalBarChart struct {
|
type horizontalBarChart struct {
|
||||||
|
|
@ -50,8 +50,6 @@ type HorizontalBarChartOption struct {
|
||||||
// The legend option
|
// The legend option
|
||||||
Legend LegendOption
|
Legend LegendOption
|
||||||
BarHeight int
|
BarHeight int
|
||||||
// Margin of bar
|
|
||||||
BarMargin int
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewHorizontalBarChart returns a horizontal bar chart renderer
|
// NewHorizontalBarChart returns a horizontal bar chart renderer
|
||||||
|
|
@ -83,9 +81,6 @@ func (h *horizontalBarChart) render(result *defaultRenderResult, seriesList Seri
|
||||||
margin = 5
|
margin = 5
|
||||||
barMargin = 3
|
barMargin = 3
|
||||||
}
|
}
|
||||||
if opt.BarMargin > 0 {
|
|
||||||
barMargin = opt.BarMargin
|
|
||||||
}
|
|
||||||
seriesCount := len(seriesList)
|
seriesCount := len(seriesList)
|
||||||
// 总的高度-两个margin-(总数-1)的barMargin
|
// 总的高度-两个margin-(总数-1)的barMargin
|
||||||
barHeight := (height - 2*margin - barMargin*(seriesCount-1)) / seriesCount
|
barHeight := (height - 2*margin - barMargin*(seriesCount-1)) / seriesCount
|
||||||
|
|
@ -141,7 +136,6 @@ func (h *horizontalBarChart) render(result *defaultRenderResult, seriesList Seri
|
||||||
fillColor = item.Style.FillColor
|
fillColor = item.Style.FillColor
|
||||||
}
|
}
|
||||||
right := w
|
right := w
|
||||||
if series.RoundRadius <= 0 {
|
|
||||||
seriesPainter.OverrideDrawingStyle(Style{
|
seriesPainter.OverrideDrawingStyle(Style{
|
||||||
FillColor: fillColor,
|
FillColor: fillColor,
|
||||||
}).Rect(chart.Box{
|
}).Rect(chart.Box{
|
||||||
|
|
@ -150,17 +144,6 @@ func (h *horizontalBarChart) render(result *defaultRenderResult, seriesList Seri
|
||||||
Right: right,
|
Right: right,
|
||||||
Bottom: y + barHeight,
|
Bottom: y + barHeight,
|
||||||
})
|
})
|
||||||
} else {
|
|
||||||
seriesPainter.OverrideDrawingStyle(Style{
|
|
||||||
FillColor: fillColor,
|
|
||||||
}).RoundedRect(chart.Box{
|
|
||||||
Top: y,
|
|
||||||
Left: 0,
|
|
||||||
Right: right,
|
|
||||||
Bottom: y + barHeight,
|
|
||||||
}, series.RoundRadius)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 如果label不需要展示,则返回
|
// 如果label不需要展示,则返回
|
||||||
if labelPainter == nil {
|
if labelPainter == nil {
|
||||||
continue
|
continue
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ import (
|
||||||
"math"
|
"math"
|
||||||
|
|
||||||
"github.com/golang/freetype/truetype"
|
"github.com/golang/freetype/truetype"
|
||||||
"git.smarteching.com/zeni/go-chart/v2/drawing"
|
"github.com/wcharczuk/go-chart/v2/drawing"
|
||||||
)
|
)
|
||||||
|
|
||||||
type lineChart struct {
|
type lineChart struct {
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"git.smarteching.com/zeni/go-chart/v2/drawing"
|
"github.com/wcharczuk/go-chart/v2/drawing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMarkLine(t *testing.T) {
|
func TestMarkLine(t *testing.T) {
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"git.smarteching.com/zeni/go-chart/v2/drawing"
|
"github.com/wcharczuk/go-chart/v2/drawing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMarkPoint(t *testing.T) {
|
func TestMarkPoint(t *testing.T) {
|
||||||
|
|
|
||||||
48
painter.go
48
painter.go
|
|
@ -28,7 +28,7 @@ import (
|
||||||
"math"
|
"math"
|
||||||
|
|
||||||
"github.com/golang/freetype/truetype"
|
"github.com/golang/freetype/truetype"
|
||||||
"git.smarteching.com/zeni/go-chart/v2"
|
"github.com/wcharczuk/go-chart/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ValueFormatter func(float64) string
|
type ValueFormatter func(float64) string
|
||||||
|
|
@ -803,48 +803,6 @@ func (p *Painter) Rect(box Box) *Painter {
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Painter) RoundedRect(box Box, radius int) *Painter {
|
|
||||||
r := (box.Right - box.Left) / 2
|
|
||||||
if radius > r {
|
|
||||||
radius = r
|
|
||||||
}
|
|
||||||
rx := float64(radius)
|
|
||||||
ry := float64(radius)
|
|
||||||
p.MoveTo(box.Left+radius, box.Top)
|
|
||||||
p.LineTo(box.Right-radius, box.Top)
|
|
||||||
|
|
||||||
cx := box.Right - radius
|
|
||||||
cy := box.Top + radius
|
|
||||||
// right top
|
|
||||||
p.ArcTo(cx, cy, rx, ry, -math.Pi/2, math.Pi/2)
|
|
||||||
|
|
||||||
p.LineTo(box.Right, box.Bottom-radius)
|
|
||||||
|
|
||||||
// right bottom
|
|
||||||
cx = box.Right - radius
|
|
||||||
cy = box.Bottom - radius
|
|
||||||
p.ArcTo(cx, cy, rx, ry, 0.0, math.Pi/2)
|
|
||||||
|
|
||||||
p.LineTo(box.Left+radius, box.Bottom)
|
|
||||||
|
|
||||||
// left bottom
|
|
||||||
cx = box.Left + radius
|
|
||||||
cy = box.Bottom - radius
|
|
||||||
p.ArcTo(cx, cy, rx, ry, math.Pi/2, math.Pi/2)
|
|
||||||
|
|
||||||
p.LineTo(box.Left, box.Top+radius)
|
|
||||||
|
|
||||||
// left top
|
|
||||||
cx = box.Left + radius
|
|
||||||
cy = box.Top + radius
|
|
||||||
p.ArcTo(cx, cy, rx, ry, math.Pi, math.Pi/2)
|
|
||||||
|
|
||||||
p.Close()
|
|
||||||
p.FillStroke()
|
|
||||||
p.Fill()
|
|
||||||
return p
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Painter) LegendLineDot(box Box) *Painter {
|
func (p *Painter) LegendLineDot(box Box) *Painter {
|
||||||
width := box.Width()
|
width := box.Width()
|
||||||
height := box.Height()
|
height := box.Height()
|
||||||
|
|
@ -860,7 +818,3 @@ func (p *Painter) LegendLineDot(box Box) *Painter {
|
||||||
p.FillStroke()
|
p.FillStroke()
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Painter) GetRenderer() chart.Renderer {
|
|
||||||
return p.render
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -28,8 +28,8 @@ import (
|
||||||
|
|
||||||
"github.com/golang/freetype/truetype"
|
"github.com/golang/freetype/truetype"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"git.smarteching.com/zeni/go-chart/v2"
|
"github.com/wcharczuk/go-chart/v2"
|
||||||
"git.smarteching.com/zeni/go-chart/v2/drawing"
|
"github.com/wcharczuk/go-chart/v2/drawing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPainterOption(t *testing.T) {
|
func TestPainterOption(t *testing.T) {
|
||||||
|
|
@ -343,29 +343,6 @@ func TestPainter(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRoundedRect(t *testing.T) {
|
|
||||||
assert := assert.New(t)
|
|
||||||
p, err := NewPainter(PainterOptions{
|
|
||||||
Width: 400,
|
|
||||||
Height: 300,
|
|
||||||
Type: ChartOutputSVG,
|
|
||||||
})
|
|
||||||
assert.Nil(err)
|
|
||||||
p.OverrideDrawingStyle(Style{
|
|
||||||
FillColor: drawing.ColorWhite,
|
|
||||||
StrokeWidth: 1,
|
|
||||||
StrokeColor: drawing.ColorWhite,
|
|
||||||
}).RoundedRect(Box{
|
|
||||||
Left: 10,
|
|
||||||
Right: 30,
|
|
||||||
Bottom: 150,
|
|
||||||
Top: 10,
|
|
||||||
}, 5)
|
|
||||||
buf, err := p.Bytes()
|
|
||||||
assert.Nil(err)
|
|
||||||
assert.Equal("<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"400\" height=\"300\">\\n<path d=\"M 15 10\nL 25 10\nL 25 10\nA 5 5 90.00 0 1 30 15\nL 30 145\nL 30 145\nA 5 5 90.00 0 1 25 150\nL 15 150\nL 15 150\nA 5 5 90.00 0 1 10 145\nL 10 15\nL 10 15\nA 5 5 90.00 0 1 15 10\nZ\" style=\"stroke-width:1;stroke:rgba(255,255,255,1.0);fill:rgba(255,255,255,1.0)\"/><path d=\"\" style=\"stroke-width:1;stroke:rgba(255,255,255,1.0);fill:rgba(255,255,255,1.0)\"/></svg>", string(buf))
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestPainterTextFit(t *testing.T) {
|
func TestPainterTextFit(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
p, err := NewPainter(PainterOptions{
|
p, err := NewPainter(PainterOptions{
|
||||||
|
|
|
||||||
243
pie_chart.go
243
pie_chart.go
|
|
@ -27,7 +27,7 @@ import (
|
||||||
"math"
|
"math"
|
||||||
|
|
||||||
"github.com/golang/freetype/truetype"
|
"github.com/golang/freetype/truetype"
|
||||||
"git.smarteching.com/zeni/go-chart/v2"
|
"github.com/wcharczuk/go-chart/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type pieChart struct {
|
type pieChart struct {
|
||||||
|
|
@ -63,96 +63,6 @@ func NewPieChart(p *Painter, opt PieChartOption) *pieChart {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type sector struct {
|
|
||||||
value float64
|
|
||||||
percent float64
|
|
||||||
cx int
|
|
||||||
cy int
|
|
||||||
rx float64
|
|
||||||
ry float64
|
|
||||||
start float64
|
|
||||||
delta float64
|
|
||||||
offset int
|
|
||||||
quadrant int
|
|
||||||
lineStartX int
|
|
||||||
lineStartY int
|
|
||||||
lineBranchX int
|
|
||||||
lineBranchY int
|
|
||||||
lineEndX int
|
|
||||||
lineEndY int
|
|
||||||
showLabel bool
|
|
||||||
label string
|
|
||||||
series Series
|
|
||||||
color Color
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewSector(cx int, cy int, radius float64, labelRadius float64, value float64, currentValue float64, totalValue float64, labelLineLength int, label string, series Series, color Color) sector {
|
|
||||||
s := sector{}
|
|
||||||
s.value = value
|
|
||||||
s.percent = value / totalValue
|
|
||||||
s.cx = cx
|
|
||||||
s.cy = cy
|
|
||||||
s.rx = radius
|
|
||||||
s.ry = radius
|
|
||||||
p := (currentValue + value/2) / totalValue
|
|
||||||
if p < 0.25 {
|
|
||||||
s.quadrant = 1
|
|
||||||
} else if p < 0.5 {
|
|
||||||
s.quadrant = 4
|
|
||||||
} else if p < 0.75 {
|
|
||||||
s.quadrant = 3
|
|
||||||
} else {
|
|
||||||
s.quadrant = 2
|
|
||||||
}
|
|
||||||
s.start = chart.PercentToRadians(currentValue/totalValue) - math.Pi/2
|
|
||||||
s.delta = chart.PercentToRadians(value / totalValue)
|
|
||||||
angle := s.start + s.delta/2
|
|
||||||
s.lineStartX = cx + int(radius*math.Cos(angle))
|
|
||||||
s.lineStartY = cy + int(radius*math.Sin(angle))
|
|
||||||
s.lineBranchX = cx + int(labelRadius*math.Cos(angle))
|
|
||||||
s.lineBranchY = cy + int(labelRadius*math.Sin(angle))
|
|
||||||
s.offset = labelLineLength
|
|
||||||
if s.lineBranchX <= cx {
|
|
||||||
s.offset *= -1
|
|
||||||
}
|
|
||||||
s.lineEndX = s.lineBranchX + s.offset
|
|
||||||
s.lineEndY = s.lineBranchY
|
|
||||||
s.series = series
|
|
||||||
s.color = color
|
|
||||||
s.showLabel = series.Label.Show
|
|
||||||
s.label = NewPieLabelFormatter([]string{label}, series.Label.Formatter)(0, s.value, s.percent)
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *sector) calculateY(prevY int) int {
|
|
||||||
for i := 0; i <= s.cy; i++ {
|
|
||||||
if s.quadrant <= 2 {
|
|
||||||
if (prevY - s.lineBranchY) > labelFontSize+5 {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
s.lineBranchY -= 1
|
|
||||||
} else {
|
|
||||||
if (s.lineBranchY - prevY) > labelFontSize+5 {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
s.lineBranchY += 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
s.lineEndY = s.lineBranchY
|
|
||||||
return s.lineBranchY
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *sector) calculateTextXY(textBox Box) (x int, y int) {
|
|
||||||
textMargin := 3
|
|
||||||
x = s.lineEndX + textMargin
|
|
||||||
y = s.lineEndY + textBox.Height()>>1 - 1
|
|
||||||
if s.offset < 0 {
|
|
||||||
textWidth := textBox.Width()
|
|
||||||
x = s.lineEndX - textWidth - textMargin
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *pieChart) render(result *defaultRenderResult, seriesList SeriesList) (Box, error) {
|
func (p *pieChart) render(result *defaultRenderResult, seriesList SeriesList) (Box, error) {
|
||||||
opt := p.opt
|
opt := p.opt
|
||||||
values := make([]float64, len(seriesList))
|
values := make([]float64, len(seriesList))
|
||||||
|
|
@ -191,103 +101,98 @@ func (p *pieChart) render(result *defaultRenderResult, seriesList SeriesList) (B
|
||||||
theme := opt.Theme
|
theme := opt.Theme
|
||||||
|
|
||||||
currentValue := float64(0)
|
currentValue := float64(0)
|
||||||
|
prevPoints := make([]Point, 0)
|
||||||
|
|
||||||
var quadrant1, quadrant2, quadrant3, quadrant4 []sector
|
isOverride := func(x, y int) bool {
|
||||||
for index, v := range values {
|
for _, p := range prevPoints {
|
||||||
series := seriesList[index]
|
if math.Abs(float64(p.Y-y)) > labelFontSize {
|
||||||
color := theme.GetSeriesColor(index)
|
|
||||||
if index == len(values)-1 {
|
|
||||||
if color == theme.GetSeriesColor(0) {
|
|
||||||
color = theme.GetSeriesColor(1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
s := NewSector(cx, cy, radius, labelRadius, v, currentValue, total, labelLineWidth, seriesNames[index], series, color)
|
|
||||||
switch quadrant := s.quadrant; quadrant {
|
|
||||||
case 1:
|
|
||||||
quadrant1 = append([]sector{s}, quadrant1...)
|
|
||||||
case 2:
|
|
||||||
quadrant2 = append(quadrant2, s)
|
|
||||||
case 3:
|
|
||||||
quadrant3 = append([]sector{s}, quadrant3...)
|
|
||||||
case 4:
|
|
||||||
quadrant4 = append(quadrant4, s)
|
|
||||||
}
|
|
||||||
currentValue += v
|
|
||||||
}
|
|
||||||
sectors := append(quadrant1, quadrant4...)
|
|
||||||
sectors = append(sectors, quadrant3...)
|
|
||||||
sectors = append(sectors, quadrant2...)
|
|
||||||
|
|
||||||
currentQuadrant := 0
|
|
||||||
prevY := 0
|
|
||||||
maxY := 0
|
|
||||||
minY := 0
|
|
||||||
for _, s := range sectors {
|
|
||||||
seriesPainter.OverrideDrawingStyle(Style{
|
|
||||||
StrokeWidth: 1,
|
|
||||||
StrokeColor: s.color,
|
|
||||||
FillColor: s.color,
|
|
||||||
})
|
|
||||||
seriesPainter.MoveTo(s.cx, s.cy)
|
|
||||||
seriesPainter.ArcTo(s.cx, s.cy, s.rx, s.ry, s.start, s.delta).LineTo(s.cx, s.cy).Close().FillStroke()
|
|
||||||
if !s.showLabel {
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if currentQuadrant != s.quadrant {
|
// label可能较多内容,不好计算横向占用空间
|
||||||
if s.quadrant == 1 {
|
// 因此x的位置需要中间位置两侧,否则认为override
|
||||||
minY = cy * 2
|
if (p.X <= cx && x <= cx) ||
|
||||||
maxY = 0
|
(p.X > cx && x > cx) {
|
||||||
prevY = cy * 2
|
return true
|
||||||
}
|
|
||||||
if s.quadrant == 2 {
|
|
||||||
if currentQuadrant != 3 {
|
|
||||||
prevY = s.lineEndY
|
|
||||||
} else {
|
|
||||||
prevY = minY
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if s.quadrant == 3 {
|
return false
|
||||||
if currentQuadrant != 4 {
|
|
||||||
prevY = s.lineEndY
|
|
||||||
} else {
|
|
||||||
minY = cy * 2
|
|
||||||
maxY = 0
|
|
||||||
prevY = 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for index, v := range values {
|
||||||
|
seriesPainter.OverrideDrawingStyle(Style{
|
||||||
|
StrokeWidth: 1,
|
||||||
|
StrokeColor: theme.GetSeriesColor(index),
|
||||||
|
FillColor: theme.GetSeriesColor(index),
|
||||||
|
})
|
||||||
|
seriesPainter.MoveTo(cx, cy)
|
||||||
|
start := chart.PercentToRadians(currentValue/total) - math.Pi/2
|
||||||
|
currentValue += v
|
||||||
|
percent := (v / total)
|
||||||
|
delta := chart.PercentToRadians(percent)
|
||||||
|
seriesPainter.ArcTo(cx, cy, radius, radius, start, delta).
|
||||||
|
LineTo(cx, cy).
|
||||||
|
Close().
|
||||||
|
FillStroke()
|
||||||
|
|
||||||
|
series := seriesList[index]
|
||||||
|
// 是否显示label
|
||||||
|
showLabel := series.Label.Show
|
||||||
|
if !showLabel {
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
if s.quadrant == 4 {
|
|
||||||
if currentQuadrant != 1 {
|
// label的角度为饼块中间
|
||||||
prevY = s.lineEndY
|
angle := start + delta/2
|
||||||
} else {
|
startx := cx + int(radius*math.Cos(angle))
|
||||||
prevY = maxY
|
starty := cy + int(radius*math.Sin(angle))
|
||||||
|
|
||||||
|
endx := cx + int(labelRadius*math.Cos(angle))
|
||||||
|
endy := cy + int(labelRadius*math.Sin(angle))
|
||||||
|
// 计算是否有重叠,如果有则调整y坐标位置
|
||||||
|
// 最多只尝试5次
|
||||||
|
for i := 0; i < 5; i++ {
|
||||||
|
if !isOverride(endx, endy) {
|
||||||
|
break
|
||||||
}
|
}
|
||||||
|
endy -= (labelFontSize << 1)
|
||||||
}
|
}
|
||||||
currentQuadrant = s.quadrant
|
prevPoints = append(prevPoints, Point{
|
||||||
|
X: endx,
|
||||||
|
Y: endy,
|
||||||
|
})
|
||||||
|
|
||||||
|
seriesPainter.MoveTo(startx, starty)
|
||||||
|
seriesPainter.LineTo(endx, endy)
|
||||||
|
offset := labelLineWidth
|
||||||
|
if endx < cx {
|
||||||
|
offset *= -1
|
||||||
}
|
}
|
||||||
prevY = s.calculateY(prevY)
|
seriesPainter.MoveTo(endx, endy)
|
||||||
if prevY > maxY {
|
endx += offset
|
||||||
maxY = prevY
|
seriesPainter.LineTo(endx, endy)
|
||||||
}
|
|
||||||
if prevY < minY {
|
|
||||||
minY = prevY
|
|
||||||
}
|
|
||||||
seriesPainter.MoveTo(s.lineStartX, s.lineStartY)
|
|
||||||
seriesPainter.LineTo(s.lineBranchX, s.lineBranchY)
|
|
||||||
seriesPainter.MoveTo(s.lineBranchX, s.lineBranchY)
|
|
||||||
seriesPainter.LineTo(s.lineEndX, s.lineEndY)
|
|
||||||
seriesPainter.Stroke()
|
seriesPainter.Stroke()
|
||||||
|
|
||||||
textStyle := Style{
|
textStyle := Style{
|
||||||
FontColor: theme.GetTextColor(),
|
FontColor: theme.GetTextColor(),
|
||||||
FontSize: labelFontSize,
|
FontSize: labelFontSize,
|
||||||
Font: opt.Font,
|
Font: opt.Font,
|
||||||
}
|
}
|
||||||
if !s.series.Label.Color.IsZero() {
|
if !series.Label.Color.IsZero() {
|
||||||
textStyle.FontColor = s.series.Label.Color
|
textStyle.FontColor = series.Label.Color
|
||||||
}
|
}
|
||||||
seriesPainter.OverrideTextStyle(textStyle)
|
seriesPainter.OverrideTextStyle(textStyle)
|
||||||
x, y := s.calculateTextXY(seriesPainter.MeasureText(s.label))
|
text := NewPieLabelFormatter(seriesNames, series.Label.Formatter)(index, v, percent)
|
||||||
seriesPainter.Text(s.label, x, y)
|
textBox := seriesPainter.MeasureText(text)
|
||||||
|
textMargin := 3
|
||||||
|
x := endx + textMargin
|
||||||
|
y := endy + textBox.Height()>>1 - 1
|
||||||
|
if offset < 0 {
|
||||||
|
textWidth := textBox.Width()
|
||||||
|
x = endx - textWidth - textMargin
|
||||||
}
|
}
|
||||||
|
seriesPainter.Text(text, x, y)
|
||||||
|
}
|
||||||
|
|
||||||
return p.p.box, nil
|
return p.p.box, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -27,8 +27,8 @@ import (
|
||||||
|
|
||||||
"github.com/dustin/go-humanize"
|
"github.com/dustin/go-humanize"
|
||||||
"github.com/golang/freetype/truetype"
|
"github.com/golang/freetype/truetype"
|
||||||
"git.smarteching.com/zeni/go-chart/v2"
|
"github.com/wcharczuk/go-chart/v2"
|
||||||
"git.smarteching.com/zeni/go-chart/v2/drawing"
|
"github.com/wcharczuk/go-chart/v2/drawing"
|
||||||
)
|
)
|
||||||
|
|
||||||
type radarChart struct {
|
type radarChart struct {
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/dustin/go-humanize"
|
"github.com/dustin/go-humanize"
|
||||||
"git.smarteching.com/zeni/go-chart/v2"
|
"github.com/wcharczuk/go-chart/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SeriesData struct {
|
type SeriesData struct {
|
||||||
|
|
@ -126,8 +126,6 @@ type Series struct {
|
||||||
Name string
|
Name string
|
||||||
// Radius for Pie chart, e.g.: 40%, default is "40%"
|
// Radius for Pie chart, e.g.: 40%, default is "40%"
|
||||||
Radius string
|
Radius string
|
||||||
// Round for bar chart
|
|
||||||
RoundRadius int
|
|
||||||
// Mark point for series
|
// Mark point for series
|
||||||
MarkPoint SeriesMarkPoint
|
MarkPoint SeriesMarkPoint
|
||||||
// Make line for series
|
// Make line for series
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ package charts
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/golang/freetype/truetype"
|
"github.com/golang/freetype/truetype"
|
||||||
"git.smarteching.com/zeni/go-chart/v2"
|
"github.com/wcharczuk/go-chart/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type labelRenderValue struct {
|
type labelRenderValue struct {
|
||||||
|
|
|
||||||
4
table.go
4
table.go
|
|
@ -26,8 +26,8 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/golang/freetype/truetype"
|
"github.com/golang/freetype/truetype"
|
||||||
"git.smarteching.com/zeni/go-chart/v2"
|
"github.com/wcharczuk/go-chart/v2"
|
||||||
"git.smarteching.com/zeni/go-chart/v2/drawing"
|
"github.com/wcharczuk/go-chart/v2/drawing"
|
||||||
)
|
)
|
||||||
|
|
||||||
type tableChart struct {
|
type tableChart struct {
|
||||||
|
|
|
||||||
2
theme.go
2
theme.go
|
|
@ -24,7 +24,7 @@ package charts
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/golang/freetype/truetype"
|
"github.com/golang/freetype/truetype"
|
||||||
"git.smarteching.com/zeni/go-chart/v2/drawing"
|
"github.com/wcharczuk/go-chart/v2/drawing"
|
||||||
)
|
)
|
||||||
|
|
||||||
const ThemeDark = "dark"
|
const ThemeDark = "dark"
|
||||||
|
|
|
||||||
4
util.go
4
util.go
|
|
@ -29,8 +29,8 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/dustin/go-humanize"
|
"github.com/dustin/go-humanize"
|
||||||
"git.smarteching.com/zeni/go-chart/v2"
|
"github.com/wcharczuk/go-chart/v2"
|
||||||
"git.smarteching.com/zeni/go-chart/v2/drawing"
|
"github.com/wcharczuk/go-chart/v2/drawing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TrueFlag() *bool {
|
func TrueFlag() *bool {
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,8 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"git.smarteching.com/zeni/go-chart/v2"
|
"github.com/wcharczuk/go-chart/v2"
|
||||||
"git.smarteching.com/zeni/go-chart/v2/drawing"
|
"github.com/wcharczuk/go-chart/v2/drawing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGetDefaultInt(t *testing.T) {
|
func TestGetDefaultInt(t *testing.T) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue