Skip to content

Commit

Permalink
优化图表
Browse files Browse the repository at this point in the history
  • Loading branch information
CuteReimu committed May 16, 2024
1 parent 539a016 commit 3cf6573
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 21 deletions.
6 changes: 3 additions & 3 deletions maplebot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ image_expire_hours: 72

### 中文乱码问题

对于“洗魔方”功能,如遇Linux下中文乱码,请将**宋体**文件`simsun.ttc`放入`/usr/share/fonts`中,然后执行以下shell
对于“洗魔方”功能,如遇Linux下中文乱码,请将**黑体**文件`SIMHEI.TTF`放入`/usr/share/fonts`中,然后执行以下shell

```shell
# 刷新字体缓存
fc-cache
# 查看是否有宋体
fc-list :lang=zh | grep 宋体
# 查看是否有黑体
fc-list :lang=zh | grep 黑体
```
19 changes: 10 additions & 9 deletions maplebot/cube.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func calculateCubeAll() MessageChain {
styles[ss[i][0]] = append(styles[ss[i][0]], &Style{FillColor: drawing.Color{R: 255, G: 130, B: 171, A: 128}})
cost = red
} else {
styles[ss[i][0]] = append(styles[ss[i][0]], &Style{FillColor: drawing.Color{A: 128}})
styles[ss[i][0]] = append(styles[ss[i][0]], &Style{FillColor: drawing.Color{A: 32}})
cost = black
}
ss[i] = append(ss[i], formatInt64(cost))
Expand All @@ -188,8 +188,9 @@ func calculateCubeAll() MessageChain {
header = append(header, target)
}
p, err := TableOptionRender(TableChartOption{
Header: header,
Data: ss,
Header: header,
Data: ss,
HeaderFontColor: Color{R: 35, G: 35, B: 35, A: 255},
CellStyle: func(cell TableCell) *Style {
if cell.Column > 0 && cell.Row > 0 && len(cell.Text) > 0 {
return styles[ss[cell.Row-1][0]][cell.Column-1]
Expand Down Expand Up @@ -223,7 +224,7 @@ func calculateCube(s string) MessageChain {
styles = append(styles, &Style{FillColor: drawing.Color{R: 255, G: 130, B: 171, A: 128}})
eToLCost = eToLR
} else {
styles = append(styles, &Style{FillColor: drawing.Color{A: 128}})
styles = append(styles, &Style{FillColor: drawing.Color{A: 32}})
eToLCost = eToLB
}
ss := make([][]string, 0, len(selections)+1)
Expand All @@ -236,7 +237,7 @@ func calculateCube(s string) MessageChain {
styles = append(styles, &Style{FillColor: drawing.Color{R: 255, G: 130, B: 171, A: 128}})
cost = red
} else {
styles = append(styles, &Style{FillColor: drawing.Color{A: 128}})
styles = append(styles, &Style{FillColor: drawing.Color{A: 32}})
cost = black
}
var target string
Expand All @@ -247,9 +248,10 @@ func calculateCube(s string) MessageChain {
ss = append(ss, []string{target, formatInt64(cost)})
}
p, err := TableOptionRender(TableChartOption{
Width: 400,
Header: []string{fmt.Sprintf("%d级%s", nameLevel.level, s), "(底色表示魔方颜色)"},
Data: ss,
Width: 400,
Header: []string{fmt.Sprintf("%d级%s", nameLevel.level, s), "(底色表示魔方颜色)"},
Data: ss,
HeaderFontColor: Color{R: 35, G: 35, B: 35, A: 255},
CellStyle: func(cell TableCell) *Style {
if cell.Column > 0 && cell.Row > 0 && len(cell.Text) > 0 {
return styles[cell.Row-1]
Expand Down Expand Up @@ -279,7 +281,6 @@ func init() {
if err := json.Unmarshal(cubeRatesJson, &cubeRates); err != nil {
panic(err)
}
SetDefaultTableSetting(TableDarkThemeSetting)
}

var cubeCost = map[string]int64{
Expand Down
18 changes: 17 additions & 1 deletion maplebot/find_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,27 @@ func findRole(name string) MessageChain {
maxValue = math.Ceil(maxValue/factor) * factor * 6
p, err := BarRender(
[][]float64{values},
ThemeOptionFunc(ThemeDark),
PaddingOptionFunc(Box{Top: 30, Left: 10, Right: 54, Bottom: 10}),
XAxisDataOptionFunc(labels),
MarkLineOptionFunc(0, SeriesMarkDataTypeAverage),
MarkPointOptionFunc(0, SeriesMarkDataTypeMax, SeriesMarkDataTypeMin),
YAxisOptionFunc(YAxisOption{Min: NewFloatPoint(0), Max: &maxValue}),
func(opt *ChartOption) {
opt.ValueFormatter = func(f float64) string {
switch {
case f < 1000.0:
return fmt.Sprintf("%.0f", f)
case f < 1000000.0:
return fmt.Sprintf("%.0fK", float64(f)/1000.0)
case f < 1000000000.0:
return fmt.Sprintf("%.0fM", float64(f)/1000000.0)
case f < 1000000000000.0:
return fmt.Sprintf("%.0fB", float64(f)/1000000000.0)
default:
return fmt.Sprintf("%.0fT", float64(f)/1000000000000.0)
}
}
},
)
if err != nil {
slog.Error("render chart failed", "error", err)
Expand Down
6 changes: 3 additions & 3 deletions maplebot/font.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func init() {
if err != nil {
return err
}
if filepath.Base(path) == "simsun.ttc" {
if filepath.Base(path) == "SIMHEI.TTF" {
fontFilePath = path
return filepath.SkipAll
}
Expand All @@ -45,11 +45,11 @@ func init() {
slog.Warn("Failed to read font file.", "err", err)
return
}
err = InstallFont("simsun", fontBytes)
err = InstallFont("simhei", fontBytes)
if err != nil {
slog.Warn("Failed to install font.", "err", err)
return
}
font, _ := GetFont("simsun")
font, _ := GetFont("simhei")
SetDefaultFont(font)
}
6 changes: 1 addition & 5 deletions maplebot/star_force.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ func calculateStarForce1(content string) MessageChain {
s += fmt.Sprintf(",平均花费了%s金币,平均炸了%s次,平均点了%s次", data...)
image := drawStarForce(cur, des, itemLevel, boomProtect, thirtyOff, fiveTenFifteen, mesos/float64(testCount), testCount)
if image != nil {
s += "\n花费分布图:\n"
return MessageChain{&Plain{Text: s}, image}
}
return MessageChain{&Plain{Text: s}}
Expand Down Expand Up @@ -294,7 +293,6 @@ func calculateStarForce2(itemLevel int, thirtyOff, fiveTenFifteen bool) MessageC
s += fmt.Sprintf(",平均花费了%s金币,平均炸了%s次,平均点了%s次", data...)
image := drawStarForce(0, des, itemLevel, boomProtect, thirtyOff, fiveTenFifteen, mesos22/1000, 1000)
if image != nil {
s += "\n花费分布图:\n"
return MessageChain{&Plain{Text: s}, image}
}
return MessageChain{&Plain{Text: s}}
Expand Down Expand Up @@ -356,9 +354,7 @@ func drawStarForce(cur, des, itemLevel int, boomProtect, thirtyOff, fiveTenFifte
}
p, err := PieRender(
values,
TitleOptionFunc(TitleOption{
Text: fmt.Sprintf("%d to %d Mesos cost", cur, des),
}),
PaddingOptionFunc(Box{Top: 50}),
LegendOptionFunc(LegendOption{
Show: FalseFlag(),
Data: labels,
Expand Down

0 comments on commit 3cf6573

Please # to comment.