refactor: adjust font size of mark point
This commit is contained in:
parent
4121829e6e
commit
92458aece2
7 changed files with 25 additions and 11 deletions
|
|
@ -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`.
|
||||
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -28,6 +28,7 @@ import (
|
|||
)
|
||||
|
||||
const labelFontSize = 10
|
||||
const smallLabelFontSize = 8
|
||||
const defaultDotWidth = 2.0
|
||||
const defaultStrokeWidth = 2.0
|
||||
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ func TestMarkPoint(t *testing.T) {
|
|||
}
|
||||
return p.Bytes()
|
||||
},
|
||||
result: "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"600\" height=\"400\">\\n<path d=\"M 67 62\nA 15 15 330.00 1 1 73 62\nL 70 48\nZ\" style=\"stroke-width:0;stroke:none;fill:rgba(0,0,0,1.0)\"/><path d=\"M 55 48\nQ70,85 85,48\nZ\" style=\"stroke-width:0;stroke:none;fill:rgba(0,0,0,1.0)\"/><text x=\"66\" y=\"53\" style=\"stroke-width:0;stroke:none;fill:rgba(70,70,70,1.0);font-size:12.8px;font-family:'Roboto Medium',sans-serif\">3</text></svg>",
|
||||
result: "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"600\" height=\"400\">\\n<path d=\"M 67 62\nA 15 15 330.00 1 1 73 62\nL 70 48\nZ\" style=\"stroke-width:0;stroke:none;fill:rgba(0,0,0,1.0)\"/><path d=\"M 55 48\nQ70,85 85,48\nZ\" style=\"stroke-width:0;stroke:none;fill:rgba(0,0,0,1.0)\"/><text x=\"66\" y=\"53\" style=\"stroke-width:0;stroke:none;fill:rgba(238,238,238,1.0);font-size:12.8px;font-family:'Roboto Medium',sans-serif\">3</text></svg>",
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue