CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-superset-ui--legacy-plugin-chart-heatmap

Apache Superset legacy heatmap chart plugin providing D3.js-based visualization for correlation matrices and data density patterns.

Pending
Overview
Eval results
Files

heatmap-visualization.mddocs/

Heatmap Visualization

Core D3.js-based heatmap visualization component that renders data as color-coded cells in a grid format with interactive features.

Capabilities

Heatmap Function (Internal)

Internal D3.js visualization function that renders the heatmap. This function is wrapped by the React component and used automatically by the plugin framework.

/**
 * Internal function that renders a heatmap visualization in the specified DOM element
 * Used automatically by the ReactHeatmap component wrapper
 * @param element - DOM element to render the heatmap into
 * @param props - Configuration properties for the visualization
 */
function Heatmap(element: HTMLElement, props: HeatmapProps): void;

Heatmap Props Interface

Complete configuration interface for the heatmap visualization.

interface HeatmapProps {
  /** Data structure containing records and value bounds */
  data: {
    records: HeatmapRecord[];
    extents: [number, number];
  };
  /** Chart width in pixels */
  width: number;
  /** Chart height in pixels */  
  height: number;
  /** Bottom margin configuration (auto or pixel value) */
  bottomMargin: string | number;
  /** Canvas image rendering mode */
  canvasImageRendering: 'pixelated' | 'auto';
  /** Color scheme identifier */
  colorScheme: string;
  /** X-axis column name */
  columnX: string;
  /** Y-axis column name */
  columnY: string;
  /** Left margin configuration (auto or pixel value) */
  leftMargin: string | number;
  /** Metric configuration (string name or object) */
  metric: string | { label: string; [key: string]: any };
  /** Whether to use normalized values for coloring */
  normalized: boolean;
  /** Number format string for value display */
  numberFormat: string;
  /** Whether to show color legend */
  showLegend: boolean;
  /** Whether to show percentage in tooltips */
  showPercentage: boolean;
  /** Whether to show values inside cells */
  showValues: boolean;
  /** X-axis sorting method */
  sortXAxis: 'alpha_asc' | 'alpha_desc' | 'value_asc' | 'value_desc';
  /** Y-axis sorting method */
  sortYAxis: 'alpha_asc' | 'alpha_desc' | 'value_asc' | 'value_desc';
  /** X-axis scale interval for tick marks */
  xScaleInterval: number;
  /** Y-axis scale interval for tick marks */
  yScaleInterval: number;
  /** Value bounds for color scale [min, max] */
  yAxisBounds: [number | null, number | null];
}

interface HeatmapRecord {
  /** X-axis category value */
  x: string;
  /** Y-axis category value */
  y: string;
  /** Numeric value for the cell */
  v: number;
  /** Percentage value (0-1) */
  perc: number;
  /** Rank value for normalization (0-1) */
  rank: number;
}

React Wrapper Component

Styled React component that wraps the D3 heatmap using the reactify pattern with emotion CSS-in-JS theming.

/**
 * React wrapper component created using reactify pattern
 * Converts the D3 Heatmap function into a React component
 */
const ReactComponent = reactify(Component);

/**
 * Main React Heatmap component with styling and theming
 * @param props - React props including className and heatmap properties
 * @returns Styled React component with Global emotion styles
 */
function ReactHeatmap(props: ReactHeatmapProps): React.ReactElement;

interface ReactHeatmapProps extends HeatmapProps {
  /** CSS class name for styling */
  className?: string;
}

PropTypes Definition

The D3 Heatmap component uses PropTypes for runtime type checking:

const propTypes = {
  data: PropTypes.shape({
    records: PropTypes.arrayOf(
      PropTypes.shape({
        x: PropTypes.string,
        y: PropTypes.string,
        v: PropTypes.number,
        perc: PropTypes.number,
        rank: PropTypes.number,
      }),
    ),
    extents: PropTypes.arrayOf(PropTypes.number),
  }),
  width: PropTypes.number,
  height: PropTypes.number,
  bottomMargin: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
  colorScheme: PropTypes.string,
  columnX: PropTypes.string,
  columnY: PropTypes.string,
  leftMargin: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
  metric: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
  normalized: PropTypes.bool,
  numberFormat: PropTypes.string,
  showLegend: PropTypes.bool,
  showPercentage: PropTypes.bool,
  showValues: PropTypes.bool,
  sortXAxis: PropTypes.string,
  sortYAxis: PropTypes.string,
  xScaleInterval: PropTypes.number,
  yScaleInterval: PropTypes.number,
  yAxisBounds: PropTypes.arrayOf(PropTypes.number),
};

