@parca/profile 0.19.139 → 0.19.142

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 (170) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/GraphTooltipArrow/Content.js +224 -30
  3. package/dist/GraphTooltipArrow/DockedGraphTooltip/index.js +192 -33
  4. package/dist/GraphTooltipArrow/ExpandOnHoverValue.js +53 -3
  5. package/dist/GraphTooltipArrow/index.d.ts.map +1 -1
  6. package/dist/GraphTooltipArrow/index.js +86 -56
  7. package/dist/GraphTooltipArrow/useGraphTooltip/index.js +37 -37
  8. package/dist/GraphTooltipArrow/useGraphTooltipMetaInfo/index.js +103 -73
  9. package/dist/MatchersInput/SuggestionItem.js +91 -12
  10. package/dist/MatchersInput/SuggestionsList.d.ts +2 -1
  11. package/dist/MatchersInput/SuggestionsList.d.ts.map +1 -1
  12. package/dist/MatchersInput/SuggestionsList.js +371 -157
  13. package/dist/MatchersInput/SuggestionsList.test.d.ts +2 -0
  14. package/dist/MatchersInput/SuggestionsList.test.d.ts.map +1 -0
  15. package/dist/MatchersInput/index.js +308 -115
  16. package/dist/MetricsCircle/index.js +39 -3
  17. package/dist/MetricsGraph/MetricsContextMenu/index.js +119 -19
  18. package/dist/MetricsGraph/MetricsInfoPanel/index.js +81 -20
  19. package/dist/MetricsGraph/MetricsTooltip/index.d.ts.map +1 -1
  20. package/dist/MetricsGraph/MetricsTooltip/index.js +107 -74
  21. package/dist/MetricsGraph/index.js +552 -203
  22. package/dist/MetricsGraph/useMetricsGraphDimensions.js +46 -25
  23. package/dist/MetricsGraph/utils/colorMapping.js +24 -17
  24. package/dist/MetricsSeries/index.js +70 -7
  25. package/dist/PreSelectedMatchers/index.d.ts.map +1 -1
  26. package/dist/PreSelectedMatchers/index.js +249 -102
  27. package/dist/ProfileExplorer/ProfileExplorerCompare.js +240 -49
  28. package/dist/ProfileExplorer/ProfileExplorerSingle.js +98 -11
  29. package/dist/ProfileExplorer/index.js +183 -32
  30. package/dist/ProfileFlameChart/SamplesStrips/SamplesGraph/index.js +333 -148
  31. package/dist/ProfileFlameChart/SamplesStrips/SamplesStrips.stories.js +69 -35
  32. package/dist/ProfileFlameChart/SamplesStrips/index.js +645 -134
  33. package/dist/ProfileFlameChart/SamplesStrips/labelSetUtils.js +114 -55
  34. package/dist/ProfileFlameChart/index.js +266 -134
  35. package/dist/ProfileFlameGraph/FlameGraphArrow/ContextMenu.js +287 -88
  36. package/dist/ProfileFlameGraph/FlameGraphArrow/ContextMenuWrapper.js +56 -20
  37. package/dist/ProfileFlameGraph/FlameGraphArrow/FlameGraphNodes.js +211 -140
  38. package/dist/ProfileFlameGraph/FlameGraphArrow/MemoizedTooltip.js +133 -38
  39. package/dist/ProfileFlameGraph/FlameGraphArrow/MiniMap.js +261 -216
  40. package/dist/ProfileFlameGraph/FlameGraphArrow/TextWithEllipsis.d.ts.map +1 -1
  41. package/dist/ProfileFlameGraph/FlameGraphArrow/TextWithEllipsis.js +71 -45
  42. package/dist/ProfileFlameGraph/FlameGraphArrow/TooltipContext.d.ts.map +1 -1
  43. package/dist/ProfileFlameGraph/FlameGraphArrow/TooltipContext.js +58 -28
  44. package/dist/ProfileFlameGraph/FlameGraphArrow/ZoomControls.d.ts.map +1 -1
  45. package/dist/ProfileFlameGraph/FlameGraphArrow/ZoomControls.js +59 -8
  46. package/dist/ProfileFlameGraph/FlameGraphArrow/index.js +396 -179
  47. package/dist/ProfileFlameGraph/FlameGraphArrow/useBatchedRendering.d.ts.map +1 -1
  48. package/dist/ProfileFlameGraph/FlameGraphArrow/useBatchedRendering.js +68 -50
  49. package/dist/ProfileFlameGraph/FlameGraphArrow/useMappingList.js +62 -38
  50. package/dist/ProfileFlameGraph/FlameGraphArrow/useNodeColor.js +14 -6
  51. package/dist/ProfileFlameGraph/FlameGraphArrow/useScrollViewport.js +124 -82
  52. package/dist/ProfileFlameGraph/FlameGraphArrow/useVisibleNodes.js +160 -98
  53. package/dist/ProfileFlameGraph/FlameGraphArrow/useZoom.js +232 -112
  54. package/dist/ProfileFlameGraph/FlameGraphArrow/utils.js +137 -114
  55. package/dist/ProfileFlameGraph/benchmarks/benchdata/populateData.js +85 -0
  56. package/dist/ProfileFlameGraph/index.js +324 -148
  57. package/dist/ProfileMetricsGraph/hooks/useQueryRange.js +140 -32
  58. package/dist/ProfileMetricsGraph/index.js +518 -259
  59. package/dist/ProfileSelector/CompareButton.js +132 -12
  60. package/dist/ProfileSelector/MetricsGraphSection.js +234 -67
  61. package/dist/ProfileSelector/index.d.ts.map +1 -1
  62. package/dist/ProfileSelector/index.js +730 -142
  63. package/dist/ProfileSelector/useAutoQuerySelector.js +249 -130
  64. package/dist/ProfileSource.js +230 -163
  65. package/dist/ProfileTypeSelector/index.js +214 -125
  66. package/dist/ProfileView/components/ActionButtons/GroupByDropdown.js +50 -4
  67. package/dist/ProfileView/components/ActionButtons/SortByDropdown.js +139 -33
  68. package/dist/ProfileView/components/ColorStackLegend.js +184 -55
  69. package/dist/ProfileView/components/DashboardItems/index.js +87 -28
  70. package/dist/ProfileView/components/DashboardLayout/index.js +108 -16
  71. package/dist/ProfileView/components/DiffLegend.js +172 -29
  72. package/dist/ProfileView/components/GroupByLabelsDropdown/index.js +199 -55
  73. package/dist/ProfileView/components/InvertCallStack/index.js +99 -10
  74. package/dist/ProfileView/components/ProfileFilters/filterPresets.js +260 -315
  75. package/dist/ProfileView/components/ProfileFilters/index.js +518 -215
  76. package/dist/ProfileView/components/ProfileFilters/useProfileFilters.js +370 -306
  77. package/dist/ProfileView/components/ProfileFilters/useProfileFiltersUrlState.js +188 -120
  78. package/dist/ProfileView/components/ProfileHeader/index.js +105 -11
  79. package/dist/ProfileView/components/ShareButton/ResultBox.js +119 -16
  80. package/dist/ProfileView/components/ShareButton/index.js +352 -62
  81. package/dist/ProfileView/components/Toolbars/MultiLevelDropdown.d.ts.map +1 -1
  82. package/dist/ProfileView/components/Toolbars/MultiLevelDropdown.js +675 -195
  83. package/dist/ProfileView/components/Toolbars/SwitchMenuItem.js +94 -7
  84. package/dist/ProfileView/components/Toolbars/TableColumnsDropdown.js +198 -157
  85. package/dist/ProfileView/components/Toolbars/index.js +441 -21
  86. package/dist/ProfileView/components/ViewSelector/Dropdown.js +233 -22
  87. package/dist/ProfileView/components/ViewSelector/index.js +211 -91
  88. package/dist/ProfileView/components/VisualizationContainer/index.d.ts.map +1 -1
  89. package/dist/ProfileView/components/VisualizationContainer/index.js +52 -7
  90. package/dist/ProfileView/components/VisualizationPanel.js +185 -8
  91. package/dist/ProfileView/context/DashboardContext.js +84 -28
  92. package/dist/ProfileView/context/ProfileViewContext.js +56 -15
  93. package/dist/ProfileView/hooks/useAutoSelectDimension.js +71 -41
  94. package/dist/ProfileView/hooks/useProfileMetadata.js +50 -18
  95. package/dist/ProfileView/hooks/useResetFlameGraphState.js +31 -10
  96. package/dist/ProfileView/hooks/useResetStateOnProfileTypeChange.js +72 -29
  97. package/dist/ProfileView/hooks/useResetStateOnSeriesChange.js +39 -13
  98. package/dist/ProfileView/hooks/useVisualizationState.js +262 -87
  99. package/dist/ProfileView/index.js +383 -45
  100. package/dist/ProfileView/types/visualization.js +1 -13
  101. package/dist/ProfileView/utils/colorUtils.js +8 -7
  102. package/dist/ProfileViewWithData.js +332 -237
  103. package/dist/QueryControls/index.js +418 -47
  104. package/dist/Sandwich/components/CalleesSection.js +54 -4
  105. package/dist/Sandwich/components/CallersSection.js +97 -27
  106. package/dist/Sandwich/components/TableSection.js +77 -4
  107. package/dist/Sandwich/index.js +125 -12
  108. package/dist/Sandwich/utils/processRowData.js +48 -39
  109. package/dist/SelectWithRefresh/index.js +102 -28
  110. package/dist/SimpleMatchers/Select.js +520 -187
  111. package/dist/SimpleMatchers/index.js +590 -288
  112. package/dist/SourceView/Highlighter.js +230 -70
  113. package/dist/SourceView/LineNo.js +72 -17
  114. package/dist/SourceView/index.js +177 -101
  115. package/dist/SourceView/lang-detector/ext-to-lang.json +798 -798
  116. package/dist/SourceView/lang-detector/index.js +28 -14
  117. package/dist/SourceView/useSelectedLineRange.js +97 -16
  118. package/dist/Table/ColorCell.js +42 -1
  119. package/dist/Table/ColumnsVisibility.js +114 -6
  120. package/dist/Table/MoreDropdown.js +121 -27
  121. package/dist/Table/TableContextMenu.js +150 -139
  122. package/dist/Table/TableContextMenuWrapper.js +59 -14
  123. package/dist/Table/hooks/useColorManagement.js +58 -16
  124. package/dist/Table/hooks/useTableConfiguration.d.ts.map +1 -1
  125. package/dist/Table/hooks/useTableConfiguration.js +331 -168
  126. package/dist/Table/index.js +222 -126
  127. package/dist/Table/utils/functions.js +169 -144
  128. package/dist/Table/utils/topAndBottomExpandedRowModel.js +69 -52
  129. package/dist/TimelineGuide/index.js +209 -16
  130. package/dist/TopTable/benchmarks/benchdata/populateData.js +91 -0
  131. package/dist/TopTable/index.js +340 -122
  132. package/dist/contexts/LabelsQueryProvider.js +94 -32
  133. package/dist/contexts/UnifiedLabelsContext.js +114 -49
  134. package/dist/contexts/utils.js +37 -15
  135. package/dist/hooks/useCompareModeMeta.js +157 -94
  136. package/dist/hooks/useLabels.js +295 -52
  137. package/dist/hooks/useQueryState.js +371 -330
  138. package/dist/index.js +21 -16
  139. package/dist/testdata/fg-diff.json +3750 -0
  140. package/dist/testdata/fg-simple.json +1879 -0
  141. package/dist/testdata/link_data.json +56 -0
  142. package/dist/testdata/tabular.json +30 -0
  143. package/dist/testdata/test_flamegraph.json +26846 -0
  144. package/dist/testdata/test_graph.json +53 -0
  145. package/dist/useDelayedLoader.js +32 -18
  146. package/dist/useGrpcQuery/index.js +71 -11
  147. package/dist/useHasProfileData.js +90 -12
  148. package/dist/useQuery.js +205 -64
  149. package/dist/useSumBy.d.ts.map +1 -1
  150. package/dist/useSumBy.js +294 -138
  151. package/dist/utils.js +62 -30
  152. package/package.json +9 -9
  153. package/src/GraphTooltipArrow/index.tsx +3 -0
  154. package/src/MatchersInput/SuggestionsList.test.tsx +70 -0
  155. package/src/MatchersInput/SuggestionsList.tsx +11 -10
  156. package/src/MatchersInput/index.tsx +1 -1
  157. package/src/MetricsGraph/MetricsTooltip/index.tsx +22 -34
  158. package/src/PreSelectedMatchers/index.tsx +3 -0
  159. package/src/ProfileFlameGraph/FlameGraphArrow/TextWithEllipsis.tsx +3 -0
  160. package/src/ProfileFlameGraph/FlameGraphArrow/TooltipContext.tsx +3 -0
  161. package/src/ProfileFlameGraph/FlameGraphArrow/ZoomControls.tsx +3 -0
  162. package/src/ProfileFlameGraph/FlameGraphArrow/useBatchedRendering.ts +3 -0
  163. package/src/ProfileSelector/index.tsx +30 -7
  164. package/src/ProfileView/components/Toolbars/MultiLevelDropdown.tsx +3 -0
  165. package/src/ProfileView/components/VisualizationContainer/index.tsx +3 -0
  166. package/src/Table/hooks/useTableConfiguration.tsx +7 -13
  167. package/src/useDelayedLoader.ts +10 -10
  168. package/src/useSumBy.ts +12 -18
  169. package/dist/ProfileView/components/ProfileFilters/useProfileFiltersUrlState.test.js +0 -541
  170. package/dist/hooks/useQueryState.test.js +0 -984
