@perses-dev/components 0.8.0 → 0.9.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 (131) hide show
  1. package/dist/Drawer/Drawer.d.ts +3 -4
  2. package/dist/Drawer/Drawer.d.ts.map +1 -1
  3. package/dist/Drawer/Drawer.js +35 -1
  4. package/dist/Drawer/Drawer.js.map +1 -0
  5. package/dist/Drawer/index.js +15 -1
  6. package/dist/Drawer/index.js.map +1 -0
  7. package/dist/EChart.d.ts.map +1 -1
  8. package/dist/EChart.js +142 -1
  9. package/dist/EChart.js.map +1 -0
  10. package/dist/ErrorAlert.js +25 -1
  11. package/dist/ErrorAlert.js.map +1 -0
  12. package/dist/ErrorBoundary.js +16 -1
  13. package/dist/ErrorBoundary.js.map +1 -0
  14. package/dist/GaugeChart/GaugeChart.js +172 -1
  15. package/dist/GaugeChart/GaugeChart.js.map +1 -0
  16. package/dist/GaugeChart/index.js +15 -1
  17. package/dist/GaugeChart/index.js.map +1 -0
  18. package/dist/InfoTooltip/InfoTooltip.js +79 -1
  19. package/dist/InfoTooltip/InfoTooltip.js.map +1 -0
  20. package/dist/InfoTooltip/InfoTooltip.test.js +36 -1
  21. package/dist/InfoTooltip/InfoTooltip.test.js.map +1 -0
  22. package/dist/InfoTooltip/index.js +15 -1
  23. package/dist/InfoTooltip/index.js.map +1 -0
  24. package/dist/LineChart/LineChart.js +198 -1
  25. package/dist/LineChart/LineChart.js.map +1 -0
  26. package/dist/LineChart/index.js +15 -1
  27. package/dist/LineChart/index.js.map +1 -0
  28. package/dist/LineChart/utils.js +63 -1
  29. package/dist/LineChart/utils.js.map +1 -0
  30. package/dist/StatChart/StatChart.js +121 -1
  31. package/dist/StatChart/StatChart.js.map +1 -0
  32. package/dist/StatChart/StatChart.test.js +82 -1
  33. package/dist/StatChart/StatChart.test.js.map +1 -0
  34. package/dist/StatChart/index.js +15 -1
  35. package/dist/StatChart/index.js.map +1 -0
  36. package/dist/TimeRangeSelector/AbsoluteTimePicker.js +175 -1
  37. package/dist/TimeRangeSelector/AbsoluteTimePicker.js.map +1 -0
  38. package/dist/TimeRangeSelector/TimeRangeSelector.js +52 -1
  39. package/dist/TimeRangeSelector/TimeRangeSelector.js.map +1 -0
  40. package/dist/TimeRangeSelector/index.js +16 -1
  41. package/dist/TimeRangeSelector/index.js.map +1 -0
  42. package/dist/TimeRangeSelector/utils.js +36 -1
  43. package/dist/TimeRangeSelector/utils.js.map +1 -0
  44. package/dist/Tooltip/SeriesInfo.js +143 -1
  45. package/dist/Tooltip/SeriesInfo.js.map +1 -0
  46. package/dist/Tooltip/SeriesMarker.js +33 -1
  47. package/dist/Tooltip/SeriesMarker.js.map +1 -0
  48. package/dist/Tooltip/Tooltip.js +72 -1
  49. package/dist/Tooltip/Tooltip.js.map +1 -0
  50. package/dist/Tooltip/TooltipContent.js +89 -1
  51. package/dist/Tooltip/TooltipContent.js.map +1 -0
  52. package/dist/Tooltip/focused-series.js +108 -1
  53. package/dist/Tooltip/focused-series.js.map +1 -0
  54. package/dist/Tooltip/focused-series.test.js +75 -1
  55. package/dist/Tooltip/focused-series.test.js.map +1 -0
  56. package/dist/Tooltip/index.js +16 -1
  57. package/dist/Tooltip/index.js.map +1 -0
  58. package/dist/Tooltip/tooltip-model.js +80 -1
  59. package/dist/Tooltip/tooltip-model.js.map +1 -0
  60. package/dist/Tooltip/utils.js +46 -1
  61. package/dist/Tooltip/utils.js.map +1 -0
  62. package/dist/cjs/Drawer/Drawer.js +26 -13
  63. package/dist/cjs/Drawer/index.js +16 -17
  64. package/dist/cjs/EChart.js +114 -89
  65. package/dist/cjs/ErrorAlert.js +16 -12
  66. package/dist/cjs/ErrorBoundary.js +10 -6
  67. package/dist/cjs/GaugeChart/GaugeChart.js +90 -57
  68. package/dist/cjs/GaugeChart/index.js +16 -17
  69. package/dist/cjs/InfoTooltip/InfoTooltip.js +90 -33
  70. package/dist/cjs/InfoTooltip/InfoTooltip.test.js +27 -17
  71. package/dist/cjs/InfoTooltip/index.js +16 -17
  72. package/dist/cjs/LineChart/LineChart.js +122 -87
  73. package/dist/cjs/LineChart/index.js +16 -17
  74. package/dist/cjs/LineChart/utils.js +23 -23
  75. package/dist/cjs/StatChart/StatChart.js +107 -46
  76. package/dist/cjs/StatChart/StatChart.test.js +65 -21
  77. package/dist/cjs/StatChart/index.js +16 -17
  78. package/dist/cjs/TimeRangeSelector/AbsoluteTimePicker.js +144 -64
  79. package/dist/cjs/TimeRangeSelector/TimeRangeSelector.js +45 -22
  80. package/dist/cjs/TimeRangeSelector/index.js +17 -18
  81. package/dist/cjs/TimeRangeSelector/utils.js +19 -16
  82. package/dist/cjs/Tooltip/SeriesInfo.js +120 -48
  83. package/dist/cjs/Tooltip/SeriesMarker.js +20 -11
  84. package/dist/cjs/Tooltip/Tooltip.js +95 -67
  85. package/dist/cjs/Tooltip/TooltipContent.js +76 -31
  86. package/dist/cjs/Tooltip/focused-series.js +40 -36
  87. package/dist/cjs/Tooltip/focused-series.test.js +36 -16
  88. package/dist/cjs/Tooltip/index.js +17 -18
  89. package/dist/cjs/Tooltip/tooltip-model.js +46 -30
  90. package/dist/cjs/Tooltip/utils.js +13 -16
  91. package/dist/cjs/context/ChartsThemeProvider.js +65 -13
  92. package/dist/cjs/index.js +27 -28
  93. package/dist/cjs/model/graph.js +10 -5
  94. package/dist/cjs/model/index.js +18 -19
  95. package/dist/cjs/model/theme.js +4 -2
  96. package/dist/cjs/model/units.js +68 -51
  97. package/dist/cjs/test/index.js +16 -17
  98. package/dist/cjs/test/render.js +22 -12
  99. package/dist/cjs/test/setup-tests.js +4 -2
  100. package/dist/cjs/utils/combine-sx.js +15 -16
  101. package/dist/cjs/utils/index.js +17 -18
  102. package/dist/cjs/utils/theme-gen.js +64 -55
  103. package/dist/cjs/utils/theme-gen.test.js +14 -12
  104. package/dist/context/ChartsThemeProvider.js +36 -1
  105. package/dist/context/ChartsThemeProvider.js.map +1 -0
  106. package/dist/index.js +26 -1
  107. package/dist/index.js.map +1 -0
  108. package/dist/model/graph.js +15 -1
  109. package/dist/model/graph.js.map +1 -0
  110. package/dist/model/index.js +17 -1
  111. package/dist/model/index.js.map +1 -0
  112. package/dist/model/theme.js +15 -1
  113. package/dist/model/theme.js.map +1 -0
  114. package/dist/model/units.d.ts.map +1 -1
  115. package/dist/model/units.js +196 -1
  116. package/dist/model/units.js.map +1 -0
  117. package/dist/test/index.js +15 -1
  118. package/dist/test/index.js.map +1 -0
  119. package/dist/test/render.js +32 -1
  120. package/dist/test/render.js.map +1 -0
  121. package/dist/test/setup-tests.js +18 -1
  122. package/dist/test/setup-tests.js.map +1 -0
  123. package/dist/utils/combine-sx.js +27 -1
  124. package/dist/utils/combine-sx.js.map +1 -0
  125. package/dist/utils/index.js +16 -1
  126. package/dist/utils/index.js.map +1 -0
  127. package/dist/utils/theme-gen.js +183 -1
  128. package/dist/utils/theme-gen.js.map +1 -0
  129. package/dist/utils/theme-gen.test.js +196 -1
  130. package/dist/utils/theme-gen.test.js.map +1 -0
  131. package/package.json +8 -4
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  // Copyright 2022 The Perses Authors
3
2
  // Licensed under the Apache License, Version 2.0 (the "License");
