@perses-dev/components 0.31.0 → 0.33.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 (111) hide show
  1. package/dist/ContentWithLegend/ContentWithLegend.d.ts +11 -0
  2. package/dist/ContentWithLegend/ContentWithLegend.d.ts.map +1 -0
  3. package/dist/ContentWithLegend/ContentWithLegend.js +65 -0
  4. package/dist/ContentWithLegend/ContentWithLegend.js.map +1 -0
  5. package/dist/ContentWithLegend/index.d.ts +2 -0
  6. package/dist/ContentWithLegend/index.d.ts.map +1 -0
  7. package/dist/ContentWithLegend/index.js +15 -0
  8. package/dist/ContentWithLegend/index.js.map +1 -0
  9. package/dist/ContentWithLegend/model/content-with-legend-model.d.ts +68 -0
  10. package/dist/ContentWithLegend/model/content-with-legend-model.d.ts.map +1 -0
  11. package/dist/ContentWithLegend/model/content-with-legend-model.js +90 -0
  12. package/dist/ContentWithLegend/model/content-with-legend-model.js.map +1 -0
  13. package/dist/EChart/EChart.d.ts.map +1 -1
  14. package/dist/EChart/EChart.js +9 -1
  15. package/dist/EChart/EChart.js.map +1 -1
  16. package/dist/Legend/Legend.d.ts.map +1 -1
  17. package/dist/Legend/Legend.js +30 -15
  18. package/dist/Legend/Legend.js.map +1 -1
  19. package/dist/Legend/ListLegend.d.ts.map +1 -1
  20. package/dist/Legend/ListLegend.js +2 -23
  21. package/dist/Legend/ListLegend.js.map +1 -1
  22. package/dist/Legend/ListLegendItem.d.ts +1 -1
  23. package/dist/Legend/TableLegend.d.ts +12 -0
  24. package/dist/Legend/TableLegend.d.ts.map +1 -0
  25. package/dist/Legend/TableLegend.js +61 -0
  26. package/dist/Legend/TableLegend.js.map +1 -0
  27. package/dist/LegendOptionsEditor/LegendOptionsEditor.d.ts.map +1 -1
  28. package/dist/LegendOptionsEditor/LegendOptionsEditor.js +35 -3
  29. package/dist/LegendOptionsEditor/LegendOptionsEditor.js.map +1 -1
  30. package/dist/LineChart/LineChart.d.ts.map +1 -1
  31. package/dist/LineChart/LineChart.js +60 -22
  32. package/dist/LineChart/LineChart.js.map +1 -1
  33. package/dist/StatChart/StatChart.d.ts.map +1 -1
  34. package/dist/StatChart/StatChart.js +8 -1
  35. package/dist/StatChart/StatChart.js.map +1 -1
  36. package/dist/Table/InnerTable.js +1 -1
  37. package/dist/Table/InnerTable.js.map +1 -1
  38. package/dist/Table/TableCell.js +1 -1
  39. package/dist/Table/TableCell.js.map +1 -1
  40. package/dist/Table/TableRow.d.ts.map +1 -1
  41. package/dist/Table/TableRow.js +3 -3
  42. package/dist/Table/TableRow.js.map +1 -1
  43. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.d.ts +5 -5
  44. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.d.ts.map +1 -1
  45. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.js +36 -54
  46. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.js.map +1 -1
  47. package/dist/TimeSeriesTooltip/TooltipContent.d.ts +0 -2
  48. package/dist/TimeSeriesTooltip/TooltipContent.d.ts.map +1 -1
  49. package/dist/TimeSeriesTooltip/TooltipContent.js +21 -97
  50. package/dist/TimeSeriesTooltip/TooltipContent.js.map +1 -1
  51. package/dist/TimeSeriesTooltip/TooltipHeader.d.ts +12 -0
  52. package/dist/TimeSeriesTooltip/TooltipHeader.d.ts.map +1 -0
  53. package/dist/TimeSeriesTooltip/TooltipHeader.js +163 -0
  54. package/dist/TimeSeriesTooltip/TooltipHeader.js.map +1 -0
  55. package/dist/TimeSeriesTooltip/index.d.ts +1 -0
  56. package/dist/TimeSeriesTooltip/index.d.ts.map +1 -1
  57. package/dist/TimeSeriesTooltip/index.js +1 -0
  58. package/dist/TimeSeriesTooltip/index.js.map +1 -1
  59. package/dist/TimeSeriesTooltip/nearby-series.d.ts +2 -2
  60. package/dist/TimeSeriesTooltip/nearby-series.d.ts.map +1 -1
  61. package/dist/TimeSeriesTooltip/nearby-series.js +2 -2
  62. package/dist/TimeSeriesTooltip/nearby-series.js.map +1 -1
  63. package/dist/TimeSeriesTooltip/tooltip-model.d.ts +10 -14
  64. package/dist/TimeSeriesTooltip/tooltip-model.d.ts.map +1 -1
  65. package/dist/TimeSeriesTooltip/tooltip-model.js +2 -1
  66. package/dist/TimeSeriesTooltip/tooltip-model.js.map +1 -1
  67. package/dist/TimeSeriesTooltip/utils.js +2 -2
  68. package/dist/TimeSeriesTooltip/utils.js.map +1 -1
  69. package/dist/cjs/ContentWithLegend/ContentWithLegend.js +70 -0
  70. package/dist/cjs/ContentWithLegend/index.js +28 -0
  71. package/dist/cjs/ContentWithLegend/model/content-with-legend-model.js +100 -0
  72. package/dist/cjs/EChart/EChart.js +9 -1
  73. package/dist/cjs/Legend/Legend.js +30 -15
  74. package/dist/cjs/Legend/ListLegend.js +2 -23
  75. package/dist/cjs/Legend/TableLegend.js +67 -0
  76. package/dist/cjs/LegendOptionsEditor/LegendOptionsEditor.js +34 -2
  77. package/dist/cjs/LineChart/LineChart.js +60 -22
  78. package/dist/cjs/StatChart/StatChart.js +8 -1
  79. package/dist/cjs/Table/InnerTable.js +1 -1
  80. package/dist/cjs/Table/TableCell.js +1 -1
  81. package/dist/cjs/Table/TableRow.js +2 -2
  82. package/dist/cjs/TimeSeriesTooltip/TimeSeriesTooltip.js +34 -91
  83. package/dist/cjs/TimeSeriesTooltip/TooltipContent.js +19 -100
  84. package/dist/cjs/TimeSeriesTooltip/TooltipHeader.js +174 -0
  85. package/dist/cjs/TimeSeriesTooltip/index.js +1 -0
  86. package/dist/cjs/TimeSeriesTooltip/nearby-series.js +2 -2
  87. package/dist/cjs/TimeSeriesTooltip/tooltip-model.js +3 -1
  88. package/dist/cjs/TimeSeriesTooltip/utils.js +2 -2
  89. package/dist/cjs/index.js +1 -0
  90. package/dist/cjs/model/legend.js +30 -1
  91. package/dist/cjs/theme/component-overrides/paper.js +27 -0
  92. package/dist/cjs/theme/palette/background.js +2 -2
  93. package/dist/cjs/theme/theme.js +2 -0
  94. package/dist/index.d.ts +1 -0
  95. package/dist/index.d.ts.map +1 -1
  96. package/dist/index.js +1 -0
  97. package/dist/index.js.map +1 -1
  98. package/dist/model/legend.d.ts +9 -3
  99. package/dist/model/legend.d.ts.map +1 -1
  100. package/dist/model/legend.js +26 -1
  101. package/dist/model/legend.js.map +1 -1
  102. package/dist/theme/component-overrides/paper.d.ts +3 -0
  103. package/dist/theme/component-overrides/paper.d.ts.map +1 -0
  104. package/dist/theme/component-overrides/paper.js +21 -0
  105. package/dist/theme/component-overrides/paper.js.map +1 -0
  106. package/dist/theme/palette/background.js +2 -2
  107. package/dist/theme/palette/background.js.map +1 -1
  108. package/dist/theme/theme.d.ts.map +1 -1
  109. package/dist/theme/theme.js +2 -0
  110. package/dist/theme/theme.js.map +1 -1
  111. package/package.json +4 -7
