Skip to content

Commit

Permalink
docs(flamegraph): FrameColorProvider / FrameFontProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
bric3 committed Jun 9, 2022
1 parent d2867b5 commit 432de76
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,28 @@
import static io.github.bric3.fireplace.flamegraph.FrameRenderingFlags.isHighlighting;
import static io.github.bric3.fireplace.flamegraph.FrameRenderingFlags.isHovered;

/**
* Strategy for choosing the colors of a frame.
*
* @param <T> The type of the frame node (depends on the source of profiling data).
*/
public interface FrameColorProvider<T> {
class ColorModel {
public Color background;
public Color foreground;

public ColorModel(Color background, Color foreground) {
/**
* Data-structure that hold the computed colors for a frame.
*
* @param background The background color of the frame.
* @param foreground The foreground color of the frame.
*/
ColorModel(Color background, Color foreground) {
this.background = background;
this.foreground = foreground;
}

public ColorModel set(Color background, Color foreground) {
ColorModel set(Color background, Color foreground) {
this.background = background;
this.foreground = foreground;
return this;
Expand All @@ -49,10 +60,22 @@ public ColorModel copy() {
}
}

/**
* Returns the color model for the given <code>frame</code> according to the given <code>flags</code>.
*
* <p>
* An implementation may choose to return the same instance of color model
* for all frames to save allocations.
* </p>
*
* @param frame The frame
* @param flags The flags
* @return The color model for this frame
*/
ColorModel getColors(FrameBox<T> frame, int flags) ;

static <T> FrameColorProvider<T> defaultColorProvider(Function<FrameBox<T>, Color> frameColorFunction) {
Objects.requireNonNull(frameColorFunction, "frameColorFunction");
static <T> FrameColorProvider<T> defaultColorProvider(Function<FrameBox<T>, Color> frameBaseColorFunction) {
Objects.requireNonNull(frameBaseColorFunction, "frameColorFunction");
return new FrameColorProvider<T>() {
/**
* The color used to draw frames that are highlighted.
Expand All @@ -63,7 +86,7 @@ static <T> FrameColorProvider<T> defaultColorProvider(Function<FrameBox<T>, Colo

@Override
public ColorModel getColors(FrameBox<T> frame, int flags) {
Color baseBackgroundColor = frameColorFunction.apply(frame);
Color baseBackgroundColor = frameBaseColorFunction.apply(frame);
Color backgroundColor = baseBackgroundColor;

if (isFocusing(flags) && !isFocusedFrame(flags)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
import static io.github.bric3.fireplace.flamegraph.FrameRenderingFlags.isHighlightedFrame;
import static io.github.bric3.fireplace.flamegraph.FrameRenderingFlags.isPartialFrame;

/**
* Strategy for choosing the font of a frame.
*
* @param <T> The type of the frame node (depends on the source of profiling data).
*/
public interface FrameFontProvider<T> {

/**
Expand All @@ -31,7 +36,7 @@ public interface FrameFontProvider<T> {
* parameter is <code>null</code>. Possibly honoring the <code>flags</code>.
* </p>
*
* @param frame The frame to get the font for, can be null.
* @param frame The frame to get the font for, can be <code>null</code>.
* @param flags The flags
* @return The font to use for the frame and flags.
*/
Expand Down

0 comments on commit 432de76

Please sign in to comment.