@perses-dev/core 0.0.0-snapshot-panel-extra-content-3-17f9c42 → 0.0.0-snapshot-scatterplot-fix-imports-95e1b59

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (190) hide show
  1. package/dist/cjs/constants/dashboard-defaults.js +6 -2
  2. package/dist/cjs/constants/dialog.js +3 -1
  3. package/dist/cjs/constants/index.js +11 -9
  4. package/dist/cjs/index.js +12 -10
  5. package/dist/cjs/model/calculations.js +61 -51
  6. package/dist/cjs/model/ephemeraldashboard.js +16 -0
  7. package/dist/cjs/model/http-proxy.js +16 -0
  8. package/dist/cjs/model/index.js +35 -26
  9. package/dist/cjs/model/kind.js +39 -0
  10. package/dist/cjs/model/legend.js +39 -19
  11. package/dist/cjs/model/resource.js +9 -0
  12. package/dist/cjs/model/rolebindings.js +16 -0
  13. package/dist/cjs/model/roles.js +60 -0
  14. package/dist/cjs/model/secrets.js +16 -0
  15. package/dist/cjs/model/time-series-queries.js +3 -1
  16. package/dist/cjs/model/time.js +151 -65
  17. package/dist/cjs/model/trace-data.js +16 -0
  18. package/dist/cjs/model/units/bytes.js +37 -25
  19. package/dist/cjs/model/units/constants.js +3 -1
  20. package/dist/cjs/model/units/decimal.js +22 -16
  21. package/dist/cjs/model/units/index.js +13 -11
  22. package/dist/cjs/model/units/percent.js +26 -19
  23. package/dist/cjs/model/units/throughput.js +113 -0
  24. package/dist/cjs/model/units/time.js +99 -38
  25. package/dist/cjs/model/units/types.js +5 -2
  26. package/dist/cjs/model/units/units.js +81 -45
  27. package/dist/cjs/model/units/utils.js +13 -7
  28. package/dist/cjs/model/variables.js +16 -3
  29. package/dist/cjs/utils/event.js +3 -1
  30. package/dist/cjs/utils/fetch.js +32 -7
  31. package/dist/cjs/utils/index.js +17 -14
  32. package/dist/cjs/utils/is-empty-object.js +3 -1
  33. package/dist/cjs/utils/mathjs.js +4 -2
  34. package/dist/cjs/utils/memo.js +10 -6
  35. package/dist/cjs/utils/panel-refs.js +9 -3
  36. package/dist/cjs/utils/text.js +33 -21
  37. package/dist/cjs/utils/time-series-data.js +21 -11
  38. package/dist/cjs/utils/types.js +16 -0
  39. package/dist/constants/dashboard-defaults.js.map +1 -1
  40. package/dist/constants/dialog.js.map +1 -1
  41. package/dist/constants/index.js.map +1 -1
  42. package/dist/index.js.map +1 -1
  43. package/dist/model/calculations.d.ts +12 -12
  44. package/dist/model/calculations.d.ts.map +1 -1
  45. package/dist/model/calculations.js +46 -46
  46. package/dist/model/calculations.js.map +1 -1
  47. package/dist/model/dashboard.js.map +1 -1
  48. package/dist/model/datasource.d.ts +17 -3
  49. package/dist/model/datasource.d.ts.map +1 -1
  50. package/dist/model/datasource.js +3 -1
  51. package/dist/model/datasource.js.map +1 -1
  52. package/dist/model/definitions.d.ts +1 -1
  53. package/dist/model/definitions.d.ts.map +1 -1
  54. package/dist/model/definitions.js +3 -0
  55. package/dist/model/definitions.js.map +1 -1
  56. package/dist/model/display.d.ts +1 -1
  57. package/dist/model/display.d.ts.map +1 -1
  58. package/dist/model/display.js.map +1 -1
  59. package/dist/model/ephemeraldashboard.d.ts +15 -0
  60. package/dist/model/ephemeraldashboard.d.ts.map +1 -0
  61. package/dist/model/ephemeraldashboard.js +15 -0
  62. package/dist/model/ephemeraldashboard.js.map +1 -0
  63. package/dist/model/http-proxy.d.ts +16 -0
  64. package/dist/model/http-proxy.d.ts.map +1 -0
  65. package/dist/model/http-proxy.js +15 -0
  66. package/dist/model/http-proxy.js.map +1 -0
  67. package/dist/model/http.d.ts +1 -1
  68. package/dist/model/http.d.ts.map +1 -1
  69. package/dist/model/index.d.ts +7 -0
  70. package/dist/model/index.d.ts.map +1 -1
  71. package/dist/model/index.js +7 -0
  72. package/dist/model/index.js.map +1 -1
  73. package/dist/model/kind.d.ts +3 -0
  74. package/dist/model/kind.d.ts.map +1 -0
  75. package/dist/model/kind.js +31 -0
  76. package/dist/model/kind.js.map +1 -0
  77. package/dist/model/layout.d.ts +1 -1
  78. package/dist/model/layout.d.ts.map +1 -1
  79. package/dist/model/layout.js.map +1 -1
  80. package/dist/model/legend.d.ts +9 -9
  81. package/dist/model/legend.d.ts.map +1 -1
  82. package/dist/model/legend.js +9 -9
  83. package/dist/model/legend.js.map +1 -1
  84. package/dist/model/panels.d.ts +5 -2
  85. package/dist/model/panels.d.ts.map +1 -1
  86. package/dist/model/panels.js +3 -1
  87. package/dist/model/panels.js.map +1 -1
  88. package/dist/model/project.js.map +1 -1
  89. package/dist/model/query.d.ts +15 -2
  90. package/dist/model/query.d.ts.map +1 -1
  91. package/dist/model/query.js +4 -1
  92. package/dist/model/query.js.map +1 -1
  93. package/dist/model/resource.d.ts +3 -2
  94. package/dist/model/resource.d.ts.map +1 -1
  95. package/dist/model/resource.js +3 -1
  96. package/dist/model/resource.js.map +1 -1
  97. package/dist/model/rolebindings.d.ts +27 -0
  98. package/dist/model/rolebindings.d.ts.map +1 -0
  99. package/dist/model/rolebindings.js +15 -0
  100. package/dist/model/rolebindings.js.map +1 -0
  101. package/dist/model/roles.d.ts +32 -0
  102. package/dist/model/roles.d.ts.map +1 -0
  103. package/dist/model/roles.js +41 -0
  104. package/dist/model/roles.js.map +1 -0
  105. package/dist/model/secrets.d.ts +44 -0
  106. package/dist/model/secrets.d.ts.map +1 -0
  107. package/dist/model/secrets.js +15 -0
  108. package/dist/model/secrets.js.map +1 -0
  109. package/dist/model/thresholds.d.ts +2 -2
  110. package/dist/model/thresholds.d.ts.map +1 -1
  111. package/dist/model/thresholds.js.map +1 -1
  112. package/dist/model/time-series-data.js.map +1 -1
  113. package/dist/model/time-series-queries.d.ts +3 -3
  114. package/dist/model/time-series-queries.d.ts.map +1 -1
  115. package/dist/model/time-series-queries.js.map +1 -1
  116. package/dist/model/time.d.ts +15 -11
  117. package/dist/model/time.d.ts.map +1 -1
  118. package/dist/model/time.js +117 -57
  119. package/dist/model/time.js.map +1 -1
  120. package/dist/model/trace-data.d.ts +20 -0
  121. package/dist/model/trace-data.d.ts.map +1 -0
  122. package/dist/model/trace-data.js +18 -0
  123. package/dist/model/trace-data.js.map +1 -0
  124. package/dist/model/units/bytes.d.ts +8 -8
  125. package/dist/model/units/bytes.d.ts.map +1 -1
  126. package/dist/model/units/bytes.js +27 -21
  127. package/dist/model/units/bytes.js.map +1 -1
  128. package/dist/model/units/constants.js.map +1 -1
  129. package/dist/model/units/decimal.d.ts +8 -8
  130. package/dist/model/units/decimal.d.ts.map +1 -1
  131. package/dist/model/units/decimal.js +14 -14
  132. package/dist/model/units/decimal.js.map +1 -1
  133. package/dist/model/units/index.js.map +1 -1
  134. package/dist/model/units/percent.d.ts +7 -7
  135. package/dist/model/units/percent.d.ts.map +1 -1
  136. package/dist/model/units/percent.js +17 -16
  137. package/dist/model/units/percent.js.map +1 -1
  138. package/dist/model/units/throughput.d.ts +13 -0
  139. package/dist/model/units/throughput.d.ts.map +1 -0
  140. package/dist/model/units/throughput.js +94 -0
  141. package/dist/model/units/throughput.js.map +1 -0
  142. package/dist/model/units/time.d.ts +15 -15
  143. package/dist/model/units/time.d.ts.map +1 -1
  144. package/dist/model/units/time.js +87 -34
  145. package/dist/model/units/time.js.map +1 -1
  146. package/dist/model/units/types.d.ts +18 -9
  147. package/dist/model/units/types.d.ts.map +1 -1
  148. package/dist/model/units/types.js +2 -1
  149. package/dist/model/units/types.js.map +1 -1
  150. package/dist/model/units/units.d.ts +50 -31
  151. package/dist/model/units/units.d.ts.map +1 -1
  152. package/dist/model/units/units.js +52 -37
  153. package/dist/model/units/units.js.map +1 -1
  154. package/dist/model/units/utils.d.ts +2 -2
  155. package/dist/model/units/utils.d.ts.map +1 -1
  156. package/dist/model/units/utils.js +4 -4
  157. package/dist/model/units/utils.js.map +1 -1
  158. package/dist/model/variables.d.ts +28 -9
  159. package/dist/model/variables.d.ts.map +1 -1
  160. package/dist/model/variables.js +3 -0
  161. package/dist/model/variables.js.map +1 -1
  162. package/dist/test/setup-tests.js.map +1 -1
  163. package/dist/utils/event.js.map +1 -1
  164. package/dist/utils/fetch.d.ts +3 -1
  165. package/dist/utils/fetch.d.ts.map +1 -1
  166. package/dist/utils/fetch.js +21 -4
  167. package/dist/utils/fetch.js.map +1 -1
  168. package/dist/utils/index.d.ts +2 -1
  169. package/dist/utils/index.d.ts.map +1 -1
  170. package/dist/utils/index.js +2 -1
  171. package/dist/utils/index.js.map +1 -1
  172. package/dist/utils/is-empty-object.js.map +1 -1
  173. package/dist/utils/mathjs.js +1 -1
  174. package/dist/utils/mathjs.js.map +1 -1
  175. package/dist/utils/memo.js +2 -2
  176. package/dist/utils/memo.js.map +1 -1
  177. package/dist/utils/panel-refs.js.map +1 -1
  178. package/dist/utils/text.d.ts +7 -7
  179. package/dist/utils/text.d.ts.map +1 -1
  180. package/dist/utils/text.js +17 -17
  181. package/dist/utils/text.js.map +1 -1
  182. package/dist/utils/time-series-data.d.ts +1 -1
  183. package/dist/utils/time-series-data.d.ts.map +1 -1
  184. package/dist/utils/time-series-data.js +7 -7
  185. package/dist/utils/time-series-data.js.map +1 -1
  186. package/dist/utils/types.d.ts +2 -0
  187. package/dist/utils/types.d.ts.map +1 -0
  188. package/dist/utils/types.js +15 -0
  189. package/dist/utils/types.js.map +1 -0
  190. package/package.json +5 -4
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/model/time.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Duration, sub } from 'date-fns';\n\nexport type UnixTimeMs = number;\n\nexport type DateTimeFormat = number | string;\n\nexport interface AbsoluteTimeRange {\n start: Date;\n end: Date;\n}\n\nexport interface RelativeTimeRange {\n // End date or undefined if relative to the current Date\n end?: Date;\n pastDuration: DurationString;\n}\n\nexport type TimeRangeValue = AbsoluteTimeRange | RelativeTimeRange;\n\n/**\n * Determine whether a given time range is relative\n */\nexport function isRelativeTimeRange(timeRange: TimeRangeValue): timeRange is RelativeTimeRange {\n return (timeRange as RelativeTimeRange).pastDuration !== undefined;\n}\n\n/**\n * Determine whether a given time range is absolute\n */\nexport function isAbsoluteTimeRange(timeRange: TimeRangeValue): timeRange is AbsoluteTimeRange {\n return (timeRange as AbsoluteTimeRange).start !== undefined && (timeRange as AbsoluteTimeRange).end !== undefined;\n}\n\n/**\n * Returns an absolute time range from a RelativeTimeRange.\n */\nexport function toAbsoluteTimeRange(timeRange: RelativeTimeRange): AbsoluteTimeRange {\n const end = timeRange.end ?? new Date();\n\n return {\n start: sub(end, parseDurationString(timeRange.pastDuration)),\n end,\n };\n}\n\ntype MillisecondsDurationString = `${number}ms`;\ntype SecondsDurationString = `${number}s`;\ntype MinutesDurationString = `${number}m`;\ntype HoursDurationString = `${number}h`;\ntype DaysDurationString = `${number}d`;\ntype WeeksDurationString = `${number}w`;\ntype YearsDurationString = `${number}y`;\n\nexport type DurationString = Exclude<\n `${YearsDurationString | ''}${WeeksDurationString | ''}${DaysDurationString | ''}${HoursDurationString | ''}${\n | MinutesDurationString\n | ''}${SecondsDurationString | ''}${MillisecondsDurationString | ''}`,\n ''\n>;\n\nconst DURATION_REGEX = /^(?:(\\d+)y)?(?:(\\d+)w)?(?:(\\d+)d)?(?:(\\d+)h)?(?:(\\d+)m)?(?:(\\d+)s)?(?:(\\d+)ms)?$/;\n\n/**\n * Parses a DurationString into a Duration object with numeric values that can\n * be used to do Date math. Throws if not a valid duration string.\n */\nexport function parseDurationString(durationString: string): Duration {\n const matches = DURATION_REGEX.exec(durationString);\n if (matches === null) {\n throw new Error(`Invalid duration string '${durationString}'`);\n }\n\n return {\n years: parseInt(matches[1] ?? '0'),\n months: 0,\n weeks: parseInt(matches[2] ?? '0'),\n days: parseInt(matches[3] ?? '0'),\n hours: parseInt(matches[4] ?? '0'),\n minutes: parseInt(matches[5] ?? '0'),\n seconds: parseInt(matches[6] ?? '0') + parseInt(matches[7] ?? '0') / 1000,\n };\n}\n\n/**\n * Returns true if the given string is a valid DurationString.\n */\nexport function isDurationString(maybeDuration: string): maybeDuration is DurationString {\n if (maybeDuration === '') return false;\n return DURATION_REGEX.test(maybeDuration);\n}\n\nconst DEFAULT_STEP_MS = 15000;\n\nconst ROUNDED_STEP_INTERVALS = [\n // max: 0.015s\n { maxMs: 15, roundedStepMs: 10, display: '0.01s' },\n // max: 0.035s\n { maxMs: 35, roundedStepMs: 20, display: '0.02s' },\n // max: 0.075s\n { maxMs: 75, roundedStepMs: 50, display: '0.05s' },\n // max: 0.15s\n { maxMs: 150, roundedStepMs: 100, display: '0.1s' },\n // max: 0.35s\n { maxMs: 350, roundedStepMs: 200, display: '0.2s' },\n // max: 0.75s\n { maxMs: 750, roundedStepMs: 500, display: '0.5s' },\n // max: 1.5s\n { maxMs: 1500, roundedStepMs: 1000, display: '1s' },\n // max: 3.5s\n { maxMs: 3500, roundedStepMs: 2000, display: '2s' },\n // max: 7.5s\n { maxMs: 7500, roundedStepMs: 5000, display: '5s' },\n // max: 12.5s\n { maxMs: 12500, roundedStepMs: 10000, display: '10s' },\n // max: 17.5s\n { maxMs: 17500, roundedStepMs: 15000, display: '15s' },\n // max: 25s\n { maxMs: 25000, roundedStepMs: 20000, display: '20s' },\n // max: 45s\n { maxMs: 45000, roundedStepMs: 30000, display: '30s' },\n // max: 1.5m\n { maxMs: 90000, roundedStepMs: 60000, display: '1m' },\n // max: 3.5m\n { maxMs: 210000, roundedStepMs: 120000, display: '2m' },\n // max: 7.5m\n { maxMs: 450000, roundedStepMs: 300000, display: '5m' },\n // max: 12.5m\n { maxMs: 750000, roundedStepMs: 600000, display: '10m' },\n // max: 12.5m\n { maxMs: 1050000, roundedStepMs: 900000, display: '15m' },\n // max: 25m\n { maxMs: 1500000, roundedStepMs: 1200000, display: '20m' },\n // max: 45m\n { maxMs: 2700000, roundedStepMs: 1800000, display: '30m' },\n // max: 1.5h\n { maxMs: 5400000, roundedStepMs: 3600000, display: '1h' },\n // max: 2.5h\n { maxMs: 9000000, roundedStepMs: 7200000, display: '2h' },\n // max: 4.5h\n { maxMs: 16200000, roundedStepMs: 10800000, display: '3h' },\n // max: 9h\n { maxMs: 32400000, roundedStepMs: 21600000, display: '6h' },\n // max: 1d\n { maxMs: 86400000, roundedStepMs: 43200000, display: '12h' },\n // max: 1w\n { maxMs: 604800000, roundedStepMs: 86400000, display: '1d' },\n // max: 3w\n { maxMs: 1814400000, roundedStepMs: 604800000, display: '1w' },\n // max: 6w\n { maxMs: 3628800000, roundedStepMs: 2592000000, display: '30d' },\n // max: 2y\n { maxMs: 63072000000, roundedStepMs: 31536000000, display: '1y' },\n];\n\n/**\n * Round interval to clearer increments\n */\nexport function roundStepInterval(stepMs: number) {\n for (const { maxMs, roundedStepMs } of ROUNDED_STEP_INTERVALS) {\n if (stepMs < maxMs) {\n return roundedStepMs;\n }\n }\n return DEFAULT_STEP_MS;\n}\n\n/**\n * Gets a suggested step/interval size for a time range based on the width of a visual component.\n */\nexport function getSuggestedStepMs(timeRange: AbsoluteTimeRange, width: number) {\n const queryRangeMs = timeRange.end.valueOf() - timeRange.start.valueOf();\n const stepMs = Math.floor(queryRangeMs / width);\n return roundStepInterval(stepMs);\n}\n"],"names":["sub","isRelativeTimeRange","timeRange","pastDuration","undefined","isAbsoluteTimeRange","start","end","toAbsoluteTimeRange","Date","parseDurationString","DURATION_REGEX","durationString","matches","exec","Error","years","parseInt","months","weeks","days","hours","minutes","seconds","isDurationString","maybeDuration","test","DEFAULT_STEP_MS","ROUNDED_STEP_INTERVALS","maxMs","roundedStepMs","display","roundStepInterval","stepMs","getSuggestedStepMs","width","queryRangeMs","valueOf","Math","floor"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAA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E,IAAI;KAAE;IAC5D,UAAU;IACV;QAAEF,KAAK,EAAE,UAAU;QAAEC,aAAa,EAAE,SAAS;QAAEC,OAAO,EAAE,IAAI;KAAE;IAC9D,UAAU;IACV;QAAEF,KAAK,EAAE,UAAU;QAAEC,aAAa,EAAE,UAAU;QAAEC,OAAO,EAAE,KAAK;KAAE;IAChE,UAAU;IACV;QAAEF,KAAK,EAAE,WAAW;QAAEC,aAAa,EAAE,WAAW;QAAEC,OAAO,EAAE,IAAI;KAAE;CAClE,AAAC;AAEF;;CAEC,GACD,OAAO,SAASC,iBAAiB,CAACC,MAAc,EAAE;IAChD,KAAK,MAAM,EAAEJ,KAAK,CAAA,EAAEC,aAAa,CAAA,EAAE,IAAIF,sBAAsB,CAAE;QAC7D,IAAIK,MAAM,GAAGJ,KAAK,EAAE;YAClB,OAAOC,aAAa,CAAC;QACvB,CAAC;IACH,CAAC;IACD,OAAOH,eAAe,CAAC;AACzB,CAAC;AAED;;CAEC,GACD,OAAO,SAASO,kBAAkB,CAAChC,SAA4B,EAAEiC,KAAa,EAAE;IAC9E,MAAMC,YAAY,GAAGlC,SAAS,CAACK,GAAG,CAAC8B,OAAO,EAAE,GAAGnC,SAAS,CAACI,KAAK,CAAC+B,OAAO,EAAE,AAAC;IACzE,MAAMJ,MAAM,GAAGK,IAAI,CAACC,KAAK,CAACH,YAAY,GAAGD,KAAK,CAAC,AAAC;IAChD,OAAOH,iBAAiB,CAACC,MAAM,CAAC,CAAC;AACnC,CAAC"}
1
+ {"version":3,"sources":["../../src/model/time.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Duration, sub } from 'date-fns';\n\nconst ONE_SECOND_IN_MS = 1000;\nconst ONE_MINUTE_IN_MS = 60000;\nconst ONE_HOUR_IN_MS = 3600000;\nconst ONE_DAY_IN_MS = 86400000; // assuming a day has always 24h\nconst ONE_WEEK_IN_MS = 604800000; // assuming a week has always 7d\nconst ONE_YEAR_IN_MS = 31536000000; // assuming a year has always 365d\n\nexport type UnixTimeMs = number;\n\nexport type DateTimeFormat = number | string;\n\nexport interface AbsoluteTimeRange {\n start: Date;\n end: Date;\n}\n\nexport interface RelativeTimeRange {\n // End date or undefined if relative to the current Date\n end?: Date;\n pastDuration: DurationString;\n}\n\nexport type TimeRangeValue = AbsoluteTimeRange | RelativeTimeRange;\n\n/**\n * Determine whether a given time range is relative\n */\nexport function isRelativeTimeRange(timeRange: TimeRangeValue): timeRange is RelativeTimeRange {\n return (timeRange as RelativeTimeRange).pastDuration !== undefined;\n}\n\n/**\n * Determine whether a given time range is absolute\n */\nexport function isAbsoluteTimeRange(timeRange: TimeRangeValue): timeRange is AbsoluteTimeRange {\n return (timeRange as AbsoluteTimeRange).start !== undefined && (timeRange as AbsoluteTimeRange).end !== undefined;\n}\n\n/**\n * Returns an absolute time range from a RelativeTimeRange.\n */\nexport function toAbsoluteTimeRange(timeRange: RelativeTimeRange): AbsoluteTimeRange {\n const end = timeRange.end ?? new Date();\n\n return {\n start: sub(end, parseDurationString(timeRange.pastDuration)),\n end,\n };\n}\n\ntype MillisecondsDurationString = `${number}ms`;\ntype SecondsDurationString = `${number}s`;\ntype MinutesDurationString = `${number}m`;\ntype HoursDurationString = `${number}h`;\ntype DaysDurationString = `${number}d`;\ntype WeeksDurationString = `${number}w`;\ntype YearsDurationString = `${number}y`;\n\nexport type DurationString = Exclude<\n `${YearsDurationString | ''}${WeeksDurationString | ''}${DaysDurationString | ''}${HoursDurationString | ''}${\n | MinutesDurationString\n | ''}${SecondsDurationString | ''}${MillisecondsDurationString | ''}`,\n ''\n>;\n\nexport const DURATION_REGEX = /^(?:(\\d+)y)?(?:(\\d+)w)?(?:(\\d+)d)?(?:(\\d+)h)?(?:(\\d+)m)?(?:(\\d+)s)?(?:(\\d+)ms)?$/;\n\n/**\n * Parses a DurationString into a Duration object with numeric values that can\n * be used to do Date math. Throws if not a valid duration string.\n */\nexport function parseDurationString(durationString: string): Duration {\n const matches = DURATION_REGEX.exec(durationString);\n if (matches === null) {\n throw new Error(`Invalid duration string '${durationString}'`);\n }\n\n return {\n years: parseInt(matches[1] ?? '0'),\n months: 0,\n weeks: parseInt(matches[2] ?? '0'),\n days: parseInt(matches[3] ?? '0'),\n hours: parseInt(matches[4] ?? '0'),\n minutes: parseInt(matches[5] ?? '0'),\n seconds: parseInt(matches[6] ?? '0') + parseInt(matches[7] ?? '0') / 1000,\n };\n}\n\n/**\n * Returns true if the given string is a valid DurationString.\n */\nexport function isDurationString(maybeDuration: string): maybeDuration is DurationString {\n if (maybeDuration === '') return false;\n return DURATION_REGEX.test(maybeDuration);\n}\n\nexport function intervalToPrometheusDuration(timeRange: AbsoluteTimeRange): Duration {\n const durationInMs = timeRange.end.valueOf() - timeRange.start.valueOf();\n return msToPrometheusDuration(durationInMs);\n}\n\nexport function msToPrometheusDuration(durationInMs: number): Duration {\n const years = Math.trunc(durationInMs / ONE_YEAR_IN_MS);\n if (years > 0) durationInMs -= years * ONE_YEAR_IN_MS;\n const weeks = Math.trunc(durationInMs / ONE_WEEK_IN_MS);\n if (weeks > 0) durationInMs -= weeks * ONE_WEEK_IN_MS;\n const days = Math.trunc(durationInMs / ONE_DAY_IN_MS);\n if (days > 0) durationInMs -= days * ONE_DAY_IN_MS;\n const hours = Math.trunc(durationInMs / ONE_HOUR_IN_MS);\n if (hours > 0) durationInMs -= hours * ONE_HOUR_IN_MS;\n const minutes = Math.trunc(durationInMs / ONE_MINUTE_IN_MS);\n if (minutes > 0) durationInMs -= minutes * ONE_MINUTE_IN_MS;\n\n return {\n years: years,\n months: 0,\n weeks: weeks,\n days: days,\n hours: hours,\n minutes: minutes,\n seconds: durationInMs / 1000,\n };\n}\n\nexport function formatDuration(duration: Duration): DurationString {\n const result: string[] = [];\n if (duration.years) {\n result.push(`${duration.years}y`);\n }\n if (duration.weeks) {\n result.push(`${duration.weeks}w`);\n }\n if (duration.days) {\n result.push(`${duration.days}d`);\n }\n if (duration.hours) {\n result.push(`${duration.hours}h`);\n }\n if (duration.minutes) {\n result.push(`${duration.minutes}m`);\n }\n if (duration.seconds) {\n const seconds = Math.trunc(duration.seconds);\n if (seconds) {\n result.push(`${seconds}s`);\n }\n const ms = (duration.seconds - seconds) * 1000;\n if (ms) {\n result.push(`${ms}ms`);\n }\n }\n return result.join('') as DurationString;\n}\n\nconst DEFAULT_STEP_MS = 15000;\n\nconst ROUNDED_STEP_INTERVALS = [\n // max: 0.015s\n { maxMs: 15, roundedStepMs: 10, display: '0.01s' },\n // max: 0.035s\n { maxMs: 35, roundedStepMs: 20, display: '0.02s' },\n // max: 0.075s\n { maxMs: 75, roundedStepMs: 50, display: '0.05s' },\n // max: 0.15s\n { maxMs: 150, roundedStepMs: 100, display: '0.1s' },\n // max: 0.35s\n { maxMs: 350, roundedStepMs: 200, display: '0.2s' },\n // max: 0.75s\n { maxMs: 750, roundedStepMs: 500, display: '0.5s' },\n // max: 1.5s\n { maxMs: ONE_SECOND_IN_MS * 1.5, roundedStepMs: ONE_SECOND_IN_MS, display: '1s' },\n // max: 3.5s\n { maxMs: ONE_SECOND_IN_MS * 3.5, roundedStepMs: ONE_SECOND_IN_MS * 2, display: '2s' },\n // max: 7.5s\n { maxMs: ONE_SECOND_IN_MS * 7.5, roundedStepMs: ONE_SECOND_IN_MS * 5, display: '5s' },\n // max: 12.5s\n { maxMs: ONE_SECOND_IN_MS * 12.5, roundedStepMs: ONE_SECOND_IN_MS * 10, display: '10s' },\n // max: 17.5s\n { maxMs: ONE_SECOND_IN_MS * 17.5, roundedStepMs: ONE_SECOND_IN_MS * 15, display: '15s' },\n // max: 25s\n { maxMs: ONE_SECOND_IN_MS * 25, roundedStepMs: ONE_SECOND_IN_MS * 20, display: '20s' },\n // max: 45s\n { maxMs: ONE_SECOND_IN_MS * 45, roundedStepMs: ONE_SECOND_IN_MS * 30, display: '30s' },\n // max: 1.5m\n { maxMs: ONE_MINUTE_IN_MS * 1.5, roundedStepMs: ONE_MINUTE_IN_MS, display: '1m' },\n // max: 3.5m\n { maxMs: ONE_MINUTE_IN_MS * 3.5, roundedStepMs: ONE_MINUTE_IN_MS * 2, display: '2m' },\n // max: 7.5m\n { maxMs: ONE_MINUTE_IN_MS * 7.5, roundedStepMs: ONE_MINUTE_IN_MS * 5, display: '5m' },\n // max: 12.5m\n { maxMs: ONE_MINUTE_IN_MS * 12.5, roundedStepMs: ONE_MINUTE_IN_MS * 10, display: '10m' },\n // max: 12.5m\n { maxMs: ONE_MINUTE_IN_MS * 12.5, roundedStepMs: ONE_MINUTE_IN_MS * 15, display: '15m' },\n // max: 25m\n { maxMs: ONE_MINUTE_IN_MS * 25, roundedStepMs: ONE_MINUTE_IN_MS * 20, display: '20m' },\n // max: 45m\n { maxMs: ONE_MINUTE_IN_MS * 45, roundedStepMs: ONE_MINUTE_IN_MS * 30, display: '30m' },\n // max: 1.5h\n { maxMs: ONE_HOUR_IN_MS * 1.5, roundedStepMs: ONE_HOUR_IN_MS, display: '1h' },\n // max: 2.5h\n { maxMs: ONE_HOUR_IN_MS * 2.5, roundedStepMs: ONE_HOUR_IN_MS * 2, display: '2h' },\n // max: 4.5h\n { maxMs: ONE_HOUR_IN_MS * 4.5, roundedStepMs: ONE_HOUR_IN_MS * 3, display: '3h' },\n // max: 9h\n { maxMs: ONE_HOUR_IN_MS * 9, roundedStepMs: ONE_HOUR_IN_MS * 6, display: '6h' },\n // max: 1d\n { maxMs: ONE_DAY_IN_MS, roundedStepMs: ONE_HOUR_IN_MS * 12, display: '12h' },\n // max: 1w\n { maxMs: ONE_WEEK_IN_MS, roundedStepMs: ONE_DAY_IN_MS, display: '1d' },\n // max: 3w\n { maxMs: ONE_WEEK_IN_MS * 3, roundedStepMs: ONE_WEEK_IN_MS, display: '1w' },\n // max: 6w\n { maxMs: ONE_WEEK_IN_MS * 6, roundedStepMs: ONE_DAY_IN_MS * 30, display: '30d' },\n // max: 2y\n { maxMs: ONE_YEAR_IN_MS * 2, roundedStepMs: ONE_YEAR_IN_MS, display: '1y' },\n];\n\n/**\n * Round interval to clearer increments\n */\nexport function roundStepInterval(stepMs: number) {\n for (const { maxMs, roundedStepMs } of ROUNDED_STEP_INTERVALS) {\n if (stepMs < maxMs) {\n return roundedStepMs;\n }\n }\n return DEFAULT_STEP_MS;\n}\n\n/**\n * Gets a suggested step/interval size for a time range based on the width of a visual component.\n */\nexport function getSuggestedStepMs(timeRange: AbsoluteTimeRange, width: number) {\n const queryRangeMs = timeRange.end.valueOf() - timeRange.start.valueOf();\n const stepMs = Math.floor(queryRangeMs / width);\n return roundStepInterval(stepMs);\n}\n"],"names":["sub","ONE_SECOND_IN_MS","ONE_MINUTE_IN_MS","ONE_HOUR_IN_MS","ONE_DAY_IN_MS","ONE_WEEK_IN_MS","ONE_YEAR_IN_MS","isRelativeTimeRange","timeRange","pastDuration","undefined","isAbsoluteTimeRange","start","end","toAbsoluteTimeRange","Date","parseDurationString","DURATION_REGEX","durationString","matches","exec","Error","years","parseInt","months","weeks","days","hours","minutes","seconds","isDurationString","maybeDuration","test","intervalToPrometheusDuration","durationInMs","valueOf","msToPrometheusDuration","Math","trunc","formatDuration","duration","result","push","ms","join","DEFAULT_STEP_MS","ROUNDED_STEP_INTERVALS","maxMs","roundedStepMs","display","roundStepInterval","stepMs","getSuggestedStepMs","width","queryRangeMs","floor"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAAmBA,GAAG,QAAQ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Data {
2
+ executedQueryString?: string;
3
+ }
4
+ export interface TraceValue {
5
+ startTimeUnixMs: number;
6
+ durationMs: number;
7
+ spanCount?: number;
8
+ errorCount?: number;
9
+ traceId?: string;
10
+ name?: string;
11
+ }
12
+ /**
13
+ * A generalized data-model that will be used by Panel components
14
+ * to display traces.
15
+ */
16
+ export interface TraceData {
17
+ traces: TraceValue[];
18
+ metadata?: TraceMetaData;
19
+ }
20
+ //# sourceMappingURL=trace-data.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trace-data.d.ts","sourceRoot":"","sources":["../../src/model/trace-data.ts"],"names":[],"mappings":"AAaA,MAAM,WAAW,aAAa;IAC5B,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,MAAM,WAAW,UAAU;IACzB,eAAe,EAAE,MAAM,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;GAGG;AACH,MAAM,WAAW,SAAS;IACxB,MAAM,EAAE,UAAU,EAAE,CAAC;IACrB,QAAQ,CAAC,EAAE,aAAa,CAAC;CAC1B"}
@@ -0,0 +1,18 @@
1
+ // Copyright 2023 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
+ /**
14
+ * A generalized data-model that will be used by Panel components
15
+ * to display traces.
16
+ */ export { };
17
+
18
+ //# sourceMappingURL=trace-data.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/model/trace-data.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport interface TraceMetaData {\n executedQueryString?: string;\n}\n\nexport interface TraceValue {\n startTimeUnixMs: number;\n durationMs: number;\n spanCount?: number;\n errorCount?: number;\n traceId?: string;\n name?: string;\n}\n\n/**\n * A generalized data-model that will be used by Panel components\n * to display traces.\n */\nexport interface TraceData {\n traces: TraceValue[];\n metadata?: TraceMetaData;\n}\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAejC;;;CAGC,GACD,WAGC"}
@@ -1,13 +1,13 @@
1
1
  import { UnitGroupConfig, UnitConfig } from './types';
2
- declare const bytesUnitKinds: readonly ["Bytes"];
3
- declare type BytesUnitKind = (typeof bytesUnitKinds)[number];
4
- export declare type BytesUnitOptions = {
5
- kind: BytesUnitKind;
6
- decimal_places?: number;
7
- abbreviate?: boolean;
2
+ declare const bytesUnits: readonly ["bytes"];
3
+ type BytesUnit = (typeof bytesUnits)[number];
4
+ export type BytesFormatOptions = {
5
+ unit: BytesUnit;
6
+ decimalPlaces?: number;
7
+ shortValues?: boolean;
8
8
  };
9
9
  export declare const BYTES_GROUP_CONFIG: UnitGroupConfig;
10
- export declare const BYTES_UNIT_CONFIG: Readonly<Record<BytesUnitKind, UnitConfig>>;
11
- export declare function formatBytes(bytes: number, options: BytesUnitOptions): string;
10
+ export declare const BYTES_UNIT_CONFIG: Readonly<Record<BytesUnit, UnitConfig>>;
11
+ export declare function formatBytes(bytes: number, { shortValues, decimalPlaces }: BytesFormatOptions): string;
12
12
  export {};
13
13
  //# sourceMappingURL=bytes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"bytes.d.ts","sourceRoot":"","sources":["../../../src/model/units/bytes.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAKtD,QAAA,MAAM,cAAc,oBAAqB,CAAC;AAC1C,aAAK,aAAa,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC;AACrD,oBAAY,gBAAgB,GAAG;IAC7B,IAAI,EAAE,aAAa,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AACF,eAAO,MAAM,kBAAkB,EAAE,eAIhC,CAAC;AACF,eAAO,MAAM,iBAAiB,EAAE,QAAQ,CAAC,MAAM,CAAC,aAAa,EAAE,UAAU,CAAC,CAOzE,CAAC;AAEF,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,UAmCnE"}
1
+ {"version":3,"file":"bytes.d.ts","sourceRoot":"","sources":["../../../src/model/units/bytes.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAatD,QAAA,MAAM,UAAU,oBAAqB,CAAC;AACtC,KAAK,SAAS,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC;AAC7C,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,EAAE,SAAS,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AACF,eAAO,MAAM,kBAAkB,EAAE,eAIhC,CAAC;AACF,eAAO,MAAM,iBAAiB,EAAE,QAAQ,CAAC,MAAM,CAAC,SAAS,EAAE,UAAU,CAAC,CAKrE,CAAC;AAEF,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,WAAW,EAAE,aAAa,EAAE,EAAE,kBAAkB,UAmC5F"}
@@ -12,54 +12,60 @@
12
12
  // limitations under the License.
13
13
  import numbro from 'numbro';
14
14
  import { MAX_SIGNIFICANT_DIGITS } from './constants';
15
- import { hasDecimalPlaces, limitDecimalPlaces, shouldAbbreviate } from './utils';
16
- const DEFAULT_NUMBRO_MANTISSA = 2;
17
- const bytesUnitKinds = [
18
- 'Bytes'
15
+ import { hasDecimalPlaces, limitDecimalPlaces, shouldShortenValues } from './utils';
16
+ /**
17
+ * We consider the units for bytes to be powers of 1000.
18
+ * In other words:
19
+ * 1 KB = 1000 bytes (1000^1 bytes)
20
+ * 1 MB = 1,000,000 bytes (1000^2 bytes)
21
+ * etc.
22
+ */ const DEFAULT_NUMBRO_MANTISSA = 2;
23
+ const bytesUnits = [
24
+ 'bytes'
19
25
  ];
20
26
  export const BYTES_GROUP_CONFIG = {
21
27
  label: 'Bytes',
22
- decimal_places: true,
23
- abbreviate: true
28
+ decimalPlaces: true,
29
+ shortValues: true
24
30
  };
25
31
  export const BYTES_UNIT_CONFIG = {
26
- // These units are powers of 1000.
27
- // In other words, 1 KB = 1000 bytes.
28
- Bytes: {
32
+ bytes: {
29
33
  group: 'Bytes',
30
34
  label: 'Bytes'
31
35
  }
32
36
  };
33
- export function formatBytes(bytes, options) {
34
- const { abbreviate , decimal_places } = options;
35
- if (!shouldAbbreviate(abbreviate) || Math.abs(bytes) < 1000) {
37
+ export function formatBytes(bytes, { shortValues, decimalPlaces }) {
38
+ // If we're showing the entire value, we can use Intl.NumberFormat.
39
+ if (!shouldShortenValues(shortValues) || Math.abs(bytes) < 1000) {
36
40
  const formatterOptions = {
37
41
  style: 'unit',
38
42
  unit: 'byte',
39
43
  unitDisplay: 'long',
40
44
  useGrouping: true
41
45
  };
42
- if (hasDecimalPlaces(decimal_places)) {
43
- formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimal_places);
44
- formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimal_places);
46
+ if (hasDecimalPlaces(decimalPlaces)) {
47
+ formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimalPlaces);
48
+ formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimalPlaces);
45
49
  } else {
46
50
  // This can happen if bytes is between -1000 and 1000
47
- if (shouldAbbreviate(abbreviate)) {
51
+ if (shouldShortenValues(shortValues)) {
48
52
  formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;
49
53
  }
50
54
  }
51
- return Intl.NumberFormat('en-US', formatterOptions).format(bytes);
55
+ const formatter = Intl.NumberFormat('en-US', formatterOptions);
56
+ return formatter.format(bytes);
52
57
  }
53
- // numbro is able to add units like KB, MB, GB, etc. correctly
58
+ // If we're showing the shorten value, we use numbro.
59
+ // numbro is able to add units like KB, MB, GB, etc. correctly.
54
60
  return numbro(bytes).format({
55
61
  output: 'byte',
56
62
  base: 'decimal',
57
63
  spaceSeparated: true,
58
- mantissa: hasDecimalPlaces(decimal_places) ? decimal_places : DEFAULT_NUMBRO_MANTISSA,
64
+ mantissa: hasDecimalPlaces(decimalPlaces) ? decimalPlaces : DEFAULT_NUMBRO_MANTISSA,
59
65
  // trimMantissa trims trailing 0s
60
- trimMantissa: !hasDecimalPlaces(decimal_places),
66
+ trimMantissa: !hasDecimalPlaces(decimalPlaces),
61
67
  // optionalMantissa excludes all the decimal places if they're all zeros
62
- optionalMantissa: !hasDecimalPlaces(decimal_places)
68
+ optionalMantissa: !hasDecimalPlaces(decimalPlaces)
63
69
  });
64
70
  }
65
71
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/model/units/bytes.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport numbro from 'numbro';\n\nimport { MAX_SIGNIFICANT_DIGITS } from './constants';\nimport { UnitGroupConfig, UnitConfig } from './types';\nimport { hasDecimalPlaces, limitDecimalPlaces, shouldAbbreviate } from './utils';\n\nconst DEFAULT_NUMBRO_MANTISSA = 2;\n\nconst bytesUnitKinds = ['Bytes'] as const;\ntype BytesUnitKind = (typeof bytesUnitKinds)[number];\nexport type BytesUnitOptions = {\n kind: BytesUnitKind;\n decimal_places?: number;\n abbreviate?: boolean;\n};\nexport const BYTES_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Bytes',\n decimal_places: true,\n abbreviate: true,\n};\nexport const BYTES_UNIT_CONFIG: Readonly<Record<BytesUnitKind, UnitConfig>> = {\n // These units are powers of 1000.\n // In other words, 1 KB = 1000 bytes.\n Bytes: {\n group: 'Bytes',\n label: 'Bytes',\n },\n};\n\nexport function formatBytes(bytes: number, options: BytesUnitOptions) {\n const { abbreviate, decimal_places } = options;\n\n if (!shouldAbbreviate(abbreviate) || Math.abs(bytes) < 1000) {\n const formatterOptions: Intl.NumberFormatOptions = {\n style: 'unit',\n unit: 'byte',\n unitDisplay: 'long',\n useGrouping: true,\n };\n\n if (hasDecimalPlaces(decimal_places)) {\n formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimal_places);\n formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimal_places);\n } else {\n // This can happen if bytes is between -1000 and 1000\n if (shouldAbbreviate(abbreviate)) {\n formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n }\n\n return Intl.NumberFormat('en-US', formatterOptions).format(bytes);\n }\n\n // numbro is able to add units like KB, MB, GB, etc. correctly\n return numbro(bytes).format({\n output: 'byte',\n base: 'decimal',\n spaceSeparated: true,\n mantissa: hasDecimalPlaces(decimal_places) ? decimal_places : DEFAULT_NUMBRO_MANTISSA,\n // trimMantissa trims trailing 0s\n trimMantissa: !hasDecimalPlaces(decimal_places),\n // optionalMantissa excludes all the decimal places if they're all zeros\n optionalMantissa: !hasDecimalPlaces(decimal_places),\n });\n}\n"],"names":["numbro","MAX_SIGNIFICANT_DIGITS","hasDecimalPlaces","limitDecimalPlaces","shouldAbbreviate","DEFAULT_NUMBRO_MANTISSA","bytesUnitKinds","BYTES_GROUP_CONFIG","label","decimal_places","abbreviate","BYTES_UNIT_CONFIG","Bytes","group","formatBytes","bytes","options","Math","abs","formatterOptions","style","unit","unitDisplay","useGrouping","minimumFractionDigits","maximumFractionDigits","maximumSignificantDigits","Intl","NumberFormat","format","output","base","spaceSeparated","mantissa","trimMantissa","optionalMantissa"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,OAAOA,MAAM,MAAM,QAAQ,CAAC;AAE5B,SAASC,sBAAsB,QAAQ,aAAa,CAAC;AAErD,SAASC,gBAAgB,EAAEC,kBAAkB,EAAEC,gBAAgB,QAAQ,SAAS,CAAC;AAEjF,MAAMC,uBAAuB,GAAG,CAAC,AAAC;AAElC,MAAMC,cAAc,GAAG;IAAC,OAAO;CAAC,AAAS,AAAC;AAO1C,OAAO,MAAMC,kBAAkB,GAAoB;IACjDC,KAAK,EAAE,OAAO;IACdC,cAAc,EAAE,IAAI;IACpBC,UAAU,EAAE,IAAI;CACjB,CAAC;AACF,OAAO,MAAMC,iBAAiB,GAAgD;IAC5E,kCAAkC;IAClC,qCAAqC;IACrCC,KAAK,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CAACjC,gBAAgB,CAACO,cAAc,CAAC;KACpD,CAAC,CAAC;AACL,CAAC"}
1
+ {"version":3,"sources":["../../../src/model/units/bytes.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport numbro from 'numbro';\n\nimport { MAX_SIGNIFICANT_DIGITS } from './constants';\nimport { UnitGroupConfig, UnitConfig } from './types';\nimport { hasDecimalPlaces, limitDecimalPlaces, shouldShortenValues } from './utils';\n\n/**\n * We consider the units for bytes to be powers of 1000.\n * In other words:\n * 1 KB = 1000 bytes (1000^1 bytes)\n * 1 MB = 1,000,000 bytes (1000^2 bytes)\n * etc.\n */\n\nconst DEFAULT_NUMBRO_MANTISSA = 2;\n\nconst bytesUnits = ['bytes'] as const;\ntype BytesUnit = (typeof bytesUnits)[number];\nexport type BytesFormatOptions = {\n unit: BytesUnit;\n decimalPlaces?: number;\n shortValues?: boolean;\n};\nexport const BYTES_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Bytes',\n decimalPlaces: true,\n shortValues: true,\n};\nexport const BYTES_UNIT_CONFIG: Readonly<Record<BytesUnit, UnitConfig>> = {\n bytes: {\n group: 'Bytes',\n label: 'Bytes',\n },\n};\n\nexport function formatBytes(bytes: number, { shortValues, decimalPlaces }: BytesFormatOptions) {\n // If we're showing the entire value, we can use Intl.NumberFormat.\n if (!shouldShortenValues(shortValues) || Math.abs(bytes) < 1000) {\n const formatterOptions: Intl.NumberFormatOptions = {\n style: 'unit',\n unit: 'byte',\n unitDisplay: 'long',\n useGrouping: true,\n };\n\n if (hasDecimalPlaces(decimalPlaces)) {\n formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimalPlaces);\n formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimalPlaces);\n } else {\n // This can happen if bytes is between -1000 and 1000\n if (shouldShortenValues(shortValues)) {\n formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n }\n const formatter = Intl.NumberFormat('en-US', formatterOptions);\n return formatter.format(bytes);\n }\n\n // If we're showing the shorten value, we use numbro.\n // numbro is able to add units like KB, MB, GB, etc. correctly.\n return numbro(bytes).format({\n output: 'byte',\n base: 'decimal',\n spaceSeparated: true,\n mantissa: hasDecimalPlaces(decimalPlaces) ? decimalPlaces : DEFAULT_NUMBRO_MANTISSA,\n // trimMantissa trims trailing 0s\n trimMantissa: !hasDecimalPlaces(decimalPlaces),\n // optionalMantissa excludes all the decimal places if they're all zeros\n optionalMantissa: !hasDecimalPlaces(decimalPlaces),\n });\n}\n"],"names":["numbro","MAX_SIGNIFICANT_DIGITS","hasDecimalPlaces","limitDecimalPlaces","shouldShortenValues","DEFAULT_NUMBRO_MANTISSA","bytesUnits","BYTES_GROUP_CONFIG","label","decimalPlaces","shortValues","BYTES_UNIT_CONFIG","bytes","group","formatBytes","Math","abs","formatterOptions","style","unit","unitDisplay","useGrouping","minimumFractionDigits","maximumFractionDigits","maximumSignificantDigits","formatter","Intl","NumberFormat","format","output","base","spaceSeparated","mantissa","trimMantissa","optionalMantissa"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,OAAOA,YAAY,SAAS;AAE5B,SAASC,sBAAsB,QAAQ,cAAc;AAErD,SAASC,gBAAgB,EAAEC,kBAAkB,EAAEC,mBAAmB,QAAQ,UAAU;AAEpF;;;;;;CAMC,GAED,MAAMC,0BAA0B;AAEhC,MAAMC,aAAa;IAAC;CAAQ;AAO5B,OAAO,MAAMC,qBAAsC;IACjDC,OAAO;IACPC,eAAe;IACfC,aAAa;AACf,EAAE;AACF,OAAO,MAAMC,oBAA6D;IACxEC,OAAO;QACLC,OAAO;QACPL,OAAO;IACT;AACF,EAAE;AAEF,OAAO,SAASM,YAAYF,KAAa,EAAE,EAAEF,WAAW,EAAED,aAAa,EAAsB;IAC3F,mEAAmE;IACnE,IAAI,CAACL,oBAAoBM,gBAAgBK,KAAKC,GAAG,CAACJ,SAAS,MAAM;QAC/D,MAAMK,mBAA6C;YACjDC,OAAO;YACPC,MAAM;YACNC,aAAa;YACbC,aAAa;QACf;QAEA,IAAInB,iBAAiBO,gBAAgB;YACnCQ,iBAAiBK,qBAAqB,GAAGnB,mBAAmBM;YAC5DQ,iBAAiBM,qBAAqB,GAAGpB,mBAAmBM;QAC9D,OAAO;YACL,qDAAqD;YACrD,IAAIL,oBAAoBM,cAAc;gBACpCO,iBAAiBO,wBAAwB,GAAGvB;YAC9C;QACF;QACA,MAAMwB,YAAYC,KAAKC,YAAY,CAAC,SAASV;QAC7C,OAAOQ,UAAUG,MAAM,CAAChB;IAC1B;IAEA,qDAAqD;IACrD,+DAA+D;IAC/D,OAAOZ,OAAOY,OAAOgB,MAAM,CAAC;QAC1BC,QAAQ;QACRC,MAAM;QACNC,gBAAgB;QAChBC,UAAU9B,iBAAiBO,iBAAiBA,gBAAgBJ;QAC5D,iCAAiC;QACjC4B,cAAc,CAAC/B,iBAAiBO;QAChC,wEAAwE;QACxEyB,kBAAkB,CAAChC,iBAAiBO;IACtC;AACF"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/model/units/constants.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n// Common constants needed across individual unit groups and the overall\n// combined units.\nexport const MAX_SIGNIFICANT_DIGITS = 3;\n"],"names":["MAX_SIGNIFICANT_DIGITS"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,wEAAwE;AACxE,kBAAkB;AAClB,OAAO,MAAMA,sBAAsB,GAAG,CAAC,CAAC"}
1
+ {"version":3,"sources":["../../../src/model/units/constants.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n// Common constants needed across individual unit groups and the overall\n// combined units.\nexport const MAX_SIGNIFICANT_DIGITS = 3;\n"],"names":["MAX_SIGNIFICANT_DIGITS"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,wEAAwE;AACxE,kBAAkB;AAClB,OAAO,MAAMA,yBAAyB,EAAE"}
@@ -1,13 +1,13 @@
1
1
  import { UnitGroupConfig, UnitConfig } from './types';
2
- declare const decimalUnitKinds: readonly ["Decimal"];
3
- declare type DecimalUnitKind = (typeof decimalUnitKinds)[number];
4
- export declare type DecimalUnitOptions = {
5
- kind: DecimalUnitKind;
6
- decimal_places?: number;
7
- abbreviate?: boolean;
2
+ declare const decimalUnits: readonly ["decimal"];
3
+ type DecimalUnit = (typeof decimalUnits)[number];
4
+ export type DecimalFormatOptions = {
5
+ unit: DecimalUnit;
6
+ decimalPlaces?: number;
7
+ shortValues?: boolean;
8
8
  };
9
9
  export declare const DECIMAL_GROUP_CONFIG: UnitGroupConfig;
10
- export declare const DECIMAL_UNIT_CONFIG: Readonly<Record<DecimalUnitKind, UnitConfig>>;
11
- export declare function formatDecimal(value: number, options: DecimalUnitOptions): string;
10
+ export declare const DECIMAL_UNIT_CONFIG: Readonly<Record<DecimalUnit, UnitConfig>>;
11
+ export declare function formatDecimal(value: number, { shortValues, decimalPlaces }: DecimalFormatOptions): string;
12
12
  export {};
13
13
  //# sourceMappingURL=decimal.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"decimal.d.ts","sourceRoot":"","sources":["../../../src/model/units/decimal.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGtD,QAAA,MAAM,gBAAgB,sBAAuB,CAAC;AAC9C,aAAK,eAAe,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC;AACzD,oBAAY,kBAAkB,GAAG;IAC/B,IAAI,EAAE,eAAe,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AACF,eAAO,MAAM,oBAAoB,EAAE,eAIlC,CAAC;AACF,eAAO,MAAM,mBAAmB,EAAE,QAAQ,CAAC,MAAM,CAAC,eAAe,EAAE,UAAU,CAAC,CAK7E,CAAC;AAEF,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,kBAAkB,GAAG,MAAM,CAsBhF"}
1
+ {"version":3,"file":"decimal.d.ts","sourceRoot":"","sources":["../../../src/model/units/decimal.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGtD,QAAA,MAAM,YAAY,sBAAuB,CAAC;AAC1C,KAAK,WAAW,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC;AACjD,MAAM,MAAM,oBAAoB,GAAG;IACjC,IAAI,EAAE,WAAW,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AACF,eAAO,MAAM,oBAAoB,EAAE,eAIlC,CAAC;AACF,eAAO,MAAM,mBAAmB,EAAE,QAAQ,CAAC,MAAM,CAAC,WAAW,EAAE,UAAU,CAAC,CAKzE,CAAC;AAEF,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,WAAW,EAAE,aAAa,EAAE,EAAE,oBAAoB,GAAG,MAAM,CAqBzG"}
@@ -11,39 +11,39 @@
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
13
  import { MAX_SIGNIFICANT_DIGITS } from './constants';
14
- import { hasDecimalPlaces, limitDecimalPlaces, shouldAbbreviate } from './utils';
15
- const decimalUnitKinds = [
16
- 'Decimal'
14
+ import { hasDecimalPlaces, limitDecimalPlaces, shouldShortenValues } from './utils';
15
+ const decimalUnits = [
16
+ 'decimal'
17
17
  ];
18
18
  export const DECIMAL_GROUP_CONFIG = {
19
19
  label: 'Decimal',
20
- decimal_places: true,
21
- abbreviate: true
20
+ decimalPlaces: true,
21
+ shortValues: true
22
22
  };
23
23
  export const DECIMAL_UNIT_CONFIG = {
24
- Decimal: {
24
+ decimal: {
25
25
  group: 'Decimal',
26
26
  label: 'Decimal'
27
27
  }
28
28
  };
29
- export function formatDecimal(value, options) {
30
- const { abbreviate , decimal_places } = options;
29
+ export function formatDecimal(value, { shortValues, decimalPlaces }) {
31
30
  const formatterOptions = {
32
31
  style: 'decimal',
33
32
  useGrouping: true
34
33
  };
35
- if (shouldAbbreviate(abbreviate)) {
34
+ if (shouldShortenValues(shortValues)) {
36
35
  formatterOptions.notation = 'compact';
37
36
  }
38
- if (hasDecimalPlaces(decimal_places)) {
39
- formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimal_places);
40
- formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimal_places);
37
+ if (hasDecimalPlaces(decimalPlaces)) {
38
+ formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimalPlaces);
39
+ formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimalPlaces);
41
40
  } else {
42
- if (shouldAbbreviate(abbreviate)) {
41
+ if (shouldShortenValues(shortValues)) {
43
42
  formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;
44
43
  }
45
44
  }
46
- return Intl.NumberFormat('en-US', formatterOptions).format(value);
45
+ const formatter = Intl.NumberFormat('en-US', formatterOptions);
46
+ return formatter.format(value);
47
47
  }
48
48
 
49
49
  //# sourceMappingURL=decimal.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/model/units/decimal.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { MAX_SIGNIFICANT_DIGITS } from './constants';\nimport { UnitGroupConfig, UnitConfig } from './types';\nimport { hasDecimalPlaces, limitDecimalPlaces, shouldAbbreviate } from './utils';\n\nconst decimalUnitKinds = ['Decimal'] as const;\ntype DecimalUnitKind = (typeof decimalUnitKinds)[number];\nexport type DecimalUnitOptions = {\n kind: DecimalUnitKind;\n decimal_places?: number;\n abbreviate?: boolean;\n};\nexport const DECIMAL_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Decimal',\n decimal_places: true,\n abbreviate: true,\n};\nexport const DECIMAL_UNIT_CONFIG: Readonly<Record<DecimalUnitKind, UnitConfig>> = {\n Decimal: {\n group: 'Decimal',\n label: 'Decimal',\n },\n};\n\nexport function formatDecimal(value: number, options: DecimalUnitOptions): string {\n const { abbreviate, decimal_places } = options;\n\n const formatterOptions: Intl.NumberFormatOptions = {\n style: 'decimal',\n useGrouping: true,\n };\n\n if (shouldAbbreviate(abbreviate)) {\n formatterOptions.notation = 'compact';\n }\n\n if (hasDecimalPlaces(decimal_places)) {\n formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimal_places);\n formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimal_places);\n } else {\n if (shouldAbbreviate(abbreviate)) {\n formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n }\n\n return Intl.NumberFormat('en-US', formatterOptions).format(value);\n}\n"],"names":["MAX_SIGNIFICANT_DIGITS","hasDecimalPlaces","limitDecimalPlaces","shouldAbbreviate","decimalUnitKinds","DECIMAL_GROUP_CONFIG","label","decimal_places","abbreviate","DECIMAL_UNIT_CONFIG","Decimal","group","formatDecimal","value","options","formatterOptions","style","useGrouping","notation","minimumFractionDigits","maximumFractionDigits","maximumSignificantDigits","Intl","NumberFormat","format"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,sBAAsB,QAAQ,aAAa,CAAC;AAErD,SAASC,gBAAgB,EAAEC,kBAAkB,EAAEC,gBAAgB,QAAQ,SAAS,CAAC;AAEjF,MAAMC,gBAAgB,GAAG;IAAC,SAAS;CAAC,AAAS,AAAC;AAO9C,OAAO,MAAMC,oBAAoB,GAAoB;IACnDC,KAAK,EAAE,SAAS;IAChBC,cAAc,EAAE,IAAI;IACpBC,UAAU,EAAE,IAAI;CACjB,CAAC;AACF,OAAO,MAAMC,mBAAmB,GAAkD;IAChFC,OAAO,EAAE;QACPC,KAAK,EAAE,SAAS;QAChBL,KAAK,EAAE,SAAS;KACjB;CACF,CAAC;AAEF,OAAO,SAASM,aAAa,CAACC,KAAa,EAAEC,OAA2B,EAAU;IAChF,MAAM,EAAEN,UAAU,CAAA,EAAED,cAAc,CAAA,EAAE,GAAGO,OAAO,AAAC;IAE/C,MAAMC,gBAAgB,GAA6B;QACjDC,KAAK,EAAE,SAAS;QAChBC,WAAW,EAAE,IAAI;KAClB,AAAC;IAEF,IAAId,gBAAgB,CAACK,UAAU,CAAC,EAAE;QAChCO,gBAAgB,CAACG,QAAQ,GAAG,SAAS,CAAC;IACxC,CAAC;IAED,IAAIjB,gBAAgB,CAACM,cAAc,CAAC,EAAE;QACpCQ,gBAAgB,CAACI,qBAAqB,GAAGjB,kBAAkB,CAACK,cAAc,CAAC,CAAC;QAC5EQ,gBAAgB,CAACK,qBAAqB,GAAGlB,kBAAkB,CAACK,cAAc,CAAC,CAAC;IAC9E,OAAO;QACL,IAAIJ,gBAAgB,CAACK,UAAU,CAAC,EAAE;YAChCO,gBAAgB,CAACM,wBAAwB,GAAGrB,sBAAsB,CAAC;QACrE,CAAC;IACH,CAAC;IAED,OAAOsB,IAAI,CAACC,YAAY,CAAC,OAAO,EAAER,gBAAgB,CAAC,CAACS,MAAM,CAACX,KAAK,CAAC,CAAC;AACpE,CAAC"}
1
+ {"version":3,"sources":["../../../src/model/units/decimal.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { MAX_SIGNIFICANT_DIGITS } from './constants';\nimport { UnitGroupConfig, UnitConfig } from './types';\nimport { hasDecimalPlaces, limitDecimalPlaces, shouldShortenValues } from './utils';\n\nconst decimalUnits = ['decimal'] as const;\ntype DecimalUnit = (typeof decimalUnits)[number];\nexport type DecimalFormatOptions = {\n unit: DecimalUnit;\n decimalPlaces?: number;\n shortValues?: boolean;\n};\nexport const DECIMAL_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Decimal',\n decimalPlaces: true,\n shortValues: true,\n};\nexport const DECIMAL_UNIT_CONFIG: Readonly<Record<DecimalUnit, UnitConfig>> = {\n decimal: {\n group: 'Decimal',\n label: 'Decimal',\n },\n};\n\nexport function formatDecimal(value: number, { shortValues, decimalPlaces }: DecimalFormatOptions): string {\n const formatterOptions: Intl.NumberFormatOptions = {\n style: 'decimal',\n useGrouping: true,\n };\n\n if (shouldShortenValues(shortValues)) {\n formatterOptions.notation = 'compact';\n }\n\n if (hasDecimalPlaces(decimalPlaces)) {\n formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimalPlaces);\n formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimalPlaces);\n } else {\n if (shouldShortenValues(shortValues)) {\n formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n }\n\n const formatter = Intl.NumberFormat('en-US', formatterOptions);\n return formatter.format(value);\n}\n"],"names":["MAX_SIGNIFICANT_DIGITS","hasDecimalPlaces","limitDecimalPlaces","shouldShortenValues","decimalUnits","DECIMAL_GROUP_CONFIG","label","decimalPlaces","shortValues","DECIMAL_UNIT_CONFIG","decimal","group","formatDecimal","value","formatterOptions","style","useGrouping","notation","minimumFractionDigits","maximumFractionDigits","maximumSignificantDigits","formatter","Intl","NumberFormat","format"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,sBAAsB,QAAQ,cAAc;AAErD,SAASC,gBAAgB,EAAEC,kBAAkB,EAAEC,mBAAmB,QAAQ,UAAU;AAEpF,MAAMC,eAAe;IAAC;CAAU;AAOhC,OAAO,MAAMC,uBAAwC;IACnDC,OAAO;IACPC,eAAe;IACfC,aAAa;AACf,EAAE;AACF,OAAO,MAAMC,sBAAiE;IAC5EC,SAAS;QACPC,OAAO;QACPL,OAAO;IACT;AACF,EAAE;AAEF,OAAO,SAASM,cAAcC,KAAa,EAAE,EAAEL,WAAW,EAAED,aAAa,EAAwB;IAC/F,MAAMO,mBAA6C;QACjDC,OAAO;QACPC,aAAa;IACf;IAEA,IAAIb,oBAAoBK,cAAc;QACpCM,iBAAiBG,QAAQ,GAAG;IAC9B;IAEA,IAAIhB,iBAAiBM,gBAAgB;QACnCO,iBAAiBI,qBAAqB,GAAGhB,mBAAmBK;QAC5DO,iBAAiBK,qBAAqB,GAAGjB,mBAAmBK;IAC9D,OAAO;QACL,IAAIJ,oBAAoBK,cAAc;YACpCM,iBAAiBM,wBAAwB,GAAGpB;QAC9C;IACF;IAEA,MAAMqB,YAAYC,KAAKC,YAAY,CAAC,SAAST;IAC7C,OAAOO,UAAUG,MAAM,CAACX;AAC1B"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/model/units/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './utils';\nexport * from './units';\nexport * from './constants';\nexport * from './types';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC"}
1
+ {"version":3,"sources":["../../../src/model/units/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './utils';\nexport * from './units';\nexport * from './constants';\nexport * from './types';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,UAAU;AACxB,cAAc,UAAU;AACxB,cAAc,cAAc;AAC5B,cAAc,UAAU"}
@@ -1,12 +1,12 @@
1
1
  import { UnitGroupConfig, UnitConfig } from './types';
2
- declare const percentUnitKinds: readonly ["Percent", "PercentDecimal", "%"];
3
- declare type PercentUnitKind = (typeof percentUnitKinds)[number];
4
- export declare type PercentUnitOptions = {
5
- kind: PercentUnitKind;
6
- decimal_places?: number;
2
+ declare const percentUnits: readonly ["percent", "percent-decimal", "%"];
3
+ type PercentUnit = (typeof percentUnits)[number];
4
+ export type PercentFormatOptions = {
5
+ unit: PercentUnit;
6
+ decimalPlaces?: number;
7
7
  };
8
8
  export declare const PERCENT_GROUP_CONFIG: UnitGroupConfig;
9
- export declare const PERCENT_UNIT_CONFIG: Readonly<Record<PercentUnitKind, UnitConfig>>;
10
- export declare function formatPercent(value: number, { kind, decimal_places }: PercentUnitOptions): string;
9
+ export declare const PERCENT_UNIT_CONFIG: Readonly<Record<PercentUnit, UnitConfig>>;
10
+ export declare function formatPercent(value: number, { unit, decimalPlaces }: PercentFormatOptions): string;
11
11
  export {};
12
12
  //# sourceMappingURL=percent.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"percent.d.ts","sourceRoot":"","sources":["../../../src/model/units/percent.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGtD,QAAA,MAAM,gBAAgB,6CAA8C,CAAC;AACrE,aAAK,eAAe,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC;AACzD,oBAAY,kBAAkB,GAAG;IAC/B,IAAI,EAAE,eAAe,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AACF,eAAO,MAAM,oBAAoB,EAAE,eAGlC,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,QAAQ,CAAC,MAAM,CAAC,eAAe,EAAE,UAAU,CAAC,CAgB7E,CAAC;AAEF,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,EAAE,kBAAkB,GAAG,MAAM,CAmBjG"}
1
+ {"version":3,"file":"percent.d.ts","sourceRoot":"","sources":["../../../src/model/units/percent.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGtD,QAAA,MAAM,YAAY,8CAA+C,CAAC;AAClE,KAAK,WAAW,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC;AACjD,MAAM,MAAM,oBAAoB,GAAG;IACjC,IAAI,EAAE,WAAW,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AACF,eAAO,MAAM,oBAAoB,EAAE,eAGlC,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,QAAQ,CAAC,MAAM,CAAC,WAAW,EAAE,UAAU,CAAC,CAgBzE,CAAC;AAEF,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE,EAAE,oBAAoB,GAAG,MAAM,CAoBlG"}
@@ -12,22 +12,22 @@
12
12
  // limitations under the License.
13
13
  import { MAX_SIGNIFICANT_DIGITS } from './constants';
14
14
  import { hasDecimalPlaces, limitDecimalPlaces } from './utils';
15
- const percentUnitKinds = [
16
- 'Percent',
17
- 'PercentDecimal',
15
+ const percentUnits = [
16
+ 'percent',
17
+ 'percent-decimal',
18
18
  '%'
19
19
  ];
20
20
  export const PERCENT_GROUP_CONFIG = {
21
- label: 'Percent',
22
- decimal_places: true
21
+ label: 'percent',
22
+ decimalPlaces: true
23
23
  };
24
24
  const PERCENT_GROUP = 'Percent';
25
25
  export const PERCENT_UNIT_CONFIG = {
26
- Percent: {
26
+ percent: {
27
27
  group: PERCENT_GROUP,
28
28
  label: 'Percent (0-100)'
29
29
  },
30
- PercentDecimal: {
30
+ 'percent-decimal': {
31
31
  group: PERCENT_GROUP,
32
32
  label: 'Percent (0.0-1.0)'
33
33
  },
@@ -39,22 +39,23 @@ export const PERCENT_UNIT_CONFIG = {
39
39
  label: '%'
40
40
  }
41
41
  };
42
- export function formatPercent(value, { kind , decimal_places }) {
43
- // Intl.NumberFormat translates 0 -> 0%, 0.5 -> 50%, 1 -> 100%
44
- if (kind === 'Percent') {
45
- value = value / 100;
46
- }
42
+ export function formatPercent(value, { unit, decimalPlaces }) {
47
43
  const formatterOptions = {
48
44
  style: 'percent',
49
45
  useGrouping: true
50
46
  };
51
- if (hasDecimalPlaces(decimal_places)) {
52
- formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimal_places);
53
- formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimal_places);
47
+ if (hasDecimalPlaces(decimalPlaces)) {
48
+ formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimalPlaces);
49
+ formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimalPlaces);
54
50
  } else {
55
51
  formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;
56
52
  }
57
- return Intl.NumberFormat('en-US', formatterOptions).format(value);
53
+ // Intl.NumberFormat translates 0 -> 0%, 0.5 -> 50%, 1 -> 100%, etc.
54
+ if (unit === 'percent') {
55
+ value = value / 100;
56
+ }
57
+ const formatter = Intl.NumberFormat('en-US', formatterOptions);
58
+ return formatter.format(value);
58
59
  }
59
60
 
60
61
  //# sourceMappingURL=percent.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/model/units/percent.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { MAX_SIGNIFICANT_DIGITS } from './constants';\nimport { UnitGroupConfig, UnitConfig } from './types';\nimport { hasDecimalPlaces, limitDecimalPlaces } from './utils';\n\nconst percentUnitKinds = ['Percent', 'PercentDecimal', '%'] as const;\ntype PercentUnitKind = (typeof percentUnitKinds)[number];\nexport type PercentUnitOptions = {\n kind: PercentUnitKind;\n decimal_places?: number;\n};\nexport const PERCENT_GROUP_CONFIG: UnitGroupConfig = {\n label: 'Percent',\n decimal_places: true,\n};\nconst PERCENT_GROUP = 'Percent';\nexport const PERCENT_UNIT_CONFIG: Readonly<Record<PercentUnitKind, UnitConfig>> = {\n Percent: {\n group: PERCENT_GROUP,\n label: 'Percent (0-100)',\n },\n PercentDecimal: {\n group: PERCENT_GROUP,\n label: 'Percent (0.0-1.0)',\n },\n '%': {\n // This option is not shown in the selector because it is a shorthand\n // duplicate of `Percent`.\n disableSelectorOption: true,\n group: PERCENT_GROUP,\n label: '%',\n },\n};\n\nexport function formatPercent(value: number, { kind, decimal_places }: PercentUnitOptions): string {\n // Intl.NumberFormat translates 0 -> 0%, 0.5 -> 50%, 1 -> 100%\n if (kind === 'Percent') {\n value = value / 100;\n }\n\n const formatterOptions: Intl.NumberFormatOptions = {\n style: 'percent',\n useGrouping: true,\n };\n\n if (hasDecimalPlaces(decimal_places)) {\n formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimal_places);\n formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimal_places);\n } else {\n formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n\n return Intl.NumberFormat('en-US', formatterOptions).format(value);\n}\n"],"names":["MAX_SIGNIFICANT_DIGITS","hasDecimalPlaces","limitDecimalPlaces","percentUnitKinds","PERCENT_GROUP_CONFIG","label","decimal_places","PERCENT_GROUP","PERCENT_UNIT_CONFIG","Percent","group","PercentDecimal","disableSelectorOption","formatPercent","value","kind","formatterOptions","style","useGrouping","minimumFractionDigits","maximumFractionDigits","maximumSignificantDigits","Intl","NumberFormat","format"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,sBAAsB,QAAQ,aAAa,CAAC;AAErD,SAASC,gBAAgB,EAAEC,kBAAkB,QAAQ,SAAS,CAAC;AAE/D,MAAMC,gBAAgB,GAAG;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.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { MAX_SIGNIFICANT_DIGITS } from './constants';\nimport { UnitGroupConfig, UnitConfig } from './types';\nimport { hasDecimalPlaces, limitDecimalPlaces } from './utils';\n\nconst percentUnits = ['percent', 'percent-decimal', '%'] as const;\ntype PercentUnit = (typeof percentUnits)[number];\nexport type PercentFormatOptions = {\n unit: PercentUnit;\n decimalPlaces?: number;\n};\nexport const PERCENT_GROUP_CONFIG: UnitGroupConfig = {\n label: 'percent',\n decimalPlaces: true,\n};\nconst PERCENT_GROUP = 'Percent';\nexport const PERCENT_UNIT_CONFIG: Readonly<Record<PercentUnit, UnitConfig>> = {\n percent: {\n group: PERCENT_GROUP,\n label: 'Percent (0-100)',\n },\n 'percent-decimal': {\n group: PERCENT_GROUP,\n label: 'Percent (0.0-1.0)',\n },\n '%': {\n // This option is not shown in the selector because it is a shorthand\n // duplicate of `Percent`.\n disableSelectorOption: true,\n group: PERCENT_GROUP,\n label: '%',\n },\n};\n\nexport function formatPercent(value: number, { unit, decimalPlaces }: PercentFormatOptions): string {\n const formatterOptions: Intl.NumberFormatOptions = {\n style: 'percent',\n useGrouping: true,\n };\n\n if (hasDecimalPlaces(decimalPlaces)) {\n formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimalPlaces);\n formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimalPlaces);\n } else {\n formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;\n }\n\n // Intl.NumberFormat translates 0 -> 0%, 0.5 -> 50%, 1 -> 100%, etc.\n if (unit === 'percent') {\n value = value / 100;\n }\n\n const formatter = Intl.NumberFormat('en-US', formatterOptions);\n return formatter.format(value);\n}\n"],"names":["MAX_SIGNIFICANT_DIGITS","hasDecimalPlaces","limitDecimalPlaces","percentUnits","PERCENT_GROUP_CONFIG","label","decimalPlaces","PERCENT_GROUP","PERCENT_UNIT_CONFIG","percent","group","disableSelectorOption","formatPercent","value","unit","formatterOptions","style","useGrouping","minimumFractionDigits","maximumFractionDigits","maximumSignificantDigits","formatter","Intl","NumberFormat","format"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,sBAAsB,QAAQ,cAAc;AAErD,SAASC,gBAAgB,EAAEC,kBAAkB,QAAQ,UAAU;AAE/D,MAAMC,eAAe;IAAC;IAAW;IAAmB;CAAI;AAMxD,OAAO,MAAMC,uBAAwC;IACnDC,OAAO;IACPC,eAAe;AACjB,EAAE;AACF,MAAMC,gBAAgB;AACtB,OAAO,MAAMC,sBAAiE;IAC5EC,SAAS;QACPC,OAAOH;QACPF,OAAO;IACT;IACA,mBAAmB;QACjBK,OAAOH;QACPF,OAAO;IACT;IACA,KAAK;QACH,qEAAqE;QACrE,0BAA0B;QAC1BM,uBAAuB;QACvBD,OAAOH;QACPF,OAAO;IACT;AACF,EAAE;AAEF,OAAO,SAASO,cAAcC,KAAa,EAAE,EAAEC,IAAI,EAAER,aAAa,EAAwB;IACxF,MAAMS,mBAA6C;QACjDC,OAAO;QACPC,aAAa;IACf;IAEA,IAAIhB,iBAAiBK,gBAAgB;QACnCS,iBAAiBG,qBAAqB,GAAGhB,mBAAmBI;QAC5DS,iBAAiBI,qBAAqB,GAAGjB,mBAAmBI;IAC9D,OAAO;QACLS,iBAAiBK,wBAAwB,GAAGpB;IAC9C;IAEA,oEAAoE;IACpE,IAAIc,SAAS,WAAW;QACtBD,QAAQA,QAAQ;IAClB;IAEA,MAAMQ,YAAYC,KAAKC,YAAY,CAAC,SAASR;IAC7C,OAAOM,UAAUG,MAAM,CAACX;AAC1B"}
@@ -0,0 +1,13 @@
1
+ import { UnitGroupConfig, UnitConfig } from './types';
2
+ declare const throughputUnits: readonly ["counts/sec", "events/sec", "messages/sec", "ops/sec", "packets/sec", "reads/sec", "records/sec", "requests/sec", "rows/sec", "writes/sec"];
3
+ type ThroughputUnit = (typeof throughputUnits)[number];
4
+ export type ThroughputFormatOptions = {
5
+ unit: ThroughputUnit;
6
+ decimalPlaces?: number;
7
+ shortValues?: boolean;
8
+ };
9
+ export declare const THROUGHPUT_GROUP_CONFIG: UnitGroupConfig;
10
+ export declare const THROUGHPUT_UNIT_CONFIG: Readonly<Record<ThroughputUnit, UnitConfig>>;
11
+ export declare function formatThroughput(value: number, { unit, shortValues, decimalPlaces }: ThroughputFormatOptions): string;
12
+ export {};
13
+ //# sourceMappingURL=throughput.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"throughput.d.ts","sourceRoot":"","sources":["../../../src/model/units/throughput.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAGtD,QAAA,MAAM,eAAe,uJAWX,CAAC;AACX,KAAK,cAAc,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC;AACvD,MAAM,MAAM,uBAAuB,GAAG;IACpC,IAAI,EAAE,cAAc,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AACF,eAAO,MAAM,uBAAuB,EAAE,eAGrC,CAAC;AAEF,eAAO,MAAM,sBAAsB,EAAE,QAAQ,CAAC,MAAM,CAAC,cAAc,EAAE,UAAU,CAAC,CAyC/E,CAAC;AAEF,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,aAAa,EAAE,EAAE,uBAAuB,GAAG,MAAM,CAqBrH"}