Visualization Features

Canvas Rendering

The heatmap uses HTML5 Canvas for efficient rendering of large datasets:

  • Pixel-Perfect Rendering: Each data point maps to individual pixels
  • Color Interpolation: Smooth color gradients based on data values
  • Performance Optimization: Canvas rendering handles thousands of data points
  • Image Smoothing Control: Configurable pixelated or smooth rendering

Interactive Tooltips

Hover tooltips display detailed information for each cell:

  • Position-Aware: Tooltips adjust position to stay within viewport
  • Rich Content: Shows X/Y values, metric value, and optional percentage
  • Dynamic Visibility: Tooltips hide over empty cells
  • Styled with Theme: Uses Superset theme colors and typography

Axis Management

Smart axis labeling with overflow handling:

  • Dynamic Margins: Automatically adjusts margins based on label lengths
  • Label Rotation: Rotates X-axis labels if they don't fit
  • Tick Intervals: Configurable intervals to prevent overcrowding
  • Sorting Options: Multiple sorting methods for both axes

Color Legend

Optional color legend showing value-to-color mapping:

  • Scale Representation: Shows color gradient with value markers
  • Formatted Values: Uses configured number format for legend labels
  • Positioned Layout: Automatically positioned to avoid overlap

Usage Examples

Basic Heatmap

// Note: Heatmap function is not directly exported - it's used through ReactHeatmap
import ReactHeatmap from '@superset-ui/legacy-plugin-chart-heatmap';

const element = document.getElementById('heatmap-container');
const props = {
  data: {
    records: [
      { x: 'Product A', y: 'Region 1', v: 100, perc: 0.2, rank: 0.5 },
      { x: 'Product B', y: 'Region 2', v: 150, perc: 0.3, rank: 0.7 },
    ],
    extents: [0, 200]
  },
  width: 600,
  height: 400,
  colorScheme: 'schemeBlues',
  columnX: 'Product',
  columnY: 'Region',
  metric: 'Sales',
  showLegend: true,
  showValues: false,
  normalized: false,
  numberFormat: '.2f',
  sortXAxis: 'alpha_asc',
  sortYAxis: 'value_desc',
  xScaleInterval: 1,
  yScaleInterval: 1,
  leftMargin: 'auto',
  bottomMargin: 'auto',
  yAxisBounds: [null, null]
};

// For direct D3 usage, you would need to import the internal component
// This is not the recommended approach - use ReactHeatmap instead

React Component Usage

import ReactHeatmap from '@superset-ui/legacy-plugin-chart-heatmap';

function MyComponent() {
  return (
    <ReactHeatmap
      data={{
        records: [
          { x: 'Mon', y: 'Hour 9', v: 25, perc: 0.15, rank: 0.4 },
          { x: 'Tue', y: 'Hour 10', v: 40, perc: 0.25, rank: 0.6 },
        ],
        extents: [0, 100]
      }}
      width={800}
      height={600}
      colorScheme='schemeReds'
      columnX='Day'
      columnY='Time'
      metric='Activity'
      showLegend={true}
      showValues={true}
      showPercentage={true}
      normalized={false}
    />
  );
}

Advanced Configuration

// Complex heatmap with custom styling and normalization
const advancedProps = {
  data: correlationMatrix, // Large dataset
  width: 1000,
  height: 800,
  colorScheme: 'schemePiYG', // Diverging color scheme
  normalized: true, // Use rank-based coloring
  showLegend: true,
  showValues: false, // Too many cells for values
  showPercentage: true,
  leftMargin: 120, // Fixed margin for long labels
  bottomMargin: 80,
  xScaleInterval: 2, // Show every 2nd label
  yScaleInterval: 3, // Show every 3rd label
  sortXAxis: 'value_desc', // Sort by correlation strength
  sortYAxis: 'value_desc',
  yAxisBounds: [-1, 1], // Correlation bounds
  numberFormat: '.3f', // 3 decimal places
  canvasImageRendering: 'pixelated' // Sharp edges
};

Install with Tessl CLI

npx tessl i tessl/npm-superset-ui--legacy-plugin-chart-heatmap

docs

chart-configuration.md

heatmap-visualization.md

index.md

plugin-registration.md

tile.json