diff --git a/README.md b/README.md
index 8183871..d7d94f7 100644
--- a/README.md
+++ b/README.md
@@ -5,7 +5,7 @@
[中文](./README_zh.md)
-`go-charts` base on [go-chart](https://github.com/wcharczuk/go-chart),it is simpler way for generating charts, which supports `svg` and `png` format and themes: `light`, `dark`, `grafana` and `ant`.
+`go-charts` base on [go-chart](https://github.com/wcharczuk/go-chart),it is simpler way for generating charts, which supports `svg` and `png` format and themes: `light`, `dark`, `grafana` and `ant`. The default format is `png` and the default theme is `light`.
`Apache ECharts` is popular among Front-end developers, so `go-charts` supports the option of `Apache ECharts`. Developers can generate charts almost the same as `Apache ECharts`.
diff --git a/README_zh.md b/README_zh.md
index fed2d61..dbdaaf3 100644
--- a/README_zh.md
+++ b/README_zh.md
@@ -3,7 +3,7 @@
[](https://github.com/vicanso/go-charts/blob/master/LICENSE)
[](https://github.com/vicanso/go-charts/actions)
-`go-charts`基于[go-chart](https://github.com/wcharczuk/go-chart),更简单方便的形式生成数据图表,支持`svg`与`png`两种方式的输出,支持主题`light`, `dark`, `grafana`以及`ant`。
+`go-charts`基于[go-chart](https://github.com/wcharczuk/go-chart),更简单方便的形式生成数据图表,支持`svg`与`png`两种方式的输出,支持主题`light`, `dark`, `grafana`以及`ant`。默认的输入格式为`png`,默认主题为`light`。
`Apache ECharts`在前端开发中得到众多开发者的认可,因此`go-charts`提供了兼容`Apache ECharts`的配置参数,简单快捷的生成相似的图表(`svg`或`png`),方便插入至Email或分享使用。下面为常用的图表截图(主题为light与grafana):
diff --git a/chart_option_test.go b/chart_option_test.go
index c77bb4f..5e53e46 100644
--- a/chart_option_test.go
+++ b/chart_option_test.go
@@ -277,7 +277,7 @@ func TestBarRender(t *testing.T) {
assert.Nil(err)
data, err := p.Bytes()
assert.Nil(err)
- assert.Equal("", string(data))
+ assert.Equal("", string(data))
}
func TestHorizontalBarRender(t *testing.T) {
diff --git a/charts.go b/charts.go
index cd1ac2b..a2e0ec0 100644
--- a/charts.go
+++ b/charts.go
@@ -28,6 +28,7 @@ import (
)
const labelFontSize = 10
+const smallLabelFontSize = 8
const defaultDotWidth = 2.0
const defaultStrokeWidth = 2.0
diff --git a/echarts_test.go b/echarts_test.go
index 9c31286..4d50d9e 100644
--- a/echarts_test.go
+++ b/echarts_test.go
@@ -578,5 +578,5 @@ func TestRenderEChartsToSVG(t *testing.T) {
]
}`)
assert.Nil(err)
- assert.Equal("", string(data))
+ assert.Equal("", string(data))
}
diff --git a/mark_point.go b/mark_point.go
index 3d43a73..014b17f 100644
--- a/mark_point.go
+++ b/mark_point.go
@@ -24,6 +24,7 @@ package charts
import (
"github.com/golang/freetype/truetype"
+ "github.com/wcharczuk/go-chart/v2/drawing"
)
func NewMarkPoint(markPointTypes ...string) SeriesMarkPoint {
@@ -63,7 +64,6 @@ func NewMarkPointPainter(p *Painter) *markPointPainter {
func (m *markPointPainter) Render() (Box, error) {
painter := m.p
- theme := m.p.theme
for _, opt := range m.options {
s := opt.Series
if len(s.MarkPoint.Data) == 0 {
@@ -75,15 +75,23 @@ func (m *markPointPainter) Render() (Box, error) {
if symbolSize == 0 {
symbolSize = 30
}
- painter.OverrideDrawingStyle(Style{
- FillColor: opt.FillColor,
- }).OverrideTextStyle(Style{
- FontColor: theme.GetTextColor(),
+ textStyle := Style{
+ FontColor: drawing.Color{
+ R: 238,
+ G: 238,
+ B: 238,
+ A: 255,
+ },
FontSize: labelFontSize,
StrokeWidth: 1,
Font: opt.Font,
- })
+ }
+ painter.OverrideDrawingStyle(Style{
+ FillColor: opt.FillColor,
+ }).OverrideTextStyle(textStyle)
for _, markPointData := range s.MarkPoint.Data {
+ textStyle.FontSize = labelFontSize
+ painter.OverrideTextStyle(textStyle)
p := points[summary.MinIndex]
value := summary.MinValue
switch markPointData.Type {
@@ -95,6 +103,11 @@ func (m *markPointPainter) Render() (Box, error) {
painter.Pin(p.X, p.Y-symbolSize>>1, symbolSize)
text := commafWithDigits(value)
textBox := painter.MeasureText(text)
+ if textBox.Width() > symbolSize {
+ textStyle.FontSize = smallLabelFontSize
+ painter.OverrideTextStyle(textStyle)
+ textBox = painter.MeasureText(text)
+ }
painter.Text(text, p.X-textBox.Width()>>1, p.Y-symbolSize>>1-2)
}
}
diff --git a/mark_point_test.go b/mark_point_test.go
index 1a810cf..ffa01a7 100644
--- a/mark_point_test.go
+++ b/mark_point_test.go
@@ -69,7 +69,7 @@ func TestMarkPoint(t *testing.T) {
}
return p.Bytes()
},
- result: "",
+ result: "",
},
}