All checks were successful
continuous-integration/drone/push Build is passing
42 lines
1.2 KiB
Go
42 lines
1.2 KiB
Go
package handler
|
|
|
|
import "encoding/json"
|
|
|
|
type lineChartConfig struct {
|
|
Height int `json:"height,omitempty"`
|
|
XTicks int `json:"xTicks,omitempty"`
|
|
YTicks int `json:"yTicks,omitempty"`
|
|
YLabel string `json:"yLabel,omitempty"`
|
|
XLabel string `json:"xLabel,omitempty"`
|
|
Labels []string `json:"labels"`
|
|
TickLabels []string `json:"tickLabels,omitempty"`
|
|
Series []lineChartSeries `json:"series"`
|
|
HoverRows []lineChartHoverRow `json:"hoverRows,omitempty"`
|
|
}
|
|
|
|
type lineChartSeries struct {
|
|
Name string `json:"name"`
|
|
Color string `json:"color"`
|
|
Values []float64 `json:"values"`
|
|
Dash []float64 `json:"dash,omitempty"`
|
|
LineWidth float64 `json:"lineWidth,omitempty"`
|
|
TooltipFormat string `json:"tooltipFormat,omitempty"`
|
|
TooltipHidden bool `json:"tooltipHidden,omitempty"`
|
|
}
|
|
|
|
type lineChartHoverRow struct {
|
|
Name string `json:"name"`
|
|
Values []string `json:"values"`
|
|
}
|
|
|
|
func encodeLineChartConfig(cfg lineChartConfig) string {
|
|
if len(cfg.Labels) == 0 || len(cfg.Series) == 0 {
|
|
return ""
|
|
}
|
|
out, err := json.Marshal(cfg)
|
|
if err != nil {
|
|
return ""
|
|
}
|
|
return string(out)
|
|
}
|