@@ -20,9 +20,10 @@ Object.defineProperty(exports, "TimeSeriesTooltip", {
20
20
  });
21
21
  const _jsxRuntime = require("react/jsx-runtime");
22
22
  const _material = require("@mui/material");
23
- const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
23
+ const _react = require("react");
24
24
  const _useResizeObserver = /*#__PURE__*/ _interopRequireDefault(require("use-resize-observer"));
25
25
  const _tooltipContent = require("./TooltipContent");
26
+ const _tooltipHeader = require("./TooltipHeader");
26
27
  const _nearbySeries = require("./nearby-series");
27
28
  const _tooltipModel = require("./tooltip-model");
28
29
  const _utils = require("./utils");
@@ -31,59 +32,20 @@ function _interopRequireDefault(obj) {
31
32
  default: obj
32
33
  };
33
34
  }
34
- function _getRequireWildcardCache(nodeInterop) {
35
- if (typeof WeakMap !== "function") return null;
36
- var cacheBabelInterop = new WeakMap();
37
- var cacheNodeInterop = new WeakMap();
38
- return (_getRequireWildcardCache = function(nodeInterop) {
39
- return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
40
- })(nodeInterop);
41
- }
42
- function _interopRequireWildcard(obj, nodeInterop) {
43
- if (!nodeInterop && obj && obj.__esModule) {
44
- return obj;
45
- }
46
- if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
47
- return {
48
- default: obj
49
- };
50
- }
51
- var cache = _getRequireWildcardCache(nodeInterop);
52
- if (cache && cache.has(obj)) {
53
- return cache.get(obj);
54
- }
55
- var newObj = {};
56
- var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
57
- for(var key in obj){
58
- if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
59
- var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
60
- if (desc && (desc.get || desc.set)) {
61
- Object.defineProperty(newObj, key, desc);
62
- } else {
63
- newObj[key] = obj[key];
64
- }
65
- }
66
- }
67
- newObj.default = obj;
68
- if (cache) {
69
- cache.set(obj, newObj);
70
- }
71
- return newObj;
72
- }
73
- const TimeSeriesTooltip = /*#__PURE__*/ _react.default.memo(function TimeSeriesTooltip({ chartRef , chartData , wrapLabels , isTooltipPinned , unit , onUnpinClick }) {
35
+ const TimeSeriesTooltip = /*#__PURE__*/ (0, _react.memo)(function TimeSeriesTooltip({ chartRef , chartData , wrapLabels , unit , onUnpinClick , pinnedPos }) {
74
36
  const [showAllSeries, setShowAllSeries] = (0, _react.useState)(false);
75
- const [pinnedPos, setPinnedPos] = (0, _react.useState)(null);
76
37
  const mousePos = (0, _tooltipModel.useMousePosition)();
77
38
  const { height , width , ref: tooltipRef } = (0, _useResizeObserver.default)();
39
+ const isTooltipPinned = pinnedPos !== null;
78
40
  if (mousePos === null || mousePos.target === null) return null;
79
41
  // Ensure user is hovering over a chart before checking for nearby series.
80
42
  if (pinnedPos === null && mousePos.target.tagName !== 'CANVAS') return null;
81
43
  const chart = chartRef.current;
82
44
  var ref;
83
- const chartWidth = (ref = chart === null || chart === void 0 ? void 0 : chart.getWidth()) !== null && ref !== void 0 ? ref : _tooltipModel.FALLBACK_CHART_WIDTH; // Fallback width not likely to every be needed.
45
+ const chartWidth = (ref = chart === null || chart === void 0 ? void 0 : chart.getWidth()) !== null && ref !== void 0 ? ref : _tooltipModel.FALLBACK_CHART_WIDTH; // Fallback width not likely to ever be needed.
84
46
  const cursorTransform = (0, _utils.assembleTransform)(mousePos, chartWidth, pinnedPos, height !== null && height !== void 0 ? height : 0, width !== null && width !== void 0 ? width : 0);
85
47
  // Get series nearby the cursor and pass into tooltip content children.
86
- const focusedSeries = (0, _nearbySeries.getNearbySeriesData)({
48
+ const nearbySeries = (0, _nearbySeries.getNearbySeriesData)({
87
49
  mousePos,
88
50
  chartData,
89
51
  pinnedPos,
@@ -91,27 +53,25 @@ const TimeSeriesTooltip = /*#__PURE__*/ _react.default.memo(function TimeSeriesT
91
53
  unit,
92
54
  showAllSeries
93
55
  });
94
- if (focusedSeries.length === 0) {
56
+ if (nearbySeries.length === 0) {
95
57
  return null;
96
58
  }
97
- if (isTooltipPinned === true && pinnedPos === null) {
98
- setPinnedPos(mousePos);
99
- }
100
- // Option for user to see all series instead of only the nearby focused series.
101
- // Only relevant when there are more total series than are visible.
102
- const showAllSeriesToggle = isTooltipPinned === true && showAllSeries === false && chartData.timeSeries.length > 1 && focusedSeries.length !== chartData.timeSeries.length;
59
+ const totalSeries = chartData.timeSeries.length;
60
+ var ref1;
103
61
  return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Portal, {
104
- children: /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
62
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
105
63
  ref: tooltipRef,
106
- sx: (theme)=>({
64
+ sx: (theme)=>{
65
+ var ref;
66
+ return {
107
67
  minWidth: _tooltipModel.TOOLTIP_MIN_WIDTH,
108
68
  maxWidth: _tooltipModel.TOOLTIP_MAX_WIDTH,
109
69
  maxHeight: _tooltipModel.TOOLTIP_MAX_HEIGHT,
110
- padding: theme.spacing(0.5, 2),
70
+ padding: 0,
111
71
  position: 'absolute',
112
72
  top: 0,
113
73
  left: 0,
114
- backgroundColor: '#2E313E',
74
+ backgroundColor: (ref1 = (ref = theme.palette.designSystem) === null || ref === void 0 ? void 0 : ref.grey[800]) !== null && ref1 !== void 0 ? ref1 : _tooltipModel.TOOLTIP_BG_COLOR_FALLBACK,
115
75
  borderRadius: '6px',
116
76
  color: '#fff',
117
77
  fontSize: '11px',
@@ -123,45 +83,28 @@ const TimeSeriesTooltip = /*#__PURE__*/ _react.default.memo(function TimeSeriesT
123
83
  '&:hover': {
124
84
  overflowY: 'auto'
125
85
  }
126
- }),
86
+ };
87
+ },
127
88
  style: {
128
89
  transform: cursorTransform
129
90
  },
130
- children: [
131
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_tooltipContent.TooltipContent, {
132
- series: focusedSeries,
133
- wrapLabels: wrapLabels,
134
- isTooltipPinned: isTooltipPinned,
135
- onUnpinClick: ()=>{
136
- setPinnedPos(null);
137
- if (onUnpinClick !== undefined) {
138
- onUnpinClick();
139
- }
140
- }
141
- }),
142
- showAllSeriesToggle && /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
143
- direction: "row",
144
- gap: 1,
145
- alignItems: "center",
146
- sx: {
147
- textAlign: 'right'
148
- },
149
- children: [
150
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
151
- children: "Show All?"
152
- }),
153
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Switch, {
154
- checked: showAllSeries,
155
- onChange: (_, checked)=>setShowAllSeries(checked),
156
- sx: (theme)=>({
157
- '& .MuiSwitch-switchBase': {
158
- color: theme.palette.common.white
159
- }
160
- })
161
- })
162
- ]
163
- })
164
- ]
91
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
92
+ spacing: 0.5,
93
+ children: [
94
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_tooltipHeader.TooltipHeader, {
95
+ nearbySeries: nearbySeries,
96
+ totalSeries: totalSeries,
97
+ isTooltipPinned: isTooltipPinned,
98
+ showAllSeries: showAllSeries,
99
+ onShowAllClick: (checked)=>setShowAllSeries(checked),
100
+ onUnpinClick: onUnpinClick
101
+ }),
102
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_tooltipContent.TooltipContent, {
103
+ series: nearbySeries,
104
+ wrapLabels: wrapLabels
105
+ })
106
+ ]
107
+ })
165
108
  })
