@perses-dev/components 0.19.0 → 0.21.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 (119) hide show
  1. package/dist/DateTimeRangePicker/AbsoluteTimePicker.d.ts.map +1 -1
  2. package/dist/DateTimeRangePicker/AbsoluteTimePicker.js +4 -3
  3. package/dist/DateTimeRangePicker/AbsoluteTimePicker.js.map +1 -1
  4. package/dist/DateTimeRangePicker/DateTimeRangePicker.d.ts +1 -0
  5. package/dist/DateTimeRangePicker/DateTimeRangePicker.d.ts.map +1 -1
  6. package/dist/DateTimeRangePicker/DateTimeRangePicker.js +3 -1
  7. package/dist/DateTimeRangePicker/DateTimeRangePicker.js.map +1 -1
  8. package/dist/DateTimeRangePicker/TimeRangeSelector.d.ts +1 -0
  9. package/dist/DateTimeRangePicker/TimeRangeSelector.d.ts.map +1 -1
  10. package/dist/DateTimeRangePicker/TimeRangeSelector.js +9 -3
  11. package/dist/DateTimeRangePicker/TimeRangeSelector.js.map +1 -1
  12. package/dist/DateTimeRangePicker/utils.d.ts +1 -1
  13. package/dist/DateTimeRangePicker/utils.d.ts.map +1 -1
  14. package/dist/DateTimeRangePicker/utils.js +5 -4
  15. package/dist/DateTimeRangePicker/utils.js.map +1 -1
  16. package/dist/GaugeChart/GaugeChart.d.ts +11 -2
  17. package/dist/GaugeChart/GaugeChart.d.ts.map +1 -1
  18. package/dist/GaugeChart/GaugeChart.js +58 -10
  19. package/dist/GaugeChart/GaugeChart.js.map +1 -1
  20. package/dist/InfoTooltip/InfoTooltip.d.ts +3 -1
  21. package/dist/InfoTooltip/InfoTooltip.d.ts.map +1 -1
  22. package/dist/InfoTooltip/InfoTooltip.js +4 -2
  23. package/dist/InfoTooltip/InfoTooltip.js.map +1 -1
  24. package/dist/LegendOptionsEditor/LegendOptionsEditor.d.ts +8 -0
  25. package/dist/LegendOptionsEditor/LegendOptionsEditor.d.ts.map +1 -0
  26. package/dist/LegendOptionsEditor/LegendOptionsEditor.js +82 -0
  27. package/dist/LegendOptionsEditor/LegendOptionsEditor.js.map +1 -0
  28. package/dist/LegendOptionsEditor/LegendOptionsEditor.test.d.ts +2 -0
  29. package/dist/LegendOptionsEditor/LegendOptionsEditor.test.d.ts.map +1 -0
  30. package/dist/LegendOptionsEditor/LegendOptionsEditor.test.js +41 -0
  31. package/dist/LegendOptionsEditor/LegendOptionsEditor.test.js.map +1 -0
  32. package/dist/LegendOptionsEditor/index.d.ts +2 -0
  33. package/dist/LegendOptionsEditor/index.d.ts.map +1 -0
  34. package/dist/LegendOptionsEditor/index.js +15 -0
  35. package/dist/LegendOptionsEditor/index.js.map +1 -0
  36. package/dist/LineChart/LineChart.d.ts +2 -3
  37. package/dist/LineChart/LineChart.d.ts.map +1 -1
  38. package/dist/LineChart/LineChart.js +39 -34
  39. package/dist/LineChart/LineChart.js.map +1 -1
  40. package/dist/LineChart/utils.d.ts +1 -1
  41. package/dist/LineChart/utils.d.ts.map +1 -1
  42. package/dist/LineChart/utils.js +4 -3
  43. package/dist/LineChart/utils.js.map +1 -1
  44. package/dist/StatChart/StatChart.test.js +42 -21
  45. package/dist/StatChart/StatChart.test.js.map +1 -1
  46. package/dist/Tooltip/TooltipContent.d.ts.map +1 -1
  47. package/dist/Tooltip/TooltipContent.js +8 -9
  48. package/dist/Tooltip/TooltipContent.js.map +1 -1
  49. package/dist/UnitSelector/UnitSelector.test.js +3 -10
  50. package/dist/UnitSelector/UnitSelector.test.js.map +1 -1
  51. package/dist/cjs/DateTimeRangePicker/AbsoluteTimePicker.js +4 -3
  52. package/dist/cjs/DateTimeRangePicker/DateTimeRangePicker.js +3 -1
  53. package/dist/cjs/DateTimeRangePicker/TimeRangeSelector.js +9 -3
  54. package/dist/cjs/DateTimeRangePicker/utils.js +4 -3
  55. package/dist/cjs/GaugeChart/GaugeChart.js +66 -15
  56. package/dist/cjs/InfoTooltip/InfoTooltip.js +4 -2
  57. package/dist/cjs/LegendOptionsEditor/LegendOptionsEditor.js +88 -0
  58. package/dist/cjs/LegendOptionsEditor/LegendOptionsEditor.test.js +48 -0
  59. package/dist/cjs/LegendOptionsEditor/index.js +28 -0
  60. package/dist/cjs/LineChart/LineChart.js +40 -35
  61. package/dist/cjs/LineChart/utils.js +4 -3
  62. package/dist/cjs/StatChart/StatChart.test.js +43 -27
  63. package/dist/cjs/Tooltip/TooltipContent.js +8 -9
  64. package/dist/cjs/UnitSelector/UnitSelector.test.js +3 -10
  65. package/dist/cjs/context/TimeZoneProvider.js +90 -0
  66. package/dist/cjs/index.js +2 -0
  67. package/dist/cjs/model/graph.js +14 -3
  68. package/dist/cjs/model/units/bytes.js +32 -6
  69. package/dist/cjs/model/units/time.js +26 -62
  70. package/dist/cjs/model/units/units.js +1 -4
  71. package/dist/cjs/model/units/units.test.js +153 -0
  72. package/dist/cjs/theme/theme.js +19 -0
  73. package/dist/cjs/utils/format.js +56 -0
  74. package/dist/cjs/utils/format.test.js +47 -0
  75. package/dist/cjs/utils/index.js +1 -0
  76. package/dist/context/TimeZoneProvider.d.ts +13 -0
  77. package/dist/context/TimeZoneProvider.d.ts.map +1 -0
  78. package/dist/context/TimeZoneProvider.js +38 -0
  79. package/dist/context/TimeZoneProvider.js.map +1 -0
  80. package/dist/index.d.ts +2 -0
  81. package/dist/index.d.ts.map +1 -1
  82. package/dist/index.js +2 -0
  83. package/dist/index.js.map +1 -1
  84. package/dist/model/graph.d.ts +4 -2
  85. package/dist/model/graph.d.ts.map +1 -1
  86. package/dist/model/graph.js +4 -0
  87. package/dist/model/graph.js.map +1 -1
  88. package/dist/model/units/bytes.d.ts +6 -1
  89. package/dist/model/units/bytes.d.ts.map +1 -1
  90. package/dist/model/units/bytes.js +35 -7
  91. package/dist/model/units/bytes.js.map +1 -1
  92. package/dist/model/units/time.d.ts +11 -0
  93. package/dist/model/units/time.d.ts.map +1 -1
  94. package/dist/model/units/time.js +25 -62
  95. package/dist/model/units/time.js.map +1 -1
  96. package/dist/model/units/units.d.ts.map +1 -1
  97. package/dist/model/units/units.js +1 -4
  98. package/dist/model/units/units.js.map +1 -1
  99. package/dist/model/units/units.test.d.ts +2 -0
  100. package/dist/model/units/units.test.d.ts.map +1 -0
  101. package/dist/model/units/units.test.js +151 -0
  102. package/dist/model/units/units.test.js.map +1 -0
  103. package/dist/theme/theme.d.ts +2 -2
  104. package/dist/theme/theme.d.ts.map +1 -1
  105. package/dist/theme/theme.js +19 -0
  106. package/dist/theme/theme.js.map +1 -1
  107. package/dist/utils/format.d.ts +3 -0
  108. package/dist/utils/format.d.ts.map +1 -0
  109. package/dist/utils/format.js +44 -0
  110. package/dist/utils/format.js.map +1 -0
  111. package/dist/utils/format.test.d.ts +2 -0
  112. package/dist/utils/format.test.d.ts.map +1 -0
  113. package/dist/utils/format.test.js +45 -0
  114. package/dist/utils/format.test.js.map +1 -0
  115. package/dist/utils/index.d.ts +1 -0
  116. package/dist/utils/index.d.ts.map +1 -1
  117. package/dist/utils/index.js +1 -0
  118. package/dist/utils/index.js.map +1 -1
  119. package/package.json +3 -2
