A React component demonstrating interactive flame graph visualization with dynamic coloring capabilities. This component visualizes hierarchical data using flame graphs and provides various coloring schemes for data representation.
npm install react-flame-graph chroma-js @emotion/css antd
import FlameGraphColoringSample from './FlameGraphColoringSample';
const FlameGraphDemo = () => {
return (
<FlameGraphColoringSample
path="/flame-graph"
title="Flame Graph Coloring Demo"
/>
);
};
// Generate hierarchical data
const generatedData = generateHierarchicalData({
maxDivideCount: 3, // Number of divisions per level
levelCount: 6, // Number of levels in hierarchy
value: 40000 // Root value
});
// Apply coloring based on selected mode
const traverseGeneratedData = (node, rootValue) => {
switch (mode) {
case 'color-brewer':
// Apply Brewer color scales
node.backgroundColor = colorsScales[index];
node.color = '#ddd';
break;
case 'color-temperature':
// Apply temperature-based colors
node.backgroundColor = calcColorFromTemperature(node.value);
node.color = '#fff';
break;
case 'native':
default:
// Use native colors
return true;
}
};
Prop | Type | Description |
---|---|---|
data | Object | Hierarchical data to visualize |
enableTooltips | Boolean | Enable/disable tooltips |
width | Number | Width of the flame graph |
height | Number | Height of the flame graph |
tooltipHeight | Number | Height of tooltip container |
onChange | Function | Callback for graph changes |
Prop | Type | Description |
---|---|---|
path | String | Path for documentation |
title | String | Title of the demo |
Native Colors
Color Temperature
Brewer Colors
The component provides several interactive controls:
.Tooltip {
position: absolute;
z-index: 3;
background-color: #000;
color: #fff;
padding: 0.5rem;
.tt-name {
background-color: red;
}
.tt-value {
background-color: blue;
}
}