166
109
  });
167
110
  });
@@ -20,118 +20,37 @@ Object.defineProperty(exports, "TooltipContent", {
20
20
  });
21
21
  const _jsxRuntime = require("react/jsx-runtime");
22
22
  const _react = require("react");
23
- const _pinOutline = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/PinOutline"));
24
- const _pin = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/Pin"));
25
23
  const _material = require("@mui/material");
26
- const _timeZoneProvider = require("../context/TimeZoneProvider");
27
24
  const _seriesInfo = require("./SeriesInfo");
28
- function _interopRequireDefault(obj) {
29
- return obj && obj.__esModule ? obj : {
30
- default: obj
31
- };
32
- }
33
25
  function TooltipContent(props) {
34
- const { series , wrapLabels , isTooltipPinned , onUnpinClick } = props;
35
- const { formatWithUserTimeZone } = (0, _timeZoneProvider.useTimeZone)();
36
- const seriesTime = series && series[0] && series[0].date ? series[0].date : null;
37
- const formatTimeSeriesHeader = (timeMs)=>{
38
- const date = new Date(timeMs);
39
- const formattedDate = formatWithUserTimeZone(date, 'MMM dd, yyyy - ');
40
- const formattedTime = formatWithUserTimeZone(date, 'HH:mm:ss');
41
- return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
42
- children: [
43
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
44
- variant: "caption",
45
- sx: (theme)=>({
46
- color: theme.palette.common.white
47
- }),
48
- children: formattedDate
49
- }),
50
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
51
- variant: "caption",
52
- children: /*#__PURE__*/ (0, _jsxRuntime.jsx)("strong", {
53
- children: formattedTime
54
- })
55
- })
56
- ]
57
- });
58
- };
26
+ const { series , wrapLabels } = props;
59
27
  const sortedFocusedSeries = (0, _react.useMemo)(()=>{
60
28
  if (series === null) return null;
61
29
  return series.sort((a, b)=>a.y > b.y ? -1 : 1);
62
30
  }, [
63
31
  series
64
32
  ]);
