@perses-dev/components 0.34.0 → 0.36.0

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 (199) hide show
  1. package/dist/ContentWithLegend/ContentWithLegend.d.ts +1 -1
  2. package/dist/ContentWithLegend/ContentWithLegend.d.ts.map +1 -1
  3. package/dist/ContentWithLegend/ContentWithLegend.js +4 -2
  4. package/dist/ContentWithLegend/ContentWithLegend.js.map +1 -1
  5. package/dist/ContentWithLegend/model/content-with-legend-model.d.ts +9 -3
  6. package/dist/ContentWithLegend/model/content-with-legend-model.d.ts.map +1 -1
  7. package/dist/ContentWithLegend/model/content-with-legend-model.js +17 -7
  8. package/dist/ContentWithLegend/model/content-with-legend-model.js.map +1 -1
  9. package/dist/DateTimeRangePicker/DateTimeRangePicker.d.ts +1 -1
  10. package/dist/DateTimeRangePicker/DateTimeRangePicker.d.ts.map +1 -1
  11. package/dist/DateTimeRangePicker/DateTimeRangePicker.js.map +1 -1
  12. package/dist/DateTimeRangePicker/TimeRangeSelector.d.ts +2 -5
  13. package/dist/DateTimeRangePicker/TimeRangeSelector.d.ts.map +1 -1
  14. package/dist/DateTimeRangePicker/TimeRangeSelector.js.map +1 -1
  15. package/dist/Drawer/Drawer.js +1 -1
  16. package/dist/Drawer/Drawer.js.map +1 -1
  17. package/dist/GaugeChart/GaugeChart.d.ts +2 -2
  18. package/dist/GaugeChart/GaugeChart.d.ts.map +1 -1
  19. package/dist/GaugeChart/GaugeChart.js +7 -5
  20. package/dist/GaugeChart/GaugeChart.js.map +1 -1
  21. package/dist/Legend/CompactLegend.d.ts +3 -1
  22. package/dist/Legend/CompactLegend.d.ts.map +1 -1
  23. package/dist/Legend/CompactLegend.js +5 -2
  24. package/dist/Legend/CompactLegend.js.map +1 -1
  25. package/dist/Legend/Legend.d.ts +11 -2
  26. package/dist/Legend/Legend.d.ts.map +1 -1
  27. package/dist/Legend/Legend.js +4 -2
  28. package/dist/Legend/Legend.js.map +1 -1
  29. package/dist/Legend/ListLegend.d.ts +3 -1
  30. package/dist/Legend/ListLegend.d.ts.map +1 -1
  31. package/dist/Legend/ListLegend.js +5 -4
  32. package/dist/Legend/ListLegend.js.map +1 -1
  33. package/dist/Legend/ListLegendItem.d.ts +15 -2
  34. package/dist/Legend/ListLegendItem.d.ts.map +1 -1
  35. package/dist/Legend/ListLegendItem.js +17 -5
  36. package/dist/Legend/ListLegendItem.js.map +1 -1
  37. package/dist/Legend/TableLegend.d.ts +4 -2
  38. package/dist/Legend/TableLegend.d.ts.map +1 -1
  39. package/dist/Legend/TableLegend.js +8 -2
  40. package/dist/Legend/TableLegend.js.map +1 -1
  41. package/dist/LineChart/LineChart.d.ts +17 -3
  42. package/dist/LineChart/LineChart.d.ts.map +1 -1
  43. package/dist/LineChart/LineChart.js +33 -7
  44. package/dist/LineChart/LineChart.js.map +1 -1
  45. package/dist/LineChart/utils.d.ts +2 -1
  46. package/dist/LineChart/utils.d.ts.map +1 -1
  47. package/dist/LineChart/utils.js +14 -1
  48. package/dist/LineChart/utils.js.map +1 -1
  49. package/dist/OptionsEditorLayout/OptionsEditorControl.js +1 -1
  50. package/dist/OptionsEditorLayout/OptionsEditorControl.js.map +1 -1
  51. package/dist/RefreshIntervalPicker/RefreshIntervalPicker.d.ts +12 -0
  52. package/dist/RefreshIntervalPicker/RefreshIntervalPicker.d.ts.map +1 -0
  53. package/dist/RefreshIntervalPicker/RefreshIntervalPicker.js +45 -0
  54. package/dist/RefreshIntervalPicker/RefreshIntervalPicker.js.map +1 -0
  55. package/dist/RefreshIntervalPicker/index.d.ts +2 -0
  56. package/dist/RefreshIntervalPicker/index.d.ts.map +1 -0
  57. package/dist/{model/units → RefreshIntervalPicker}/index.js +1 -3
  58. package/dist/RefreshIntervalPicker/index.js.map +1 -0
  59. package/dist/SettingsAutocomplete/SettingsAutocomplete.d.ts +36 -0
  60. package/dist/SettingsAutocomplete/SettingsAutocomplete.d.ts.map +1 -0
  61. package/dist/SettingsAutocomplete/SettingsAutocomplete.js +65 -0
  62. package/dist/SettingsAutocomplete/SettingsAutocomplete.js.map +1 -0
  63. package/dist/SettingsAutocomplete/index.d.ts +2 -0
  64. package/dist/SettingsAutocomplete/index.d.ts.map +1 -0
  65. package/dist/{model/units/constants.js → SettingsAutocomplete/index.js} +2 -4
  66. package/dist/SettingsAutocomplete/index.js.map +1 -0
  67. package/dist/StatChart/StatChart.d.ts +3 -2
  68. package/dist/StatChart/StatChart.d.ts.map +1 -1
  69. package/dist/StatChart/StatChart.js +74 -21
  70. package/dist/StatChart/StatChart.js.map +1 -1
  71. package/dist/StatChart/calculateFontSize.d.ts +14 -0
  72. package/dist/StatChart/calculateFontSize.d.ts.map +1 -0
  73. package/dist/StatChart/calculateFontSize.js +47 -0
  74. package/dist/StatChart/calculateFontSize.js.map +1 -0
  75. package/dist/Table/InnerTable.js +2 -2
  76. package/dist/Table/InnerTable.js.map +1 -1
  77. package/dist/Table/Table.d.ts +1 -1
  78. package/dist/Table/Table.d.ts.map +1 -1
  79. package/dist/Table/Table.js +57 -9
  80. package/dist/Table/Table.js.map +1 -1
  81. package/dist/Table/TableCell.d.ts +11 -1
  82. package/dist/Table/TableCell.d.ts.map +1 -1
  83. package/dist/Table/TableCell.js +8 -3
  84. package/dist/Table/TableCell.js.map +1 -1
  85. package/dist/Table/TableCheckbox.js +1 -1
  86. package/dist/Table/TableCheckbox.js.map +1 -1
  87. package/dist/Table/TableHeaderCell.d.ts +23 -0
  88. package/dist/Table/TableHeaderCell.d.ts.map +1 -0
  89. package/dist/Table/TableHeaderCell.js +53 -0
  90. package/dist/Table/TableHeaderCell.js.map +1 -0
  91. package/dist/Table/VirtualizedTable.d.ts +3 -3
  92. package/dist/Table/VirtualizedTable.d.ts.map +1 -1
  93. package/dist/Table/VirtualizedTable.js +43 -8
  94. package/dist/Table/VirtualizedTable.js.map +1 -1
  95. package/dist/Table/model/table-model.d.ts +71 -7
  96. package/dist/Table/model/table-model.d.ts.map +1 -1
  97. package/dist/Table/model/table-model.js +6 -2
  98. package/dist/Table/model/table-model.js.map +1 -1
  99. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.d.ts +2 -1
  100. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.d.ts.map +1 -1
  101. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.js +2 -1
  102. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.js.map +1 -1
  103. package/dist/TimeSeriesTooltip/nearby-series.d.ts +2 -1
  104. package/dist/TimeSeriesTooltip/nearby-series.d.ts.map +1 -1
  105. package/dist/TimeSeriesTooltip/nearby-series.js +2 -11
  106. package/dist/TimeSeriesTooltip/nearby-series.js.map +1 -1
  107. package/dist/UnitSelector/UnitSelector.d.ts +1 -1
  108. package/dist/UnitSelector/UnitSelector.d.ts.map +1 -1
  109. package/dist/UnitSelector/UnitSelector.js +11 -24
  110. package/dist/UnitSelector/UnitSelector.js.map +1 -1
  111. package/dist/YAxisLabel.js +1 -1
  112. package/dist/YAxisLabel.js.map +1 -1
  113. package/dist/cjs/ContentWithLegend/ContentWithLegend.js +4 -2
  114. package/dist/cjs/ContentWithLegend/model/content-with-legend-model.js +17 -7
  115. package/dist/cjs/Drawer/Drawer.js +1 -1
  116. package/dist/cjs/GaugeChart/GaugeChart.js +7 -5
  117. package/dist/cjs/Legend/CompactLegend.js +5 -2
  118. package/dist/cjs/Legend/Legend.js +4 -2
  119. package/dist/cjs/Legend/ListLegend.js +5 -4
  120. package/dist/cjs/Legend/ListLegendItem.js +17 -5
  121. package/dist/cjs/Legend/TableLegend.js +8 -2
  122. package/dist/cjs/LineChart/LineChart.js +31 -5
  123. package/dist/cjs/LineChart/utils.js +14 -3
  124. package/dist/cjs/OptionsEditorLayout/OptionsEditorControl.js +1 -1
  125. package/dist/cjs/RefreshIntervalPicker/RefreshIntervalPicker.js +51 -0
  126. package/dist/cjs/{model/units → RefreshIntervalPicker}/index.js +1 -3
  127. package/dist/cjs/SettingsAutocomplete/SettingsAutocomplete.js +66 -0
  128. package/dist/cjs/{model/units/types.js → SettingsAutocomplete/index.js} +12 -12
  129. package/dist/cjs/StatChart/StatChart.js +75 -22
  130. package/dist/cjs/StatChart/calculateFontSize.js +51 -0
  131. package/dist/cjs/Table/InnerTable.js +2 -2
  132. package/dist/cjs/Table/Table.js +56 -8
  133. package/dist/cjs/Table/TableCell.js +8 -3
  134. package/dist/cjs/Table/TableCheckbox.js +1 -1
  135. package/dist/cjs/Table/TableHeaderCell.js +59 -0
  136. package/dist/cjs/Table/VirtualizedTable.js +43 -8
  137. package/dist/cjs/Table/model/table-model.js +6 -2
  138. package/dist/cjs/TimeSeriesTooltip/TimeSeriesTooltip.js +2 -1
  139. package/dist/cjs/TimeSeriesTooltip/nearby-series.js +2 -11
  140. package/dist/cjs/UnitSelector/UnitSelector.js +15 -28
  141. package/dist/cjs/YAxisLabel.js +1 -1
  142. package/dist/cjs/index.js +2 -0
  143. package/dist/cjs/model/index.js +1 -1
  144. package/dist/cjs/model/{units/constants.js → timeOption.js} +0 -7
  145. package/dist/index.d.ts +2 -0
  146. package/dist/index.d.ts.map +1 -1
  147. package/dist/index.js +2 -0
  148. package/dist/index.js.map +1 -1
  149. package/dist/model/index.d.ts +1 -1
  150. package/dist/model/index.d.ts.map +1 -1
  151. package/dist/model/index.js +1 -1
  152. package/dist/model/index.js.map +1 -1
  153. package/dist/model/theme.d.ts +4 -6
  154. package/dist/model/theme.d.ts.map +1 -1
  155. package/dist/model/theme.js.map +1 -1
  156. package/dist/model/timeOption.d.ts +6 -0
  157. package/dist/model/timeOption.d.ts.map +1 -0
  158. package/dist/model/{units/types.js → timeOption.js} +2 -9
  159. package/dist/model/timeOption.js.map +1 -0
  160. package/package.json +3 -4
  161. package/dist/cjs/model/units/bytes.js +0 -84
  162. package/dist/cjs/model/units/decimal.js +0 -62
  163. package/dist/cjs/model/units/percent.js +0 -73
  164. package/dist/cjs/model/units/time.js +0 -105
  165. package/dist/cjs/model/units/units.js +0 -101
  166. package/dist/cjs/model/units/utils.js +0 -42
  167. package/dist/model/units/bytes.d.ts +0 -13
  168. package/dist/model/units/bytes.d.ts.map +0 -1
  169. package/dist/model/units/bytes.js +0 -66
  170. package/dist/model/units/bytes.js.map +0 -1
  171. package/dist/model/units/constants.d.ts +0 -2
  172. package/dist/model/units/constants.d.ts.map +0 -1
  173. package/dist/model/units/constants.js.map +0 -1
  174. package/dist/model/units/decimal.d.ts +0 -13
  175. package/dist/model/units/decimal.d.ts.map +0 -1
  176. package/dist/model/units/decimal.js +0 -49
  177. package/dist/model/units/decimal.js.map +0 -1
  178. package/dist/model/units/index.d.ts +0 -4
  179. package/dist/model/units/index.d.ts.map +0 -1
  180. package/dist/model/units/index.js.map +0 -1
  181. package/dist/model/units/percent.d.ts +0 -12
  182. package/dist/model/units/percent.d.ts.map +0 -1
  183. package/dist/model/units/percent.js +0 -60
  184. package/dist/model/units/percent.js.map +0 -1
  185. package/dist/model/units/time.d.ts +0 -22
  186. package/dist/model/units/time.d.ts.map +0 -1
  187. package/dist/model/units/time.js +0 -91
  188. package/dist/model/units/time.js.map +0 -1
  189. package/dist/model/units/types.d.ts +0 -47
  190. package/dist/model/units/types.d.ts.map +0 -1
  191. package/dist/model/units/types.js.map +0 -1
  192. package/dist/model/units/units.d.ts +0 -40
  193. package/dist/model/units/units.d.ts.map +0 -1
  194. package/dist/model/units/units.js +0 -80
  195. package/dist/model/units/units.js.map +0 -1
  196. package/dist/model/units/utils.d.ts +0 -4
  197. package/dist/model/units/utils.d.ts.map +0 -1
  198. package/dist/model/units/utils.js +0 -32
  199. package/dist/model/units/utils.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/model/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 './graph';\nexport * from './theme';\nexport * from './units';\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,SAAS,CAAC"}
