Skip to content

Commit

Permalink
feature(flamegraph): Allow to override some colors of the dimmed colo…
Browse files Browse the repository at this point in the history
…r provider

Refs: #80
  • Loading branch information
bric3 committed Jul 14, 2022
1 parent 1225990 commit 4f5540f
Showing 1 changed file with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@
import static io.github.bric3.fireplace.flamegraph.FrameRenderingFlags.isMinimapMode;

public class DimmingFrameColorProvider<T> implements FrameColorProvider<T> {
public static final Color DIMMED_TEXT = new DarkLightColor(
public static final Color DIMMED_TEXT_COLOR = new DarkLightColor(
Colors.rgba(28, 43, 52, 0.68f),
Colors.rgba(255, 255, 255, 0.51f)
);

public static final Color HOVERED_NODE = new DarkLightColor(
public static final Color HOVERED_BACKGROUND_COLOR = new DarkLightColor(
new Color(0xFFE0C268, true),
new Color(0xD0E0C268, true)
);

public static final Color ROOT_NODE = new DarkLightColor(
public static final Color ROOT_BACKGROUND_COLOR = new DarkLightColor(
new Color(0xFFEAF6FC),
new Color(0xFF091222)
);
Expand All @@ -68,19 +68,22 @@ public class DimmingFrameColorProvider<T> implements FrameColorProvider<T> {

private final ConcurrentHashMap<Color, Color> dimmedColorCache = new ConcurrentHashMap<>();

private Color rootBackGroundColor = ROOT_BACKGROUND_COLOR;
private Color dimmedTextColor = DIMMED_TEXT_COLOR;
private Color hoveredBackgroundColor = HOVERED_BACKGROUND_COLOR;

public DimmingFrameColorProvider(Function<FrameBox<T>, Color> baseColorFunction) {
this.baseColorFunction = baseColorFunction;
}


@Override
public ColorModel getColors(FrameBox<T> frame, int flags) {
Color backgroundColor;
Color foreground;

var rootNode = frame.isRoot();
if (rootNode) {
backgroundColor = ROOT_NODE;
backgroundColor = rootBackGroundColor;
} else {
backgroundColor = baseColorFunction.apply(frame);
}
Expand All @@ -92,13 +95,13 @@ public ColorModel getColors(FrameBox<T> frame, int flags) {

if (!rootNode && shouldDim(flags)) {
backgroundColor = cachedDim(backgroundColor);
foreground = DIMMED_TEXT;
foreground = DIMMED_TEXT_COLOR;
} else {
foreground = Colors.foregroundColor(backgroundColor);
}

if (isHovered(flags) || isHoveredSibling(flags)) {
backgroundColor = Colors.blend(backgroundColor, HOVERED_NODE);
backgroundColor = Colors.blend(backgroundColor, HOVERED_BACKGROUND_COLOR);
foreground = Colors.foregroundColor(backgroundColor);
}

Expand Down Expand Up @@ -137,4 +140,19 @@ private boolean shouldDim(int flags) {
private Color cachedDim(Color color) {
return dimmedColorCache.computeIfAbsent(color, Colors::dim);
}

public DimmingFrameColorProvider<T> withRootBackgroundColor(Color rootBackgroundColor) {
this.rootBackGroundColor = rootBackgroundColor;
return this;
}

public DimmingFrameColorProvider<T> withDimmedTextColor(Color dimmedTextColor) {
this.dimmedTextColor = dimmedTextColor;
return this;
}

public DimmingFrameColorProvider<T> withHoveredBackgroundColor(Color hoveredBackgroundColor) {
this.hoveredBackgroundColor = hoveredBackgroundColor;
return this;
}
}

0 comments on commit 4f5540f

Please sign in to comment.