65
- if (sortedFocusedSeries === null || seriesTime === null) {
33
+ if (series === null || sortedFocusedSeries === null) {
66
34
  return null;
67
35
  }
68
36
  // TODO: use react-virtuoso to improve performance
69
- return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
70
- py: 1,
71
- spacing: 0.5,
72
- children: [
73
- /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
74
- sx: {
75
- display: 'flex',
76
- justifyContent: 'start',
77
- alignItems: 'center'
78
- },
79
- children: [
80
- formatTimeSeriesHeader(seriesTime),
81
- /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
82
- direction: "row",
83
- gap: 1,
84
- sx: {
85
- marginLeft: 'auto'
86
- },
87
- children: [
88
- /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Typography, {
89
- sx: {
90
- fontSize: 11
91
- },
92
- children: [
93
- "Click to ",
94
- isTooltipPinned ? 'Unpin' : 'Pin'
95
- ]
96
- }),
97
- isTooltipPinned ? /*#__PURE__*/ (0, _jsxRuntime.jsx)(_pin.default, {
98
- onClick: onUnpinClick,
99
- sx: {
100
- fontSize: 16,
101
- cursor: 'pointer'
102
- }
103
- }) : /*#__PURE__*/ (0, _jsxRuntime.jsx)(_pinOutline.default, {
104
- sx: {
105
- fontSize: 16
106
- }
107
- })
108
- ]
109
- })
110
- ]
111
- }),
112
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Divider, {
113
- sx: (theme)=>({
114
- borderColor: theme.palette.grey['500']
115
- })
37
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
38
+ sx: (theme)=>({
39
+ display: 'table',
40
+ padding: theme.spacing(0.5, 2)
116
41
  }),
117
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
118
- sx: {
119
- display: 'table'
120
- },
121
- children: sortedFocusedSeries.map(({ datumIdx , seriesIdx , seriesName , y , formattedY , markerColor , isClosestToCursor })=>{
122
- if (datumIdx === null || seriesIdx === null) return null;
123
- const key = seriesIdx.toString() + datumIdx.toString();
124
- return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_seriesInfo.SeriesInfo, {
125
- seriesName: seriesName,
126
- y: y,
127
- formattedY: formattedY,
128
- markerColor: markerColor,
129
- totalSeries: sortedFocusedSeries.length,
130
- wrapLabels: wrapLabels,
131
- emphasizeText: isClosestToCursor
132
- }, key);
133
- })
134
- })
135
- ]
42
+ children: sortedFocusedSeries.map(({ datumIdx , seriesIdx , seriesName , y , formattedY , markerColor , isClosestToCursor })=>{
43
+ if (datumIdx === null || seriesIdx === null) return null;
44
+ const key = seriesIdx.toString() + datumIdx.toString();
45
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_seriesInfo.SeriesInfo, {
46
+ seriesName: seriesName,
47
+ y: y,
48
+ formattedY: formattedY,
49
+ markerColor: markerColor,
50
+ totalSeries: sortedFocusedSeries.length,
51
+ wrapLabels: wrapLabels,
52
+ emphasizeText: isClosestToCursor
53
+ }, key);
54
+ })
136
55
  });
