@parca/profile 0.16.455 → 0.16.456

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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,10 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [0.16.456](https://github.com/parca-dev/parca/compare/@parca/profile@0.16.455...@parca/profile@0.16.456) (2024-12-16)
7
+
8
+ **Note:** Version bump only for package @parca/profile
9
+
6
10
  ## [0.16.455](https://github.com/parca-dev/parca/compare/@parca/profile@0.16.454...@parca/profile@0.16.455) (2024-12-11)
7
11
 
8
12
  **Note:** Version bump only for package @parca/profile
@@ -1 +1 @@
1
- {"version":3,"file":"IcicleGraphNodes.d.ts","sourceRoot":"","sources":["../../../src/ProfileIcicleGraph/IcicleGraphArrow/IcicleGraphNodes.tsx"],"names":[],"mappings":"AAaA,OAAO,KAA2B,MAAM,OAAO,CAAC;AAEhD,OAAO,EAAC,KAAK,EAAC,MAAM,cAAc,CAAC;AAMnC,OAAO,yCAAyC,CAAC;AAEjD,OAAO,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAa1C,eAAO,MAAM,SAAS,KAAK,CAAC;AAE5B,UAAU,qBAAqB;IAC7B,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,aAAa,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,IAAI,CA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,EAAE,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,aAAa,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;IACrC,cAAc,EAAE,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;IAC7C,gBAAgB,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;IACjD,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;IAClC,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,OAAO,CAAC;IAClB,WAAW,EAAE,OAAO,CAAC;IACrB,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,iBAAiB,EAAE,OAAO,CAAC;IAC3B,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,eAAe,EAAE,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;IAC/C,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,gCAAgC,EAAE,OAAO,CAAC;CAC3C;AAYD,eAAO,MAAM,UAAU,6CAoQrB,CAAC"}
@@ -16,6 +16,7 @@ import cx from 'classnames';
16
16
  import { selectBinaries, useAppSelector } from '@parca/store';
17
17
  import { isSearchMatch, scaleLinear } from '@parca/utilities';
18
18
  import 'react-contexify/dist/ReactContexify.css';
19
+ import TextWithEllipsis from './TextWithEllipsis';
19
20
  import { FIELD_CHILDREN, FIELD_CUMULATIVE, FIELD_DIFF, FIELD_FUNCTION_FILE_NAME, FIELD_FUNCTION_NAME, FIELD_MAPPING_FILE, } from './index';
20
21
  import useNodeColor from './useNodeColor';
21
22
  import { arrowToString, nodeLabel } from './utils';
@@ -196,5 +197,5 @@ export const IcicleNode = React.memo(function IcicleNodeNoMemo({ table, row, col
196
197
  ? `${colorForSimilarNodes} stroke-[3] [stroke-dasharray:6,4] [stroke-linecap:round] [stroke-linejoin:round] h-6`
197
198
  : 'stroke-white dark:stroke-gray-700', {
198
199
  'opacity-50': isHighlightEnabled && !isHighlighted,
199
- }) }), width > 5 && (_jsx("svg", { width: width - 5, height: height, children: _jsx("text", { x: 5, y: 15, style: { fontSize: '12px' }, children: name }) }))] }), childRows.length > 0 && (_jsx(IcicleGraphNodes, { table: table, row: row, colors: colors, colorBy: colorBy, childRows: childRows, x: x, y: RowHeight, xScale: newXScale, total: total, totalWidth: totalWidth, level: nextLevel, path: nextPath, curPath: nextCurPath, setCurPath: setCurPath, setHoveringRow: setHoveringRow, setHoveringLevel: setHoveringLevel, searchString: searchString, sortBy: sortBy, darkMode: darkMode, profileType: profileType, compareMode: compareMode, isContextMenuOpen: isContextMenuOpen, hoveringName: hoveringName, setHoveringName: setHoveringName, hoveringRow: hoveringRow, colorForSimilarNodes: colorForSimilarNodes, highlightSimilarStacksPreference: highlightSimilarStacksPreference }))] }));
200
+ }) }), width > 5 && (_jsx("svg", { width: width - 5, height: height, children: _jsx(TextWithEllipsis, { text: name, x: 5, y: 15, width: width - 10 }) }))] }), childRows.length > 0 && (_jsx(IcicleGraphNodes, { table: table, row: row, colors: colors, colorBy: colorBy, childRows: childRows, x: x, y: RowHeight, xScale: newXScale, total: total, totalWidth: totalWidth, level: nextLevel, path: nextPath, curPath: nextCurPath, setCurPath: setCurPath, setHoveringRow: setHoveringRow, setHoveringLevel: setHoveringLevel, searchString: searchString, sortBy: sortBy, darkMode: darkMode, profileType: profileType, compareMode: compareMode, isContextMenuOpen: isContextMenuOpen, hoveringName: hoveringName, setHoveringName: setHoveringName, hoveringRow: hoveringRow, colorForSimilarNodes: colorForSimilarNodes, highlightSimilarStacksPreference: highlightSimilarStacksPreference }))] }));
200
201
  });
