@grafana/flamegraph 11.5.0-218248 → 11.5.0-218279

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/dist/index.js CHANGED
@@ -976,7 +976,7 @@ const FlameGraphMetadata = react.memo(
976
976
  );
977
977
  if (sandwichedLabel) {
978
978
  parts.push(
979
- /* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
979
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { content: sandwichedLabel, placement: "top", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
980
980
  /* @__PURE__ */ jsxRuntime.jsx(ui.Icon, { size: "sm", name: "angle-right" }),
981
981
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: styles.metadataPill, children: [
982
982
  /* @__PURE__ */ jsxRuntime.jsx(ui.Icon, { size: "sm", name: "gf-show-context" }),
@@ -994,17 +994,18 @@ const FlameGraphMetadata = react.memo(
994
994
  }
995
995
  )
996
996
  ] })
997
- ] }, "sandwich")
997
+ ] }) }, "sandwich")
998
998
  );
999
999
  }
1000
1000
  if (focusedItem) {
1001
- const percentValue = Math.round(1e4 * (focusedItem.item.value / totalTicks)) / 100;
1001
+ const percentValue = totalTicks > 0 ? Math.round(1e4 * (focusedItem.item.value / totalTicks)) / 100 : 0;
1002
+ const iconName = percentValue > 0 ? "eye" : "exclamation-circle";
1002
1003
  parts.push(
1003
- /* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
1004
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { content: focusedItem.label, placement: "top", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
1004
1005
  /* @__PURE__ */ jsxRuntime.jsx(ui.Icon, { size: "sm", name: "angle-right" }),
1005
1006
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: styles.metadataPill, children: [
1006
- /* @__PURE__ */ jsxRuntime.jsx(ui.Icon, { size: "sm", name: "eye" }),
1007
- " ",
1007
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Icon, { size: "sm", name: iconName }),
1008
+ "\xA0",
1008
1009
  percentValue,
1009
1010
  "% of total",
1010
1011
  /* @__PURE__ */ jsxRuntime.jsx(
@@ -1019,7 +1020,7 @@ const FlameGraphMetadata = react.memo(
1019
1020
  }
1020
1021
  )
1021
1022
  ] })
1022
- ] }, "focus")
1023
+ ] }) }, "focus")
1023
1024
  );
1024
1025
  }
1025
1026
  return /* @__PURE__ */ jsxRuntime.jsx("div", { className: styles.metadata, children: parts });
@@ -1045,8 +1046,10 @@ const getStyles$4 = (theme) => ({
1045
1046
  margin: theme.spacing(0, 0.5)
1046
1047
  }),
1047
1048
  metadata: css.css({
1048
- margin: "8px 0",
1049
- textAlign: "center"
1049
+ display: "flex",
1050
+ alignItems: "center",
1051
+ justifyContent: "center",
1052
+ margin: "8px 0"
1050
1053
  }),
1051
1054
  metadataPillName: css.css({
1052
1055
  label: "metadataPillName",
@@ -1134,40 +1137,45 @@ const FlameGraph = ({
1134
1137
  search,
1135
1138
  selectedView
1136
1139
  };
1137
- const canvas = levelsCallers ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1138
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: styles.sandwichCanvasWrapper, children: [
1139
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: styles.sandwichMarker, children: [
1140
- "Callers",
1141
- /* @__PURE__ */ jsxRuntime.jsx(ui.Icon, { className: styles.sandwichMarkerIcon, name: "arrow-down" })
1142
- ] }),
1143
- /* @__PURE__ */ jsxRuntime.jsx(
1144
- FlameGraphCanvas,
1145
- {
1146
- ...commonCanvasProps,
1147
- root: levelsCallers[levelsCallers.length - 1][0],
1148
- depth: levelsCallers.length,
1149
- direction: "parents",
1150
- collapsing: false
1151
- }
1152
- )
1153
- ] }),
1154
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: styles.sandwichCanvasWrapper, children: [
1155
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: css.cx(styles.sandwichMarker, styles.sandwichMarkerCalees), children: [
1156
- /* @__PURE__ */ jsxRuntime.jsx(ui.Icon, { className: styles.sandwichMarkerIcon, name: "arrow-up" }),
1157
- "Callees"
1140
+ let canvas = null;
1141
+ if (levelsCallers == null ? void 0 : levelsCallers.length) {
1142
+ canvas = /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1143
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: styles.sandwichCanvasWrapper, children: [
1144
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: styles.sandwichMarker, children: [
1145
+ "Callers",
1146
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Icon, { className: styles.sandwichMarkerIcon, name: "arrow-down" })
1147
+ ] }),
1148
+ /* @__PURE__ */ jsxRuntime.jsx(
1149
+ FlameGraphCanvas,
1150
+ {
1151
+ ...commonCanvasProps,
1152
+ root: levelsCallers[levelsCallers.length - 1][0],
1153
+ depth: levelsCallers.length,
1154
+ direction: "parents",
1155
+ collapsing: false
1156
+ }
1157
+ )
1158
1158
  ] }),