137
56
  }
@@ -0,0 +1,174 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ Object.defineProperty(exports, "TooltipHeader", {
18
+ enumerable: true,
19
+ get: ()=>TooltipHeader
20
+ });
21
+ const _jsxRuntime = require("react/jsx-runtime");
22
+ const _material = require("@mui/material");
23
+ const _pin = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/Pin"));
24
+ const _pinOutline = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/PinOutline"));
25
+ const _react = require("react");
26
+ const _timeZoneProvider = require("../context/TimeZoneProvider");
27
+ const _tooltipModel = require("./tooltip-model");
28
+ function _interopRequireDefault(obj) {
29
+ return obj && obj.__esModule ? obj : {
30
+ default: obj
31
+ };
32
+ }
33
+ const TooltipHeader = /*#__PURE__*/ (0, _react.memo)(function TooltipHeader({ nearbySeries , totalSeries , isTooltipPinned , showAllSeries , onShowAllClick , onUnpinClick }) {
34
+ var ref;
35
+ const { formatWithUserTimeZone } = (0, _timeZoneProvider.useTimeZone)();
36
+ var ref1;
37
+ const seriesTimeMs = (ref1 = (ref = nearbySeries[0]) === null || ref === void 0 ? void 0 : ref.date) !== null && ref1 !== void 0 ? ref1 : null;
38
+ if (seriesTimeMs === null) {
39
+ return null;
40
+ }
41
+ const formatTimeSeriesHeader = (timeMs)=>{
42
+ const date = new Date(timeMs);
43
+ const formattedDate = formatWithUserTimeZone(date, 'MMM dd, yyyy - ');
44
+ const formattedTime = formatWithUserTimeZone(date, 'HH:mm:ss');
45
+ return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
46
+ children: [
47
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
48
+ variant: "caption",
49
+ sx: (theme)=>({
50
+ color: theme.palette.common.white
51
+ }),
52
+ children: formattedDate
53
+ }),
54
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
55
+ variant: "caption",
56
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)("strong", {
57
+ children: formattedTime
58
+ })
59
+ })
60
+ ]
61
+ });
62
+ };
63
+ // TODO: accurately calc whether more series are outside scrollable region using yBuffer, avg series name length, TOOLTIP_MAX_HEIGHT
64
+ const showAllSeriesToggle = totalSeries > 5;
65
+ var ref2;
66
+ return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
67
+ sx: (theme)=>{
68
+ var ref;
69
+ return {
70
+ width: '100%',
71
+ maxWidth: _tooltipModel.TOOLTIP_MAX_WIDTH,
72
+ padding: theme.spacing(1.5, 2, 0.5, 2),
73
+ backgroundColor: (ref2 = (ref = theme.palette.designSystem) === null || ref === void 0 ? void 0 : ref.grey[800]) !== null && ref2 !== void 0 ? ref2 : _tooltipModel.TOOLTIP_BG_COLOR_FALLBACK,
74
+ position: 'sticky',
75
+ top: 0,
76
+ left: 0
77
+ };
78
+ },
79
+ children: [
80
+ /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
81
+ sx: {
82
+ width: '100%',
83
+ display: 'flex',
84
+ justifyContent: 'start',
85
+ alignItems: 'center',
86
+ paddingBottom: 0.5
87
+ },
88
+ children: [
89
+ formatTimeSeriesHeader(seriesTimeMs),
90
+ /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
91
+ direction: "row",
92
+ gap: 1,
93
+ sx: {
94
+ marginLeft: 'auto'
95
+ },
96
+ children: [
97
+ showAllSeriesToggle && /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
98
+ direction: "row",
99
+ gap: 0.5,
100
+ alignItems: "center",
101
+ sx: {
102
+ textAlign: 'right'
103
+ },
104
+ children: [
105
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
106
+ sx: {
107
+ fontSize: 11
108
+ },
109
+ children: "Show All"
110
+ }),
111
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Switch, {
112
+ checked: showAllSeries,
113
+ size: "small",
114
+ onChange: (_, checked)=>{
115
+ if (onShowAllClick !== undefined) {
116
+ return onShowAllClick(checked);
117
+ }
118
+ },
119
+ sx: (theme)=>({
120
+ '& .MuiSwitch-switchBase': {
121
+ color: theme.palette.common.white
122
+ },
123
+ '& .MuiSwitch-track': {
124
+ backgroundColor: theme.palette.common.white
125
+ }
126
+ })
127
+ })
128
+ ]
129
+ }),
130
+ /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
131
+ direction: "row",
132
+ alignItems: "center",
133
+ children: [
134
+ /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Typography, {
135
+ sx: {
136
+ marginRight: 0.5,
137
+ fontSize: 11,
138
+ verticalAlign: 'middle'
139
+ },
140
+ children: [
141
+ "Click to ",
142
+ isTooltipPinned ? 'Unpin' : 'Pin'
143
+ ]
144
+ }),
145
+ isTooltipPinned ? /*#__PURE__*/ (0, _jsxRuntime.jsx)(_pin.default, {
146
+ onClick: ()=>{
147
+ if (onUnpinClick !== undefined) {
148
+ onUnpinClick();
149
+ }
150
+ },
151
+ sx: {
152
+ fontSize: 16,
153
+ cursor: 'pointer'
154
+ }
155
+ }) : /*#__PURE__*/ (0, _jsxRuntime.jsx)(_pinOutline.default, {
156
+ sx: {
157
+ fontSize: 16
158
+ }
159
+ })
160
+ ]
161
+ })
162
+ ]
163
+ })
164
+ ]
165
+ }),
166
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Divider, {
167
+ sx: (theme)=>({
168
+ width: '100%',
169
+ borderColor: theme.palette.grey['500']
170
+ })
171
+ })
172
+ ]
173
+ });
174
+ });
@@ -19,6 +19,7 @@ _exportStar(require("./SeriesInfo"), exports);
19
19
  _exportStar(require("./SeriesLabelsStack"), exports);