@@ -1,4 +1,14 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
2
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
4
+ function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
5
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
6
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
7
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
8
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
9
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
10
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
11
+ import { c as _c } from "react-compiler-runtime";
2
12
  // Copyright 2022 The Parca Authors
3
13
  // Licensed under the Apache License, Version 2.0 (the "License");
4
14
  // you may not use this file except in compliance with the License.
@@ -11,158 +21,333 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
11
21
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
22
  // See the License for the specific language governing permissions and
13
23
  // limitations under the License.
24
+
14
25
  import { useEffect, useMemo, useRef, useState } from 'react';
15
26
  import { Icon } from '@iconify/react';
16
27
  import cx from 'classnames';
17
28
  import * as d3 from 'd3';
18
- const DraggingWindow = ({ dragStart, currentX, }) => {
19
- const start = useMemo(() => Math.min(dragStart ?? 0, currentX ?? 0), [dragStart, currentX]);
20
- const width = useMemo(() => Math.abs((dragStart ?? 0) - (currentX ?? 0)), [dragStart, currentX]);
21
- if (dragStart === undefined || currentX === undefined) {
22
- return null;
23
- }
24
- return (_jsx("div", { style: { height: '100%', width, left: start }, className: cx('bg-gray-500 absolute top-0 opacity-50 border-x-2 border-gray-900 dark:border-gray-100') }));
29
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
30
+ var DraggingWindow = function DraggingWindow(t0) {
31
+ var $ = _c(9);
32
+ var dragStart = t0.dragStart,
33
+ currentX = t0.currentX;
34
+ var start = Math.min(dragStart !== null && dragStart !== void 0 ? dragStart : 0, currentX !== null && currentX !== void 0 ? currentX : 0);
35
+ var t1;
36
+ if ($[0] !== currentX || $[1] !== dragStart) {
37
+ t1 = Math.abs((dragStart !== null && dragStart !== void 0 ? dragStart : 0) - (currentX !== null && currentX !== void 0 ? currentX : 0));
38
+ $[0] = currentX;
39
+ $[1] = dragStart;
40
+ $[2] = t1;
41
+ } else {
42
+ t1 = $[2];
43
+ }
44
+ var width = t1;
45
+ if (dragStart === undefined || currentX === undefined) {
46
+ return null;
47
+ }
48
+ var t2;
49
+ if ($[3] !== start || $[4] !== width) {
50
+ t2 = {
51
+ height: "100%",
52
+ width: width,
53
+ left: start
54
+ };
55
+ $[3] = start;
56
+ $[4] = width;
57
+ $[5] = t2;
58
+ } else {
59
+ t2 = $[5];
60
+ }
61
+ var t3;
62
+ if ($[6] === Symbol["for"]("react.memo_cache_sentinel")) {
63
+ t3 = cx("bg-gray-500 absolute top-0 opacity-50 border-x-2 border-gray-900 dark:border-gray-100");
64
+ $[6] = t3;
65
+ } else {
66
+ t3 = $[6];
67
+ }
68
+ var t4;
69
+ if ($[7] !== t2) {
70
+ t4 = /*#__PURE__*/_jsx("div", {
71
+ style: t2,
72
+ className: t3
73
+ });
74
+ $[7] = t2;
75
+ $[8] = t4;
76
+ } else {
77
+ t4 = $[8];
78
+ }
79
+ return t4;
25
80
  };
26
- const ZoomWindow = ({ zoomWindow, onZoomWindowChange, setIsHoveringDragHandle, }) => {
27
- const windowStartHandleRef = useRef(null);
28
- const windowEndHandleRef = useRef(null);
29
- const [zoomWindowState, setZoomWindowState] = useState(zoomWindow);
30
- const [dragginStart, setDraggingStart] = useState(false);
31
- const [draggingEnd, setDraggingEnd] = useState(false);
32
- useEffect(() => {
33
- if (zoomWindow === undefined ||
34
- zoomWindowState === undefined ||
35
- zoomWindow[0] !== zoomWindowState[0] ||
36
- zoomWindow[1] !== zoomWindowState[1]) {
37
- setZoomWindowState(zoomWindow);
38
- }
39
- // eslint-disable-next-line react-hooks/exhaustive-deps
40
- }, [zoomWindow]);
41
- if (zoomWindowState === undefined) {
42
- return null;
81
+ var ZoomWindow = function ZoomWindow(_ref) {
82
+ var zoomWindow = _ref.zoomWindow,
83
+ onZoomWindowChange = _ref.onZoomWindowChange,
84
+ setIsHoveringDragHandle = _ref.setIsHoveringDragHandle;
85
+ var windowStartHandleRef = useRef(null);
86
+ var windowEndHandleRef = useRef(null);
87
+ var _useState = useState(zoomWindow),
88
+ _useState2 = _slicedToArray(_useState, 2),
89
+ zoomWindowState = _useState2[0],
90
+ setZoomWindowState = _useState2[1];
91
+ var _useState3 = useState(false),
92
+ _useState4 = _slicedToArray(_useState3, 2),
93
+ dragginStart = _useState4[0],
94
+ setDraggingStart = _useState4[1];
95
+ var _useState5 = useState(false),
96
+ _useState6 = _slicedToArray(_useState5, 2),
97
+ draggingEnd = _useState6[0],
98
+ setDraggingEnd = _useState6[1];
99
+ useEffect(function () {
100
+ if (zoomWindow === undefined || zoomWindowState === undefined || zoomWindow[0] !== zoomWindowState[0] || zoomWindow[1] !== zoomWindowState[1]) {
101
+ setZoomWindowState(zoomWindow);
43
102
  }
44
- const beforeWidth = zoomWindowState[0];
45
- const afterStart = zoomWindowState[1];
46
- return (_jsx("div", { className: "absolute w-full h-full", onMouseMove: e => {
47
- if (dragginStart) {
48
- const [x] = d3.pointer(e);
49
- if (x >= afterStart - 10) {
50
- return;
51
- }
52
- const newStart = Math.min(x, afterStart);
53
- const newEnd = Math.max(x, afterStart);
54
- setZoomWindowState([newStart, newEnd]);
55
- }
56
- if (draggingEnd) {
57
- const [x] = d3.pointer(e);
58
- if (x <= beforeWidth + 10) {
59
- return;
60
- }
61
- const newStart = Math.min(x, beforeWidth);
62
- const newEnd = Math.max(x, beforeWidth);
63
- setZoomWindowState([newStart, newEnd]);
64
- }
65
- }, onMouseLeave: () => {
66
- setDraggingStart(false);
67
- setDraggingEnd(false);
68
- }, onMouseUp: () => {
69
- if (dragginStart) {
70
- setDraggingStart(false);
71
- }
72
- if (draggingEnd) {
73
- setDraggingEnd(false);
74
- }
75
- if (zoomWindowState[0] === zoomWindow?.[0] && zoomWindowState[1] === zoomWindow?.[1]) {
76
- return;
77
- }
78
- onZoomWindowChange(zoomWindowState);
79
- setZoomWindowState(undefined);
80
- }, children: _jsxs("div", { style: {
81
- height: '100%',
82
- width: zoomWindowState[1] - zoomWindowState[0],
83
- left: zoomWindowState[0],
84
- }, className: cx('bg-gray-500/50 dark:bg-gray-400/90 absolute top-0 border-x-2 border-gray-900 dark:border-gray-100 z-20'), children: [_jsx("div", { className: "w-3 h-4 absolute top-0 left-[-7px] rounded-b bg-gray-200 dark:bg-gray-600 cursor-ew-resize flex justify-center z-30", onMouseDown: e => {
85
- setDraggingStart(true);
86
- e.stopPropagation();
87
- e.preventDefault();
88
- }, ref: windowStartHandleRef, onMouseEnter: () => {
89
- setIsHoveringDragHandle(true);
90
- }, onMouseLeave: () => {
91
- setIsHoveringDragHandle(false);
92
- }, children: _jsx(Icon, { icon: "si:drag-handle-line", className: "rotate-90", fontSize: 16 }) }), _jsx("div", { className: "w-3 h-4 absolute top-0 rounded-b bg-gray-200 dark:bg-gray-600 cursor-ew-resize flex justify-center right-[-7px]", onMouseDown: e => {
93
- setDraggingEnd(true);
94
- e.stopPropagation();
95
- e.preventDefault();
96
- }, ref: windowEndHandleRef, onMouseEnter: () => {
97
- setIsHoveringDragHandle(true);
98
- }, onMouseLeave: () => {
99
- setIsHoveringDragHandle(false);
100
- }, children: _jsx(Icon, { icon: "si:drag-handle-line", className: "rotate-90", fontSize: 16 }) })] }) }));
101
- };
102
- export const SamplesGraph = ({ data, height, width, marginLeft = 0, marginRight = 0, marginBottom = 0, marginTop = 0, fill = 'gray', selectionBounds, setSelectionBounds, stepMs, onDragStart, dragState, isAnyDragActive = false, timeBounds, }) => {
103
- const [mousePosition, setMousePosition] = useState(undefined);
104
- const [isHoveringDragHandle, setIsHoveringDragHandle] = useState(false);
105
- // use the bounds from props if provided, else compute from data
106
- const xDomain = timeBounds ?? d3.extent(data, d => d.timestamp);
107
- const x = d3.scaleUtc(xDomain, [marginLeft, width - marginRight]);
108
- // Calculate sample count range for opacity scaling
109
- const sampleCounts = data.map(d => Number(d.sampleCount ?? 1));
110
- const maxSampleCount = Math.max(...sampleCounts);
111
- const minSampleCount = Math.min(...sampleCounts);
112
- // Create opacity scale: more samples = higher opacity
113
- const opacityScale = d3
114
- .scaleLinear()
115
- .domain([minSampleCount, maxSampleCount])
116
- .range([0.5, 1.0])
117
- .clamp(true);
118
- const zoomWindow = useMemo(() => {
119
- if (selectionBounds === undefined) {
120
- return undefined;
103
+
104
+ // eslint-disable-next-line react-hooks/exhaustive-deps
105
+ }, [zoomWindow]);
106
+ if (zoomWindowState === undefined) {
107
+ return null;
108
+ }
109
+ var beforeWidth = zoomWindowState[0];
110
+ var afterStart = zoomWindowState[1];
111
+ return /*#__PURE__*/_jsx("div", {
112
+ className: "absolute w-full h-full",
113
+ onMouseMove: function onMouseMove(e) {
114
+ if (dragginStart) {
115
+ var _d3$pointer = d3.pointer(e),
116
+ _d3$pointer2 = _slicedToArray(_d3$pointer, 1),
117
+ x = _d3$pointer2[0];
118
+ if (x >= afterStart - 10) {
119
+ return;
121
120
  }
122
- return [x(selectionBounds[0]), x(selectionBounds[1])];
123
- // eslint-disable-next-line react-hooks/exhaustive-deps
124
- }, [selectionBounds]);
125
- const setSelectionBoundsWithScaling = ([startPx, endPx]) => {
126
- setSelectionBounds([x.invert(startPx).getTime(), x.invert(endPx).getTime()]);
127
- };
128
- return (_jsxs("div", { style: { height, width }, className: "relative", onMouseMove: e => {
129
- // Only track hover position when no drag is active anywhere
130
- if (isAnyDragActive)
131
- return;
132
- const [xPos, yPos] = d3.pointer(e);
133
- if (xPos >= marginLeft &&
134
- xPos <= width - marginRight &&
135
- yPos >= marginTop &&
136
- yPos <= height - marginBottom) {
137
- setMousePosition([xPos, yPos]);
138
- }
139
- else {
140
- setMousePosition(undefined);
141
- }
142
- }, onMouseLeave: () => {
143
- // Only clear hover position, drag is managed by parent
144
- setMousePosition(undefined);
145
- }, onMouseDown: e => {
146
- // only left mouse button
147
- if (e.button !== 0) {
148
- return;
149
- }
150
- // X/Y coordinate array relative to element
151
- const rel = d3.pointer(e);
152
- const xCoordinate = rel[0];
153
- if (xCoordinate >= 0 && onDragStart !== undefined) {
154
- onDragStart(xCoordinate);
155
- }
156
- e.stopPropagation();
157
- e.preventDefault();
158
- }, children: [_jsx("div", { style: { height, width: 2, left: mousePosition?.[0] ?? -1 }, className: cx('bg-gray-700/75 dark:bg-gray-200/75 absolute top-0', {
159
- hidden: mousePosition === undefined || isAnyDragActive || isHoveringDragHandle,
160
- }) }), _jsx(DraggingWindow, { dragStart: dragState?.startX, currentX: dragState?.currentX }), _jsx(ZoomWindow, { zoomWindow: zoomWindow, width: width, onZoomWindowChange: setSelectionBoundsWithScaling, setIsHoveringDragHandle: setIsHoveringDragHandle }), _jsxs("svg", { style: { width: '100%', height: '100%' }, children: [_jsx("rect", { x: marginLeft, y: 0, width: width - marginLeft - marginRight, height: height, fill: fill, fillOpacity: 0.1 }), _jsx("g", { children: data.map((d, i) => {
161
- const xPosition = x(d.timestamp);
162
- // Use stepMs for bucket width
163
- const rectWidth = x(d.timestamp + stepMs) - xPosition;
164
- // Calculate opacity based on sample count
165
- const opacity = opacityScale(Number(d.sampleCount ?? 1));
166
- return (_jsx("rect", { x: xPosition, y: 0, width: rectWidth, height: height, fill: fill, fillOpacity: opacity }, i));
167
- }) })] })] }));
121
+ var newStart = Math.min(x, afterStart);
122
+ var newEnd = Math.max(x, afterStart);
123
+ setZoomWindowState([newStart, newEnd]);
124
+ }
125
+ if (draggingEnd) {
126
+ var _d3$pointer3 = d3.pointer(e),
127
+ _d3$pointer4 = _slicedToArray(_d3$pointer3, 1),
128
+ _x = _d3$pointer4[0];
129
+ if (_x <= beforeWidth + 10) {
130
+ return;
131
+ }
132
+ var _newStart = Math.min(_x, beforeWidth);
133
+ var _newEnd = Math.max(_x, beforeWidth);
134
+ setZoomWindowState([_newStart, _newEnd]);
135
+ }
136
+ },
137
+ onMouseLeave: function onMouseLeave() {
138
+ setDraggingStart(false);
139
+ setDraggingEnd(false);
140
+ },
141
+ onMouseUp: function onMouseUp() {
142
+ if (dragginStart) {
143
+ setDraggingStart(false);
144
+ }
145
+ if (draggingEnd) {
146
+ setDraggingEnd(false);
147
+ }
148
+ if (zoomWindowState[0] === (zoomWindow === null || zoomWindow === void 0 ? void 0 : zoomWindow[0]) && zoomWindowState[1] === (zoomWindow === null || zoomWindow === void 0 ? void 0 : zoomWindow[1])) {
149
+ return;
150
+ }
151
+ onZoomWindowChange(zoomWindowState);
152
+ setZoomWindowState(undefined);
153
+ },
154
+ children: /*#__PURE__*/_jsxs("div", {
155
+ style: {
156
+ height: '100%',
157
+ width: zoomWindowState[1] - zoomWindowState[0],
158
+ left: zoomWindowState[0]
159
+ },
160
+ className: cx('bg-gray-500/50 dark:bg-gray-400/90 absolute top-0 border-x-2 border-gray-900 dark:border-gray-100 z-20'),
161
+ children: [/*#__PURE__*/_jsx("div", {
162
+ className: "w-3 h-4 absolute top-0 left-[-7px] rounded-b bg-gray-200 dark:bg-gray-600 cursor-ew-resize flex justify-center z-30",
163
+ onMouseDown: function onMouseDown(e) {
164
+ setDraggingStart(true);
165
+ e.stopPropagation();
166
+ e.preventDefault();
167
+ },
168
+ ref: windowStartHandleRef,
169
+ onMouseEnter: function onMouseEnter() {
170
+ setIsHoveringDragHandle(true);
171
+ },
172
+ onMouseLeave: function onMouseLeave() {
173
+ setIsHoveringDragHandle(false);
174
+ },
175
+ children: /*#__PURE__*/_jsx(Icon, {
176
+ icon: "si:drag-handle-line",
177
+ className: "rotate-90",
178
+ fontSize: 16
179
+ })
180
+ }), /*#__PURE__*/_jsx("div", {
181
+ className: "w-3 h-4 absolute top-0 rounded-b bg-gray-200 dark:bg-gray-600 cursor-ew-resize flex justify-center right-[-7px]",
182
+ onMouseDown: function onMouseDown(e) {
183
+ setDraggingEnd(true);
184
+ e.stopPropagation();
185
+ e.preventDefault();
186
+ },
187
+ ref: windowEndHandleRef,
188
+ onMouseEnter: function onMouseEnter() {
189
+ setIsHoveringDragHandle(true);
190
+ },
191
+ onMouseLeave: function onMouseLeave() {
192
+ setIsHoveringDragHandle(false);
193
+ },
194
+ children: /*#__PURE__*/_jsx(Icon, {
195
+ icon: "si:drag-handle-line",
196
+ className: "rotate-90",
197
+ fontSize: 16
198
+ })
199
+ })]
200
+ })
201
+ });
168
202
  };
203
+ export var SamplesGraph = function SamplesGraph(_ref2) {
204
+ var _mousePosition$;
205
+ var data = _ref2.data,
206
+ height = _ref2.height,
207
+ width = _ref2.width,
208
+ _ref2$marginLeft = _ref2.marginLeft,
209
+ marginLeft = _ref2$marginLeft === void 0 ? 0 : _ref2$marginLeft,
210
+ _ref2$marginRight = _ref2.marginRight,
211
+ marginRight = _ref2$marginRight === void 0 ? 0 : _ref2$marginRight,
212
+ _ref2$marginBottom = _ref2.marginBottom,
213
+ marginBottom = _ref2$marginBottom === void 0 ? 0 : _ref2$marginBottom,
214
+ _ref2$marginTop = _ref2.marginTop,
215
+ marginTop = _ref2$marginTop === void 0 ? 0 : _ref2$marginTop,
216
+ _ref2$fill = _ref2.fill,
217
+ fill = _ref2$fill === void 0 ? 'gray' : _ref2$fill,
218
+ selectionBounds = _ref2.selectionBounds,
219
+ setSelectionBounds = _ref2.setSelectionBounds,
220
+ stepMs = _ref2.stepMs,
221
+ onDragStart = _ref2.onDragStart,
222
+ dragState = _ref2.dragState,
223
+ _ref2$isAnyDragActive = _ref2.isAnyDragActive,
224
+ isAnyDragActive = _ref2$isAnyDragActive === void 0 ? false : _ref2$isAnyDragActive,
225
+ timeBounds = _ref2.timeBounds;
226
+ var _useState7 = useState(undefined),
227
+ _useState8 = _slicedToArray(_useState7, 2),
228
+ mousePosition = _useState8[0],
229
+ setMousePosition = _useState8[1];
230
+ var _useState9 = useState(false),
231
+ _useState0 = _slicedToArray(_useState9, 2),
232
+ isHoveringDragHandle = _useState0[0],
233
+ setIsHoveringDragHandle = _useState0[1];
234
+
235
+ // use the bounds from props if provided, else compute from data
236
+ var xDomain = timeBounds !== null && timeBounds !== void 0 ? timeBounds : d3.extent(data, function (d) {
237
+ return d.timestamp;
238
+ });
239
+ var x = d3.scaleUtc(xDomain, [marginLeft, width - marginRight]);
240
+
241
+ // Calculate sample count range for opacity scaling
242
+ var sampleCounts = data.map(function (d) {
243
+ var _d$sampleCount;
244
+ return Number((_d$sampleCount = d.sampleCount) !== null && _d$sampleCount !== void 0 ? _d$sampleCount : 1);
245
+ });
246
+ var maxSampleCount = Math.max.apply(Math, _toConsumableArray(sampleCounts));
247
+ var minSampleCount = Math.min.apply(Math, _toConsumableArray(sampleCounts));
248
+
249
+ // Create opacity scale: more samples = higher opacity
250
+ var opacityScale = d3.scaleLinear().domain([minSampleCount, maxSampleCount]).range([0.5, 1.0]).clamp(true);
251
+ var zoomWindow = useMemo(function () {
252
+ if (selectionBounds === undefined) {
253
+ return undefined;
254
+ }
255
+ return [x(selectionBounds[0]), x(selectionBounds[1])];
256
+
257
+ // eslint-disable-next-line react-hooks/exhaustive-deps
258
+ }, [selectionBounds]);
259
+ var setSelectionBoundsWithScaling = function setSelectionBoundsWithScaling(_ref3) {
260
+ var _ref4 = _slicedToArray(_ref3, 2),
261
+ startPx = _ref4[0],
262
+ endPx = _ref4[1];
263
+ setSelectionBounds([x.invert(startPx).getTime(), x.invert(endPx).getTime()]);
264
+ };
265
+ return /*#__PURE__*/_jsxs("div", {
266
+ style: {
267
+ height: height,
268
+ width: width
269
+ },
270
+ className: "relative",
271
+ onMouseMove: function onMouseMove(e) {
272
+ // Only track hover position when no drag is active anywhere
273
+ if (isAnyDragActive) return;
274
+ var _d3$pointer5 = d3.pointer(e),
275
+ _d3$pointer6 = _slicedToArray(_d3$pointer5, 2),
276
+ xPos = _d3$pointer6[0],
277
+ yPos = _d3$pointer6[1];
278
+ if (xPos >= marginLeft && xPos <= width - marginRight && yPos >= marginTop && yPos <= height - marginBottom) {
279
+ setMousePosition([xPos, yPos]);
280
+ } else {
281
+ setMousePosition(undefined);
282
+ }
283
+ },
284
+ onMouseLeave: function onMouseLeave() {
285
+ // Only clear hover position, drag is managed by parent
286
+ setMousePosition(undefined);
287
+ },
288
+ onMouseDown: function onMouseDown(e) {
289
+ // only left mouse button
290
+ if (e.button !== 0) {
291
+ return;
292
+ }
293
+
294
+ // X/Y coordinate array relative to element
295
+ var rel = d3.pointer(e);
296
+ var xCoordinate = rel[0];
297
+ if (xCoordinate >= 0 && onDragStart !== undefined) {
298
+ onDragStart(xCoordinate);
299
+ }
300
+ e.stopPropagation();
301
+ e.preventDefault();
302
+ },
303
+ children: [/*#__PURE__*/_jsx("div", {
304
+ style: {
305
+ height: height,
306
+ width: 2,
307
+ left: (_mousePosition$ = mousePosition === null || mousePosition === void 0 ? void 0 : mousePosition[0]) !== null && _mousePosition$ !== void 0 ? _mousePosition$ : -1
308
+ },
309
+ className: cx('bg-gray-700/75 dark:bg-gray-200/75 absolute top-0', {
310
+ hidden: mousePosition === undefined || isAnyDragActive || isHoveringDragHandle
311
+ })
312
+ }), /*#__PURE__*/_jsx(DraggingWindow, {
313
+ dragStart: dragState === null || dragState === void 0 ? void 0 : dragState.startX,
314
+ currentX: dragState === null || dragState === void 0 ? void 0 : dragState.currentX
315
+ }), /*#__PURE__*/_jsx(ZoomWindow, {
316
+ zoomWindow: zoomWindow,
317
+ width: width,
318
+ onZoomWindowChange: setSelectionBoundsWithScaling,
319
+ setIsHoveringDragHandle: setIsHoveringDragHandle
320
+ }), /*#__PURE__*/_jsxs("svg", {
321
+ style: {
322
+ width: '100%',
323
+ height: '100%'
324
+ },
325
+ children: [/*#__PURE__*/_jsx("rect", {
326
+ x: marginLeft,
327
+ y: 0,
328
+ width: width - marginLeft - marginRight,
329
+ height: height,
330
+ fill: fill,
331
+ fillOpacity: 0.1
332
+ }), /*#__PURE__*/_jsx("g", {
333
+ children: data.map(function (d, i) {
334
+ var _d$sampleCount2;
335
+ var xPosition = x(d.timestamp);
336
+ // Use stepMs for bucket width
337
+ var rectWidth = x(d.timestamp + stepMs) - xPosition;
338
+
339
+ // Calculate opacity based on sample count
340
+ var opacity = opacityScale(Number((_d$sampleCount2 = d.sampleCount) !== null && _d$sampleCount2 !== void 0 ? _d$sampleCount2 : 1));
341
+ return /*#__PURE__*/_jsx("rect", {
342
+ x: xPosition,
343
+ y: 0,
344
+ width: rectWidth,
345
+ height: height,
346
+ fill: fill,
347
+ fillOpacity: opacity
348
+ }, i);
349
+ })
350
+ })]
351
+ })]
352
+ });
353
+ };
@@ -1,4 +1,15 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
5
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
6
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
8
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
9
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
10
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
11
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
12
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
2
13
  // Copyright 2022 The Parca Authors
3
14
  // Licensed under the Apache License, Version 2.0 (the "License");
4
15
  // you may not use this file except in compliance with the License.
@@ -11,47 +22,70 @@ import { jsx as _jsx } from "react/jsx-runtime";
11
22
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
23
  // See the License for the specific language governing permissions and
13
24
  // limitations under the License.
25
+
14
26
  // eslint-disable-next-line import/named
15
27
  import { useArgs } from '@storybook/preview-api';
28
+ // eslint-disable-next-line import/named
29
+
16
30
  import { SamplesStrip } from './index';
31
+ import { jsx as _jsx } from "react/jsx-runtime";
17
32
  function seededRandom(seed) {
18
- return () => {
19
- seed = (seed * 16807) % 2147483647;
20
- return (seed - 1) / 2147483646;
21
- };
33
+ return function () {
34
+ seed = seed * 16807 % 2147483647;
35
+ return (seed - 1) / 2147483646;
36
+ };
22
37
  }
23
- const mockData = [[], [], []];
24
- const random = seededRandom(42);
25
- for (let i = 0; i < 200; i++) {
26
- for (let j = 0; j < mockData.length; j++) {
27
- mockData[j].push({
28
- timestamp: 1731326092000 + i * 100,
29
- value: Math.floor(random() * 100),
30
- });
31
- }
38
+ var mockData = [[], [], []];
39
+ var random = seededRandom(42);
40
+ for (var i = 0; i < 200; i++) {
41
+ for (var j = 0; j < mockData.length; j++) {
42
+ mockData[j].push({
43
+ timestamp: 1731326092000 + i * 100,
44
+ value: Math.floor(random() * 100)
45
+ });
46
+ }
32
47
  }
33
- const meta = {
34
- title: 'components/SamplesStrip',
35
- component: SamplesStrip,
48
+ var meta = {
49
+ title: 'components/SamplesStrip',
50
+ component: SamplesStrip
36
51
  };
37
52
  export default meta;
38
- export const ThreeCPUStrips = {
39
- args: {
40
- cpus: Array.from(mockData, (_, i) => ({ labels: [{ name: 'cpuid', value: i + 1 }] })),
41
- data: mockData,
42
- selectedTimeframe: { index: 1, bounds: [mockData[0][25].timestamp, mockData[0][100].timestamp] },
43
- onSelectedTimeframe: (index, bounds) => {
44
- console.log('onSelectedTimeframe', index, bounds);
45
- },
46
- bounds: [mockData[0][0].timestamp, mockData[0][mockData[0].length - 1].timestamp],
47
- stepMs: 100,
53
+ export var ThreeCPUStrips = {
54
+ args: {
55
+ cpus: Array.from(mockData, function (_, i) {
56
+ return {
57
+ labels: [{
58
+ name: 'cpuid',
59
+ value: i + 1
60
+ }]
61
+ };
62
+ }),
63
+ data: mockData,
64
+ selectedTimeframe: {
65
+ index: 1,
66
+ bounds: [mockData[0][25].timestamp, mockData[0][100].timestamp]
48
67
  },
49
- render: function Component(args) {
50
- const [, setArgs] = useArgs();
51
- const onSelectedTimeframe = (index, bounds) => {
52
- args.onSelectedTimeframe(index, bounds);
53
- setArgs({ ...args, selectedTimeframe: { index, bounds } });
54
- };
55
- return _jsx(SamplesStrip, { ...args, onSelectedTimeframe: onSelectedTimeframe });
68
+ onSelectedTimeframe: function onSelectedTimeframe(index, bounds) {
69
+ console.log('onSelectedTimeframe', index, bounds);
56
70
  },
57
- };
71
+ bounds: [mockData[0][0].timestamp, mockData[0][mockData[0].length - 1].timestamp],
72
+ stepMs: 100
73
+ },
74
+ render: function Component(args) {
75
+ var _useArgs = useArgs(),
76
+ _useArgs2 = _slicedToArray(_useArgs, 2),
77
+ setArgs = _useArgs2[1];
78
+ var onSelectedTimeframe = function onSelectedTimeframe(index, bounds) {
79
+ args.onSelectedTimeframe(index, bounds);
80
+ setArgs(_objectSpread(_objectSpread({}, args), {}, {
81
+ selectedTimeframe: {
82
+ index: index,
83
+ bounds: bounds
84
+ }
85
+ }));
86
+ };
87
+ return /*#__PURE__*/_jsx(SamplesStrip, _objectSpread(_objectSpread({}, args), {}, {
88
+ onSelectedTimeframe: onSelectedTimeframe
89
+ }));
90
+ }
91
+ };