4
3
  // you may not use this file except in compliance with the License.
@@ -11,104 +10,116 @@
11
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
11
  // See the License for the specific language governing permissions and
13
12
  // limitations under the License.
14
- var __importDefault = (this && this.__importDefault) || function (mod) {
15
- return (mod && mod.__esModule) ? mod : { "default": mod };
16
- };
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.generateChartsTheme = void 0;
19
- const merge_1 = __importDefault(require("lodash/merge"));
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ Object.defineProperty(exports, "generateChartsTheme", {
18
+ enumerable: true,
19
+ get: ()=>generateChartsTheme
20
+ });
21
+ const _lodashEs = require("lodash-es");
20
22
  const DEFAULT_TEXT_COLOR = '#222';
21
23
  function generateChartsTheme(themeName, muiTheme, echartsTheme) {
22
- var _a, _b, _c, _d, _e, _f;
23
- const primaryTextColor = (_b = (_a = muiTheme.palette.text) === null || _a === void 0 ? void 0 : _a.primary) !== null && _b !== void 0 ? _b : DEFAULT_TEXT_COLOR;
24
+ var ref, ref1, ref2, ref3, ref4;
25
+ var ref5;
26
+ const primaryTextColor = (ref5 = (ref = muiTheme.palette.text) === null || ref === void 0 ? void 0 : ref.primary) !== null && ref5 !== void 0 ? ref5 : DEFAULT_TEXT_COLOR;
24
27
  const muiConvertedTheme = {
25
28
  title: {
26
- show: false,
29
+ show: false
27
30
  },
28
31
  textStyle: {
29
32
  color: primaryTextColor,
30
33
  fontFamily: muiTheme.typography.fontFamily,
31
- fontSize: 12,
34
+ fontSize: 12
32
35
  },
33
36
  grid: {
34
37
  top: 5,
35
38
  right: 20,
36
39
  bottom: 0,
37
40
  left: 20,
38
- containLabel: true,
41
+ containLabel: true
39
42
  },
40
- color: ['#8dd3c7', '#bebada', '#fb8072', '#80b1d3', '#fdb462'],
43
+ color: [
44
+ '#8dd3c7',
45
+ '#bebada',
46
+ '#fb8072',
47
+ '#80b1d3',
48
+ '#fdb462'
49
+ ],
41
50
  categoryAxis: {
42
51
  show: true,
43
52
  axisLabel: {
44
53
  show: true,
45
54
  color: primaryTextColor,
46
- margin: 15,
55
+ margin: 15
47
56
  },
48
57
  axisTick: {
49
58
  show: false,
50
59
  length: 6,
51
60
  lineStyle: {
52
- color: muiTheme.palette.grey[600],
53
- },
61
+ color: muiTheme.palette.grey[600]
62
+ }
54
63
  },
55
64
  axisLine: {
56
65
  show: true,
57
66
  lineStyle: {
58
- color: muiTheme.palette.grey[600],
59
- },
67
+ color: muiTheme.palette.grey[600]
68
+ }
60
69
  },
61
70
  splitLine: {
62
71
  show: true,
63
72
  lineStyle: {
64
73
  width: 0.5,
65
74
  color: muiTheme.palette.grey[300],
66
- opacity: 0.6,
67
- },
75
+ opacity: 0.6
76
+ }
68
77
  },