@@ -0,0 +1,9 @@
1
+ interface Props {
2
+ text: string;
3
+ x: number;
4
+ y: number;
5
+ width: number;
6
+ }
7
+ declare function TextWithEllipsis({ text, x, y, width }: Props): JSX.Element;
8
+ export default TextWithEllipsis;
9
+ //# sourceMappingURL=TextWithEllipsis.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TextWithEllipsis.d.ts","sourceRoot":"","sources":["../../../src/ProfileIcicleGraph/IcicleGraphArrow/TextWithEllipsis.tsx"],"names":[],"mappings":"AAiBA,UAAU,KAAK;IACb,IAAI,EAAE,MAAM,CAAC;IACb,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;CACf;AA2CD,iBAAS,gBAAgB,CAAC,EAAC,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAC,EAAE,KAAK,GAAG,GAAG,CAAC,OAAO,CAuBjE;AAED,eAAe,gBAAgB,CAAC"}
@@ -0,0 +1,62 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ // Copyright 2022 The Parca Authors
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ import { useEffect, useRef, useState } from 'react';
15
+ import { USER_PREFERENCES, useUserPreference } from '@parca/hooks';
16
+ function calculateTruncatedText(text, textElement, maxWidth) {
17
+ // Create a temporary element for measurement
18
+ const tempElement = textElement.cloneNode();
19
+ tempElement.textContent = text;
20
+ textElement.parentElement?.appendChild(tempElement);
21
+ // If the text fits, return it
22
+ const fullWidth = tempElement.getComputedTextLength();
23
+ if (fullWidth <= maxWidth) {
24
+ textElement.parentElement?.removeChild(tempElement);
25
+ return text;
26
+ }
27
+ // Binary search to find the maximum text that fits
28
+ let start = 0;
29
+ let end = text.length;
30
+ let result = text;
31
+ while (start < end) {
32
+ const mid = Math.floor((start + end + 1) / 2);
33
+ const truncated = text.slice(-mid);
34
+ tempElement.textContent = truncated;
35
+ const currentWidth = tempElement.getComputedTextLength();
36
+ if (currentWidth <= maxWidth) {
37
+ result = truncated;
38
+ start = mid;
39
+ }
40
+ else {
41
+ end = mid - 1;
42
+ }
43
+ }
44
+ textElement.parentElement?.removeChild(tempElement);
45
+ return result;
46
+ }
47
+ function TextWithEllipsis({ text, x, y, width }) {
48
+ const textRef = useRef(null);
49
+ const [displayText, setDisplayText] = useState(text);
50
+ const [showFunctionNameFromLeft] = useUserPreference(USER_PREFERENCES.SHOW_FUNCTION_NAME_FROM_LEFT.key);
51
+ useEffect(() => {
52
+ const textElement = textRef.current;
53
+ if (textElement === null)
54
+ return;
55
+ const newText = showFunctionNameFromLeft
56
+ ? text
57
+ : calculateTruncatedText(text, textElement, width);
58
+ setDisplayText(newText);
59
+ }, [text, width, showFunctionNameFromLeft]);
60
+ return (_jsx("text", { ref: textRef, x: x, y: y, className: "text-xs", children: displayText }));
61
+ }
62
+ export default TextWithEllipsis;
@@ -20,5 +20,5 @@ export const VisualisationToolbar = ({ groupBy, toggleGroupBy, groupByLabels, se
20
20
  const { dashboardItems } = useDashboard();
21
21
  const isTableViz = dashboardItems?.includes('table');
22
22
  const isGraphViz = dashboardItems?.includes('icicle');
23
- return (_jsxs(_Fragment, { children: [_jsxs("div", { className: "flex w-full justify-between items-end", children: [_jsxs("div", { className: "flex gap-3 items-end", children: [_jsxs(_Fragment, { children: [_jsx(GroupByDropdown, { groupBy: groupBy, toggleGroupBy: toggleGroupBy, labels: groupByLabels, setGroupByLabels: setGroupByLabels }), _jsx(MultiLevelDropdown, { profileType: profileType, onSelect: () => { } })] }), _jsx(FilterByFunctionButton, {}), profileViewExternalSubActions != null ? profileViewExternalSubActions : null] }), _jsxs("div", { className: "flex gap-3", children: [preferencesModal != null ? _jsx(UserPreferencesModal, {}) : null, _jsx(ShareButton, { profileSource: profileSource, queryClient: queryClient, queryRequest: profileSource?.QueryRequest() ?? undefined, onDownloadPProf: onDownloadPProf, pprofdownloading: pprofdownloading ?? false, profileViewExternalSubActions: profileViewExternalSubActions }), showVisualizationSelector ? _jsx(ViewSelector, {}) : null] })] }), isGraphViz && !isTableViz && (_jsxs(_Fragment, { children: [_jsx(Divider, {}), _jsx(IcicleGraphToolbar, { curPath: curPath, setNewCurPath: setNewCurPath })] })), isTableViz && !isGraphViz && (_jsxs(_Fragment, { children: [_jsx(Divider, {}), _jsx(TableToolbar, { profileType: profileType, total: total, filtered: filtered, clearSelection: clearSelection, currentSearchString: currentSearchString })] }))] }));
23
+ return (_jsxs(_Fragment, { children: [_jsxs("div", { className: "flex w-full justify-between items-end", children: [_jsxs("div", { className: "flex gap-3 items-end", children: [_jsxs(_Fragment, { children: [_jsx(GroupByDropdown, { groupBy: groupBy, toggleGroupBy: toggleGroupBy, labels: groupByLabels, setGroupByLabels: setGroupByLabels }), _jsx(MultiLevelDropdown, { profileType: profileType, onSelect: () => { } })] }), _jsx(FilterByFunctionButton, {}), profileViewExternalSubActions != null ? profileViewExternalSubActions : null] }), _jsxs("div", { className: "flex gap-3", children: [preferencesModal === true && _jsx(UserPreferencesModal, {}), _jsx(ShareButton, { profileSource: profileSource, queryClient: queryClient, queryRequest: profileSource?.QueryRequest() ?? undefined, onDownloadPProf: onDownloadPProf, pprofdownloading: pprofdownloading ?? false, profileViewExternalSubActions: profileViewExternalSubActions }), showVisualizationSelector ? _jsx(ViewSelector, {}) : null] })] }), isGraphViz && !isTableViz && (_jsxs(_Fragment, { children: [_jsx(Divider, {}), _jsx(IcicleGraphToolbar, { curPath: curPath, setNewCurPath: setNewCurPath })] })), isTableViz && !isGraphViz && (_jsxs(_Fragment, { children: [_jsx(Divider, {}), _jsx(TableToolbar, { profileType: profileType, total: total, filtered: filtered, clearSelection: clearSelection, currentSearchString: currentSearchString })] }))] }));
24
24
  };
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@parca/profile",
3
- "version": "0.16.455",
3
+ "version": "0.16.456",
4
4
  "description": "Profile viewing libraries",
5
5
  "dependencies": {
6
6
  "@headlessui/react": "^1.7.19",
7
7
  "@iconify/react": "^4.0.0",
8
8
  "@parca/client": "0.16.125",
9
- "@parca/components": "0.16.312",
9
+ "@parca/components": "0.16.313",
10
10
  "@parca/dynamicsize": "0.16.65",
11
- "@parca/hooks": "0.0.75",
11
+ "@parca/hooks": "0.0.76",
12
12
  "@parca/icons": "0.16.71",
13
13
  "@parca/parser": "0.16.78",
14
14
  "@parca/store": "0.16.162",
@@ -74,5 +74,5 @@
74
74
  "access": "public",
75
75
  "registry": "https://registry.npmjs.org/"
76
76
  },
77
- "gitHead": "54e578f0c45ee0ae69e79306b03315c76a1227ed"
77
+ "gitHead": "0e071ed2fe26da987341ab6f8fcee0e272e9aa64"
78
78
  }
