A React component demonstrating hierarchical data visualization using flame graphs. This component provides an interactive way to visualize and analyze hierarchical data structures with customizable depth and partitioning controls.
import { FlameGraphViewer } from './FlameGraphViewer';
// Rendering a flame graph with custom dimensions
const FlameGraphDisplay = () => {
return (
<FlameGraphViewer
enableTooltips={true}
width={800}
height={500}
data={generateHierarchicalData({
maxDivideCount: 2,
levelCount: 2,
value: 1000
})}
/>
);
};
The component provides two main controls for customizing the visualization:
Dividing Count: Controls the maximum number of partitions at each level
Level Count: Controls the maximum depth of the hierarchy
The flame graph expects hierarchical data in the following format:
{
name: "Root",
value: 1000,
children: [
{
name: "Child 1",
value: 500,
children: [...]
},
{
name: "Child 2",
value: 500,
children: [...]
}
]
}
The component supports customizable tooltips that can be enabled or disabled:
<FlameGraphViewer
enableTooltips={true}
tooltipHeight={50} // Optional: Custom tooltip height
// ... other props
/>
The component consists of two main parts:
FlameGraphSample: The main container component that handles:
FlameGraphViewer: The visualization component that handles:
The flame graph can be customized through various props:
<FlameGraphViewer
width={800} // Width of the visualization
height={500} // Height of the visualization
enableTooltips={true} // Enable/disable tooltips
tooltipHeight={50} // Custom tooltip height
onChange={handleChange} // Callback for data changes
data={hierarchicalData} // The hierarchical data to visualize
/>
The component uses SCSS for styling, with customizable classes for:
.Tooltip {
position: absolute;
z-index: 3;
background-color: #000;
color: #fff;
padding: 0.5rem;
}
Prop | Type | Default | Description |
---|---|---|---|
width |
number | 800 | Width of the flame graph visualization |
height |
number | 500 | Height of the flame graph visualization |
enableTooltips |
boolean | false | Enable/disable tooltip functionality |
tooltipHeight |
number | - | Custom height for tooltips |
data |
object | - | Hierarchical data to visualize |
onChange |
function | - | Callback for data changes |
{
"dependencies": {
"react": "^17.0.0",
"react-flame-graph": "^1.0.0",
"antd": "^4.0.0",
"@emotion/css": "^11.0.0"
}
}