@@ -21,11 +21,12 @@ function _export(target, all) {
21
21
  });
22
22
  }
23
23
  _export(exports, {
24
+ TimeIntlDuration: ()=>TimeIntlDuration,
24
25
  TIME_GROUP_CONFIG: ()=>TIME_GROUP_CONFIG,
25
26
  TIME_UNIT_CONFIG: ()=>TIME_UNIT_CONFIG,
26
27
  formatTime: ()=>formatTime
27
28
  });
28
- const _dateFns = require("date-fns");
29
+ const _constants = require("./constants");
29
30
  const timeUnitKinds = [
30
31
  'Milliseconds',
31
32
  'Seconds',
@@ -38,7 +39,8 @@ const timeUnitKinds = [
38
39
  ];
39
40
  const TIME_GROUP = 'Time';
40
41
  const TIME_GROUP_CONFIG = {
41
- label: 'Time'
42
+ label: 'Time',
43
+ decimal_places: true
42
44
  };
43
45
  const TIME_UNIT_CONFIG = {
44
46
  Milliseconds: {
@@ -74,65 +76,27 @@ const TIME_UNIT_CONFIG = {
74
76
  label: 'Years'
75
77
  }
76
78
  };
79
+ var TimeIntlDuration;
80
+ (function(TimeIntlDuration) {
81
+ TimeIntlDuration["Milliseconds"] = 'millisecond';
82
+ TimeIntlDuration["Seconds"] = 'second';
83
+ TimeIntlDuration["Minutes"] = 'minute';
84
+ TimeIntlDuration["Hours"] = 'hour';
85
+ TimeIntlDuration["Days"] = 'day';
86
+ TimeIntlDuration["Weeks"] = 'week';
87
+ TimeIntlDuration["Months"] = 'month';
88
+ TimeIntlDuration["Years"] = 'year';
89
+ })(TimeIntlDuration || (TimeIntlDuration = {}));
77
90
  function formatTime(value, unitOptions) {
78
- // Create a Duration from the value based on what time unit it is
79
- const duration = {};
80
- switch(unitOptions.kind){
81
- case 'Milliseconds':
82
- duration.seconds = value / 1000;
83
- break;
84
- case 'Seconds':
85
- duration.seconds = value;
86
- break;
87
- case 'Minutes':
88
- duration.minutes = value;
89
- break;
90
- case 'Hours':
91
- duration.hours = value;
92
- break;
93
- case 'Days':
94
- duration.days = value;
95
- break;
96
- case 'Weeks':
97
- duration.weeks = value;
98
- break;
99
- case 'Months':
100
- duration.months = value;
101
- break;
102
- case 'Years':
103
- duration.years = value;
104
- break;
105
- default:
106
- {
107
- const exhaustive = unitOptions.kind;
108
- throw new Error(`Unknown time unit type ${exhaustive}`);
109
- }
110
- }
111
- // Find the largest whole time unit we can display the value in and use it
112
- const ms = (0, _dateFns.milliseconds)(duration);
113
- const seconds = ms / 1000;
114
- if (seconds < 1) {
115
- return `${ms.toFixed()} milliseconds`;
116
- }
117
- const minutes = seconds / 60;
118
- if (minutes < 1) {
119
- return `${seconds.toFixed()} seconds`;
120
- }
121
- const hours = minutes / 60;
122
- if (hours < 1) {
123
- return `${minutes.toFixed()} minutes`;
124
- }
125
- const days = hours / 24;
126
- if (days < 1) {
127
- return `${hours.toFixed()} hours`;
128
- }
129
- const weeks = days / 7;
130
- if (weeks < 1) {
131
- return `${days.toFixed()} days`;
132
- }
133
- const years = weeks / 52;
134
- if (years < 1) {
135
- return `${weeks.toFixed()} weeks`;
136
- }
137
- return `${years.toFixed()} years`;
91
+ var _decimal_places;
92
+ const decimals = (_decimal_places = unitOptions.decimal_places) !== null && _decimal_places !== void 0 ? _decimal_places : _constants.DEFAULT_DECIMAL_PLACES;
93
+ const timeUnit = TimeIntlDuration[unitOptions.kind];
94
+ const formatter = new Intl.NumberFormat('en-US', {
95
+ style: 'unit',
96
+ unit: timeUnit,
97
+ unitDisplay: 'long',
98
+ minimumFractionDigits: decimals,
99
+ maximumFractionDigits: decimals
100
+ });
101
+ return formatter.format(value);
138
102
  }
@@ -35,7 +35,6 @@ _export(exports, {
35
35
  isUnitWithAbbreviate: ()=>isUnitWithAbbreviate
36
36
  });
37
37
  const _bytes = require("./bytes");
38
- const _constants = require("./constants");
39
38
  const _decimal = require("./decimal");
40
39
  const _percent = require("./percent");
41
40
  const _time = require("./time");
@@ -65,9 +64,7 @@ function formatValue(value, unitOptions) {
65
64
  return (0, _percent.formatPercent)(value, unitOptions);
66
65
  }
67
66
  if (isBytesUnit(unitOptions)) {
68
- var _decimal_places;
69
- const decimals = (_decimal_places = unitOptions.decimal_places) !== null && _decimal_places !== void 0 ? _decimal_places : _constants.DEFAULT_DECIMAL_PLACES;
70
- return (0, _bytes.formatBytes)(value, decimals);
67
+ return (0, _bytes.formatBytes)(value, unitOptions);
71
68
  }
72
69
  const exhaustive = unitOptions;
73
70
  throw new Error(`Unknown unit options ${exhaustive}`);
@@ -0,0 +1,153 @@
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
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ const _units = require("./units");
18
+ describe('formatValue()', ()=>{
19
+ const tests = [
20
+ {
21
+ value: 100000,
22
+ unit: {
23
+ kind: 'Decimal'
24
+ },
25
+ expected: '100,000.00'
26
+ },
27
+ {
28
+ value: 155900,
29
+ unit: {
30
+ kind: 'Decimal',
31
+ decimal_places: 4
32
+ },
33
+ expected: '155,900.0000'
34
+ },
35
+ {
36
+ value: 10,
37
+ unit: {
38
+ kind: 'Percent'
39
+ },
40
+ expected: '10.00%'
41
+ },
42
+ {
43
+ value: 50,
44
+ unit: {
45
+ kind: 'Percent',
46
+ decimal_places: 0
47
+ },
48
+ expected: '50%'
49
+ },
50
+ {
51
+ value: 0.1,
52
+ unit: {
53
+ kind: 'PercentDecimal'
54
+ },
55
+ expected: '10.00%'
56
+ },
57
+ {
58
+ value: 100,
59
+ unit: {
60
+ kind: 'Bytes',
61
+ decimal_places: 0,
62
+ abbreviate: false
63
+ },
64
+ expected: '100 bytes'
65
+ },
66
+ {
67
+ value: 100,
68
+ unit: {
69
+ kind: 'Bytes',
70
+ decimal_places: -1,
71
+ abbreviate: false
72
+ },
73
+ expected: '100 bytes'
74
+ },
75
+ {
76
+ value: 225000,
77
+ unit: {
78
+ kind: 'Bytes',
79
+ decimal_places: 0,
80
+ abbreviate: true
81
+ },
82
+ expected: '220 KB'
83
+ },
84
+ {
85
+ value: 505200,
86
+ unit: {
87
+ kind: 'Bytes'
88
+ },
89
+ expected: '505,200.00 bytes'
90
+ },
91
+ {
92
+ value: 8000,
93
+ unit: {
94
+ kind: 'Milliseconds'
95
+ },
96
+ expected: '8,000.00 milliseconds'
97
+ },
98
+ {
99
+ value: 200900,
100
+ unit: {
101
+ kind: 'Seconds'
102
+ },
103
+ expected: '200,900.00 seconds'
104
+ },
105
+ {
106
+ value: 300,
107
+ unit: {
108
+ kind: 'Minutes'
109
+ },
110
+ expected: '300.00 minutes'
111
+ },
112
+ {
113
+ value: 300,
114
+ unit: {
115
+ kind: 'Hours'
116
+ },
117
+ expected: '300.00 hours'
118
+ },
119
+ {
120
+ value: 300,
121
+ unit: {
122
+ kind: 'Days'
123
+ },
124
+ expected: '300.00 days'
125
+ },
126
+ {
127
+ value: 300,
128
+ unit: {
129
+ kind: 'Weeks'
130
+ },
131
+ expected: '300.00 weeks'
132
+ },
133
+ {
134
+ value: 300,
135
+ unit: {
136
+ kind: 'Months'
137
+ },
138
+ expected: '300.00 months'
139
+ },
140
+ {
141
+ value: 300,
142
+ unit: {
143
+ kind: 'Years'
144
+ },
145
+ expected: '300.00 years'
146
+ }
147
+ ];
148
+ tests.forEach(({ value , unit , expected })=>{
149
+ it(`formats ${value} as ${JSON.stringify(unit)}`, ()=>{
150
+ expect((0, _units.formatValue)(value, unit)).toEqual(expected);
151
+ });
152
+ });
153
+ });
@@ -21,6 +21,15 @@ Object.defineProperty(exports, "getTheme", {
21
21
  const _material = require("@mui/material");
22
22
  const _paletteOptions = require("./palette/palette-options");
23
23
  const _typography = require("./typography");
24
+ const getModalBackgroundStyle = ({ theme })=>{
25
+ const backgroundStyle = theme.palette.mode === 'light' ? {} : {
26
+ backgroundImage: 'unset',
27
+ backgroundColor: theme.palette.designSystem.grey[800]
28
+ };
29
+ return {
30
+ ...backgroundStyle
31
+ };
32
+ };
24
33
  function getTheme(mode) {
25
34
  const theme = (0, _material.createTheme)({
26
35
  palette: (0, _paletteOptions.getPaletteOptions)(mode),
@@ -41,5 +50,15 @@ const components = {
41
50
  defaultProps: {
42
51
  size: 'small'
43
52
  }
53
+ },
54
+ MuiDrawer: {
55
+ styleOverrides: {
56
+ paper: getModalBackgroundStyle
57
+ }
58
+ },
59
+ MuiDialog: {
60
+ styleOverrides: {
61
+ paper: getModalBackgroundStyle
62
+ }
44
63
  }
45
64
  };
@@ -0,0 +1,56 @@
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
+ "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
+ dateFormatOptionsWithTimeZone: ()=>dateFormatOptionsWithTimeZone,
25
+ formatWithTimeZone: ()=>formatWithTimeZone
26
+ });
27
+ const _dateFnsTz = require("date-fns-tz");
28
+ const _dateFns = require("date-fns");
29
+ function dateFormatOptionsWithTimeZone(dateFormatOptions, timeZone) {
30
+ /*
31
+ * if timeZone is provided, and is not local|browser,
32
+ * then set timeZone option (recognize UTC regardless of uppercase/lowercase)
33
+ * otherwise, default to browser timeZone setting
34
+ */ if (timeZone) {
35
+ const lowerTimeZone = timeZone.toLowerCase();
36
+ if (lowerTimeZone !== 'local' && lowerTimeZone !== 'browser') {
37
+ return {
38
+ ...dateFormatOptions,
39
+ timeZone: lowerTimeZone === 'utc' ? 'UTC' : timeZone
40
+ };
41
+ }
42
+ }
43
+ return dateFormatOptions;
44
+ }
45
+ function formatWithTimeZone(date, formatString, timeZone) {
46
+ /*
47
+ * if timeZone is provided, and is not local|browser,
48
+ * then format using timeZone option (recognize UTC regardless of uppercase/lowercase)
49
+ * otherwise, format without timeZone option, defaulting to browser timeZone setting
50
+ */ const lowerTimeZone = timeZone === null || timeZone === void 0 ? void 0 : timeZone.toLowerCase();
51
+ if (!timeZone || lowerTimeZone === 'local' || lowerTimeZone === 'browser') {
52
+ return (0, _dateFns.format)(date, formatString);
53
+ } else {
54
+ return (0, _dateFnsTz.formatInTimeZone)(date, lowerTimeZone === 'utc' ? 'UTC' : timeZone, formatString);
55
+ }
56
+ }
@@ -0,0 +1,47 @@
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
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ const _format = require("./format");
18
+ const DATE = new Date(168523200000);
19
+ const DATE_FORMAT_OPTIONS = {
20
+ hour: 'numeric',
21
+ minute: 'numeric',
22
+ hourCycle: 'h23'
23
+ };
24
+ describe('formatWithTimeZone', ()=>{
25
+ it('should format in Los Angeles timezone', ()=>{
26
+ expect((0, _format.formatWithTimeZone)(DATE, 'yyyy-MM-dd HH:mm:ss', 'America/Los_Angeles')).toBe('1975-05-05 05:00:00');
27
+ });
28
+ it('should format in UTC timezone', ()=>{
29
+ expect((0, _format.formatWithTimeZone)(DATE, 'yyyy-MM-dd HH:mm:ss', 'UTC')).toBe('1975-05-05 12:00:00');
30
+ expect((0, _format.formatWithTimeZone)(DATE, 'yyyy-MM-dd HH:mm:ss', 'utc')).toBe('1975-05-05 12:00:00');
31
+ });
32
+ });
33
+ describe('dateFormatOptionsWithTimeZone', ()=>{
34
+ it('should format in Los Angeles timezone', ()=>{
35
+ const dateFormatOptions = (0, _format.dateFormatOptionsWithTimeZone)(DATE_FORMAT_OPTIONS, 'America/Los_Angeles');
36
+ expect(new Intl.DateTimeFormat(undefined, dateFormatOptions).format(DATE)).toBe('05:00');
37
+ });
38
+ it('should format in UTC timezone', ()=>{
39
+ const dateFormatOptions = (0, _format.dateFormatOptionsWithTimeZone)(DATE_FORMAT_OPTIONS, 'utc');
40
+ expect(new Intl.DateTimeFormat(undefined, dateFormatOptions).format(DATE)).toBe('12:00');
41
+ });
42
+ it('should use browser local timezone', ()=>{
43
+ expect((0, _format.dateFormatOptionsWithTimeZone)(DATE_FORMAT_OPTIONS, 'browser').timeZone).toBeUndefined();
44
+ expect((0, _format.dateFormatOptionsWithTimeZone)(DATE_FORMAT_OPTIONS, 'local').timeZone).toBeUndefined();
45
+ expect((0, _format.dateFormatOptionsWithTimeZone)(DATE_FORMAT_OPTIONS).timeZone).toBeUndefined();
46
+ });
47
+ });
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", {
17
17
  _exportStar(require("./combine-sx"), exports);
18
18
  _exportStar(require("./theme-gen"), exports);
19
19
  _exportStar(require("./component-ids"), exports);
20
+ _exportStar(require("./format"), exports);
20
21
  function _exportStar(from, to) {
21
22
  Object.keys(from).forEach(function(k) {
22
23
  if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+ export declare const TimeZoneContext: React.Context<string | undefined>;
3
+ export interface TimeZoneProviderProps {
4
+ timeZone?: string;
5
+ children?: React.ReactNode;
6
+ }
7
+ export declare function TimeZoneProvider(props: TimeZoneProviderProps): JSX.Element;
8
+ export declare function useTimeZone(): {
9
+ timeZone: string;
10
+ formatWithUserTimeZone(date: Date, formatString: string): string;
11
+ dateFormatOptionsWithUserTimeZone(dateFormatOptions: Intl.DateTimeFormatOptions): Intl.DateTimeFormatOptions;
12
+ };
13
+ //# sourceMappingURL=TimeZoneProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TimeZoneProvider.d.ts","sourceRoot":"","sources":["../../src/context/TimeZoneProvider.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAoC,MAAM,OAAO,CAAC;AAGzD,eAAO,MAAM,eAAe,mCAA+C,CAAC;AAE5E,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,eAG5D;AAED,wBAAgB,WAAW;;iCAKM,IAAI,gBAAgB,MAAM;yDAGF,KAAK,qBAAqB;EAIlF"}
@@ -0,0 +1,38 @@
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 { formatWithTimeZone, dateFormatOptionsWithTimeZone } from '../utils';
16
+ export const TimeZoneContext = /*#__PURE__*/ createContext(undefined);
17
+ export function TimeZoneProvider(props) {
18
+ const { children , timeZone } = props;
19
+ return /*#__PURE__*/ _jsx(TimeZoneContext.Provider, {
20
+ value: timeZone,
21
+ children: children
22
+ });
23
+ }
24
+ export function useTimeZone() {
25
+ const timeZone = useContext(TimeZoneContext);
26
+ return {
27
+ // fallback to "local" timezone if TimeZoneProvider is not present in the React tree
28
+ timeZone: timeZone !== null && timeZone !== void 0 ? timeZone : 'local',
29
+ formatWithUserTimeZone (date, formatString) {
30
+ return formatWithTimeZone(date, formatString, timeZone);
31
+ },
32
+ dateFormatOptionsWithUserTimeZone (dateFormatOptions) {
33
+ return dateFormatOptionsWithTimeZone(dateFormatOptions, timeZone);
34
+ }
35
+ };
36
+ }
37
+
38
+ //# sourceMappingURL=TimeZoneProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/context/TimeZoneProvider.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 { formatWithTimeZone, dateFormatOptionsWithTimeZone } from '../utils';\n\nexport const TimeZoneContext = createContext<string | undefined>(undefined);\n\nexport interface TimeZoneProviderProps {\n timeZone?: string;\n children?: React.ReactNode;\n}\n\nexport function TimeZoneProvider(props: TimeZoneProviderProps) {\n const { children, timeZone } = props;\n return <TimeZoneContext.Provider value={timeZone}>{children}</TimeZoneContext.Provider>;\n}\n\nexport function useTimeZone() {\n const timeZone = useContext(TimeZoneContext);\n return {\n // fallback to \"local\" timezone if TimeZoneProvider is not present in the React tree\n timeZone: timeZone ?? 'local',\n formatWithUserTimeZone(date: Date, formatString: string) {\n return formatWithTimeZone(date, formatString, timeZone);\n },\n dateFormatOptionsWithUserTimeZone(dateFormatOptions: Intl.DateTimeFormatOptions) {\n return dateFormatOptionsWithTimeZone(dateFormatOptions, timeZone);\n },\n };\n}\n"],"names":["React","createContext","useContext","formatWithTimeZone","dateFormatOptionsWithTimeZone","TimeZoneContext","undefined","TimeZoneProvider","props","children","timeZone","Provider","value","useTimeZone","formatWithUserTimeZone","date","formatString","dateFormatOptionsWithUserTimeZone","dateFormatOptions"],"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,kBAAkB,EAAEC,6BAA6B,QAAQ,UAAU,CAAC;AAE7E,OAAO,MAAMC,eAAe,iBAAGJ,aAAa,CAAqBK,SAAS,CAAC,CAAC;AAO5E,OAAO,SAASC,gBAAgB,CAACC,KAA4B,EAAE;IAC7D,MAAM,EAAEC,QAAQ,CAAA,EAAEC,QAAQ,CAAA,EAAE,GAAGF,KAAK,AAAC;IACrC,qBAAO,KAACH,eAAe,CAACM,QAAQ;QAACC,KAAK,EAAEF,QAAQ;kBAAGD,QAAQ;MAA4B,CAAC;AAC1F,CAAC;AAED,OAAO,SAASI,WAAW,GAAG;IAC5B,MAAMH,QAAQ,GAAGR,UAAU,CAACG,eAAe,CAAC,AAAC;IAC7C,OAAO;QACL,oFAAoF;QACpFK,QAAQ,EAAEA,QAAQ,aAARA,QAAQ,cAARA,QAAQ,GAAI,OAAO;QAC7BI,sBAAsB,EAACC,IAAU,EAAEC,YAAoB,EAAE;YACvD,OAAOb,kBAAkB,CAACY,IAAI,EAAEC,YAAY,EAAEN,QAAQ,CAAC,CAAC;QAC1D,CAAC;QACDO,iCAAiC,EAACC,iBAA6C,EAAE;YAC/E,OAAOd,6BAA6B,CAACc,iBAAiB,EAAER,QAAQ,CAAC,CAAC;QACpE,CAAC;KACF,CAAC;AACJ,CAAC"}
package/dist/index.d.ts CHANGED
@@ -7,12 +7,14 @@ export * from './GaugeChart';
7
7
  export * from './InfoTooltip';
8
8
  export * from './JSONEditor';
9
9
  export * from './Legend';
10
+ export * from './LegendOptionsEditor';
10
11
  export * from './LineChart';
11
12
  export * from './OptionsEditorLayout';
12
13
  export * from './StatChart';
13
14
  export * from './UnitSelector';
14
15
  export * from './YAxisLabel';
15
16
  export * from './context/ChartsThemeProvider';
17
+ export * from './context/TimeZoneProvider';
16
18
  export * from './utils';
17
19
  export * from './model';
18
20
  export * from './test-utils';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,cAAc,uBAAuB,CAAC;AACtC,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,+BAA+B,CAAC;AAC9C,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,cAAc,uBAAuB,CAAC;AACtC,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,+BAA+B,CAAC;AAC9C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC"}
package/dist/index.js CHANGED
@@ -19,12 +19,14 @@ export * from './GaugeChart';
19
19
  export * from './InfoTooltip';
20
20
  export * from './JSONEditor';
21
21
  export * from './Legend';
22
+ export * from './LegendOptionsEditor';
22
23
  export * from './LineChart';
23
24
  export * from './OptionsEditorLayout';
24
25
  export * from './StatChart';
25
26
  export * from './UnitSelector';
26
27
  export * from './YAxisLabel';
27
28
  export * from './context/ChartsThemeProvider';
29
+ export * from './context/TimeZoneProvider';
28
30
  export * from './utils';
29
31
  export * from './model';
30
32
  export * from './test-utils';
package/dist/index.js.map CHANGED
@@ -1 +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 './DateTimeRangePicker';\nexport * from './Drawer';\nexport * from './EChart';\nexport * from './ErrorAlert';\nexport * from './ErrorBoundary';\nexport * from './GaugeChart';\nexport * from './InfoTooltip';\nexport * from './JSONEditor';\nexport * from './Legend';\nexport * from './LineChart';\nexport * from './OptionsEditorLayout';\nexport * from './StatChart';\nexport * from './UnitSelector';\nexport * from './YAxisLabel';\nexport * from './context/ChartsThemeProvider';\nexport * from './utils';\nexport * from './model';\nexport * from './test-utils';\nexport * from './theme';\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,uBAAuB,CAAC;AACtC,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,+BAA+B,CAAC;AAC9C,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC"}
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 './DateTimeRangePicker';\nexport * from './Drawer';\nexport * from './EChart';\nexport * from './ErrorAlert';\nexport * from './ErrorBoundary';\nexport * from './GaugeChart';\nexport * from './InfoTooltip';\nexport * from './JSONEditor';\nexport * from './Legend';\nexport * from './LegendOptionsEditor';\nexport * from './LineChart';\nexport * from './OptionsEditorLayout';\nexport * from './StatChart';\nexport * from './UnitSelector';\nexport * from './YAxisLabel';\nexport * from './context/ChartsThemeProvider';\nexport * from './context/TimeZoneProvider';\nexport * from './utils';\nexport * from './model';\nexport * from './test-utils';\nexport * from './theme';\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,uBAAuB,CAAC;AACtC,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,+BAA+B,CAAC;AAC9C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC"}
@@ -9,7 +9,7 @@ export interface GraphSeries {
9
9
  }
10
10
  export declare type EChartsValues = number | null | '-';
11
11
  export interface EChartsTimeSeries extends Omit<LineSeriesOption, 'data'> {
12
- data: Iterable<GraphSeriesValueTuple> | EChartsValues[];
12
+ data: EChartsValues[];
13
13
  }
14
14
  export declare type EChartsDataFormat = {
15
15
  timeSeries: EChartsTimeSeries[];
@@ -22,7 +22,7 @@ export declare type EChartsDataFormat = {
22
22
  * Supported legend options
23
23
  */
24
24
  export interface LegendOptions {
25
- position?: 'bottom' | 'right';
25
+ position: 'bottom' | 'right';
26
26
  }
27
27
  export interface LegendItem {
28
28
  id: string;
@@ -31,4 +31,6 @@ export interface LegendItem {
31
31
  color: string;
32
32
  onClick: MouseEventHandler<HTMLLIElement>;
33
33
  }
34
+ export declare const DEFAULT_LEGEND_POSITION = "bottom";
35
+ export declare const DEFAULT_LEGEND: LegendOptions;
34
36
  //# sourceMappingURL=graph.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"graph.d.ts","sourceRoot":"","sources":["../../src/model/graph.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAGlD,eAAO,MAAM,2BAA2B,OAAO,CAAC;AAEhD,oBAAY,UAAU,GAAG,MAAM,CAAC;AAEhC,oBAAY,qBAAqB,GAAG,CAAC,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;AAE3E,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,QAAQ,CAAC,qBAAqB,CAAC,CAAC;CACzC;AAED,oBAAY,aAAa,GAAG,MAAM,GAAG,IAAI,GAAG,GAAG,CAAC;AAEhD,MAAM,WAAW,iBAAkB,SAAQ,IAAI,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAEvE,IAAI,EAAE,QAAQ,CAAC,qBAAqB,CAAC,GAAG,aAAa,EAAE,CAAC;CACzD;AAED,oBAAY,iBAAiB,GAAG;IAC9B,UAAU,EAAE,iBAAiB,EAAE,CAAC;IAChC,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,WAAW,CAAC,EAAE,UAAU,EAAE,CAAC;IAC3B,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC;CAC/B;AAED,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,OAAO,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,iBAAiB,CAAC,aAAa,CAAC,CAAC;CAC3C"}
1
+ {"version":3,"file":"graph.d.ts","sourceRoot":"","sources":["../../src/model/graph.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAGlD,eAAO,MAAM,2BAA2B,OAAO,CAAC;AAEhD,oBAAY,UAAU,GAAG,MAAM,CAAC;AAEhC,oBAAY,qBAAqB,GAAG,CAAC,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;AAE3E,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,QAAQ,CAAC,qBAAqB,CAAC,CAAC;CACzC;AAED,oBAAY,aAAa,GAAG,MAAM,GAAG,IAAI,GAAG,GAAG,CAAC;AAEhD,MAAM,WAAW,iBAAkB,SAAQ,IAAI,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAEvE,IAAI,EAAE,aAAa,EAAE,CAAC;CACvB;AAED,oBAAY,iBAAiB,GAAG;IAC9B,UAAU,EAAE,iBAAiB,EAAE,CAAC;IAChC,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,WAAW,CAAC,EAAE,UAAU,EAAE,CAAC;IAC3B,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC;CAC9B;AAED,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,OAAO,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,iBAAiB,CAAC,aAAa,CAAC,CAAC;CAC3C;AAED,eAAO,MAAM,uBAAuB,WAAW,CAAC;AAEhD,eAAO,MAAM,cAAc,EAAE,aAE5B,CAAC"}
@@ -12,5 +12,9 @@
12
12
  // limitations under the License.
13
13
  // adjust display when there are many time series to help with performance
14
14
  export const OPTIMIZED_MODE_SERIES_LIMIT = 1000;
15
+ export const DEFAULT_LEGEND_POSITION = 'bottom';
16
+ export const DEFAULT_LEGEND = {
17
+ position: DEFAULT_LEGEND_POSITION
18
+ };
15
19
 
16
20
  //# sourceMappingURL=graph.js.map
@@ -1 +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 { MouseEventHandler } from 'react';\nimport { LineSeriesOption } from 'echarts/charts';\n\n// adjust display when there are many time series to help with performance\nexport const OPTIMIZED_MODE_SERIES_LIMIT = 1000;\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 legendItems?: LegendItem[];\n xAxisMax?: number | string;\n rangeMs?: number;\n};\n\n/**\n * Supported legend options\n */\nexport interface LegendOptions {\n position?: 'bottom' | 'right';\n}\n\nexport interface LegendItem {\n id: string;\n label: string;\n isSelected: boolean;\n color: string;\n onClick: MouseEventHandler<HTMLLIElement>;\n}\n"],"names":["OPTIMIZED_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;AAKjC,0EAA0E;AAC1E,OAAO,MAAMA,2BAA2B,GAAG,IAAI,CAAC"}
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 { MouseEventHandler } from 'react';\nimport { LineSeriesOption } from 'echarts/charts';\n\n// adjust display when there are many time series to help with performance\nexport const OPTIMIZED_MODE_SERIES_LIMIT = 1000;\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: EChartsValues[];\n}\n\nexport type EChartsDataFormat = {\n timeSeries: EChartsTimeSeries[];\n xAxis: number[];\n legendItems?: LegendItem[];\n xAxisMax?: number | string;\n rangeMs?: number;\n};\n\n/**\n * Supported legend options\n */\nexport interface LegendOptions {\n position: 'bottom' | 'right';\n}\n\nexport interface LegendItem {\n id: string;\n label: string;\n isSelected: boolean;\n color: string;\n onClick: MouseEventHandler<HTMLLIElement>;\n}\n\nexport const DEFAULT_LEGEND_POSITION = 'bottom';\n\nexport const DEFAULT_LEGEND: LegendOptions = {\n position: DEFAULT_LEGEND_POSITION,\n};\n"],"names":["OPTIMIZED_MODE_SERIES_LIMIT","DEFAULT_LEGEND_POSITION","DEFAULT_LEGEND","position"],"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;AAKjC,0EAA0E;AAC1E,OAAO,MAAMA,2BAA2B,GAAG,IAAI,CAAC;AAyChD,OAAO,MAAMC,uBAAuB,GAAG,QAAQ,CAAC;AAEhD,OAAO,MAAMC,cAAc,GAAkB;IAC3CC,QAAQ,EAAEF,uBAAuB;CAClC,CAAC"}
@@ -4,9 +4,14 @@ declare type BytesUnitKind = typeof bytesUnitKinds[number];
4
4
  export declare type BytesUnitOptions = {
5
5
  kind: BytesUnitKind;
6
6
  decimal_places?: number;
7
+ abbreviate?: boolean;
7
8
  };
8
9
  export declare const BYTES_GROUP_CONFIG: UnitGroupConfig;
9
10
  export declare const BYTES_UNIT_CONFIG: Readonly<Record<BytesUnitKind, UnitConfig>>;
10
- export declare function formatBytes(bytes: number, decimals?: number): string;
11
+ /**
12
+ * Format value as bytes, use abbreviate option for more readable sizes (KB, MB, GB, etc.)
13
+ * https://stackoverflow.com/questions/15900485/correct-way-to-convert-size-in-bytes-to-kb-mb-gb-in-javascript/18650828#18650828
14
+ */
15
+ export declare function formatBytes(bytes: number, unitOptions: BytesUnitOptions): string;
11
16
  export {};
12
17
  //# sourceMappingURL=bytes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"bytes.d.ts","sourceRoot":"","sources":["../../../src/model/units/bytes.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAEtD,QAAA,MAAM,cAAc,oBAAqB,CAAC;AAC1C,aAAK,aAAa,GAAG,OAAO,cAAc,CAAC,MAAM,CAAC,CAAC;AACnD,oBAAY,gBAAgB,GAAG;IAC7B,IAAI,EAAE,aAAa,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AACF,eAAO,MAAM,kBAAkB,EAAE,eAGhC,CAAC;AACF,eAAO,MAAM,iBAAiB,EAAE,QAAQ,CAAC,MAAM,CAAC,aAAa,EAAE,UAAU,CAAC,CAKzE,CAAC;AAGF,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,SAAI,UAYtD"}
1
+ {"version":3,"file":"bytes.d.ts","sourceRoot":"","sources":["../../../src/model/units/bytes.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAEtD,QAAA,MAAM,cAAc,oBAAqB,CAAC;AAC1C,aAAK,aAAa,GAAG,OAAO,cAAc,CAAC,MAAM,CAAC,CAAC;AACnD,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,CAKzE,CAAC;AAEF;;;GAGG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,gBAAgB,UAmCvE"}