20
20
  _exportStar(require("./SeriesMarker"), exports);
21
21
  _exportStar(require("./TooltipContent"), exports);
22
+ _exportStar(require("./TooltipHeader"), exports);
22
23
  _exportStar(require("./nearby-series"), exports);
23
24
  _exportStar(require("./tooltip-model"), exports);
24
25
  _exportStar(require("./utils"), exports);
@@ -132,7 +132,7 @@ function checkforNearbySeries(data, pointInGrid, yBuffer, chart, unit) {
132
132
  }
133
133
  function getNearbySeriesData({ mousePos , pinnedPos , chartData , chart , unit , showAllSeries =false }) {
134
134
  if (chart === undefined || mousePos === null) return [];
135
- // prevents multiple tooltips showing from adjacent charts
135
+ // prevents multiple tooltips showing from adjacent charts unless tooltip is pinned
136
136
  let cursorTargetMatchesChart = false;
137
137
  if (mousePos.target !== null) {
138
138
  const currentParent = mousePos.target.parentElement;
@@ -146,7 +146,7 @@ function getNearbySeriesData({ mousePos , pinnedPos , chartData , chart , unit ,
146
146
  }
147
147
  }
148
148
  }
149
- // allows moving cursor inside tooltip
149
+ // allows moving cursor inside tooltip without it fading away
150
150
  if (pinnedPos !== null) {
151
151
  mousePos = pinnedPos;
152
152
  cursorTargetMatchesChart = true;
@@ -29,6 +29,7 @@ _export(exports, {
29
29
  FALLBACK_CHART_WIDTH: ()=>FALLBACK_CHART_WIDTH,
30
30
  NEARBY_SERIES_DESCRIPTION: ()=>NEARBY_SERIES_DESCRIPTION,
31
31
  EMPHASIZED_SERIES_DESCRIPTION: ()=>EMPHASIZED_SERIES_DESCRIPTION,
32
+ TOOLTIP_BG_COLOR_FALLBACK: ()=>TOOLTIP_BG_COLOR_FALLBACK,
32
33
  TOOLTIP_DATE_FORMAT: ()=>TOOLTIP_DATE_FORMAT,
33
34
  defaultCursorData: ()=>defaultCursorData,
34
35
  emptyTooltipData: ()=>emptyTooltipData,
@@ -37,12 +38,13 @@ _export(exports, {
37
38
  const _react = require("react");
38
39
  const TOOLTIP_MIN_WIDTH = 375;
39
40
  const TOOLTIP_MAX_WIDTH = 650;
40
- const TOOLTIP_MAX_HEIGHT = 600;
41
+ const TOOLTIP_MAX_HEIGHT = 650;
41
42
  const TOOLTIP_LABELS_MAX_WIDTH = TOOLTIP_MAX_WIDTH - 150;
42
43
  const TOOLTIP_ADJUST_Y_POS_MULTIPLIER = 0.75;
43
44
  const FALLBACK_CHART_WIDTH = 750;
44
45
  const NEARBY_SERIES_DESCRIPTION = 'nearby series showing in tooltip';
45
46
  const EMPHASIZED_SERIES_DESCRIPTION = 'emphasized series showing as bold in tooltip';
47
+ const TOOLTIP_BG_COLOR_FALLBACK = '#2E313E';
46
48
  const TOOLTIP_DATE_FORMAT = new Intl.DateTimeFormat(undefined, {
47
49
  year: 'numeric',
48
50
  month: 'short',
@@ -23,11 +23,11 @@ function assembleTransform(mousePos, chartWidth, pinnedPos, tooltipHeight, toolt
23
23
  if (mousePos === null) {
24
24
  return 'translate3d(0, 0)';
25
25
  }
26
+ const cursorPaddingX = 32;
27
+ const cursorPaddingY = 16;
26
28
  if (pinnedPos !== null) {
27
29
  mousePos = pinnedPos;
28
30
  }
29
- const cursorPaddingX = 32;
30
- const cursorPaddingY = 16;
31
31
  // Tooltip is located in a Portal attached to the body.
32
32
  // Using page coordinates instead of viewport ensures the tooltip is
33
33
  // absolutely positioned correctly as the user scrolls
package/dist/cjs/index.js CHANGED
@@ -15,6 +15,7 @@ Object.defineProperty(exports, "__esModule", {
15
15
  value: true
16
16
  });
17
17
  _exportStar(require("./ColorPicker"), exports);
18
+ _exportStar(require("./ContentWithLegend"), exports);
18
19
  _exportStar(require("./DateTimeRangePicker"), exports);
19
20
  _exportStar(require("./Dialog"), exports);
20
21
  _exportStar(require("./Drawer"), exports);
@@ -22,10 +22,14 @@ function _export(target, all) {
22
22
  }
23
23
  _export(exports, {
24
24
  legendPositions: ()=>legendPositions,
25
+ legendModes: ()=>legendModes,
25
26
  LEGEND_POSITIONS_CONFIG: ()=>LEGEND_POSITIONS_CONFIG,
27
+ LEGEND_MODE_CONFIG: ()=>LEGEND_MODE_CONFIG,
26
28
  DEFAULT_LEGEND: ()=>DEFAULT_LEGEND,
27
29
  getLegendPosition: ()=>getLegendPosition,
28
30
  isValidLegendPosition: ()=>isValidLegendPosition,
31
+ isValidLegendMode: ()=>isValidLegendMode,
32
+ getLegendMode: ()=>getLegendMode,
29
33
  validateLegendSpec: ()=>validateLegendSpec,
30
34
  isLegendItemVisuallySelected: ()=>isLegendItemVisuallySelected
31
35
  });
@@ -33,6 +37,10 @@ const legendPositions = [
33
37
  'Bottom',
34
38
  'Right'
35
39
  ];
40
+ const legendModes = [
41
+ 'List',
42
+ 'Table'
43
+ ];
36
44
  const LEGEND_POSITIONS_CONFIG = {
37
45
  Bottom: {
38
46
  label: 'Bottom'
@@ -41,8 +49,17 @@ const LEGEND_POSITIONS_CONFIG = {
41
49
  label: 'Right'
42
50
  }
43
51
  };
52
+ const LEGEND_MODE_CONFIG = {
53
+ List: {
54
+ label: 'List'
55
+ },
56
+ Table: {
57
+ label: 'Table'
58
+ }
59
+ };
44
60
  const DEFAULT_LEGEND = {
45
- position: 'Bottom'
61
+ position: 'Bottom',
62
+ mode: 'List'
46
63
  };
47
64
  function getLegendPosition(position) {
48
65
  if (position === undefined) {
@@ -56,6 +73,15 @@ function getLegendPosition(position) {
56
73
  function isValidLegendPosition(position) {
57
74
  return legendPositions.includes(position);
58
75
  }
76
+ function isValidLegendMode(mode) {
77
+ return legendModes.includes(mode);
78
+ }
79
+ function getLegendMode(mode) {
80
+ if (!mode || !isValidLegendMode(mode)) {
81
+ return DEFAULT_LEGEND.mode;
82
+ }
83
+ return mode;
84
+ }
59
85
  function validateLegendSpec(legend) {
60
86
  if (legend === undefined) {
61
87
  // undefined is valid since this is how legend is hidden by default
@@ -64,6 +90,9 @@ function validateLegendSpec(legend) {
64
90
  if (!isValidLegendPosition(legend.position)) {
65
91
  return false;
66
92
  }
93
+ if (legend.mode && !isValidLegendMode(legend.mode)) {
94
+ return false;
95
+ }
67
96
  return true;
68
97
  }
69
98
  function isLegendItemVisuallySelected(item, selectedItems) {
@@ -0,0 +1,27 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ Object.defineProperty(exports, "MuiPaper", {
18
+ enumerable: true,
19
+ get: ()=>MuiPaper
20
+ });
21
+ const MuiPaper = {
22
+ styleOverrides: {
23
+ root: ({ theme })=>({
24
+ backgroundColor: theme.palette.background.default
25
+ })
26
+ }
27
+ };