Browse Source

Merge branch 'ETA_1.9.0'

zwxi 8 months ago
parent
commit
4edc0d3497
2 changed files with 131 additions and 0 deletions
  1. 85 0
      models/tables/chart_theme/chart_theme.go
  2. 46 0
      services/chart/chart_theme.go

+ 85 - 0
models/tables/chart_theme/chart_theme.go

@@ -48,3 +48,88 @@ var ChartThemeColumns = struct {
 	ModifyTime:       "modify_time",
 	CreateTime:       "create_time",
 }
+
+
+type ColorsOptions []string
+
+type LegendOptions struct {
+	VerticalAlign string `json:"verticalAlign"`
+	ItemStyle     struct {
+		Color        string `json:"color"`
+		FontSize     int    `json:"fontSize"`
+		Cursor       string `json:"cursor"`
+		FontWeight   string `json:"fontWeight"`
+		TextOverflow string `json:"textOverflow"`
+	} `json:"itemStyle"`
+}
+
+type TitleOptions struct {
+	Align string `json:"align"`
+	Style struct {
+		Color    string `json:"color"`
+		FontSize int    `json:"fontSize"`
+	} `json:"style"`
+}
+
+type MarkerOptions struct {
+	Style struct {
+		Color    string `json:"color"`
+		FontSize int    `json:"fontSize"`
+	} `json:"style"`
+}
+
+type AxisOptions struct {
+	Style struct {
+		Color    string `json:"color"`
+		FontSize int    `json:"fontSize"`
+	} `json:"style"`
+}
+
+type DrawOption struct {
+	PlotBackgroundColor string `json:"plotBackgroundColor"`
+}
+
+type LineOptions struct {
+	DashStyle string  `json:"dashStyle"`
+	LineWidth int     `json:"lineWidth"`
+	LineType  string  `json:"lineType"`
+	Radius    float64 `json:"radius"`
+}
+
+type OldChartOptions struct {
+	ColorsOptions  []string         `json:"colorsOptions"`
+	LineOptions    LineOptions      `json:"lineOptions"`
+	LegendOptions  interface{}      `json:"legendOptions"`
+	TitleOptions   interface{}      `json:"titleOptions"`
+	MarkerOptions  interface{}      `json:"markerOptions"`
+	XAxisOptions   interface{}      `json:"xAxisOptions"`
+	YAxisOptions   interface{}      `json:"yAxisOptions"`
+	DrawOption     interface{}      `json:"drawOption"`
+	LineOptionList []LineStyleOptions `json:"lineOptionList"`
+}
+
+type NewChartOptions struct {
+	OldChartOptions
+	LineOptionList []NewLineOptions `json:"lineOptionList"`
+}
+
+type NewLineOptions struct {
+	LineOptions
+	Color     string `json:"color"`
+	DataMark  string `json:"dataMark"`
+	MarkType  string `json:"markType"`
+	MarkSize  int    `json:"markSize"`
+	MarkColor string `json:"markColor"`
+}
+
+type LineStyleOptions struct {
+	DashStyle string `json:"dashStyle"`
+	Color     string `json:"color"`
+	LineWidth int    `json:"lineWidth"`
+	LineType  string `json:"lineType"`
+	Radius    int `json:"radius"`
+	DataMark  string `json:"dataMark"`
+	MarkType  string `json:"markType"`
+	MarkSize  int `json:"markSize"`
+	MarkColor string `json:"markColor"`
+}

+ 46 - 0
services/chart/chart_theme.go

@@ -1,6 +1,7 @@
 package chart
 
 import (
+	"encoding/json"
 	"hongze/hongze_yb/models/tables/chart_theme"
 	"hongze/hongze_yb/models/tables/chart_theme_type"
 	"hongze/hongze_yb/utils"
@@ -23,6 +24,11 @@ func GetChartThemeConfig(chartThemeId, source, chartType int) (chartTheme *chart
 
 	// 如果找到了,那么就返回
 	if err == nil {
+		// 兼容历史数据,加入新字段LineOptionList
+		newConfig, e := ConvertOldChartOptions(chartTheme.Config)
+		if e == nil {
+			chartTheme.Config = newConfig
+		}
 		return
 	}
 
@@ -46,11 +52,51 @@ func GetChartThemeConfig(chartThemeId, source, chartType int) (chartTheme *chart
 
 	// 如果找到了,那么就返回
 	if chartTheme != nil {
+		// 兼容历史数据,加入新字段LineOptionList
+		newConfig, e := ConvertOldChartOptions(chartTheme.Config)
+		if e == nil {
+			chartTheme.Config = newConfig
+		}
 		return
 	}
 
 	// 如果还是没找到,那就系统的主题id
 	chartTheme, err = chart_theme.GetSystemChartTheme(chartThemeType.ChartThemeTypeID)
 
+	// 兼容历史数据,加入新字段LineOptionList
+	newConfig, e := ConvertOldChartOptions(chartTheme.Config)
+	if e == nil {
+		chartTheme.Config = newConfig
+	}
+	return
+}
+
+// 兼容历史数据,加入新字段LineOptionList
+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
 }