@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,5 +1,4 @@
1
- "use strict";
2
- // Copyright 2021 The Perses Authors
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.
5
4
  // You may obtain a copy of the License at
@@ -11,38 +10,49 @@
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
- exports.getFocusedSeriesData = exports.getNearbySeries = void 0;
16
- const tooltip_model_1 = require("./tooltip-model");
17
- /**
18
- * Returns formatted series data for the points that are close to the user's cursor
19
- * Adjust yBuffer to increase or decrease number of series shown
20
- */
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
+ getNearbySeries: ()=>getNearbySeries,
25
+ getFocusedSeriesData: ()=>getFocusedSeriesData
26
+ });
27
+ const _tooltipModel = require("./tooltip-model");
21
28
  function getNearbySeries(data, pointInGrid, yBuffer) {
22
- var _a, _b, _c, _d, _e;
23
29
  const currentFocusedData = [];
24
- const focusedX = (_a = pointInGrid[0]) !== null && _a !== void 0 ? _a : null;
25
- const focusedY = (_b = pointInGrid[1]) !== null && _b !== void 0 ? _b : null;
30
+ var ref;
31
+ const focusedX = (ref = pointInGrid[0]) !== null && ref !== void 0 ? ref : null;
32
+ var ref1;
33
+ const focusedY = (ref1 = pointInGrid[1]) !== null && ref1 !== void 0 ? ref1 : null;
26
34
  if (focusedX === null || focusedY === null) {
27
35
  return currentFocusedData;
28
36
  }
29
37
  if (Array.isArray(data.xAxis) && Array.isArray(data.timeSeries)) {
30
- for (let seriesIdx = 0; seriesIdx < data.timeSeries.length; seriesIdx++) {
38
+ for(let seriesIdx = 0; seriesIdx < data.timeSeries.length; seriesIdx++){
31
39
  const currentSeries = data.timeSeries[seriesIdx];
32
- if (currentFocusedData.length >= tooltip_model_1.TOOLTIP_MAX_ITEMS)
33
- break;
40
+ if (currentFocusedData.length >= _tooltipModel.TOOLTIP_MAX_ITEMS) break;
34
41
  if (currentSeries !== undefined) {
35
42
  const currentSeriesName = currentSeries.name ? currentSeries.name.toString() : '';
36
- const markerColor = (_c = currentSeries.color) !== null && _c !== void 0 ? _c : '#000';
43
+ var _color;
44
+ const markerColor = (_color = currentSeries.color) !== null && _color !== void 0 ? _color : '#000';
37
45
  if (Array.isArray(currentSeries.data)) {
38
- for (let datumIdx = 0; datumIdx < currentSeries.data.length; datumIdx++) {
39
- const xValue = (_d = data.xAxis[datumIdx]) !== null && _d !== void 0 ? _d : 0;
40
- const yValue = (_e = currentSeries.data[datumIdx]) !== null && _e !== void 0 ? _e : 0;
46
+ for(let datumIdx = 0; datumIdx < currentSeries.data.length; datumIdx++){
47
+ var _datumIdx;
48
+ const xValue = (_datumIdx = data.xAxis[datumIdx]) !== null && _datumIdx !== void 0 ? _datumIdx : 0;
49
+ var _datumIdx1;
50
+ const yValue = (_datumIdx1 = currentSeries.data[datumIdx]) !== null && _datumIdx1 !== void 0 ? _datumIdx1 : 0;
41
51
  if (focusedX === datumIdx) {
42
52
  if (yValue !== '-' && focusedY <= yValue + yBuffer && focusedY >= yValue - yBuffer) {
43
53
  // determine whether to convert timestamp to ms, see: https://stackoverflow.com/a/23982005/17575201
44
54
  const xValueMilliSeconds = xValue > 99999999999 ? xValue : xValue * 1000;
45
- const formattedDate = tooltip_model_1.TOOLTIP_DATE_FORMAT.format(xValueMilliSeconds);
55
+ const formattedDate = _tooltipModel.TOOLTIP_DATE_FORMAT.format(xValueMilliSeconds);
46
56
  currentFocusedData.push({
47
57
  seriesIdx: seriesIdx,
48
58
  datumIdx: datumIdx,
@@ -50,7 +60,7 @@ function getNearbySeries(data, pointInGrid, yBuffer) {
50
60
  date: formattedDate,
51
61
  x: xValue,
52
62
  y: yValue,
53
- markerColor: markerColor.toString(),
63
+ markerColor: markerColor.toString()
54
64
  });
55
65
  }
56
66
  }
@@ -61,15 +71,8 @@ function getNearbySeries(data, pointInGrid, yBuffer) {
61
71
  }
62
72
  return currentFocusedData;
63
73
  }
64
- exports.getNearbySeries = getNearbySeries;
65
- /**
66
- * Uses mouse position to determine whether user is hovering over a chart canvas
67
- * If yes, convert from pixel values to logical cartesian coordinates and return all focused series
68
- */
69
74
  function getFocusedSeriesData(mousePos, chartData, pinnedPos, chart) {
70
- var _a, _b;
71
- if (chart === undefined || mousePos === null)
72
- return [];
75
+ if (chart === undefined || mousePos === null) return [];
73
76
  // prevents multiple tooltips showing from adjacent charts
74
77
  let cursorTargetMatchesChart = false;
75
78
  if (mousePos.target !== null) {
@@ -89,16 +92,18 @@ function getFocusedSeriesData(mousePos, chartData, pinnedPos, chart) {
89
92
  mousePos = pinnedPos;
90
93
  cursorTargetMatchesChart = true;
91
94
  }
92
- if (cursorTargetMatchesChart === false)
93
- return [];
94
- if (chart['_model'] === undefined)
95
- return [];
95
+ if (cursorTargetMatchesChart === false) return [];
96
+ if (chart['_model'] === undefined) return [];
96
97
  const chartModel = chart['_model'];
97
98
  const yAxisInterval = chartModel.getComponent('yAxis').axis.scale._interval;
98
99
  const seriesNum = chartData.timeSeries.length;
99
100
  // tooltip trigger area gets smaller with more series
100
- const yBuffer = seriesNum > tooltip_model_1.TOOLTIP_MAX_ITEMS ? yAxisInterval * 0.5 : yAxisInterval * 2;
101
- const pointInPixel = [(_a = mousePos.plotCanvas.x) !== null && _a !== void 0 ? _a : 0, (_b = mousePos.plotCanvas.y) !== null && _b !== void 0 ? _b : 0];
101
+ const yBuffer = seriesNum > _tooltipModel.TOOLTIP_MAX_ITEMS ? yAxisInterval * 0.5 : yAxisInterval * 2;
102
+ var _x, _y;
103
+ const pointInPixel = [
104
+ (_x = mousePos.plotCanvas.x) !== null && _x !== void 0 ? _x : 0,
105
+ (_y = mousePos.plotCanvas.y) !== null && _y !== void 0 ? _y : 0
106
+ ];
102
107
  if (chart.containPixel('grid', pointInPixel)) {
103
108
  const pointInGrid = chart.convertFromPixel('grid', pointInPixel);
104
109
  if (pointInGrid[0] !== undefined && pointInGrid[1] !== undefined) {
@@ -107,4 +112,3 @@ function getFocusedSeriesData(mousePos, chartData, pinnedPos, chart) {
107
112
  }
108
113
  return [];
109
114
  }
110
- exports.getFocusedSeriesData = getFocusedSeriesData;
@@ -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,9 +10,12 @@
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 focused_series_1 = require("./focused-series");
16
- describe('getNearbySeries', () => {
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ const _focusedSeries = require("./focused-series");
18
+ describe('getNearbySeries', ()=>{
17
19
  const chartData = {
18
20
  timeSeries: [
19
21
  {
@@ -21,24 +23,42 @@ describe('getNearbySeries', () => {
21
23
  name: 'env="demo", instance="demo.do.prometheus", job="node", mode="test"',
22
24
  color: 'hsla(-1365438424,50%,50%,0.8)',
23
25
  data: [
24
- 0.0002315202231525094, 0.00022873082287300112, 0.00023152022315149463, 0.00023152022315149463,
26
+ 0.0002315202231525094,
25
27
  0.00022873082287300112,
28
+ 0.00023152022315149463,
29
+ 0.00023152022315149463,
30
+ 0.00022873082287300112
26
31
  ],
27
- symbol: 'circle',
32
+ symbol: 'circle'
28
33
  },
29
34
  {
30
35
  type: 'line',
31
36
  name: 'env="demo", instance="demo.do.prometheus", job="node", mode="test alt"',
32
37
  color: 'hsla(286664040,50%,50%,0.8)',
33
- data: [0.05245188284519867, 0.0524463040446356, 0.0524463040446356, 0.05247140864723438, 0.052482566248230646],
34
- symbol: 'circle',
35
- },
38
+ data: [
39
+ 0.05245188284519867,
40
+ 0.0524463040446356,
41
+ 0.0524463040446356,
42
+ 0.05247140864723438,
43
+ 0.052482566248230646
44
+ ],
45
+ symbol: 'circle'
46
+ }
47
+ ],
48
+ xAxis: [
49
+ 1654007865000,
50
+ 1654007880000,
51
+ 1654007895000,
52
+ 1654007910000,
53
+ 1654007925000
36
54
  ],
37
- xAxis: [1654007865000, 1654007880000, 1654007895000, 1654007910000, 1654007925000],
38
- rangeMs: 60000,
55
+ rangeMs: 60000
39
56
  };
40
57
  // https://echarts.apache.org/en/api.html#echartsInstance.convertFromPixel
41
- const pointInGrid = [2, 0.0560655737704918]; // converted from chart.getZr() mousemove coordinates
58
+ const pointInGrid = [
59
+ 2,
60
+ 0.0560655737704918
61
+ ]; // converted from chart.getZr() mousemove coordinates
42
62
  const yBuffer = 0.02; // calculated from y axis interval
43
63
  const focusedSeriesOutput = [
44
64
  {
@@ -48,10 +68,10 @@ describe('getNearbySeries', () => {
48
68
  seriesName: 'env="demo", instance="demo.do.prometheus", job="node", mode="test alt"',
49
69
  seriesIdx: 1,
50
70
  x: 1654007895000,
51
- y: 0.0524463040446356,
52
- },
71
+ y: 0.0524463040446356
72
+ }
53
73
  ];
54
- it('should return focused series data for points nearby the cursor', () => {
55
- expect((0, focused_series_1.getNearbySeries)(chartData, pointInGrid, yBuffer)).toEqual(focusedSeriesOutput);
74
+ it('should return focused series data for points nearby the cursor', ()=>{
75
+ expect((0, _focusedSeries.getNearbySeries)(chartData, pointInGrid, yBuffer)).toEqual(focusedSeriesOutput);
56
76
  });
57
77
  });
@@ -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,20 +10,20 @@
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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
15
- if (k2 === undefined) k2 = k;
16
- var desc = Object.getOwnPropertyDescriptor(m, k);
17
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
18
- desc = { enumerable: true, get: function() { return m[k]; } };
19
- }
20
- Object.defineProperty(o, k2, desc);
21
- }) : (function(o, m, k, k2) {
22
- if (k2 === undefined) k2 = k;
23
- o[k2] = m[k];
24
- }));
25
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- __exportStar(require("./Tooltip"), exports);
30
- __exportStar(require("./SeriesMarker"), exports);
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ _exportStar(require("./Tooltip"), exports);
18
+ _exportStar(require("./SeriesMarker"), exports);
19
+ function _exportStar(from, to) {
20
+ Object.keys(from).forEach(function(k) {
21
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
22
+ enumerable: true,
23
+ get: function() {
24
+ return from[k];
25
+ }
26
+ });
27
+ });
28
+ return from;
29
+ }
@@ -1,5 +1,4 @@
1
- "use strict";
2
- // Copyright 2021 The Perses Authors
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.
5
4
  // You may obtain a copy of the License at
@@ -11,72 +10,89 @@
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
- exports.useMousePosition = exports.emptyTooltipData = exports.defaultCursorData = exports.TOOLTIP_DATE_FORMAT = exports.TOOLTIP_MAX_ITEMS = exports.TOOLTIP_LABELS_MAX_WIDTH = exports.TOOLTIP_MAX_HEIGHT = exports.TOOLTIP_MAX_WIDTH = void 0;
16
- const react_1 = require("react");
17
- exports.TOOLTIP_MAX_WIDTH = 650;
18
- exports.TOOLTIP_MAX_HEIGHT = 230;
19
- exports.TOOLTIP_LABELS_MAX_WIDTH = exports.TOOLTIP_MAX_WIDTH - 150;
20
- exports.TOOLTIP_MAX_ITEMS = 50;
21
- exports.TOOLTIP_DATE_FORMAT = new Intl.DateTimeFormat(undefined, {
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
+ TOOLTIP_MAX_WIDTH: ()=>TOOLTIP_MAX_WIDTH,
25
+ TOOLTIP_MAX_HEIGHT: ()=>TOOLTIP_MAX_HEIGHT,
26
+ TOOLTIP_LABELS_MAX_WIDTH: ()=>TOOLTIP_LABELS_MAX_WIDTH,
27
+ TOOLTIP_MAX_ITEMS: ()=>TOOLTIP_MAX_ITEMS,
28
+ TOOLTIP_DATE_FORMAT: ()=>TOOLTIP_DATE_FORMAT,
29
+ defaultCursorData: ()=>defaultCursorData,
30
+ emptyTooltipData: ()=>emptyTooltipData,
31
+ useMousePosition: ()=>useMousePosition
32
+ });
33
+ const _react = require("react");
34
+ const TOOLTIP_MAX_WIDTH = 650;
35
+ const TOOLTIP_MAX_HEIGHT = 230;
36
+ const TOOLTIP_LABELS_MAX_WIDTH = TOOLTIP_MAX_WIDTH - 150;
37
+ const TOOLTIP_MAX_ITEMS = 50;
38
+ const TOOLTIP_DATE_FORMAT = new Intl.DateTimeFormat(undefined, {
22
39
  year: 'numeric',
23
40
  month: 'short',
24
41
  day: 'numeric',
25
42
  hour: 'numeric',
26
43
  minute: 'numeric',
27
44
  second: 'numeric',
28
- hour12: true,
45
+ hour12: true
29
46
  });
30
- exports.defaultCursorData = {
47
+ const defaultCursorData = {
31
48
  coords: {
32
49
  viewport: {
33
50
  x: 0,
34
- y: 0,
51
+ y: 0
35
52
  },
36
53
  plotCanvas: {
37
54
  x: 0,
38
- y: 0,
55
+ y: 0
39
56
  },
40
57
  zrender: {
41
58
  x: 0,
42
- y: 0,
59
+ y: 0
43
60
  },
44
- target: null,
61
+ target: null
45
62
  },
46
- chartWidth: 0,
63
+ chartWidth: 0
47
64
  };
48
- exports.emptyTooltipData = {
49
- cursor: exports.defaultCursorData,
50
- focusedSeries: null,
65
+ const emptyTooltipData = {
66
+ cursor: defaultCursorData,
67
+ focusedSeries: null
51
68
  };
52
- const useMousePosition = () => {
53
- const [coords, setCoords] = (0, react_1.useState)(null);
54
- (0, react_1.useEffect)(() => {
55
- const setFromEvent = (e) => {
69
+ const useMousePosition = ()=>{
70
+ const [coords, setCoords] = (0, _react.useState)(null);
71
+ (0, _react.useEffect)(()=>{
72
+ const setFromEvent = (e)=>{
56
73
  return setCoords({
57
74
  viewport: {
58
75
  x: e.clientX,
59
- y: e.clientY,
76
+ y: e.clientY
60
77
  },
61
78
  plotCanvas: {
62
79
  x: e.offsetX,
63
- y: e.offsetY,
80
+ y: e.offsetY
64
81
  },
65
82
  zrender: {
66
83
  // echarts canvas coordinates added automatically by zrender
67
84
  // zrX and zrY are similar to offsetX and offsetY but they return undefined when not hovering over a chart canvas
68
85
  x: e.zrX,
69
- y: e.zrY,
86
+ y: e.zrY
70
87
  },
71
88
  // necessary to check whether cursor target matches correct chart canvas (since each chart has its own mousemove listener)
72
- target: e.target,
89
+ target: e.target
73
90
  });
74
91
  };
75
92
  window.addEventListener('mousemove', setFromEvent);
76
- return () => {
93
+ return ()=>{
77
94
  window.removeEventListener('mousemove', setFromEvent);
78
95
  };
79
96
  }, []);
80
97
  return coords;
81
98
  };
82
- exports.useMousePosition = useMousePosition;
@@ -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,12 +10,15 @@
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
- exports.assembleTransform = void 0;
16
- const tooltip_model_1 = require("./tooltip-model");
17
- /**
18
- * Determine position of tooltip depending on chart dimensions and the number of focused series
19
- */
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ Object.defineProperty(exports, "assembleTransform", {
18
+ enumerable: true,
19
+ get: ()=>assembleTransform
20
+ });
21
+ const _tooltipModel = require("./tooltip-model");
20
22
  function assembleTransform(mousePos, seriesNum, chartWidth, chartHeight, pinnedPos) {
21
23
  if (mousePos === null) {
22
24
  return 'translate3d(0, 0)';
@@ -34,20 +36,15 @@ function assembleTransform(mousePos, seriesNum, chartWidth, chartHeight, pinnedP
34
36
  if (isCloseToBottom === true) {
35
37
  if (seriesNum > 6) {
36
38
  y = mousePos.viewport.y * 0.65;
37
- }
38
- else {
39
+ } else {
39
40
  y = mousePos.viewport.y * 0.75;
40
41
  }
41
- }
42
- else if (mousePos.plotCanvas.y > yPosAdjustThreshold) {
42
+ } else if (mousePos.plotCanvas.y > yPosAdjustThreshold) {
43
43
  y = mousePos.viewport.y * 0.85;
44
44
  }
45
45
  // use tooltip width to determine when to repos from right to left (width is narrower when only 1 focused series since labels wrap)
46
- const tooltipWidth = seriesNum > 1 ? tooltip_model_1.TOOLTIP_MAX_WIDTH : tooltip_model_1.TOOLTIP_MAX_WIDTH / 2;
46
+ const tooltipWidth = seriesNum > 1 ? _tooltipModel.TOOLTIP_MAX_WIDTH : _tooltipModel.TOOLTIP_MAX_WIDTH / 2;
47
47
  const xPosAdjustThreshold = chartWidth - tooltipWidth * 0.9;
48
48
  // reposition so tooltip is never too close to right side of chart or left side of browser window
49
- return mousePos.plotCanvas.x > xPosAdjustThreshold && x > tooltip_model_1.TOOLTIP_MAX_WIDTH
50
- ? `translate3d(${x - cursorPaddingX}px, ${y}px, 0) translateX(-100%)`
51
- : `translate3d(${x + cursorPaddingX}px, ${y}px, 0)`;
49
+ return mousePos.plotCanvas.x > xPosAdjustThreshold && x > _tooltipModel.TOOLTIP_MAX_WIDTH ? `translate3d(${x - cursorPaddingX}px, ${y}px, 0) translateX(-100%)` : `translate3d(${x + cursorPaddingX}px, ${y}px, 0)`;
52
50
  }
53
- exports.assembleTransform = assembleTransform;
@@ -1,7 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useChartsTheme = exports.ChartsThemeContext = exports.ChartsThemeProvider = void 0;
4
- const jsx_runtime_1 = require("react/jsx-runtime");
5
1
  // Copyright 2022 The Perses Authors
6
2
  // Licensed under the Apache License, Version 2.0 (the "License");
7
3
  // you may not use this file except in compliance with the License.
@@ -14,23 +10,79 @@ const jsx_runtime_1 = require("react/jsx-runtime");
14
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
11
  // See the License for the specific language governing permissions and
16
12
  // limitations under the License.
17
- const react_1 = require("react");
18
- const echarts_1 = require("echarts");
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
+ ChartsThemeProvider: ()=>ChartsThemeProvider,
25
+ ChartsThemeContext: ()=>ChartsThemeContext,
26
+ useChartsTheme: ()=>useChartsTheme
27
+ });
28
+ const _jsxRuntime = require("react/jsx-runtime");
29
+ const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
30
+ const _echarts = require("echarts");
31
+ function _getRequireWildcardCache(nodeInterop) {
32
+ if (typeof WeakMap !== "function") return null;
33
+ var cacheBabelInterop = new WeakMap();
34
+ var cacheNodeInterop = new WeakMap();
35
+ return (_getRequireWildcardCache = function(nodeInterop) {
36
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
37
+ })(nodeInterop);
38
+ }
39
+ function _interopRequireWildcard(obj, nodeInterop) {
40
+ if (!nodeInterop && obj && obj.__esModule) {
41
+ return obj;
42
+ }
43
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
44
+ return {
45
+ default: obj
46
+ };
47
+ }
48
+ var cache = _getRequireWildcardCache(nodeInterop);
49
+ if (cache && cache.has(obj)) {
50
+ return cache.get(obj);
51
+ }
52
+ var newObj = {};
53
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
54
+ for(var key in obj){
55
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
56
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
57
+ if (desc && (desc.get || desc.set)) {
58
+ Object.defineProperty(newObj, key, desc);
59
+ } else {
60
+ newObj[key] = obj[key];
61
+ }
62
+ }
63
+ }
64
+ newObj.default = obj;
65
+ if (cache) {
66
+ cache.set(obj, newObj);
67
+ }
68
+ return newObj;
69
+ }
19
70
  function ChartsThemeProvider(props) {
20
- const { children, themeName, chartsTheme } = props;
71
+ const { children , themeName , chartsTheme } = props;
21
72
  if (chartsTheme !== undefined && chartsTheme.echartsTheme !== undefined) {
22
73
  // register ECharts theme to be used in individual charts, see: https://apache.github.io/echarts-handbook/en/concepts/style/#theme
23
- (0, echarts_1.registerTheme)(themeName, chartsTheme.echartsTheme);
74
+ (0, _echarts.registerTheme)(themeName, chartsTheme.echartsTheme);
24
75
  }
25
- return (0, jsx_runtime_1.jsx)(exports.ChartsThemeContext.Provider, { value: chartsTheme, children: children });
76
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(ChartsThemeContext.Provider, {
77
+ value: chartsTheme,
78
+ children: children
79
+ });
26
80
  }
27
- exports.ChartsThemeProvider = ChartsThemeProvider;
28
- exports.ChartsThemeContext = (0, react_1.createContext)(undefined);
81
+ const ChartsThemeContext = /*#__PURE__*/ (0, _react.createContext)(undefined);
29
82
  function useChartsTheme() {
30
- const ctx = (0, react_1.useContext)(exports.ChartsThemeContext);
83
+ const ctx = (0, _react.useContext)(ChartsThemeContext);
31
84
  if (ctx === undefined) {
32
85
  throw new Error('No ChartsThemeContext found. Did you forget a Provider?');
33
86
  }
34
87
  return ctx;
35
88
  }
36
- exports.useChartsTheme = useChartsTheme;
package/dist/cjs/index.js CHANGED
@@ -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,30 +10,30 @@
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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
15
- if (k2 === undefined) k2 = k;
16
- var desc = Object.getOwnPropertyDescriptor(m, k);
17
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
18
- desc = { enumerable: true, get: function() { return m[k]; } };
19
- }
20
- Object.defineProperty(o, k2, desc);
21
- }) : (function(o, m, k, k2) {
22
- if (k2 === undefined) k2 = k;
23
- o[k2] = m[k];
24
- }));
25
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- __exportStar(require("./Drawer"), exports);
30
- __exportStar(require("./EChart"), exports);
31
- __exportStar(require("./ErrorAlert"), exports);
32
- __exportStar(require("./ErrorBoundary"), exports);
33
- __exportStar(require("./InfoTooltip"), exports);
34
- __exportStar(require("./LineChart"), exports);
35
- __exportStar(require("./GaugeChart"), exports);
36
- __exportStar(require("./StatChart"), exports);
37
- __exportStar(require("./TimeRangeSelector"), exports);
38
- __exportStar(require("./context/ChartsThemeProvider"), exports);
39
- __exportStar(require("./utils"), exports);
40
- __exportStar(require("./model"), exports);
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ _exportStar(require("./Drawer"), exports);
18
+ _exportStar(require("./EChart"), exports);
19
+ _exportStar(require("./ErrorAlert"), exports);
20
+ _exportStar(require("./ErrorBoundary"), exports);
21
+ _exportStar(require("./InfoTooltip"), exports);
22
+ _exportStar(require("./LineChart"), exports);
23
+ _exportStar(require("./GaugeChart"), exports);
24
+ _exportStar(require("./StatChart"), exports);
25
+ _exportStar(require("./TimeRangeSelector"), exports);
26
+ _exportStar(require("./context/ChartsThemeProvider"), exports);
27
+ _exportStar(require("./utils"), exports);
28
+ _exportStar(require("./model"), exports);
29
+ function _exportStar(from, to) {
30
+ Object.keys(from).forEach(function(k) {
31
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
32
+ enumerable: true,
33
+ get: function() {
34
+ return from[k];
35
+ }
36
+ });
37
+ });
38
+ return from;
39
+ }
@@ -1,5 +1,4 @@
1
- "use strict";
2
- // Copyright 2021 The Perses Authors
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.
5
4
  // You may obtain a copy of the License at
@@ -11,6 +10,12 @@
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
- exports.PROGRESSIVE_MODE_SERIES_LIMIT = void 0;
16
- exports.PROGRESSIVE_MODE_SERIES_LIMIT = 500;
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ Object.defineProperty(exports, "PROGRESSIVE_MODE_SERIES_LIMIT", {
18
+ enumerable: true,
19
+ get: ()=>PROGRESSIVE_MODE_SERIES_LIMIT
20
+ });
21
+ const PROGRESSIVE_MODE_SERIES_LIMIT = 500;