69
78
  splitArea: {
70
79
  show: false,
71
80
  areaStyle: {
72
- color: [muiTheme.palette.grey[300]],
73
- },
74
- },
81
+ color: [
82
+ muiTheme.palette.grey[300]
83
+ ]
84
+ }
85
+ }
75
86
  },
76
87
  valueAxis: {
77
88
  show: true,
78
89
  axisLabel: {
79
90
  color: primaryTextColor,
80
- margin: 12,
91
+ margin: 12
81
92
  },
82
93
  axisLine: {
83
- show: false,
94
+ show: false
84
95
  },
85
96
  splitLine: {
86
97
  show: true,
87
98
  lineStyle: {
88
99
  width: 0.5,
89
100
  color: muiTheme.palette.grey[300],
90
- opacity: 0.6,
91
- },
92
- },
101
+ opacity: 0.6
102
+ }
103
+ }
93
104
  },
94
105
  legend: {
95
106
  orient: 'horizontal',
96
107
  textStyle: {
97
- color: primaryTextColor,
108
+ color: primaryTextColor
98
109
  },
99
110
  pageTextStyle: {
100
- color: muiTheme.palette.grey[600],
111
+ color: muiTheme.palette.grey[600]
101
112
  },
102
- pageIconColor: (_d = (_c = muiTheme === null || muiTheme === void 0 ? void 0 : muiTheme.palette) === null || _c === void 0 ? void 0 : _c.action) === null || _d === void 0 ? void 0 : _d.active,
103
- pageIconInactiveColor: (_f = (_e = muiTheme === null || muiTheme === void 0 ? void 0 : muiTheme.palette) === null || _e === void 0 ? void 0 : _e.action) === null || _f === void 0 ? void 0 : _f.disabled,
113
+ pageIconColor: muiTheme === null || muiTheme === void 0 ? void 0 : (ref1 = muiTheme.palette) === null || ref1 === void 0 ? void 0 : (ref2 = ref1.action) === null || ref2 === void 0 ? void 0 : ref2.active,
114
+ pageIconInactiveColor: muiTheme === null || muiTheme === void 0 ? void 0 : (ref3 = muiTheme.palette) === null || ref3 === void 0 ? void 0 : (ref4 = ref3.action) === null || ref4 === void 0 ? void 0 : ref4.disabled
104
115
  },
105
116
  toolbox: {
106
117
  show: true,
107
118
  top: 10,
108
119
  right: 10,
109
120
  iconStyle: {
110
- borderColor: primaryTextColor,
111
- },
121
+ borderColor: primaryTextColor
122
+ }
112
123
  },
113
124
  tooltip: {},
114
125
  line: {
@@ -117,64 +128,62 @@ function generateChartsTheme(themeName, muiTheme, echartsTheme) {
117
128
  symbolSize: 4,
118
129
  smooth: false,
119
130
  lineStyle: {
120
- width: 1,
131
+ width: 1
121
132
  },
122
133
  emphasis: {
123
134
  lineStyle: {
124
- width: 1.5,
125
- },
126
- },
135
+ width: 1.5
136
+ }
137
+ }
127
138
  },
128
139
  bar: {
129
140
  barMaxWidth: 150,
130
141
  itemStyle: {
131
142
  borderWidth: 0,
132
- borderColor: muiTheme.palette.grey[300],
133
- },
143
+ borderColor: muiTheme.palette.grey[300]
144
+ }
134
145
  },
135
146
  gauge: {
136
147
  detail: {
137
148
  fontSize: 18,
138
149
  fontWeight: 600,
139
- valueAnimation: false,
150
+ valueAnimation: false
140
151
  },
141
152
  splitLine: {
142
153
  distance: 0,
143
154
  length: 4,
144
155
  lineStyle: {
145
- width: 1,
146
- },
156
+ width: 1
157
+ }
147
158
  },