1
+ {"version":3,"sources":["../../src/model/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 './graph';\nexport * from './theme';\nexport * from './timeOption';\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,cAAc,CAAC"}
@@ -1,7 +1,8 @@
1
- import type { EChartsOption, EChartsCoreOption, BarSeriesOption, LineSeriesOption, GaugeSeriesOption } from 'echarts';
1
+ import { ThresholdColorPalette } from '@perses-dev/core';
2
+ import type { EChartsOption, BarSeriesOption, LineSeriesOption, GaugeSeriesOption, TitleComponentOption, ComposeOption, XAXisComponentOption, YAXisComponentOption } from 'echarts';
2
3
  export interface PersesChartsTheme {
3
4
  echartsTheme: EChartsTheme;
4
- noDataOption: EChartsCoreOption;
5
+ noDataOption: NoDataOption;
5
6
  sparkline: {
6
7
  width: number;
7
8
  color: string;
@@ -24,8 +25,5 @@ export interface EChartsTheme extends EChartsOption {
24
25
  line?: LineSeriesOption;
25
26
  gauge?: GaugeSeriesOption;
26
27
  }
27
- export interface ThresholdColorPalette {
28
- defaultColor: string;
29
- palette: string[];
30
- }
28
+ export declare type NoDataOption = ComposeOption<TitleComponentOption | XAXisComponentOption | YAXisComponentOption>;
31
29
  //# sourceMappingURL=theme.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../../src/model/theme.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,aAAa,EAAE,iBAAiB,EAAE,eAAe,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEtH,MAAM,WAAW,iBAAiB;IAChC,YAAY,EAAE,YAAY,CAAC;IAC3B,YAAY,EAAE,iBAAiB,CAAC;IAChC,SAAS,EAAE;QACT,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;IACF;;OAEG;IACH,SAAS,EAAE;QACT;;WAEG;QACH,OAAO,EAAE;YACP,OAAO,EAAE,MAAM,CAAC;SACjB,CAAC;KACH,CAAC;IACF,UAAU,EAAE,qBAAqB,CAAC;CACnC;AAGD,MAAM,WAAW,YAAa,SAAQ,aAAa;IACjD,GAAG,CAAC,EAAE,eAAe,CAAC;IACtB,IAAI,CAAC,EAAE,gBAAgB,CAAC;IACxB,KAAK,CAAC,EAAE,iBAAiB,CAAC;CAC3B;AAED,MAAM,WAAW,qBAAqB;IACpC,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB"}
1
+ {"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../../src/model/theme.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,KAAK,EACV,aAAa,EACb,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,EACpB,aAAa,EACb,oBAAoB,EACpB,oBAAoB,EACrB,MAAM,SAAS,CAAC;AAEjB,MAAM,WAAW,iBAAiB;IAChC,YAAY,EAAE,YAAY,CAAC;IAC3B,YAAY,EAAE,YAAY,CAAC;IAC3B,SAAS,EAAE;QACT,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;IACF;;OAEG;IACH,SAAS,EAAE;QACT;;WAEG;QACH,OAAO,EAAE;YACP,OAAO,EAAE,MAAM,CAAC;SACjB,CAAC;KACH,CAAC;IACF,UAAU,EAAE,qBAAqB,CAAC;CACnC;AAGD,MAAM,WAAW,YAAa,SAAQ,aAAa;IACjD,GAAG,CAAC,EAAE,eAAe,CAAC;IACtB,IAAI,CAAC,EAAE,gBAAgB,CAAC;IACxB,KAAK,CAAC,EAAE,iBAAiB,CAAC;CAC3B;AAED,oBAAY,YAAY,GAAG,aAAa,CAAC,oBAAoB,GAAG,oBAAoB,GAAG,oBAAoB,CAAC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/model/theme.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 type { EChartsOption, EChartsCoreOption, BarSeriesOption, LineSeriesOption, GaugeSeriesOption } from 'echarts';\n\nexport interface PersesChartsTheme {\n echartsTheme: EChartsTheme;\n noDataOption: EChartsCoreOption;\n sparkline: {\n width: number;\n color: string;\n };\n /**\n * Theming for the container that wraps a chart.\n */\n container: {\n /**\n * Padding in pixels.\n */\n padding: {\n default: number;\n };\n };\n thresholds: ThresholdColorPalette;\n}\n\n// https://github.com/apache/echarts/issues/12489#issuecomment-643185207\nexport interface EChartsTheme extends EChartsOption {\n bar?: BarSeriesOption;\n line?: LineSeriesOption;\n gauge?: GaugeSeriesOption;\n}\n\nexport interface ThresholdColorPalette {\n defaultColor: string;\n palette: string[];\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,WAiCC"}
1
+ {"version":3,"sources":["../../src/model/theme.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 { ThresholdColorPalette } from '@perses-dev/core';\nimport type {\n EChartsOption,\n BarSeriesOption,\n LineSeriesOption,\n GaugeSeriesOption,\n TitleComponentOption,\n ComposeOption,\n XAXisComponentOption,\n YAXisComponentOption,\n} from 'echarts';\n\nexport interface PersesChartsTheme {\n echartsTheme: EChartsTheme;\n noDataOption: NoDataOption;\n sparkline: {\n width: number;\n color: string;\n };\n /**\n * Theming for the container that wraps a chart.\n */\n container: {\n /**\n * Padding in pixels.\n */\n padding: {\n default: number;\n };\n };\n thresholds: ThresholdColorPalette;\n}\n\n// https://github.com/apache/echarts/issues/12489#issuecomment-643185207\nexport interface EChartsTheme extends EChartsOption {\n bar?: BarSeriesOption;\n line?: LineSeriesOption;\n gauge?: GaugeSeriesOption;\n}\n\nexport type NoDataOption = ComposeOption<TitleComponentOption | XAXisComponentOption | YAXisComponentOption>;\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,WAwC6G"}
@@ -0,0 +1,6 @@
1
+ import { RelativeTimeRange } from '@perses-dev/core';
2
+ export interface TimeOption {
3
+ value: RelativeTimeRange;
4
+ display: string;
5
+ }
6
+ //# sourceMappingURL=timeOption.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timeOption.d.ts","sourceRoot":"","sources":["../../src/model/timeOption.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,iBAAiB,CAAC;IACzB,OAAO,EAAE,MAAM,CAAC;CACjB"}
@@ -10,13 +10,6 @@
10
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
- // Common types needed across individual unit groups and the overall combined
14
- // units.
15
- export const UNIT_GROUPS = [
16
- 'Time',
17
- 'Percent',
18
- 'Decimal',
19
- 'Bytes'
20
- ];
13
+ export { };
21
14
 
22
- //# sourceMappingURL=types.js.map
15
+ //# sourceMappingURL=timeOption.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/model/timeOption.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 { RelativeTimeRange } from '@perses-dev/core';\n\nexport interface TimeOption {\n value: RelativeTimeRange;\n display: string;\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,WAKC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@perses-dev/components",
3
- "version": "0.34.0",
3
+ "version": "0.36.0",
4
4
  "description": "Common UI components used across Perses features",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/perses/perses/blob/main/README.md",
@@ -36,7 +36,7 @@
36
36
  "@codemirror/lang-json": "^6.0.1",
37
37
  "@fontsource/lato": "^4.5.10",
38
38
  "@mui/x-date-pickers": "^5.0.0-beta.1",
39
- "@perses-dev/core": "0.34.0",
39
+ "@perses-dev/core": "0.36.0",
40
40
  "@tanstack/react-table": "^8.9.1",
41
41
  "@uiw/react-codemirror": "^4.19.1",
42
42
  "date-fns": "^2.28.0",
@@ -45,13 +45,12 @@
45
45
  "lodash": "^4.17.21",
46
46
  "mathjs": "^10.6.4",
47
47
  "mdi-material-ui": "^7.4.0",
48
- "numbro": "^2.3.6",
49
48
  "react-colorful": "^5.6.1",
50
49
  "react-error-boundary": "^3.1.4",
51
50
  "react-virtuoso": "^4.3.6"
52
51
  },
53
52
  "devDependencies": {
54
- "@perses-dev/storybook": "0.34.0"
53
+ "@perses-dev/storybook": "0.36.0"
55
54
  },
56
55
  "peerDependencies": {
57
56
  "@mui/material": "^5.10.0",
@@ -1,84 +0,0 @@
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
- "use strict";
14
- Object.defineProperty(exports, "__esModule", {
15
- value: true
16
- });
17
- function _export(target, all) {
18
- for(var name in all)Object.defineProperty(target, name, {
19
- enumerable: true,
20
- get: all[name]
21
- });
22
- }
23
- _export(exports, {
24
- BYTES_GROUP_CONFIG: ()=>BYTES_GROUP_CONFIG,
25
- BYTES_UNIT_CONFIG: ()=>BYTES_UNIT_CONFIG,
26
- formatBytes: ()=>formatBytes
27
- });
28
- const _numbro = /*#__PURE__*/ _interopRequireDefault(require("numbro"));
29
- const _constants = require("./constants");
30
- const _utils = require("./utils");
31
- function _interopRequireDefault(obj) {
32
- return obj && obj.__esModule ? obj : {
33
- default: obj
34
- };
35
- }
36
- const DEFAULT_NUMBRO_MANTISSA = 2;
37
- const bytesUnitKinds = [
38
- 'Bytes'
39
- ];
40
- const BYTES_GROUP_CONFIG = {
41
- label: 'Bytes',
42
- decimal_places: true,
43
- abbreviate: true
44
- };
45
- const BYTES_UNIT_CONFIG = {
46
- // These units are powers of 1000.
47
- // In other words, 1 KB = 1000 bytes.
48
- Bytes: {
49
- group: 'Bytes',
50
- label: 'Bytes'
51
- }
52
- };
53
- function formatBytes(bytes, options) {
54
- const { abbreviate , decimal_places } = options;
55
- if (!(0, _utils.shouldAbbreviate)(abbreviate) || Math.abs(bytes) < 1000) {
56
- const formatterOptions = {
57
- style: 'unit',
58
- unit: 'byte',
59
- unitDisplay: 'long',
60
- useGrouping: true
61
- };
62
- if ((0, _utils.hasDecimalPlaces)(decimal_places)) {
63
- formatterOptions.minimumFractionDigits = (0, _utils.limitDecimalPlaces)(decimal_places);
64
- formatterOptions.maximumFractionDigits = (0, _utils.limitDecimalPlaces)(decimal_places);
65
- } else {
66
- // This can happen if bytes is between -1000 and 1000
67
- if ((0, _utils.shouldAbbreviate)(abbreviate)) {
68
- formatterOptions.maximumSignificantDigits = _constants.MAX_SIGNIFICANT_DIGITS;
69
- }
70
- }
71
- return Intl.NumberFormat('en-US', formatterOptions).format(bytes);
72
- }
73
- // numbro is able to add units like KB, MB, GB, etc. correctly
74
- return (0, _numbro.default)(bytes).format({
75
- output: 'byte',
76
- base: 'decimal',
77
- spaceSeparated: true,
78
- mantissa: (0, _utils.hasDecimalPlaces)(decimal_places) ? decimal_places : DEFAULT_NUMBRO_MANTISSA,
79
- // trimMantissa trims trailing 0s
80
- trimMantissa: !(0, _utils.hasDecimalPlaces)(decimal_places),
81
- // optionalMantissa excludes all the decimal places if they're all zeros
82
- optionalMantissa: !(0, _utils.hasDecimalPlaces)(decimal_places)
83
- });
84
- }
@@ -1,62 +0,0 @@
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
- "use strict";
14
- Object.defineProperty(exports, "__esModule", {
15
- value: true
16
- });
17
- function _export(target, all) {
18
- for(var name in all)Object.defineProperty(target, name, {
19
- enumerable: true,
20
- get: all[name]
21
- });
22
- }
23
- _export(exports, {
24
- DECIMAL_GROUP_CONFIG: ()=>DECIMAL_GROUP_CONFIG,
25
- DECIMAL_UNIT_CONFIG: ()=>DECIMAL_UNIT_CONFIG,
26
- formatDecimal: ()=>formatDecimal
27
- });
28
- const _constants = require("./constants");
29
- const _utils = require("./utils");
30
- const decimalUnitKinds = [
31
- 'Decimal'
32
- ];
33
- const DECIMAL_GROUP_CONFIG = {
34
- label: 'Decimal',
35
- decimal_places: true,
36
- abbreviate: true
37
- };
38
- const DECIMAL_UNIT_CONFIG = {
39
- Decimal: {
40
- group: 'Decimal',
41
- label: 'Decimal'
42
- }
43
- };
44
- function formatDecimal(value, options) {
45
- const { abbreviate , decimal_places } = options;
46
- const formatterOptions = {
47
- style: 'decimal',
48
- useGrouping: true
49
- };
50
- if ((0, _utils.shouldAbbreviate)(abbreviate)) {
51
- formatterOptions.notation = 'compact';
52
- }
53
- if ((0, _utils.hasDecimalPlaces)(decimal_places)) {
54
- formatterOptions.minimumFractionDigits = (0, _utils.limitDecimalPlaces)(decimal_places);
55
- formatterOptions.maximumFractionDigits = (0, _utils.limitDecimalPlaces)(decimal_places);
56
- } else {
57
- if ((0, _utils.shouldAbbreviate)(abbreviate)) {
58
- formatterOptions.maximumSignificantDigits = _constants.MAX_SIGNIFICANT_DIGITS;
59
- }
60
- }
61
- return Intl.NumberFormat('en-US', formatterOptions).format(value);
62
- }
@@ -1,73 +0,0 @@
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
- "use strict";
14
- Object.defineProperty(exports, "__esModule", {
15
- value: true
16
- });
17
- function _export(target, all) {
18
- for(var name in all)Object.defineProperty(target, name, {
19
- enumerable: true,
20
- get: all[name]
21
- });
22
- }
23
- _export(exports, {
24
- PERCENT_GROUP_CONFIG: ()=>PERCENT_GROUP_CONFIG,
25
- PERCENT_UNIT_CONFIG: ()=>PERCENT_UNIT_CONFIG,
26
- formatPercent: ()=>formatPercent
27
- });
28
- const _constants = require("./constants");
29
- const _utils = require("./utils");
30
- const percentUnitKinds = [
31
- 'Percent',
32
- 'PercentDecimal',
33
- '%'
34
- ];
35
- const PERCENT_GROUP_CONFIG = {
36
- label: 'Percent',
37
- decimal_places: true
38
- };
39
- const PERCENT_GROUP = 'Percent';
40
- const PERCENT_UNIT_CONFIG = {
41
- Percent: {
42
- group: PERCENT_GROUP,
43
- label: 'Percent (0-100)'
44
- },
45
- PercentDecimal: {
46
- group: PERCENT_GROUP,
47
- label: 'Percent (0.0-1.0)'
48
- },
49
- '%': {
50
- // This option is not shown in the selector because it is a shorthand
51
- // duplicate of `Percent`.
52
- disableSelectorOption: true,
53
- group: PERCENT_GROUP,
54
- label: '%'
55
- }
56
- };
57
- function formatPercent(value, { kind , decimal_places }) {
58
- // Intl.NumberFormat translates 0 -> 0%, 0.5 -> 50%, 1 -> 100%
59
- if (kind === 'Percent') {
60
- value = value / 100;
61
- }
62
- const formatterOptions = {
63
- style: 'percent',
64
- useGrouping: true
65
- };
66
- if ((0, _utils.hasDecimalPlaces)(decimal_places)) {
67
- formatterOptions.minimumFractionDigits = (0, _utils.limitDecimalPlaces)(decimal_places);
68
- formatterOptions.maximumFractionDigits = (0, _utils.limitDecimalPlaces)(decimal_places);
69
- } else {
70
- formatterOptions.maximumSignificantDigits = _constants.MAX_SIGNIFICANT_DIGITS;
71
- }
72
- return Intl.NumberFormat('en-US', formatterOptions).format(value);
73
- }
@@ -1,105 +0,0 @@
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
- "use strict";
14
- Object.defineProperty(exports, "__esModule", {
15
- value: true
16
- });
17
- function _export(target, all) {
18
- for(var name in all)Object.defineProperty(target, name, {
19
- enumerable: true,
20
- get: all[name]
21
- });
22
- }
23
- _export(exports, {
24
- PersesTimeToIntlTime: ()=>PersesTimeToIntlTime,
25
- TIME_GROUP_CONFIG: ()=>TIME_GROUP_CONFIG,
26
- TIME_UNIT_CONFIG: ()=>TIME_UNIT_CONFIG,
27
- formatTime: ()=>formatTime
28
- });
29
- const _constants = require("./constants");
30
- const _utils = require("./utils");
31
- const timeUnitKinds = [
32
- 'Milliseconds',
33
- 'Seconds',
34
- 'Minutes',
35
- 'Hours',
36
- 'Days',
37
- 'Weeks',
38
- 'Months',
39
- 'Years'
40
- ];
41
- const TIME_GROUP = 'Time';
42
- const TIME_GROUP_CONFIG = {
43
- label: 'Time',
44
- decimal_places: true
45
- };
46
- const TIME_UNIT_CONFIG = {
47
- Milliseconds: {
48
- group: TIME_GROUP,
49
- label: 'Milliseconds'
50
- },
51
- Seconds: {
52
- group: TIME_GROUP,
53
- label: 'Seconds'
54
- },
55
- Minutes: {
56
- group: TIME_GROUP,
57
- label: 'Minutes'
58
- },
59
- Hours: {
60
- group: TIME_GROUP,
61
- label: 'Hours'
62
- },
63
- Days: {
64
- group: TIME_GROUP,
65
- label: 'Days'
66
- },
67
- Weeks: {
68
- group: TIME_GROUP,
69
- label: 'Weeks'
70
- },
71
- Months: {
72
- group: TIME_GROUP,
73
- label: 'Months'
74
- },
75
- Years: {
76
- group: TIME_GROUP,
77
- label: 'Years'
78
- }
79
- };
80
- var PersesTimeToIntlTime;
81
- (function(PersesTimeToIntlTime) {
82
- PersesTimeToIntlTime["Milliseconds"] = 'millisecond';
83
- PersesTimeToIntlTime["Seconds"] = 'second';
84
- PersesTimeToIntlTime["Minutes"] = 'minute';
85
- PersesTimeToIntlTime["Hours"] = 'hour';
86
- PersesTimeToIntlTime["Days"] = 'day';
87
- PersesTimeToIntlTime["Weeks"] = 'week';
88
- PersesTimeToIntlTime["Months"] = 'month';
89
- PersesTimeToIntlTime["Years"] = 'year';
90
- })(PersesTimeToIntlTime || (PersesTimeToIntlTime = {}));
91
- function formatTime(value, { kind , decimal_places }) {
92
- const isMonthOrYear = kind === 'Months' || kind === 'Years';
93
- const formatterOptions = {
94
- style: 'unit',
95
- unit: PersesTimeToIntlTime[kind],
96
- unitDisplay: isMonthOrYear ? 'long' : 'narrow'
97
- };
98
- if ((0, _utils.hasDecimalPlaces)(decimal_places)) {
99
- formatterOptions.minimumFractionDigits = (0, _utils.limitDecimalPlaces)(decimal_places);
100
- formatterOptions.maximumFractionDigits = (0, _utils.limitDecimalPlaces)(decimal_places);
101
- } else {
102
- formatterOptions.maximumSignificantDigits = _constants.MAX_SIGNIFICANT_DIGITS;
103
- }
104
- return Intl.NumberFormat('en-US', formatterOptions).format(value);
105
- }
@@ -1,101 +0,0 @@
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
- "use strict";
14
- Object.defineProperty(exports, "__esModule", {
15
- value: true
16
- });
17
- function _export(target, all) {
18
- for(var name in all)Object.defineProperty(target, name, {
19
- enumerable: true,
20
- get: all[name]
21
- });
22
- }
23
- _export(exports, {
24
- UNIT_GROUP_CONFIG: ()=>UNIT_GROUP_CONFIG,
25
- UNIT_CONFIG: ()=>UNIT_CONFIG,
26
- formatValue: ()=>formatValue,
27
- getUnitKindConfig: ()=>getUnitKindConfig,
28
- getUnitGroup: ()=>getUnitGroup,
29
- getUnitGroupConfig: ()=>getUnitGroupConfig,
30
- isTimeUnit: ()=>isTimeUnit,
31
- isPercentUnit: ()=>isPercentUnit,
32
- isDecimalUnit: ()=>isDecimalUnit,
33
- isBytesUnit: ()=>isBytesUnit,
34
- isUnitWithDecimalPlaces: ()=>isUnitWithDecimalPlaces,
35
- isUnitWithAbbreviate: ()=>isUnitWithAbbreviate
36
- });
37
- const _bytes = require("./bytes");
38
- const _decimal = require("./decimal");
39
- const _percent = require("./percent");
40
- const _time = require("./time");
41
- const UNIT_GROUP_CONFIG = {
42
- Time: _time.TIME_GROUP_CONFIG,
43
- Percent: _percent.PERCENT_GROUP_CONFIG,
44
- Decimal: _decimal.DECIMAL_GROUP_CONFIG,
45
- Bytes: _bytes.BYTES_GROUP_CONFIG
46
- };
47
- const UNIT_CONFIG = {
48
- ..._time.TIME_UNIT_CONFIG,
49
- ..._percent.PERCENT_UNIT_CONFIG,
50
- ..._decimal.DECIMAL_UNIT_CONFIG,
51
- ..._bytes.BYTES_UNIT_CONFIG
52
- };
53
- function formatValue(value, unitOptions) {
54
- if (unitOptions === undefined) {
55
- return value.toString();
56
- }
57
- if (isDecimalUnit(unitOptions)) {
58
- return (0, _decimal.formatDecimal)(value, unitOptions);
59
- }
60
- if (isTimeUnit(unitOptions)) {
61
- return (0, _time.formatTime)(value, unitOptions);
62
- }
63
- if (isPercentUnit(unitOptions)) {
64
- return (0, _percent.formatPercent)(value, unitOptions);
65
- }
66
- if (isBytesUnit(unitOptions)) {
67
- return (0, _bytes.formatBytes)(value, unitOptions);
68
- }
69
- const exhaustive = unitOptions;
70
- throw new Error(`Unknown unit options ${exhaustive}`);
71
- }
72
- function getUnitKindConfig(unitOptions) {
73
- return UNIT_CONFIG[unitOptions.kind];
74
- }
75
- function getUnitGroup(unitOptions) {
76
- return getUnitKindConfig(unitOptions).group;
77
- }
78
- function getUnitGroupConfig(unitOptions) {
79
- const unitConfig = getUnitKindConfig(unitOptions);
80
- return UNIT_GROUP_CONFIG[unitConfig.group];
81
- }
82
- function isTimeUnit(unitOptions) {
83
- return getUnitGroup(unitOptions) === 'Time';
84
- }
85
- function isPercentUnit(unitOptions) {
86
- return getUnitGroup(unitOptions) === 'Percent';
87
- }
88
- function isDecimalUnit(unitOptions) {
89
- return getUnitGroup(unitOptions) === 'Decimal';
90
- }
91
- function isBytesUnit(unitOptions) {
92
- return getUnitGroup(unitOptions) === 'Bytes';
93
- }
94
- function isUnitWithDecimalPlaces(unitOptions) {
95
- const groupConfig = getUnitGroupConfig(unitOptions);
96
- return !!groupConfig.decimal_places;
97
- }
98
- function isUnitWithAbbreviate(unitOptions) {
99
- const groupConfig = getUnitGroupConfig(unitOptions);
100
- return !!groupConfig.abbreviate;
101
- }
@@ -1,42 +0,0 @@
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
- "use strict";
14
- Object.defineProperty(exports, "__esModule", {
15
- value: true
16
- });
17
- function _export(target, all) {
18
- for(var name in all)Object.defineProperty(target, name, {
19
- enumerable: true,
20
- get: all[name]
21
- });
22
- }
23
- _export(exports, {
24
- shouldAbbreviate: ()=>shouldAbbreviate,
25
- hasDecimalPlaces: ()=>hasDecimalPlaces,
26
- limitDecimalPlaces: ()=>limitDecimalPlaces
27
- });
28
- function shouldAbbreviate(abbreviate) {
29
- return abbreviate !== false;
30
- }
31
- function hasDecimalPlaces(decimal_places) {
32
- return typeof decimal_places === 'number';
33
- }
34
- function limitDecimalPlaces(num) {
35
- if (!num) return num;
36
- if (num < 0) {
37
- num = 0;
38
- } else if (num > 20) {
39
- num = 20;
40
- }
41
- return num;
42
- }
@@ -1,13 +0,0 @@
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;
8
- };
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;
12
- export {};
13
- //# sourceMappingURL=bytes.d.ts.map
@@ -1 +0,0 @@
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,66 +0,0 @@
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
- import numbro from 'numbro';
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'
19
- ];
20
- export const BYTES_GROUP_CONFIG = {
21
- label: 'Bytes',
22
- decimal_places: true,
23
- abbreviate: true
24
- };
25
- export const BYTES_UNIT_CONFIG = {
26
- // These units are powers of 1000.
27
- // In other words, 1 KB = 1000 bytes.
28
- Bytes: {
29
- group: 'Bytes',
30
- label: 'Bytes'
31
- }
32
- };
33
- export function formatBytes(bytes, options) {
34
- const { abbreviate , decimal_places } = options;
35
- if (!shouldAbbreviate(abbreviate) || Math.abs(bytes) < 1000) {
36
- const formatterOptions = {
37
- style: 'unit',
38
- unit: 'byte',
39
- unitDisplay: 'long',
40
- useGrouping: true
41
- };
42
- if (hasDecimalPlaces(decimal_places)) {
43
- formatterOptions.minimumFractionDigits = limitDecimalPlaces(decimal_places);
44
- formatterOptions.maximumFractionDigits = limitDecimalPlaces(decimal_places);
45
- } else {
46
- // This can happen if bytes is between -1000 and 1000
47
- if (shouldAbbreviate(abbreviate)) {
48
- formatterOptions.maximumSignificantDigits = MAX_SIGNIFICANT_DIGITS;
49
- }
50
- }
51
- return Intl.NumberFormat('en-US', formatterOptions).format(bytes);
52
- }
53
- // numbro is able to add units like KB, MB, GB, etc. correctly
54
- return numbro(bytes).format({
55
- output: 'byte',
56
- base: 'decimal',
57
- spaceSeparated: true,
58
- mantissa: hasDecimalPlaces(decimal_places) ? decimal_places : DEFAULT_NUMBRO_MANTISSA,
59
- // trimMantissa trims trailing 0s
60
- trimMantissa: !hasDecimalPlaces(decimal_places),
61
- // optionalMantissa excludes all the decimal places if they're all zeros
62
- optionalMantissa: !hasDecimalPlaces(decimal_places)
63
- });
64
- }
65
-
66
- //# sourceMappingURL=bytes.js.map