|
8 | 8 | "github.com/grafana/grafana-foundation-sdk/go/dashboard" |
9 | 9 | "github.com/grafana/grafana-foundation-sdk/go/gauge" |
10 | 10 | "github.com/grafana/grafana-foundation-sdk/go/heatmap" |
| 11 | + "github.com/grafana/grafana-foundation-sdk/go/histogram" |
11 | 12 | "github.com/grafana/grafana-foundation-sdk/go/logs" |
12 | 13 | "github.com/grafana/grafana-foundation-sdk/go/prometheus" |
13 | 14 | "github.com/grafana/grafana-foundation-sdk/go/stat" |
@@ -177,6 +178,7 @@ type Panel struct { |
177 | 178 | logPanelBuilder *logs.PanelBuilder |
178 | 179 | heatmapBuilder *heatmap.PanelBuilder |
179 | 180 | textPanelBuilder *text.PanelBuilder |
| 181 | + histogramPanelBuilder *histogram.PanelBuilder |
180 | 182 | businessVariablePanelBuilder *businessvariable.PanelBuilder |
181 | 183 | alertBuilders []*alerting.RuleBuilder |
182 | 184 | } |
@@ -895,6 +897,172 @@ func NewTextPanel(options *TextPanelOptions) *Panel { |
895 | 897 | } |
896 | 898 | } |
897 | 899 |
|
| 900 | +type HistogramPanelOptions struct { |
| 901 | + *PanelOptions |
| 902 | + LineWidth *float64 |
| 903 | + ScaleDistribution common.ScaleDistribution |
| 904 | + LegendOptions *LegendOptions |
| 905 | + ToolTipOptions *ToolTipOptions |
| 906 | + ThresholdStyle common.GraphThresholdsStyleMode |
| 907 | + DrawStyle common.GraphDrawStyle |
| 908 | + StackingMode common.StackingMode |
| 909 | + Combine *bool |
| 910 | + FillOpacity *uint32 |
| 911 | + BucketOffset *float32 |
| 912 | + BucketCount *int32 |
| 913 | + BucketSize *int32 |
| 914 | + AxisBorderShow *bool |
| 915 | + AxisLabel string |
| 916 | + AxisSoftMax *float64 |
| 917 | + AxisSoftMin *float64 |
| 918 | + AxisColorMode common.AxisColorMode |
| 919 | + AxisCenteredZero *bool |
| 920 | + AxisGridShow *bool |
| 921 | + AxisPlacement common.AxisPlacement |
| 922 | + AxisWidth *float64 |
| 923 | +} |
| 924 | + |
| 925 | +func NewHistogramPanel(options *HistogramPanelOptions) *Panel { |
| 926 | + setDefaults(options.PanelOptions) |
| 927 | + |
| 928 | + if options.ScaleDistribution == "" { |
| 929 | + options.ScaleDistribution = common.ScaleDistributionLinear |
| 930 | + } |
| 931 | + |
| 932 | + if options.LineWidth == nil { |
| 933 | + options.LineWidth = Pointer[float64](1) |
| 934 | + } |
| 935 | + |
| 936 | + if options.LegendOptions == nil { |
| 937 | + options.LegendOptions = &LegendOptions{} |
| 938 | + } |
| 939 | + |
| 940 | + if options.ToolTipOptions == nil { |
| 941 | + options.ToolTipOptions = &ToolTipOptions{} |
| 942 | + } |
| 943 | + |
| 944 | + if options.StackingMode == "" { |
| 945 | + options.StackingMode = common.StackingModeNone |
| 946 | + } |
| 947 | + |
| 948 | + newPanel := histogram.NewPanelBuilder(). |
| 949 | + Datasource(datasourceRef(options.Datasource)). |
| 950 | + Title(*options.Title). |
| 951 | + Description(options.Description). |
| 952 | + Transparent(options.Transparent). |
| 953 | + Span(options.Span). |
| 954 | + Height(options.Height). |
| 955 | + Unit(options.Unit). |
| 956 | + NoValue(options.NoValue). |
| 957 | + ScaleDistribution(common.NewScaleDistributionConfigBuilder(). |
| 958 | + Type(options.ScaleDistribution), |
| 959 | + ). |
| 960 | + Tooltip(newToolTip(options.ToolTipOptions)). |
| 961 | + Stacking(common.NewStackingConfigBuilder(). |
| 962 | + Mode(options.StackingMode), |
| 963 | + ) |
| 964 | + |
| 965 | + if options.Interval != "" { |
| 966 | + newPanel.Interval(options.Interval) |
| 967 | + } |
| 968 | + |
| 969 | + if options.Decimals != nil { |
| 970 | + newPanel.Decimals(*options.Decimals) |
| 971 | + } |
| 972 | + |
| 973 | + if options.Min != nil { |
| 974 | + newPanel.Min(*options.Min) |
| 975 | + } |
| 976 | + |
| 977 | + if options.Max != nil { |
| 978 | + newPanel.Max(*options.Max) |
| 979 | + } |
| 980 | + |
| 981 | + for _, q := range options.Query { |
| 982 | + newPanel.WithTarget(newQuery(q)) |
| 983 | + } |
| 984 | + |
| 985 | + if options.Threshold != nil { |
| 986 | + newPanel.Thresholds(newThresholds(options.Threshold)) |
| 987 | + } |
| 988 | + |
| 989 | + if options.Transforms != nil { |
| 990 | + for _, transform := range options.Transforms { |
| 991 | + newPanel.WithTransformation(newTransform(transform)) |
| 992 | + } |
| 993 | + } |
| 994 | + |
| 995 | + if options.Overrides != nil { |
| 996 | + for _, override := range options.Overrides { |
| 997 | + newPanel.WithOverride(newOverride(override)) |
| 998 | + } |
| 999 | + } |
| 1000 | + |
| 1001 | + if options.Combine != nil { |
| 1002 | + newPanel.Combine(*options.Combine) |
| 1003 | + } |
| 1004 | + |
| 1005 | + if options.ColorScheme != "" { |
| 1006 | + newPanel.ColorScheme(dashboard.NewFieldColorBuilder().Mode(options.ColorScheme)) |
| 1007 | + } |
| 1008 | + |
| 1009 | + if options.FillOpacity != nil { |
| 1010 | + newPanel.FillOpacity(*options.FillOpacity) |
| 1011 | + } |
| 1012 | + |
| 1013 | + if options.BucketOffset != nil { |
| 1014 | + newPanel.BucketOffset(*options.BucketOffset) |
| 1015 | + } |
| 1016 | + |
| 1017 | + if options.BucketCount != nil { |
| 1018 | + newPanel.BucketCount(*options.BucketCount) |
| 1019 | + } |
| 1020 | + |
| 1021 | + if options.BucketSize != nil { |
| 1022 | + newPanel.BucketSize(*options.BucketSize) |
| 1023 | + } |
| 1024 | + |
| 1025 | + if options.AxisBorderShow != nil { |
| 1026 | + newPanel.AxisBorderShow(*options.AxisBorderShow) |
| 1027 | + } |
| 1028 | + |
| 1029 | + if options.AxisLabel != "" { |
| 1030 | + newPanel.AxisLabel(options.AxisLabel) |
| 1031 | + } |
| 1032 | + |
| 1033 | + if options.AxisSoftMax != nil { |
| 1034 | + newPanel.AxisSoftMax(*options.AxisSoftMax) |
| 1035 | + } |
| 1036 | + |
| 1037 | + if options.AxisSoftMin != nil { |
| 1038 | + newPanel.AxisSoftMin(*options.AxisSoftMin) |
| 1039 | + } |
| 1040 | + |
| 1041 | + if options.AxisColorMode != "" { |
| 1042 | + newPanel.AxisColorMode(options.AxisColorMode) |
| 1043 | + } |
| 1044 | + |
| 1045 | + if options.AxisCenteredZero != nil { |
| 1046 | + newPanel.AxisCenteredZero(*options.AxisCenteredZero) |
| 1047 | + } |
| 1048 | + |
| 1049 | + if options.AxisGridShow != nil { |
| 1050 | + newPanel.AxisGridShow(*options.AxisGridShow) |
| 1051 | + } |
| 1052 | + |
| 1053 | + if options.AxisPlacement != "" { |
| 1054 | + newPanel.AxisPlacement(options.AxisPlacement) |
| 1055 | + } |
| 1056 | + |
| 1057 | + if options.AxisWidth != nil { |
| 1058 | + newPanel.AxisWidth(*options.AxisWidth) |
| 1059 | + } |
| 1060 | + |
| 1061 | + return &Panel{ |
| 1062 | + histogramPanelBuilder: newPanel, |
| 1063 | + } |
| 1064 | +} |
| 1065 | + |
898 | 1066 | type BusinessVariablePanelOptions struct { |
899 | 1067 | *PanelOptions |
900 | 1068 | DisplayMode businessvariable.DisplayMode |
|
0 commit comments