Class FlameGraphSeries


public class FlameGraphSeries extends HierarchySeries

A flame graph: each node is a bar as wide as its share of its parent, and its children sit on top of it, so the widest stacks are where the time (or memory, or any other total) goes. The root is the bottom row. With setInverted(true) the root is the top row and the children hang below it, which is usually called an icicle chart.

Tapping a bar zooms into it: that node becomes the bottom row and spans the full width. Tapping the breadcrumb goes back up. A branch is as wide as the sum of its children, so time a function spends in its own code goes in a leaf child of its own, conventionally named "self". Bars too narrow for their text show none, and the tooltip always shows the name and value.

Bars take the node's own color when it has one. Otherwise they get warm colors, picked from the node's name so the same function keeps its color between captures; setWarmColors(false) uses the theme's palette by top level branch instead, as a treemap does.

TreeNode main = new TreeNode("main");
TreeNode load = main.add(new TreeNode("load"));
load.add(new TreeNode("parse", 30));
load.add(new TreeNode("decode", 20));
TreeNode render = main.add(new TreeNode("render"));
render.add(new TreeNode("layout", 25));
render.add(new TreeNode("paint", 15));
Chart chart = new Chart();
chart.addSeries(new FlameGraphSeries("CPU", main));

A flame graph Inverted, as an icicle chart

  • Constructor Details

    • FlameGraphSeries

      public FlameGraphSeries(String name, TreeNode root)

      Creates a flame graph.

      Parameters
      • name: the series name

      • root: the tree's root, drawn as the bottom row

  • Method Details

    • setInverted

      public FlameGraphSeries setInverted(boolean inverted)

      Draws the root at the top and the children below it (an icicle chart) instead of the root at the bottom.

      Parameters
      • inverted: true for the root at the top
      Returns

      this series

    • isInverted

      public boolean isInverted()

      True when the root is drawn at the top.

      Returns

      true for an icicle chart

    • setWarmColors

      public FlameGraphSeries setWarmColors(boolean warm)

      Chooses between warm colors picked from each node's name, the default, and the theme's palette by top level branch.

      Parameters
      • warm: false for the theme's palette
      Returns

      this series

    • isWarmColors

      public boolean isWarmColors()

      True when bars get warm colors picked from their names.

      Returns

      true by default

    • paint

      public void paint(ChartContext ctx)
      Description copied from class: Series

      Paints the series.

      Parameters
      • ctx: the current frame: graphics, plot area, axes and animation progress
      Specified by:
      paint in class Series
    • collapsed

      protected float[] collapsed(float[] r)
      Description copied from class: HierarchySeries

      The geometry a node added by a data change grows from: by default the geometry itself, so the node appears in place.

      Parameters
      • geometry: the node's geometry after the change
      Returns

      a new array of the same length

      Overrides:
      collapsed in class HierarchySeries
    • contains

      protected boolean contains(float[] r, float x, float y)
      Description copied from class: HierarchySeries

      True if the absolute point lies in a recorded geometry.

      Parameters
      • geometry: a recorded geometry

      • x: absolute x

      • y: absolute y

      Returns

      true on a hit

      Specified by:
      contains in class HierarchySeries
    • anchor

      protected float[] anchor(float[] r)
      Description copied from class: HierarchySeries

      The anchor point of a recorded geometry, {x, y} absolute.

      Parameters
      • geometry: a recorded geometry
      Returns

      the point a tooltip points at

      Specified by:
      anchor in class HierarchySeries