1159
- /* @__PURE__ */ jsxRuntime.jsx(
1160
- FlameGraphCanvas,
1161
- {
1162
- ...commonCanvasProps,
1163
- root: levels[0][0],
1164
- depth: levels.length,
1165
- direction: "children",
1166
- collapsing: false
1167
- }
1168
- )
1169
- ] })
1170
- ] }) : /* @__PURE__ */ jsxRuntime.jsx(FlameGraphCanvas, { ...commonCanvasProps, root: levels[0][0], depth: levels.length, direction: "children" });
1159
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: styles.sandwichCanvasWrapper, children: [
1160
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: css.cx(styles.sandwichMarker, styles.sandwichMarkerCalees), children: [
1161
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Icon, { className: styles.sandwichMarkerIcon, name: "arrow-up" }),
1162
+ "Callees"
1163
+ ] }),
1164
+ /* @__PURE__ */ jsxRuntime.jsx(
1165
+ FlameGraphCanvas,
1166
+ {
1167
+ ...commonCanvasProps,
1168
+ root: levels[0][0],
1169
+ depth: levels.length,
1170
+ direction: "children",
1171
+ collapsing: false
1172
+ }
1173
+ )
1174
+ ] })
1175
+ ] });
1176
+ } else if (levels == null ? void 0 : levels.length) {
1177
+ canvas = /* @__PURE__ */ jsxRuntime.jsx(FlameGraphCanvas, { ...commonCanvasProps, root: levels[0][0], depth: levels.length, direction: "children" });
1178
+ }
1171
1179
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: styles.graph, children: [
1172
1180
  /* @__PURE__ */ jsxRuntime.jsx(
1173
1181
  FlameGraphMetadata,
@@ -2110,6 +2118,7 @@ const FlameGraphContainer = ({
2110
2118
  vertical,
2111
2119
  showFlameGraphOnly,
2112
2120
  disableCollapsing,
2121
+ keepFocusOnDataChange,
2113
2122
  getExtraContextMenuButtons
2114
2123
  }) => {
2115
2124
  const [focusedItemData, setFocusedItemData] = react.useState();
@@ -2143,13 +2152,40 @@ const FlameGraphContainer = ({
2143
2152
  setRangeMin(0);
2144
2153
  setRangeMax(1);
2145
2154
  }, [setFocusedItemData, setRangeMax, setRangeMin]);
2146
- function resetSandwich() {
2155
+ const resetSandwich = react.useCallback(() => {
2147
2156
  setSandwichItem(void 0);
2148
- }
2157
+ }, [setSandwichItem]);
2149
2158
  react.useEffect(() => {
2150
- resetFocus();
2151
- resetSandwich();
2152
- }, [data, resetFocus]);
2159
+ var _a;
2160
+ if (!keepFocusOnDataChange) {
2161
+ resetFocus();
2162
+ resetSandwich();
2163
+ return;
2164
+ }
2165
+ if (dataContainer && focusedItemData) {
2166
+ const item = (_a = dataContainer.getNodesWithLabel(focusedItemData.label)) == null ? void 0 : _a[0];
2167
+ if (item) {
2168
+ setFocusedItemData({ ...focusedItemData, item });
2169
+ const levels = dataContainer.getLevels();
2170
+ const totalViewTicks = levels.length ? levels[0][0].value : 0;
2171
+ setRangeMin(item.start / totalViewTicks);
2172
+ setRangeMax((item.start + item.value) / totalViewTicks);
2173
+ } else {
2174
+ setFocusedItemData({
2175
+ ...focusedItemData,
2176
+ item: {
2177
+ start: 0,
2178
+ value: 0,
2179
+ itemIndexes: [],
2180
+ children: [],
2181
+ level: 0
2182
+ }
2183
+ });
2184
+ setRangeMin(0);
2185
+ setRangeMax(1);
2186
+ }
2187
+ }
2188
+ }, [dataContainer, keepFocusOnDataChange]);
2153
2189
  const onSymbolClick = react.useCallback(
2154
2190
  (symbol) => {
2155
2191
  if (search === symbol) {