CtrlK
BlogDocsLog inGet started
Tessl Logo

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

Superset Legacy Chart plugin providing calendar heatmap visualization for time-series data

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

index.mddocs/

@superset-ui/legacy-plugin-chart-calendar

@superset-ui/legacy-plugin-chart-calendar is a Superset chart plugin that provides calendar heatmap visualization for time-series data. It renders data as color-coded cells in a calendar format, making it ideal for identifying patterns, trends, and outliers in temporal data over days, weeks, months, or years.

Package Information

  • Package Name: @superset-ui/legacy-plugin-chart-calendar
  • Package Type: npm
  • Language: JavaScript/TypeScript
  • Installation: npm install @superset-ui/legacy-plugin-chart-calendar

Core Imports

import CalendarChartPlugin from "@superset-ui/legacy-plugin-chart-calendar";

For importing utilities (not commonly needed in typical usage):

// Note: Utilities are internal and not exported from main entry
// They are only accessible from built lib structure
import { getFormattedUTCTime } from "@superset-ui/legacy-plugin-chart-calendar/lib/utils";

Basic Usage

import CalendarChartPlugin from "@superset-ui/legacy-plugin-chart-calendar";

// Register the plugin with Superset
const calendarPlugin = new CalendarChartPlugin();

// The plugin is typically registered with Superset's chart registry
// and used through Superset's SuperChart component

Architecture

The calendar chart plugin is built around several key components:

  • CalendarChartPlugin: Main plugin class that integrates with Superset's chart framework
  • Calendar Component: Core D3-based visualization that renders the calendar heatmap
  • ReactCalendar: React wrapper component with styled theme integration
  • Transform Functions: Data transformation utilities that convert Superset props to chart format
  • Control Panel: Configuration interface for chart customization options
  • Utilities: Helper functions for time formatting and data processing

Capabilities

Main Plugin Class

The primary export that registers the calendar chart with Superset's chart framework.

/**
 * Main chart plugin class extending Superset's ChartPlugin
 */
export default class CalendarChartPlugin extends ChartPlugin {
  constructor();
}

Calendar Visualization Component

Core visualization function that creates the calendar heatmap using D3 and cal-heatmap library.

/**
 * Creates a calendar heatmap visualization in the specified DOM element
 * @param {HTMLElement} element - DOM element to render the chart in
 * @param {CalendarProps} props - Chart configuration and data properties
 */
function Calendar(element, props);

interface CalendarProps {
  /** Chart data structure with metrics and timestamps */
  data: CalendarData;
  /** Chart height in pixels */
  height: number;
  /** Distance between calendar cells in pixels (default: 3) */
  cellPadding?: number;
  /** Border radius for calendar cells in pixels (default: 0) */
  cellRadius?: number;
  /** Size of square calendar cells in pixels (default: 10) */
  cellSize?: number;
  /** Time granularity for grouping (hour, day, week, month, year) */
  domainGranularity: string;
  /** Time granularity for individual cells (min, hour, day, week, month) */
  subdomainGranularity: string;
  /** Color scheme name for visualization */
  linearColorScheme: string;
  /** Whether to display the color legend */
  showLegend: boolean;
  /** Whether to display metric names as titles */
  showMetricName: boolean;
  /** Whether to display values within calendar cells */
  showValues: boolean;
  /** Number of color intensity steps */
  steps: number;
  /** Function to format time values for display */
  timeFormatter: (timestamp: number) => string;
  /** Function to format numeric values for display */
  valueFormatter: (value: number) => string;
  /** Mapping for verbose metric names */
  verboseMap: object;
}

interface CalendarData {
  /** Object mapping metric names to timestamp-value pairs */
  data: Record<string, Record<string, number>>;
  /** Domain granularity setting */
  domain: string;
  /** Number of time periods to display */
  range: number;
  /** Start timestamp in milliseconds */
  start: number;
  /** Subdomain granularity setting */
  subdomain: string;
}

React Calendar Component

Styled React wrapper component that integrates with Superset's theming system.

/**
 * React wrapper component (internally named 'Calender') for the Calendar visualization with theming
 * @param {ReactCalendarProps} props - Component props including className and other properties  
 */
function ReactCalendar(props);

interface ReactCalendarProps {
  /** CSS class name for styling (required) */
  className: string;
  /** Additional props passed to underlying Calendar component (default: {}) */
  otherProps?: object;
}

Data Transformation

Transforms Superset chart properties into the format expected by the Calendar component.