@@ -23,6 +23,7 @@ import 'react-contexify/dist/ReactContexify.css';
23
23
 
24
24
  import {ProfileType} from '@parca/parser';
25
25
 
26
+ import TextWithEllipsis from './TextWithEllipsis';
26
27
  import {
27
28
  FIELD_CHILDREN,
28
29
  FIELD_CUMULATIVE,
@@ -412,9 +413,12 @@ export const IcicleNode = React.memo(function IcicleNodeNoMemo({
412
413
  />
413
414
  {width > 5 && (
414
415
  <svg width={width - 5} height={height}>
415
- <text x={5} y={15} style={{fontSize: '12px'}}>
416
- {name}
417
- </text>
416
+ <TextWithEllipsis
417
+ text={name}
418
+ x={5}
419
+ y={15}
420
+ width={width - 10} // Subtract padding from available width
421
+ />
418
422
  </svg>
419
423
  )}
420
424
  </g>
@@ -0,0 +1,91 @@
1
+ // Copyright 2022 The Parca 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
+
14
+ import {useEffect, useRef, useState} from 'react';
15
+
16
+ import {USER_PREFERENCES, useUserPreference} from '@parca/hooks';
17
+
18
+ interface Props {
19
+ text: string;
20
+ x: number;
21
+ y: number;
22
+ width: number;
23
+ }
24
+
25
+ function calculateTruncatedText(
26
+ text: string,
27
+ textElement: SVGTextElement,
28
+ maxWidth: number
29
+ ): string {
30
+ // Create a temporary element for measurement
31
+ const tempElement = textElement.cloneNode() as SVGTextElement;
32
+ tempElement.textContent = text;
33
+ textElement.parentElement?.appendChild(tempElement);
34
+
35
+ // If the text fits, return it
36
+ const fullWidth = tempElement.getComputedTextLength();
37
+ if (fullWidth <= maxWidth) {
38
+ textElement.parentElement?.removeChild(tempElement);
39
+ return text;
40
+ }
41
+
42
+ // Binary search to find the maximum text that fits
43
+ let start = 0;
44
+ let end = text.length;
45
+ let result = text;
46
+
47
+ while (start < end) {
48
+ const mid = Math.floor((start + end + 1) / 2);
49
+ const truncated = text.slice(-mid);
50
+
51
+ tempElement.textContent = truncated;
52
+ const currentWidth = tempElement.getComputedTextLength();
53
+
54
+ if (currentWidth <= maxWidth) {
55
+ result = truncated;
56
+ start = mid;
57
+ } else {
58
+ end = mid - 1;
59
+ }
60
+ }
61
+
62
+ textElement.parentElement?.removeChild(tempElement);
63
+ return result;
64
+ }
65
+
66
+ function TextWithEllipsis({text, x, y, width}: Props): JSX.Element {
67
+ const textRef = useRef<SVGTextElement>(null);
68
+ const [displayText, setDisplayText] = useState(text);
69
+ const [showFunctionNameFromLeft] = useUserPreference<boolean>(
70
+ USER_PREFERENCES.SHOW_FUNCTION_NAME_FROM_LEFT.key
71
+ );
72
+
73
+ useEffect(() => {
74
+ const textElement = textRef.current;
75
+ if (textElement === null) return;
76
+
77
+ const newText = showFunctionNameFromLeft
78
+ ? text
79
+ : calculateTruncatedText(text, textElement, width);
80
+
81
+ setDisplayText(newText);
82
+ }, [text, width, showFunctionNameFromLeft]);
83
+
84
+ return (
85
+ <text ref={textRef} x={x} y={y} className="text-xs">
86
+ {displayText}
87
+ </text>
88
+ );
89
+ }
90
+
91
+ export default TextWithEllipsis;
@@ -157,7 +157,7 @@ export const VisualisationToolbar: FC<VisualisationToolbarProps> = ({
157
157
  {profileViewExternalSubActions != null ? profileViewExternalSubActions : null}
158
158
  </div>
159
159
  <div className="flex gap-3">
160
- {preferencesModal != null ? <UserPreferencesModal /> : null}
160
+ {preferencesModal === true && <UserPreferencesModal />}
161
161
  <ShareButton
162
162
  profileSource={profileSource}
163
163
  queryClient={queryClient}