148
- splitNumber: 12,
149
- },
159
+ splitNumber: 12
160
+ }
150
161
  };
151
162
  return {
152
163
  themeName,
153
- echartsTheme: (0, merge_1.default)(muiConvertedTheme, echartsTheme),
164
+ echartsTheme: (0, _lodashEs.merge)(muiConvertedTheme, echartsTheme),
154
165
  noDataOption: {
155
166
  title: {
156
167
  show: true,
157
168
  textStyle: {
158
169
  color: primaryTextColor,
159
170
  fontSize: 16,
160
- fontWeight: 400,
171
+ fontWeight: 400
161
172
  },
162
173
  text: 'No data',
163
174
  left: 'center',
164
- top: 'center',
175
+ top: 'center'
165
176
  },
166
177
  xAxis: {
167
- show: false,
178
+ show: false
168
179
  },
169
180
  yAxis: {
170
- show: false,
171
- },
181
+ show: false
182
+ }
172
183
  },
173
184
  sparkline: {
174
185
  width: 2,
175
- color: '#1976d2',
176
- },
177
- // TODO: add thresholdColors to theme
186
+ color: '#1976d2'
187
+ }
178
188
  };
179
189
  }
180
- exports.generateChartsTheme = generateChartsTheme;
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  // Copyright 2022 The Perses Authors
3
2
  // Licensed under the Apache License, Version 2.0 (the "License");
4
3
  // you may not use this file except in compliance with the License.
@@ -11,24 +10,27 @@
11
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
11
  // See the License for the specific language governing permissions and
