diff --git a/packages/grafana-flamegraph/src/FlameGraph/FlameGraph.test.tsx b/packages/grafana-flamegraph/src/FlameGraph/FlameGraph.test.tsx
index 70694baf986..fc152e96b00 100644
--- a/packages/grafana-flamegraph/src/FlameGraph/FlameGraph.test.tsx
+++ b/packages/grafana-flamegraph/src/FlameGraph/FlameGraph.test.tsx
@@ -1,7 +1,7 @@
import { fireEvent, render, screen } from '@testing-library/react';
import React from 'react';
-import { createDataFrame, createTheme } from '@grafana/data';
+import { createDataFrame } from '@grafana/data';
import { ColorScheme } from '../types';
@@ -48,7 +48,6 @@ describe('FlameGraph', () => {
onFocusPillClick={onFocusPillClick}
onSandwichPillClick={onSandwichPillClick}
colorScheme={ColorScheme.ValueBased}
- getTheme={() => createTheme({ colors: { mode: 'dark' } })}
/>
);
return {
diff --git a/packages/grafana-flamegraph/src/FlameGraph/FlameGraph.tsx b/packages/grafana-flamegraph/src/FlameGraph/FlameGraph.tsx
index 0af2073284b..485d8b5e19a 100644
--- a/packages/grafana-flamegraph/src/FlameGraph/FlameGraph.tsx
+++ b/packages/grafana-flamegraph/src/FlameGraph/FlameGraph.tsx
@@ -20,7 +20,6 @@ import { css } from '@emotion/css';
import React, { MouseEvent as ReactMouseEvent, useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { useMeasure } from 'react-use';
-import { GrafanaTheme2 } from '@grafana/data';
import { Icon } from '@grafana/ui';
import { PIXELS_PER_LEVEL } from '../constants';
@@ -48,7 +47,6 @@ type Props = {
onFocusPillClick: () => void;
onSandwichPillClick: () => void;
colorScheme: ColorScheme | ColorSchemeDiff;
- getTheme: () => GrafanaTheme2;
};
const FlameGraph = ({
@@ -66,7 +64,6 @@ const FlameGraph = ({
onFocusPillClick,
onSandwichPillClick,
colorScheme,
- getTheme,
}: Props) => {
const styles = getStyles();
@@ -108,7 +105,6 @@ const FlameGraph = ({
totalColorTicks: data.isDiffFlamegraph() ? totalProfileTicks : totalViewTicks,
totalTicksRight: totalProfileTicksRight,
wrapperWidth,
- getTheme,
});
const onGraphClick = useCallback(
@@ -186,7 +182,6 @@ const FlameGraph = ({
return (
-
+
{clickedItemData && (
> =
totalTicks={17}
onFocusPillClick={onFocusPillClick}
onSandwichPillClick={onSandwichPillClick}
- getTheme={() => createTheme({ colors: { mode: 'dark' } })}
{...props}
/>
);
diff --git a/packages/grafana-flamegraph/src/FlameGraph/FlameGraphMetadata.tsx b/packages/grafana-flamegraph/src/FlameGraph/FlameGraphMetadata.tsx
index 78073c5c90d..9a896f33a0d 100644
--- a/packages/grafana-flamegraph/src/FlameGraph/FlameGraphMetadata.tsx
+++ b/packages/grafana-flamegraph/src/FlameGraph/FlameGraphMetadata.tsx
@@ -2,7 +2,7 @@ import { css } from '@emotion/css';
import React, { ReactNode } from 'react';
import { getValueFormat, GrafanaTheme2 } from '@grafana/data';
-import { Icon, IconButton } from '@grafana/ui';
+import { Icon, IconButton, useStyles2 } from '@grafana/ui';
import { ClickedItemData } from '../types';
@@ -15,12 +15,11 @@ type Props = {
onSandwichPillClick: () => void;
focusedItem?: ClickedItemData;
sandwichedLabel?: string;
- getTheme: () => GrafanaTheme2;
};
const FlameGraphMetadata = React.memo(
- ({ data, focusedItem, totalTicks, sandwichedLabel, onFocusPillClick, onSandwichPillClick, getTheme }: Props) => {
- const styles = getStyles(getTheme());
+ ({ data, focusedItem, totalTicks, sandwichedLabel, onFocusPillClick, onSandwichPillClick }: Props) => {
+ const styles = useStyles2(getStyles);
const parts: ReactNode[] = [];
const ticksVal = getValueFormat('short')(totalTicks);
diff --git a/packages/grafana-flamegraph/src/FlameGraph/FlameGraphTooltip.tsx b/packages/grafana-flamegraph/src/FlameGraph/FlameGraphTooltip.tsx
index 1949d2ba08c..fe9d7dd1316 100644
--- a/packages/grafana-flamegraph/src/FlameGraph/FlameGraphTooltip.tsx
+++ b/packages/grafana-flamegraph/src/FlameGraph/FlameGraphTooltip.tsx
@@ -2,7 +2,7 @@ import { css } from '@emotion/css';
import React from 'react';
import { DisplayValue, getValueFormat, GrafanaTheme2 } from '@grafana/data';
-import { InteractiveTable, Portal, VizTooltipContainer } from '@grafana/ui';
+import { InteractiveTable, Portal, useStyles2, VizTooltipContainer } from '@grafana/ui';
import { FlameGraphDataContainer, LevelItem } from './dataTransform';
@@ -11,11 +11,10 @@ type Props = {
totalTicks: number;
position?: { x: number; y: number };
item?: LevelItem;
- getTheme: () => GrafanaTheme2;
};
-const FlameGraphTooltip = ({ data, item, totalTicks, position, getTheme }: Props) => {
- const styles = getStyles(getTheme());
+const FlameGraphTooltip = ({ data, item, totalTicks, position }: Props) => {
+ const styles = useStyles2(getStyles);
if (!(item && position)) {
return null;
diff --git a/packages/grafana-flamegraph/src/FlameGraph/rendering.ts b/packages/grafana-flamegraph/src/FlameGraph/rendering.ts
index b017ddbed2b..b38ade060a5 100644
--- a/packages/grafana-flamegraph/src/FlameGraph/rendering.ts
+++ b/packages/grafana-flamegraph/src/FlameGraph/rendering.ts
@@ -3,6 +3,7 @@ import { RefObject, useEffect, useMemo, useState } from 'react';
import color from 'tinycolor2';
import { GrafanaTheme2 } from '@grafana/data';
+import { useTheme2 } from '@grafana/ui';
import {
BAR_BORDER_WIDTH,
@@ -41,7 +42,6 @@ type RenderOptions = {
totalTicksRight: number | undefined;
colorScheme: ColorScheme | ColorSchemeDiff;
focusedItemData?: ClickedItemData;
- getTheme: () => GrafanaTheme2;
};
export function useFlameRender(options: RenderOptions) {
@@ -59,7 +59,6 @@ export function useFlameRender(options: RenderOptions) {
totalTicksRight,
colorScheme,
focusedItemData,
- getTheme,
} = options;
const foundLabels = useMemo(() => {
if (search) {
@@ -79,7 +78,7 @@ export function useFlameRender(options: RenderOptions) {
}, [search, data]);
const ctx = useSetupCanvas(canvasRef, wrapperWidth, levels.length);
- const theme = getTheme();
+ const theme = useTheme2();
useEffect(() => {
if (!ctx) {
diff --git a/packages/grafana-flamegraph/src/FlameGraphContainer.tsx b/packages/grafana-flamegraph/src/FlameGraphContainer.tsx
index 18970d094b2..6aacd816674 100644
--- a/packages/grafana-flamegraph/src/FlameGraphContainer.tsx
+++ b/packages/grafana-flamegraph/src/FlameGraphContainer.tsx
@@ -3,6 +3,7 @@ import React, { useCallback, useEffect, useMemo, useState } from 'react';
import { useMeasure } from 'react-use';
import { DataFrame, GrafanaTheme2 } from '@grafana/data';
+import { ThemeContext } from '@grafana/ui';
import FlameGraph from './FlameGraph/FlameGraph';
import { FlameGraphDataContainer } from './FlameGraph/dataTransform';
@@ -133,75 +134,76 @@ const FlameGraphContainer = ({
}
return (
-
-
{
- setSelectedView(view);
- onViewSelected?.(view);
- }}
- containerWidth={containerWidth}
- onReset={() => {
- resetFocus();
- resetSandwich();
- }}
- textAlign={textAlign}
- onTextAlignChange={(align) => {
- setTextAlign(align);
- onTextAlignSelected?.(align);
- }}
- showResetButton={Boolean(focusedItemData || sandwichItem)}
- colorScheme={colorScheme}
- onColorSchemeChange={setColorScheme}
- stickyHeader={Boolean(stickyHeader)}
- extraHeaderElements={extraHeaderElements}
- vertical={vertical}
- isDiffMode={Boolean(dataContainer.isDiffFlamegraph())}
- getTheme={getTheme}
- />
+ // We add the theme context to bridge the gap if this is rendered in non grafana environment where the context
+ // isn't already provided.
+
+
+
{
+ setSelectedView(view);
+ onViewSelected?.(view);
+ }}
+ containerWidth={containerWidth}
+ onReset={() => {
+ resetFocus();
+ resetSandwich();
+ }}
+ textAlign={textAlign}
+ onTextAlignChange={(align) => {
+ setTextAlign(align);
+ onTextAlignSelected?.(align);
+ }}
+ showResetButton={Boolean(focusedItemData || sandwichItem)}
+ colorScheme={colorScheme}
+ onColorSchemeChange={setColorScheme}
+ stickyHeader={Boolean(stickyHeader)}
+ extraHeaderElements={extraHeaderElements}
+ vertical={vertical}
+ isDiffMode={Boolean(dataContainer.isDiffFlamegraph())}
+ />
-
- {selectedView !== SelectedView.FlameGraph && (
-
- )}
+
+ {selectedView !== SelectedView.FlameGraph && (
+
+ )}
- {selectedView !== SelectedView.TopTable && (
- setFocusedItemData(data)}
- focusedItemData={focusedItemData}
- textAlign={textAlign}
- sandwichItem={sandwichItem}
- onSandwich={(label: string) => {
- resetFocus();
- setSandwichItem(label);
- }}
- onFocusPillClick={resetFocus}
- onSandwichPillClick={resetSandwich}
- colorScheme={colorScheme}
- />
- )}
+ {selectedView !== SelectedView.TopTable && (
+ setFocusedItemData(data)}
+ focusedItemData={focusedItemData}
+ textAlign={textAlign}
+ sandwichItem={sandwichItem}
+ onSandwich={(label: string) => {
+ resetFocus();
+ setSandwichItem(label);
+ }}
+ onFocusPillClick={resetFocus}
+ onSandwichPillClick={resetSandwich}
+ colorScheme={colorScheme}
+ />
+ )}
+
-
+
);
};
diff --git a/packages/grafana-flamegraph/src/FlameGraphHeader.test.tsx b/packages/grafana-flamegraph/src/FlameGraphHeader.test.tsx
index edc0f9ddb42..76935d7d198 100644
--- a/packages/grafana-flamegraph/src/FlameGraphHeader.test.tsx
+++ b/packages/grafana-flamegraph/src/FlameGraphHeader.test.tsx
@@ -3,8 +3,6 @@ import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import React from 'react';
-import { createTheme } from '@grafana/data';
-
import FlameGraphHeader from './FlameGraphHeader';
import { ColorScheme, SelectedView } from './types';
@@ -28,7 +26,6 @@ describe('FlameGraphHeader', () => {
showResetButton={true}
colorScheme={ColorScheme.ValueBased}
onColorSchemeChange={onSchemeChange}
- getTheme={() => createTheme({ colors: { mode: 'dark' } })}
stickyHeader={false}
isDiffMode={false}
{...props}
diff --git a/packages/grafana-flamegraph/src/FlameGraphHeader.tsx b/packages/grafana-flamegraph/src/FlameGraphHeader.tsx
index 9d3f601d8d8..7c521af4714 100644
--- a/packages/grafana-flamegraph/src/FlameGraphHeader.tsx
+++ b/packages/grafana-flamegraph/src/FlameGraphHeader.tsx
@@ -4,7 +4,7 @@ import useDebounce from 'react-use/lib/useDebounce';
import usePrevious from 'react-use/lib/usePrevious';
import { GrafanaTheme2, SelectableValue } from '@grafana/data';
-import { Button, Dropdown, Input, Menu, RadioButtonGroup } from '@grafana/ui';
+import { Button, Dropdown, Input, Menu, RadioButtonGroup, useStyles2 } from '@grafana/ui';
import { byPackageGradient, byValueGradient, diffColorBlindGradient, diffDefaultGradient } from './FlameGraph/colors';
import { MIN_WIDTH_TO_SHOW_BOTH_TOPTABLE_AND_FLAMEGRAPH } from './constants';
@@ -25,7 +25,6 @@ type Props = {
stickyHeader: boolean;
vertical?: boolean;
isDiffMode: boolean;
- getTheme: () => GrafanaTheme2;
extraHeaderElements?: React.ReactNode;
};
@@ -46,9 +45,8 @@ const FlameGraphHeader = ({
extraHeaderElements,
vertical,
isDiffMode,
- getTheme,
}: Props) => {
- const styles = getStyles(getTheme(), stickyHeader);
+ const styles = useStyles2(getStyles, stickyHeader);
const [localSearch, setLocalSearch] = useSearchInput(search, setSearch);
const suffix =
@@ -95,12 +93,7 @@ const FlameGraphHeader = ({
aria-label={'Reset focus and sandwich state'}
/>
)}
-
+
size="sm"
disabled={selectedView === SelectedView.TopTable}
@@ -124,12 +117,11 @@ const FlameGraphHeader = ({
type ColorSchemeButtonProps = {
value: ColorScheme | ColorSchemeDiff;
onChange: (colorScheme: ColorScheme | ColorSchemeDiff) => void;
- getTheme: () => GrafanaTheme2;
isDiffMode: boolean;
};
function ColorSchemeButton(props: ColorSchemeButtonProps) {
// TODO: probably create separate getStyles
- const styles = getStyles(props.getTheme(), false);
+ const styles = useStyles2(getStyles, false);
let menu = (