/**
 * Transforms Superset chart props into Calendar component format
 * @param {SupersetChartProps} chartProps - Standard Superset chart properties
 * @returns {CalendarProps} Transformed properties for Calendar component
 */
function transformProps(chartProps);

interface SupersetChartProps {
  /** Chart height */
  height: number;
  /** Form data containing chart configuration */
  formData: FormData;
  /** Query results data array */
  queriesData: array;
  /** Datasource metadata with verboseMap */
  datasource: object;
}

interface FormData {
  /** Cell styling options */
  cellPadding: number;
  cellRadius: number;
  cellSize: number;
  /** Time granularity settings (snake_case in form data) */
  domainGranularity: string;
  subdomainGranularity: string;
  /** Visual options */
  linearColorScheme: string;
  showLegend: boolean;
  showMetricName: boolean;
  showValues: boolean;
  steps: number;
  /** Formatting options */
  xAxisTimeFormat: string;
  yAxisFormat: string;
}

Control Panel Configuration

Configuration schema for the chart's control panel interface in Superset.

/**
 * Control panel configuration for chart customization options
 */
const controlPanel: ControlPanelConfig;

interface ControlPanelConfig {
  /** Array of control panel sections */
  controlPanelSections: ControlPanelSection[];
  /** Override settings for specific controls */
  controlOverrides: Record<string, any>;
}

Time Formatting Utilities

Utility functions for handling time formatting with UTC timezone assumptions.

/**
 * Formats timestamp as UTC time string, adjusting for timezone offset
 * @param ts - Timestamp to format (number or string)
 * @param timeFormat - Optional D3 time format string
 * @returns Formatted time string
 */
export function getFormattedUTCTime(
  ts: number | string,
  timeFormat?: string
): string;

Usage Examples

Basic Calendar Chart Setup

import CalendarChartPlugin from "@superset-ui/legacy-plugin-chart-calendar";

// Create and register the plugin
const calendarPlugin = new CalendarChartPlugin();

// Example data format expected by the calendar
const sampleData = {
  data: {
    "page_views": {
      "1640995200.0": 150,    // 2022-01-01 values
      "1641081600.0": 200,    // 2022-01-02 values
      "1641168000.0": 175     // 2022-01-03 values
    }
  },
  domain: "month",
  range: 12,
  start: 1640995200000,  // Start timestamp in milliseconds
  subdomain: "day"
};

Custom Time Formatting

import { getFormattedUTCTime } from "@superset-ui/legacy-plugin-chart-calendar/lib/utils";

// Format timestamps for display
const timestamp = 1640995200000;
const formatted = getFormattedUTCTime(timestamp, "%Y-%m-%d");
console.log(formatted); // "2022-01-01"

// Using different format patterns
const timeOnly = getFormattedUTCTime(timestamp, "%H:%M:%S");
const fullFormat = getFormattedUTCTime(timestamp, "%B %d, %Y");

Chart Configuration Options

// Example configuration for chart customization
const chartConfig = {
  cellSize: 15,           // Size of calendar cells (default: 10)
  cellPadding: 3,         // Space between cells (default: 3 in Calendar, 2 in control panel)
  cellRadius: 2,          // Border radius for cells (default: 0)
  steps: 5,               // Number of color intensity levels (default: 10)
  showLegend: true,       // Display color legend (default: true)
  showValues: false,      // Hide values in cells (default: false)
  showMetricName: true,   // Show metric name as title (default: true)
  domain_granularity: "month",    // Group by months (note: snake_case)
  subdomain_granularity: "day",   // Individual cells are days (note: snake_case)
  linearColorScheme: "blues"      // Color scheme
};

Data Format Requirements

The calendar chart expects data in a specific nested structure:

{
  "data": {
    "metric_name": {
      "timestamp_as_string": numeric_value,
      "1640995200.0": 150,
      "1641081600.0": 200
    }
  },
  "domain": "month",        // Time grouping level
  "range": 12,              // Number of domains to show
  "start": 1640995200000,   // Start time in milliseconds
  "subdomain": "day"        // Individual cell time unit
}

Color Schemes and Styling

The calendar chart supports Superset's color schemes and integrates with the theming system:

  • Uses sequential color schemes from @superset-ui/core
  • Automatically applies theme colors for tooltips and UI elements
  • Supports custom CSS styling through className props
  • Color intensity maps data values to visual representation

Error Handling

The calendar chart includes built-in error handling for:

  • Invalid or missing data structures
  • Malformed timestamp formats
  • Configuration validation errors
  • DOM rendering failures

When errors occur, the chart will typically fail gracefully without breaking the parent application.

docs

index.md

tile.json