github.com/perses/shared/cue@v0.55.0

common/format.cue raw

 1// Copyright The Perses Authors
 2// Licensed under the Apache License, Version 2.0 (the "License");
 3// you may not use this file except in compliance with the License.
 4// You may obtain a copy of the License at
 5//
 6// http://www.apache.org/licenses/LICENSE-2.0
 7//
 8// Unless required by applicable law or agreed to in writing, software
 9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
13
14package common
15
16import "strings"
17
18// Shared optional fields once; unit is refined by each format branch.
19#format: {
20	unit?: string
21	// Optional display override (axis / legend / tooltip). unit stays the stable key.
22	customLabel?: strings.MinRunes(1)
23	#simpleFormat | #floatFormat | #shortenableFormat
24}
25
26#simpleFormat: {
27	unit?: #dateFormat.unit
28}
29
30#floatFormat: {
31	unit?:          #timeFormat.unit | #percentFormat.unit | #currencyFormat.unit | #temperatureFormat.unit
32	decimalPlaces?: number
33}
34
35#shortenableFormat: {
36	unit?:          #decimalFormat.unit | #bitsFormat.unit | #bytesFormat.unit | #throughputFormat.unit
37	decimalPlaces?: number
38	shortValues?:   bool
39}
40
41#timeFormat: {
42	unit:          "nanoseconds" | "microseconds" | "milliseconds" | "seconds" | "minutes" | "hours" | "days" | "weeks" | "months" | "years"
43	decimalPlaces?: number
44}
45
46#percentFormat: {
47	unit:          "percent" | "percent-decimal"
48	decimalPlaces?: number
49}
50
51#decimalFormat: {
52	unit:          "decimal"
53	decimalPlaces?: number
54	shortValues?:   bool
55}
56
57#bitsFormat: {
58	unit:          "bits" | "decbits"
59	decimalPlaces?: number
60	shortValues?:   bool
61}
62
63#bytesFormat: {
64	unit:          "bytes" | "decbytes"
65	decimalPlaces?: number
66	shortValues?:   bool
67}
68
69#throughputFormat: {
70	unit:          "bits/sec" | "decbits/sec" | "bytes/sec" | "decbytes/sec" | "counts/sec" | "events/sec" | "messages/sec" | "ops/sec" | "packets/sec" | "reads/sec" | "records/sec" | "requests/sec" | "rows/sec" | "writes/sec"
71	decimalPlaces?: number
72	shortValues?:   bool
73}
74
75#currencyFormat: {
76	unit:          "aud" | "cad" | "chf" | "cny" | "eur" | "gbp" | "hkd" | "inr" | "jpy" | "krw" | "nok" | "nzd" | "sek" | "sgd" | "usd"
77	decimalPlaces?: number
78}
79
80#temperatureFormat: {
81	unit: "celsius" | "fahrenheit"
82	decimalPlaces?: number
83}
84
85#dateFormat: {
86	unit: "datetime-iso" | "datetime-us" | "datetime-local" | "date-iso" | "date-us" | "date-local" | "time-local" | "time-iso" | "time-us" | "relative-time" | "unix-timestamp" | "unix-timestamp-ms"
87}