@@ -15,7 +15,9 @@ import (
1515 "github.com/grafana/grafana-foundation-sdk/go/table"
1616 "github.com/grafana/grafana-foundation-sdk/go/text"
1717 "github.com/grafana/grafana-foundation-sdk/go/timeseries"
18+
1819 "github.com/smartcontractkit/chainlink-common/observability-lib/grafana/businessvariable"
20+ "github.com/smartcontractkit/chainlink-common/observability-lib/grafana/polystat"
1921)
2022
2123type QueryType string
@@ -180,6 +182,7 @@ type Panel struct {
180182 textPanelBuilder * text.PanelBuilder
181183 histogramPanelBuilder * histogram.PanelBuilder
182184 businessVariablePanelBuilder * businessvariable.PanelBuilder
185+ polystatPanelBuilder * polystat.PanelBuilder
183186 alertBuilders []* alerting.RuleBuilder
184187}
185188
@@ -437,7 +440,7 @@ func NewTimeSeriesPanel(options *TimeSeriesPanelOptions) *Panel {
437440 }
438441
439442 var alertBuilders []* alerting.RuleBuilder
440- if options . AlertsOptions != nil && len (options .AlertsOptions ) > 0 {
443+ if len (options .AlertsOptions ) > 0 {
441444 for _ , alert := range options .AlertsOptions {
442445 // this is used as an internal mechanism to set the panel title in the alert to associate panelId with alert
443446 alert .PanelTitle = * options .Title
@@ -1092,3 +1095,126 @@ func NewBusinessVariablePanel(options *BusinessVariablePanelOptions) *Panel {
10921095 businessVariablePanelBuilder : newPanel ,
10931096 }
10941097}
1098+
1099+ type PolystatPanelOptions struct {
1100+ * PanelOptions
1101+ Queries []Query
1102+ OperatorName polystat.OperatorName
1103+ PolygonGlobalFillColor string
1104+ PolygonSize polystat.PolygonSize
1105+ Columns * int
1106+ Rows * int
1107+ DisplayLimit * int
1108+ DefaultClickThrough string
1109+ DefaultClickThroughNewTab bool
1110+ DefaultClickThroughSanitize bool
1111+ AnimationSpeed * int
1112+ Radius string
1113+ TooltipDisplayMode string
1114+ TooltipPrimarySortBy polystat.SortByField
1115+ TooltipPrimarySortDirection polystat.SortByDirection
1116+ TooltipSecondarySortBy polystat.SortByField
1117+ TooltipSecondarySortDirection polystat.SortByDirection
1118+ GlobalUnitFormat string
1119+ GlobalDecimals * int
1120+ GlobalDisplayMode string
1121+ GlobalDisplayTextTriggeredEmpty string
1122+ GlobalThresholds []polystat.Threshold
1123+ }
1124+
1125+ func NewPolystatPanel (options * PolystatPanelOptions ) * Panel {
1126+ setDefaults (options .PanelOptions )
1127+
1128+ newPanel := polystat .NewPanelBuilder ().
1129+ Datasource (datasourceRef (options .Datasource )).
1130+ Title (* options .Title ).
1131+ Description (options .Description ).
1132+ Transparent (options .Transparent ).
1133+ Span (options .Span ).
1134+ Height (options .Height ).
1135+ OperatorName (options .OperatorName )
1136+
1137+ if options .PolygonGlobalFillColor != "" {
1138+ newPanel .PolygonGlobalFillColor (options .PolygonGlobalFillColor )
1139+ }
1140+
1141+ if options .PolygonSize != 0 {
1142+ newPanel .PolygonSize (options .PolygonSize )
1143+ }
1144+
1145+ if options .Columns != nil {
1146+ newPanel .Columns (* options .Columns )
1147+ }
1148+
1149+ if options .Rows != nil {
1150+ newPanel .Rows (* options .Rows )
1151+ }
1152+
1153+ if options .DisplayLimit != nil {
1154+ newPanel .DisplayLimit (* options .DisplayLimit )
1155+ }
1156+
1157+ if options .DefaultClickThrough != "" {
1158+ newPanel .DefaultClickThrough (options .DefaultClickThrough )
1159+ }
1160+
1161+ newPanel .DefaultClickThroughNewTab (options .DefaultClickThroughNewTab )
1162+
1163+ newPanel .DefaultClickThroughSanitize (options .DefaultClickThroughSanitize )
1164+
1165+ if options .AnimationSpeed != nil {
1166+ newPanel .AnimationSpeed (* options .AnimationSpeed )
1167+ }
1168+
1169+ if options .Radius != "" {
1170+ newPanel .Radius (options .Radius )
1171+ }
1172+
1173+ if options .TooltipDisplayMode != "" {
1174+ newPanel .TooltipDisplayMode (options .TooltipDisplayMode )
1175+ }
1176+
1177+ if options .TooltipPrimarySortBy != "" {
1178+ newPanel .TooltipPrimarySortBy (options .TooltipPrimarySortBy )
1179+ }
1180+
1181+ if options .TooltipPrimarySortDirection != "" {
1182+ newPanel .TooltipPrimarySortDirection (options .TooltipPrimarySortDirection )
1183+ }
1184+
1185+ if options .TooltipSecondarySortBy != "" {
1186+ newPanel .TooltipSecondarySortBy (options .TooltipSecondarySortBy )
1187+ }
1188+
1189+ if options .TooltipSecondarySortDirection != "" {
1190+ newPanel .TooltipSecondarySortDirection (options .TooltipSecondarySortDirection )
1191+ }
1192+
1193+ if options .GlobalUnitFormat != "" {
1194+ newPanel .GlobalUnitFormat (options .GlobalUnitFormat )
1195+ }
1196+
1197+ if options .GlobalDecimals != nil {
1198+ newPanel .GlobalDecimals (* options .GlobalDecimals )
1199+ }
1200+
1201+ if options .GlobalDisplayMode != "" {
1202+ newPanel .GlobalDisplayMode (options .GlobalDisplayMode )
1203+ }
1204+
1205+ if options .GlobalDisplayTextTriggeredEmpty != "" {
1206+ newPanel .GlobalDisplayTextTriggeredEmpty (options .GlobalDisplayTextTriggeredEmpty )
1207+ }
1208+
1209+ if len (options .GlobalThresholds ) > 0 {
1210+ newPanel .GlobalThresholds (options .GlobalThresholds )
1211+ }
1212+
1213+ for _ , query := range options .Queries {
1214+ newPanel .WithTarget (newQuery (query ))
1215+ }
1216+
1217+ return & Panel {
1218+ polystatPanelBuilder : newPanel ,
1219+ }
1220+ }
0 commit comments