Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[#11921] FlameGraph > Set colors for each application name #11920

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ const FlameNodeComponent = <T,>({
width={width}
height={height}
style={{
...nodeStyle,
fill: isHover ? hoverColor : color,
...nodeStyle,
}}
/>
<text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import {
TransactionInfoType as TransactionInfo,
colors,
} from '@pinpoint-fe/ui/constants';
import {
getColorByString,
getContrastingTextColor,
getDarkenHexColor,
} from '@pinpoint-fe/ui/lib/colors';
import { FlameGraph } from '../../FlameGraph';
import { cn } from '../../../lib';
import { TimelineDetail } from './TimelineDetail';
Expand Down Expand Up @@ -144,15 +149,22 @@ export const TimelineFetcher = ({ transactionInfo }: TimelineFetcherProps) => {
data={flameGraphData}
start={transactionInfo?.callStackStart}
end={transactionInfo?.callStackEnd}
customNodeStyle={(node, color) => {
customNodeStyle={(node, _color) => {
const nodeApplicationName = node?.detail?.args?.['Application Name'] || '';
const color = nodeApplicationName ? getColorByString(nodeApplicationName) : _color?.color;
const hoverColor = getDarkenHexColor(color);

const id = node.detail.args.id;
const isFocused = focusedNodeId === id || selectedTrace?.args.id === id;

return {
fill: isFocused ? color?.hoverColor : color?.color,
fill: isFocused ? hoverColor : color,
stroke: colors.white,
strokeWidth: 0.5,
};
}}
customTextStyle={(node) => {
customTextStyle={(node, _color) => {
const nodeApplicationName = node?.detail?.args?.['Application Name'] || '';
const id = node.detail.args.id;
const isFocused = focusedNodeId === id || selectedTrace?.args.id === id;
const isHighLighted = searchedListIds?.includes(id);
Expand All @@ -165,7 +177,9 @@ export const TimelineFetcher = ({ transactionInfo }: TimelineFetcherProps) => {
paintOrder: 'stroke',
strokeLinejoin: 'round',
}
: {};
: {
fill: getContrastingTextColor(getColorByString(nodeApplicationName)) || _color,
};
return {
...hilightedStyle,
fontWeight: isFocused ? 'bold' : '',
Expand Down
15 changes: 15 additions & 0 deletions web-frontend/src/main/v3/packages/ui/src/lib/colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,18 @@ export const getDarkenHexColor = (hexColor: string, amount = 0.2) => {

return darkenedHex;
};

export function getColorByString(input: string): string {
let hash = 0;
for (let i = 0; i < input.length; i++) {
hash = input.charCodeAt(i) + ((hash << 5) - hash);
}

let color = '#';
for (let i = 0; i < 3; i++) {
const value = (hash >> (i * 8)) & 0xff;
color += ('00' + value.toString(16)).slice(-2);
}

return color;
}