123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- package chart
- import (
- "encoding/json"
- "hongze/hongze_yb/models/tables/chart_theme"
- "hongze/hongze_yb/models/tables/chart_theme_type"
- "hongze/hongze_yb/utils"
- )
- func GetChartThemeConfig(chartThemeId, source, chartType int) (chartTheme *chart_theme.ChartTheme, err error) {
- chartTheme, err = chart_theme.GetChartThemeId(chartThemeId)
- if err != nil && err != utils.ErrNoRow {
- return
- }
-
- if err == nil {
-
- newConfig, e := ConvertOldChartOptions(chartTheme.Config)
- if e == nil {
- chartTheme.Config = newConfig
- }
- return
- }
- err = nil
-
-
- chartThemeType, err := chart_theme_type.GetChartThemeTypeByChartTypeAndSource(chartType, source)
- if err != nil {
- return
- }
-
- chartTheme, err = chart_theme.GetChartThemeId(chartThemeType.DefaultChartThemeID)
- if err != nil && err != utils.ErrNoRow {
- return
- }
- err = nil
-
- if chartTheme != nil {
-
- newConfig, e := ConvertOldChartOptions(chartTheme.Config)
- if e == nil {
- chartTheme.Config = newConfig
- }
- return
- }
-
- chartTheme, err = chart_theme.GetSystemChartTheme(chartThemeType.ChartThemeTypeID)
-
- newConfig, e := ConvertOldChartOptions(chartTheme.Config)
- if e == nil {
- chartTheme.Config = newConfig
- }
- return
- }
- func ConvertOldChartOptions(config string) (newConfig string, err error) {
- var oldTheme chart_theme.OldChartOptions
- var newTheme chart_theme.NewChartOptions
- err = json.Unmarshal([]byte(config), &oldTheme)
- if err != nil {
- return
- }
- if oldTheme.LineOptionList != nil && len(oldTheme.LineOptionList) > 0 {
- newConfig = config
- return
- }
- newTheme.OldChartOptions = oldTheme
- for i := 0; i < 10; i++ {
- newLineOption := chart_theme.NewLineOptions{
- LineOptions: oldTheme.LineOptions,
- Color: oldTheme.ColorsOptions[i],
- DataMark: "none",
- MarkType: "square",
- MarkSize: 5,
- MarkColor: oldTheme.ColorsOptions[i],
- }
- newTheme.LineOptionList = append(newTheme.LineOptionList, newLineOption)
- }
- newThemeStr, _ := json.Marshal(newTheme)
- newConfig = string(newThemeStr)
- return
- }
|