13
12
  // limitations under the License.
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const material_1 = require("@mui/material");
16
- const theme_gen_1 = require("./theme-gen");
17
- describe('generateChartsTheme', () => {
18
- const muiTheme = (0, material_1.createTheme)({});
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ const _material = require("@mui/material");
18
+ const _themeGen = require("./theme-gen");
19
+ describe('generateChartsTheme', ()=>{
20
+ const muiTheme = (0, _material.createTheme)({});
19
21
  const echartsThemeOverrides = {
20
22
  legend: {
21
23
  textStyle: {
22
- color: 'yellow',
23
- },
24
+ color: 'yellow'
25
+ }
24
26
  },
25
27
  line: {
26
28
  showSymbol: true,
27
- smooth: true,
28
- },
29
+ smooth: true
30
+ }
29
31
  };
30
- const chartsTheme = (0, theme_gen_1.generateChartsTheme)('perses', muiTheme, echartsThemeOverrides);
31
- it('should return perses specific charts theme from converted MUI theme', () => {
32
+ const chartsTheme = (0, _themeGen.generateChartsTheme)('perses', muiTheme, echartsThemeOverrides);
33
+ it('should return perses specific charts theme from converted MUI theme', ()=>{
32
34
  expect(chartsTheme).toMatchInlineSnapshot(`
33
35
  Object {
34
36
  "echartsTheme": Object {
@@ -1 +1,36 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import{createContext,useContext}from"react";import{registerTheme}from"echarts";export function ChartsThemeProvider(e){const{children:t,themeName:r,chartsTheme:o}=e;return void 0!==o&&void 0!==o.echartsTheme&&registerTheme(r,o.echartsTheme),_jsx(ChartsThemeContext.Provider,{value:o,children:t})}export const ChartsThemeContext=createContext(void 0);export function useChartsTheme(){const e=useContext(ChartsThemeContext);if(void 0===e)throw new Error("No ChartsThemeContext found. Did you forget a Provider?");return e}
1
+ // Copyright 2022 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 { jsx as _jsx } from "react/jsx-runtime";
14
+ import React, { createContext, useContext } from 'react';
15
+ import { registerTheme } from 'echarts';
16
+ export function ChartsThemeProvider(props) {
17
+ const { children , themeName , chartsTheme } = props;
18
+ if (chartsTheme !== undefined && chartsTheme.echartsTheme !== undefined) {
19
+ // register ECharts theme to be used in individual charts, see: https://apache.github.io/echarts-handbook/en/concepts/style/#theme
20
+ registerTheme(themeName, chartsTheme.echartsTheme);
21
+ }
22
+ return /*#__PURE__*/ _jsx(ChartsThemeContext.Provider, {
23
+ value: chartsTheme,
24
+ children: children
25
+ });
26
+ }
27
+ export const ChartsThemeContext = /*#__PURE__*/ createContext(undefined);
28
+ export function useChartsTheme() {
29
+ const ctx = useContext(ChartsThemeContext);
30
+ if (ctx === undefined) {
31
+ throw new Error('No ChartsThemeContext found. Did you forget a Provider?');
32
+ }
33
+ return ctx;
34
+ }
35
+
36
+ //# sourceMappingURL=ChartsThemeProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/context/ChartsThemeProvider.tsx"],"sourcesContent":["// Copyright 2022 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 React, { createContext, useContext } from 'react';\nimport { registerTheme } from 'echarts';\nimport { PersesChartsTheme } from '../model';\n\nexport interface ChartsThemeProviderProps {\n themeName: string;\n chartsTheme?: PersesChartsTheme;\n children?: React.ReactNode;\n}\n\nexport function ChartsThemeProvider(props: ChartsThemeProviderProps) {\n const { children, themeName, chartsTheme } = props;\n\n if (chartsTheme !== undefined && chartsTheme.echartsTheme !== undefined) {\n // register ECharts theme to be used in individual charts, see: https://apache.github.io/echarts-handbook/en/concepts/style/#theme\n registerTheme(themeName, chartsTheme.echartsTheme);\n }\n\n return <ChartsThemeContext.Provider value={chartsTheme}>{children}</ChartsThemeContext.Provider>;\n}\n\nexport const ChartsThemeContext = createContext<PersesChartsTheme | undefined>(undefined);\n\nexport function useChartsTheme(): PersesChartsTheme {\n const ctx = useContext(ChartsThemeContext);\n if (ctx === undefined) {\n throw new Error('No ChartsThemeContext found. Did you forget a Provider?');\n }\n return ctx;\n}\n"],"names":["React","createContext","useContext","registerTheme","ChartsThemeProvider","props","children","themeName","chartsTheme","undefined","echartsTheme","ChartsThemeContext","Provider","value","useChartsTheme","ctx","Error"],"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;AAAA,OAAOA,KAAK,IAAIC,aAAa,EAAEC,UAAU,QAAQ,OAAO,CAAC;AACzD,SAASC,aAAa,QAAQ,SAAS,CAAC;AASxC,OAAO,SAASC,mBAAmB,CAACC,KAA+B,EAAE;IACnE,MAAM,EAAEC,QAAQ,CAAA,EAAEC,SAAS,CAAA,EAAEC,WAAW,CAAA,EAAE,GAAGH,KAAK,AAAC;IAEnD,IAAIG,WAAW,KAAKC,SAAS,IAAID,WAAW,CAACE,YAAY,KAAKD,SAAS,EAAE;QACvE,kIAAkI;QAClIN,aAAa,CAACI,SAAS,EAAEC,WAAW,CAACE,YAAY,CAAC,CAAC;IACrD,CAAC;IAED,qBAAO,KAACC,kBAAkB,CAACC,QAAQ;QAACC,KAAK,EAAEL,WAAW;kBAAGF,QAAQ;MAA+B,CAAC;AACnG,CAAC;AAED,OAAO,MAAMK,kBAAkB,iBAAGV,aAAa,CAAgCQ,SAAS,CAAC,CAAC;AAE1F,OAAO,SAASK,cAAc,GAAsB;IAClD,MAAMC,GAAG,GAAGb,UAAU,CAACS,kBAAkB,CAAC,AAAC;IAC3C,IAAII,GAAG,KAAKN,SAAS,EAAE;QACrB,MAAM,IAAIO,KAAK,CAAC,yDAAyD,CAAC,CAAC;IAC7E,CAAC;IACD,OAAOD,GAAG,CAAC;AACb,CAAC"}
package/dist/index.js CHANGED
@@ -1 +1,26 @@
1
- export*from"./Drawer";export*from"./EChart";export*from"./ErrorAlert";export*from"./ErrorBoundary";export*from"./InfoTooltip";export*from"./LineChart";export*from"./GaugeChart";export*from"./StatChart";export*from"./TimeRangeSelector";export*from"./context/ChartsThemeProvider";export*from"./utils";export*from"./model";
1
+ // Copyright 2022 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
+ export * from './Drawer';
14
+ export * from './EChart';
15
+ export * from './ErrorAlert';
16
+ export * from './ErrorBoundary';
17
+ export * from './InfoTooltip';
18
+ export * from './LineChart';
19
+ export * from './GaugeChart';
20
+ export * from './StatChart';
21
+ export * from './TimeRangeSelector';
22
+ export * from './context/ChartsThemeProvider';
23
+ export * from './utils';
24
+ export * from './model';
25
+
26
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["// Copyright 2022 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 './Drawer';\nexport * from './EChart';\nexport * from './ErrorAlert';\nexport * from './ErrorBoundary';\nexport * from './InfoTooltip';\nexport * from './LineChart';\nexport * from './GaugeChart';\nexport * from './StatChart';\nexport * from './TimeRangeSelector';\nexport * from './context/ChartsThemeProvider';\nexport * from './utils';\nexport * from './model';\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,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC"}
@@ -1 +1,15 @@
1
- export const PROGRESSIVE_MODE_SERIES_LIMIT=500;
1
+ // Copyright 2022 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
+ export const PROGRESSIVE_MODE_SERIES_LIMIT = 500;
14
+
15
+ //# sourceMappingURL=graph.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/model/graph.ts"],"sourcesContent":["// Copyright 2022 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 { LineSeriesOption } from 'echarts/charts';\n\nexport const PROGRESSIVE_MODE_SERIES_LIMIT = 500;\n\nexport type UnixTimeMs = number;\n\nexport type GraphSeriesValueTuple = [timestamp: UnixTimeMs, value: number];\n\nexport interface GraphSeries {\n name: string;\n values: Iterable<GraphSeriesValueTuple>;\n}\n\nexport type EChartsValues = number | null | '-';\n\nexport interface EChartsTimeSeries extends Omit<LineSeriesOption, 'data'> {\n // TODO: support dataset and both category / time xAxis types\n data: Iterable<GraphSeriesValueTuple> | EChartsValues[];\n}\n\nexport type EChartsDataFormat = {\n timeSeries: EChartsTimeSeries[];\n xAxis: number[];\n xAxisMax?: number | string;\n rangeMs?: number;\n};\n"],"names":["PROGRESSIVE_MODE_SERIES_LIMIT"],"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;AAIjC,OAAO,MAAMA,6BAA6B,GAAG,GAAG,CAAC"}
@@ -1 +1,17 @@
1
- export*from"./graph";export*from"./theme";export*from"./units";
1
+ // Copyright 2022 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
+ export * from './graph';
14
+ export * from './theme';
15
+ export * from './units';
16
+
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/model/index.ts"],"sourcesContent":["// Copyright 2022 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 +1,15 @@
1
- export{};
1
+ // Copyright 2022 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
+ export { };
14
+
15
+ //# sourceMappingURL=theme.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/model/theme.ts"],"sourcesContent":["// Copyright 2022 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 themeName: string;\n echartsTheme: EChartsTheme;\n noDataOption: EChartsCoreOption;\n sparkline: {\n width: number;\n color: string;\n };\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"],"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,WAiBC"}
@@ -1 +1 @@
1
- {"version":3,"file":"units.d.ts","sourceRoot":"","sources":["../../src/model/units.ts"],"names":[],"mappings":"AAgBA,eAAO,MAAM,sBAAsB,IAAI,CAAC;AAExC,oBAAY,WAAW,GAAG,eAAe,GAAG,kBAAkB,GAAG,kBAAkB,GAAG,gBAAgB,CAAC;AAEvG,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,WAAW,GAAG,MAAM,CAwB5E;AAGD,QAAA,MAAM,aAAa,8FAA+F,CAAC;AAGnH,aAAK,eAAe,GAAG;IACrB,IAAI,EAAE,OAAO,aAAa,CAAC,MAAM,CAAC,CAAC;CACpC,CAAC;AA2EF,QAAA,MAAM,gBAAgB,6CAA8C,CAAC;AAGrE,aAAK,kBAAkB,GAAG;IACxB,IAAI,EAAE,OAAO,gBAAgB,CAAC,MAAM,CAAC,CAAC;IACtC,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAiBF,QAAA,MAAM,gBAAgB,sBAAuB,CAAC;AAG9C,aAAK,kBAAkB,GAAG;IACxB,IAAI,EAAE,OAAO,gBAAgB,CAAC,MAAM,CAAC,CAAC;IACtC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AAuBF;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,SAAI,UAG9D;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,GAAG,MAAM,CAYlF;AAGD,QAAA,MAAM,cAAc,oBAAqB,CAAC;AAG1C,aAAK,gBAAgB,GAAG;IACtB,IAAI,EAAE,OAAO,cAAc,CAAC,MAAM,CAAC,CAAC;IACpC,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC"}
1
+ {"version":3,"file":"units.d.ts","sourceRoot":"","sources":["../../src/model/units.ts"],"names":[],"mappings":"AAgBA,eAAO,MAAM,sBAAsB,IAAI,CAAC;AAExC,oBAAY,WAAW,GAAG,eAAe,GAAG,kBAAkB,GAAG,kBAAkB,GAAG,gBAAgB,CAAC;AAEvG,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,WAAW,GAAG,MAAM,CAwB5E;AAGD,QAAA,MAAM,aAAa,8FAA+F,CAAC;AAGnH,aAAK,eAAe,GAAG;IACrB,IAAI,EAAE,OAAO,aAAa,CAAC,MAAM,CAAC,CAAC;CACpC,CAAC;AA4EF,QAAA,MAAM,gBAAgB,6CAA8C,CAAC;AAGrE,aAAK,kBAAkB,GAAG;IACxB,IAAI,EAAE,OAAO,gBAAgB,CAAC,MAAM,CAAC,CAAC;IACtC,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAiBF,QAAA,MAAM,gBAAgB,sBAAuB,CAAC;AAG9C,aAAK,kBAAkB,GAAG;IACxB,IAAI,EAAE,OAAO,gBAAgB,CAAC,MAAM,CAAC,CAAC;IACtC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AAuBF;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,SAAI,UAG9D;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,GAAG,MAAM,CAYlF;AAGD,QAAA,MAAM,cAAc,oBAAqB,CAAC;AAG1C,aAAK,gBAAgB,GAAG;IACtB,IAAI,EAAE,OAAO,cAAc,CAAC,MAAM,CAAC,CAAC;IACpC,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC"}
@@ -1 +1,196 @@
1
- import{milliseconds}from"date-fns";import{round}from"mathjs";export const DEFAULT_DECIMAL_PLACES=2;export function formatValue(e,t){var n;if(void 0===t)return e.toString();if(isDecimalUnit(t))return formatDecimal(e,t);if(isTimeUnit(t))return formatTime(e,t);if(isPercentUnit(t))return formatPercent(e,t);if(isBytesUnit(t))return formatBytes(e,null!==(n=t.decimal_places)&&void 0!==n?n:2);throw new Error(`Unknown unit options ${t}`)}const timeUnitKinds=["Milliseconds","Seconds","Minutes","Hours","Days","Weeks","Months","Years"],timeUnitKindsSet=new Set(timeUnitKinds);function isTimeUnit(e){return timeUnitKindsSet.has(e.kind)}function formatTime(e,t){const n={};switch(t.kind){case"Milliseconds":n.seconds=e/1e3;break;case"Seconds":n.seconds=e;break;case"Minutes":n.minutes=e;break;case"Hours":n.hours=e;break;case"Days":n.days=e;break;case"Weeks":n.weeks=e;break;case"Months":n.months=e;break;case"Years":n.years=e;break;default:const i=t.kind;throw new Error(`Unknown time unit type ${i}`)}const i=milliseconds(n),r=i/1e3;if(r<1)return`${i.toFixed()} milliseconds`;const s=r/60;if(s<1)return`${r.toFixed()} seconds`;const o=s/60;if(o<1)return`${s.toFixed()} minutes`;const a=o/24;if(a<1)return`${o.toFixed()} hours`;const c=a/7;if(c<1)return`${a.toFixed()} days`;const d=c/52;return d<1?`${c.toFixed()} weeks`:`${d.toFixed()} years`}const percentUnitKinds=["Percent","PercentDecimal","%"],percentUnitKindsSet=new Set(percentUnitKinds);function isPercentUnit(e){return percentUnitKindsSet.has(e.kind)}function formatPercent(e,t){var n;const i=null!==(n=t.decimal_places)&&void 0!==n?n:2;return"PercentDecimal"===t.kind&&(e*=100),e.toFixed(i)+"%"}const decimalUnitKinds=["Decimal"],decimalUnitKindsSet=new Set(decimalUnitKinds);function isDecimalUnit(e){return decimalUnitKindsSet.has(e.kind)}function formatDecimal(e,t){var n;const i=null!==(n=t.decimal_places)&&void 0!==n?n:2;if(!0===t.abbreviate)return abbreviateLargeNumber(e,i);const r={style:"decimal",minimumFractionDigits:0,maximumFractionDigits:i,useGrouping:!0};return new Intl.NumberFormat("en-US",r).format(e)}export function abbreviateLargeNumber(e,t=2){return formatNumber(e,(e=>round(e,t)))}export function formatNumber(e,t){const n=null!=t?t:Math.round;return e>=1e12?n(e/1e12)+"T":e>=1e9?n(e/1e9)+"B":e>=1e6?n(e/1e6)+"M":e>=1e3?n(e/1e3)+"K":e.toString()}const bytesUnitKinds=["Bytes"],bytesUnitKindsSet=new Set(bytesUnitKinds);function isBytesUnit(e){return bytesUnitKindsSet.has(e.kind)}function formatBytes(e,t=2){if(0===e)return"0 Bytes";const n=t<0?0:t,i=Math.max(0,Math.floor(Math.log(e)/Math.log(1024)));return parseFloat((e/Math.pow(1024,i)).toFixed(n))+" "+["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"][i]}
1
+ // Copyright 2022 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 { milliseconds } from 'date-fns';
14
+ import { round } from 'mathjs';
15
+ export const DEFAULT_DECIMAL_PLACES = 2;
16
+ export function formatValue(value, unitOptions) {
17
+ if (unitOptions === undefined) {
18
+ return value.toString();
19
+ }
20
+ if (isDecimalUnit(unitOptions)) {
21
+ return formatDecimal(value, unitOptions);
22
+ }
23
+ if (isTimeUnit(unitOptions)) {
24
+ return formatTime(value, unitOptions);
25
+ }
26
+ if (isPercentUnit(unitOptions)) {
27
+ return formatPercent(value, unitOptions);
28
+ }
29
+ if (isBytesUnit(unitOptions)) {
30
+ var _decimal_places;
31
+ const decimals = (_decimal_places = unitOptions.decimal_places) !== null && _decimal_places !== void 0 ? _decimal_places : DEFAULT_DECIMAL_PLACES;
32
+ return formatBytes(value, decimals);
33
+ }
34
+ const exhaustive = unitOptions;
35
+ throw new Error(`Unknown unit options ${exhaustive}`);
36
+ }
37
+ /* Time Unit Conversion */ const timeUnitKinds = [
38
+ 'Milliseconds',
39
+ 'Seconds',
40
+ 'Minutes',
41
+ 'Hours',
42
+ 'Days',
43
+ 'Weeks',
44
+ 'Months',
45
+ 'Years'
46
+ ];
47
+ const timeUnitKindsSet = new Set(timeUnitKinds);
48
+ function isTimeUnit(unitOptions) {
49
+ return timeUnitKindsSet.has(unitOptions.kind);
50
+ }
51
+ function formatTime(value, unitOptions) {
52
+ // Create a Duration from the value based on what time unit it is
53
+ const duration = {};
54
+ switch(unitOptions.kind){
55
+ case 'Milliseconds':
56
+ duration.seconds = value / 1000;
57
+ break;
58
+ case 'Seconds':
59
+ duration.seconds = value;
60
+ break;
61
+ case 'Minutes':
62
+ duration.minutes = value;
63
+ break;
64
+ case 'Hours':
65
+ duration.hours = value;
66
+ break;
67
+ case 'Days':
68
+ duration.days = value;
69
+ break;
70
+ case 'Weeks':
71
+ duration.weeks = value;
72
+ break;
73
+ case 'Months':
74
+ duration.months = value;
75
+ break;
76
+ case 'Years':
77
+ duration.years = value;
78
+ break;
79
+ default:
80
+ {
81
+ const exhaustive = unitOptions.kind;
82
+ throw new Error(`Unknown time unit type ${exhaustive}`);
83
+ }
84
+ }
85
+ // Find the largest whole time unit we can display the value in and use it
86
+ const ms = milliseconds(duration);
87
+ const seconds = ms / 1000;
88
+ if (seconds < 1) {
89
+ return `${ms.toFixed()} milliseconds`;
90
+ }
91
+ const minutes = seconds / 60;
92
+ if (minutes < 1) {
93
+ return `${seconds.toFixed()} seconds`;
94
+ }
95
+ const hours = minutes / 60;
96
+ if (hours < 1) {
97
+ return `${minutes.toFixed()} minutes`;
98
+ }
99
+ const days = hours / 24;
100
+ if (days < 1) {
101
+ return `${hours.toFixed()} hours`;
102
+ }
103
+ const weeks = days / 7;
104
+ if (weeks < 1) {
105
+ return `${days.toFixed()} days`;
106
+ }
107
+ const years = weeks / 52;
108
+ if (years < 1) {
109
+ return `${weeks.toFixed()} weeks`;
110
+ }
111
+ return `${years.toFixed()} years`;
112
+ }
113
+ /* Percent Unit Conversion */ const percentUnitKinds = [
114
+ 'Percent',
115
+ 'PercentDecimal',
116
+ '%'
117
+ ];
118
+ const percentUnitKindsSet = new Set(percentUnitKinds);
119
+ function isPercentUnit(unitOptions) {
120
+ return percentUnitKindsSet.has(unitOptions.kind);
121
+ }
122
+ function formatPercent(value, unitOptions) {
123
+ var _decimal_places;
124
+ const decimals = (_decimal_places = unitOptions.decimal_places) !== null && _decimal_places !== void 0 ? _decimal_places : DEFAULT_DECIMAL_PLACES;
125
+ if (unitOptions.kind === 'PercentDecimal') {
126
+ value = value * 100;
127
+ }
128
+ return value.toFixed(decimals) + '%';
129
+ }
130
+ /* Decimal Unit Conversion */ const decimalUnitKinds = [
131
+ 'Decimal'
132
+ ];
133
+ const decimalUnitKindsSet = new Set(decimalUnitKinds);
134
+ function isDecimalUnit(unitOptions) {
135
+ return decimalUnitKindsSet.has(unitOptions.kind);
136
+ }
137
+ function formatDecimal(value, unitOptions) {
138
+ var _decimal_places;
139
+ const decimals = (_decimal_places = unitOptions.decimal_places) !== null && _decimal_places !== void 0 ? _decimal_places : DEFAULT_DECIMAL_PLACES;
140
+ if (unitOptions.abbreviate === true) {
141
+ return abbreviateLargeNumber(value, decimals);
142
+ }
143
+ const formatParams = {
144
+ style: 'decimal',
145
+ minimumFractionDigits: 0,
146
+ maximumFractionDigits: decimals,
147
+ useGrouping: true
148
+ };
149
+ const decimalFormatter = new Intl.NumberFormat('en-US', formatParams);
150
+ return decimalFormatter.format(value);
151
+ }
152
+ /**
153
+ * Takes large numbers and abbreviates them with the appropriate suffix
154
+ * 10123 -> 10.123k
155
+ * 1000000 -> 1M
156
+ */ export function abbreviateLargeNumber(num, decimals = 2) {
157
+ const modifier = (n)=>round(n, decimals);
158
+ return formatNumber(num, modifier);
159
+ }
160
+ /**
161
+ * Takes large numbers, rounds and abbreviates them with the appropriate suffix
162
+ * Add modifier to run on output value prior to unit being added (defaults to rounding)
163
+ */ export function formatNumber(num, modifier) {
164
+ const fn = modifier !== null && modifier !== void 0 ? modifier : Math.round;
165
+ return num >= 1e12 ? fn(num / 1e12) + 'T' : num >= 1e9 ? fn(num / 1e9) + 'B' : num >= 1e6 ? fn(num / 1e6) + 'M' : num >= 1e3 ? fn(num / 1e3) + 'K' : num.toString();
166
+ }
167
+ /* Bytes Unit Conversion */ const bytesUnitKinds = [
168
+ 'Bytes'
169
+ ];
170
+ const bytesUnitKindsSet = new Set(bytesUnitKinds);
171
+ function isBytesUnit(unitOptions) {
172
+ return bytesUnitKindsSet.has(unitOptions.kind);
173
+ }
174
+ // https://stackoverflow.com/questions/15900485/correct-way-to-convert-size-in-bytes-to-kb-mb-gb-in-javascript/18650828#18650828
175
+ function formatBytes(bytes, decimals = 2) {
176
+ if (bytes === 0) return '0 Bytes';
177
+ const k = 1024;
178
+ const dm = decimals < 0 ? 0 : decimals;
179
+ const sizes = [
180
+ 'Bytes',
181
+ 'KB',
182
+ 'MB',
183
+ 'GB',
184
+ 'TB',
185
+ 'PB',
186
+ 'EB',
187
+ 'ZB',
188
+ 'YB'
189
+ ];
190
+ // Math.max(0, ...) ensures that we don't return -1 as a value for the index.
191
+ // Why? When the number of bytes are between -1 and 1, Math.floor(Math.log(bytes)/Math.log(1024)) returns -1.
192
+ const i = Math.max(0, Math.floor(Math.log(bytes) / Math.log(k)));
193
+ return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
194
+ }
195
+
196
+ //# sourceMappingURL=units.js.map