master
go 255 lines 6.67 KB
Raw
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 package funcapi
4
5 import "encoding/json"
6
7 // FieldType defines the column data type used for rendering and alignment.
8 type FieldType uint8
9
10 const (
11 // FieldTypeNone uses no special type handling.
12 FieldTypeNone FieldType = iota
13 // FieldTypeInteger is for integer counts and metrics.
14 FieldTypeInteger
15 // FieldTypeFloat is for fractional metrics.
16 FieldTypeFloat
17 // FieldTypeBoolean is for true/false values.
18 FieldTypeBoolean
19 // FieldTypeString is for text and categorical values.
20 FieldTypeString
21 // FieldTypeDetailString is used when the UI expects the detail-string type.
22 FieldTypeDetailString
23 // FieldTypeBarWithInteger is for progress-style values; set Max for bars.
24 FieldTypeBarWithInteger
25 // FieldTypeDuration is for duration values paired with a duration transform.
26 FieldTypeDuration
27 // FieldTypeTimestamp is for epoch timestamps paired with datetime transforms.
28 FieldTypeTimestamp
29 // FieldTypeArray is for array values.
30 FieldTypeArray
31 // FieldTypeFeedTemplate is for feed template rows.
32 FieldTypeFeedTemplate
33 )
34
35 // String returns the UI keyword used for this field type.
36 func (t FieldType) String() string {
37 switch t {
38 case FieldTypeInteger:
39 return "integer"
40 case FieldTypeFloat:
41 return "float"
42 case FieldTypeBoolean:
43 return "boolean"
44 case FieldTypeString:
45 return "string"
46 case FieldTypeDetailString:
47 return "detail-string"
48 case FieldTypeBarWithInteger:
49 return "bar-with-integer"
50 case FieldTypeDuration:
51 return "duration"
52 case FieldTypeTimestamp:
53 return "timestamp"
54 case FieldTypeArray:
55 return "array"
56 case FieldTypeFeedTemplate:
57 return "feedTemplate"
58 default:
59 return "none"
60 }
61 }
62
63 // MarshalJSON encodes the field type as a UI keyword.
64 func (t FieldType) MarshalJSON() ([]byte, error) {
65 return json.Marshal(t.String())
66 }
67
68 // FieldVisual defines how values are rendered in the UI.
69 type FieldVisual uint8
70
71 const (
72 // FieldVisualValue renders plain values.
73 FieldVisualValue FieldVisual = iota
74 // FieldVisualBar renders values as bars.
75 FieldVisualBar
76 // FieldVisualPill renders values as pills for categories/status.
77 FieldVisualPill
78 // FieldVisualRichValue selects the richValue visualization.
79 FieldVisualRichValue
80 // FieldVisualFeedTemplate selects the feedTemplate visualization.
81 FieldVisualFeedTemplate
82 // FieldVisualRowOptions selects the rowOptions visualization.
83 FieldVisualRowOptions
84 )
85
86 // String returns the UI keyword used for this visualization.
87 func (v FieldVisual) String() string {
88 switch v {
89 case FieldVisualBar:
90 return "bar"
91 case FieldVisualPill:
92 return "pill"
93 case FieldVisualRichValue:
94 return "richValue"
95 case FieldVisualFeedTemplate:
96 return "feedTemplate"
97 case FieldVisualRowOptions:
98 return "rowOptions"
99 default:
100 return "value"
101 }
102 }
103
104 // MarshalJSON encodes the visualization as a UI keyword.
105 func (v FieldVisual) MarshalJSON() ([]byte, error) {
106 return json.Marshal(v.String())
107 }
108
109 // FieldTransform defines how raw values are formatted for display.
110 type FieldTransform uint8
111
112 const (
113 // FieldTransformNone leaves values unformatted.
114 FieldTransformNone FieldTransform = iota
115 // FieldTransformNumber formats numbers and respects DecimalPoints.
116 FieldTransformNumber
117 // FieldTransformDuration formats duration values.
118 FieldTransformDuration
119 // FieldTransformDatetime formats millisecond timestamps (simple tables).
120 FieldTransformDatetime
121 // FieldTransformDatetimeUsec formats microsecond timestamps (log explorers).
122 FieldTransformDatetimeUsec
123 // FieldTransformText selects the text transform.
124 FieldTransformText
125 // FieldTransformXML selects the xml transform.
126 FieldTransformXML
127 )
128
129 // String returns the UI keyword used for this transform.
130 func (t FieldTransform) String() string {
131 switch t {
132 case FieldTransformNumber:
133 return "number"
134 case FieldTransformDuration:
135 return "duration"
136 case FieldTransformDatetime:
137 return "datetime"
138 case FieldTransformDatetimeUsec:
139 return "datetime_usec"
140 case FieldTransformText:
141 return "text"
142 case FieldTransformXML:
143 return "xml"
144 default:
145 return "none"
146 }
147 }
148
149 // MarshalJSON encodes the transform as a UI keyword.
150 func (t FieldTransform) MarshalJSON() ([]byte, error) {
151 return json.Marshal(t.String())
152 }
153
154 // FieldSort defines the default sort direction for a column.
155 type FieldSort uint8
156
157 const (
158 // FieldSortAscending orders values from low to high.
159 FieldSortAscending FieldSort = iota
160 // FieldSortDescending orders values from high to low.
161 FieldSortDescending
162 )
163
164 // String returns the UI keyword used for this sort direction.
165 func (s FieldSort) String() string {
166 switch s {
167 case FieldSortDescending:
168 return "descending"
169 default:
170 return "ascending"
171 }
172 }
173
174 // MarshalJSON encodes the sort direction as a UI keyword.
175 func (s FieldSort) MarshalJSON() ([]byte, error) {
176 return json.Marshal(s.String())
177 }
178
179 // FieldSummary defines aggregation behavior when grouping rows.
180 type FieldSummary uint8
181
182 const (
183 // FieldSummaryCount counts rows in each group.
184 FieldSummaryCount FieldSummary = iota
185 // FieldSummaryUniqueCount counts unique values in each group.
186 FieldSummaryUniqueCount
187 // FieldSummarySum sums numeric values in each group.
188 FieldSummarySum
189 // FieldSummaryMin takes the minimum value in each group.
190 FieldSummaryMin
191 // FieldSummaryMax takes the maximum value in each group.
192 FieldSummaryMax
193 // FieldSummaryMean averages values in each group.
194 FieldSummaryMean
195 // FieldSummaryMedian takes the median value in each group.
196 FieldSummaryMedian
197 )
198
199 // String returns the UI keyword used for this summary.
200 func (s FieldSummary) String() string {
201 switch s {
202 case FieldSummaryUniqueCount:
203 return "uniqueCount"
204 case FieldSummarySum:
205 return "sum"
206 case FieldSummaryMin:
207 return "min"
208 case FieldSummaryMax:
209 return "max"
210 case FieldSummaryMean:
211 return "mean"
212 case FieldSummaryMedian:
213 return "median"
214 default:
215 return "count"
216 }
217 }
218
219 // MarshalJSON encodes the summary as a UI keyword.
220 func (s FieldSummary) MarshalJSON() ([]byte, error) {
221 return json.Marshal(s.String())
222 }
223
224 // FieldFilter defines the filter UI type for a column.
225 type FieldFilter uint8
226
227 const (
228 // FieldFilterNone disables filtering for the column.
229 FieldFilterNone FieldFilter = iota
230 // FieldFilterRange is for numeric ranges.
231 FieldFilterRange
232 // FieldFilterMultiselect is for categorical values.
233 FieldFilterMultiselect
234 // FieldFilterFacet enables faceted filters (log explorers).
235 FieldFilterFacet
236 )
237
238 // String returns the UI keyword used for this filter.
239 func (f FieldFilter) String() string {
240 switch f {
241 case FieldFilterRange:
242 return "range"
243 case FieldFilterMultiselect:
244 return "multiselect"
245 case FieldFilterFacet:
246 return "facet"
247 default:
248 return "none"
249 }
250 }
251
252 // MarshalJSON encodes the filter as a UI keyword.
253 func (f FieldFilter) MarshalJSON() ([]byte, error) {
254 return json.Marshal(f.String())
255 }