or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/npm-superset-ui--legacy-plugin-chart-sankey-loop

React-based Sankey diagram visualization plugin with loop support for Apache Superset

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@superset-ui/legacy-plugin-chart-sankey-loop@0.18.x

To install, run

npx @tessl/cli install tessl/npm-superset-ui--legacy-plugin-chart-sankey-loop@0.18.0

index.mddocs/

Superset UI Legacy Plugin Chart Sankey Loop

A React-based Sankey diagram visualization plugin with loop support for Apache Superset. This plugin provides interactive data visualization capabilities for exploring complex network relationships and flow data that includes cyclic relationships, extending traditional Sankey diagrams to handle loops in data flows.

Package Information

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

Core Imports

import SankeyChartPlugin from '@superset-ui/legacy-plugin-chart-sankey-loop';

For CommonJS:

const SankeyChartPlugin = require('@superset-ui/legacy-plugin-chart-sankey-loop');

Basic Usage

import SankeyChartPlugin from '@superset-ui/legacy-plugin-chart-sankey-loop';

// Register the plugin with Superset
const sankeyPlugin = new SankeyChartPlugin();
sankeyPlugin.configure({ key: 'sankey-loop' }).register();

For use with SuperChart:

import { SuperChart } from '@superset-ui/core';

<SuperChart
  chartType="sankey-loop"
  width={600}
  height={600}
  formData={{
    groupby: ['source', 'target'],
    metric: 'value',
    color_scheme: 'd3Category10',
    // ... other form data options
  }}
  queriesData={[{
    data: [
      { source: 'A', target: 'B', value: 10 },
      { source: 'B', target: 'C', value: 15 },
      { source: 'C', target: 'A', value: 5 }, // Loop back to A
      // ... more link data
    ]
  }]}
/>

Architecture

The plugin is built around the Superset chart plugin architecture and includes:

  • Chart Plugin: SankeyChartPlugin class extending Superset's ChartPlugin
  • React Component: ReactSankeyLoop component for React integration
  • D3 Visualization: SankeyLoop D3-based rendering engine with loop support
  • Data Transformation: transformProps function for Superset data integration
  • Control Panel: Configuration interface for chart customization

Capabilities

SankeyChartPlugin

Main plugin class for registering and configuring the Sankey diagram with loops visualization in Superset.

/**
 * Main chart plugin class for Sankey diagram with loops visualization
 * Extends ChartPlugin from @superset-ui/core
 */
class SankeyChartPlugin extends ChartPlugin {
  constructor();
}

The plugin is configured with:

  • Chart metadata: Name, description, thumbnail, and credits
  • Dynamic chart loading: Lazy-loads the React component
  • Data transformation: Processes Superset query data into chart format
  • Control panel: Provides UI controls for chart configuration

Plugin Registration

Register the plugin with Superset's chart registry.

/**
 * Configure the plugin with registration key and optional settings
 * @param config - Plugin configuration object with key and other options
 * @param replace - If true, replace entire config; otherwise merge
 * @returns Configured plugin instance for method chaining
 */
configure(config: { key: string, [key: string]: any }, replace?: boolean): SankeyChartPlugin;

/**
 * Register the plugin with Superset's chart registries
 * Registers in ChartMetadataRegistry, ChartComponentRegistry, 
 * ChartControlPanelRegistry, and ChartTransformPropsRegistry
 * @returns Plugin instance for method chaining
 */
register(): SankeyChartPlugin;

/**
 * Remove the plugin from all Superset registries
 * @returns Plugin instance for method chaining
 */
unregister(): SankeyChartPlugin;

/**
 * Reset plugin configuration to defaults
 * @returns Plugin instance for method chaining
 */
resetConfig(): SankeyChartPlugin;

Usage Example:

import SankeyChartPlugin from '@superset-ui/legacy-plugin-chart-sankey-loop';

const plugin = new SankeyChartPlugin();
plugin.configure({ key: 'sankey-loop' }).register();

SankeyLoop D3 Visualization Component

Core D3-based visualization function that renders the Sankey diagram with loop support. This is the underlying rendering engine used by the React wrapper.

/**
 * Renders a Sankey diagram with loop support using D3.js
 * @param element - DOM element to render the chart into
 * @param props - Chart configuration and data
 */
function SankeyLoop(element: HTMLElement, props: SankeyLoopProps): void;

interface SankeyLoopProps {
  /** Array of link data representing flows between nodes */
  data: Array<{
    source: string;
    target: string;
    value: number;
  }>;
  /** Chart width in pixels */
  width: number;
  /** Chart height in pixels */
  height: number;
  /** Color scheme identifier */
  colorScheme: string;
  /** Slice identifier for consistent coloring */
  sliceId: string | number;
  /** Chart margins (optional, uses default if not provided) */
  margin?: {
    top: number;
    right: number;
    bottom: number;
    left: number;
  };
}

Key Implementation Details:

  • Uses d3-sankey-diagram library version ^0.7.3 for loop support
  • Applies sankeyDiagram() layout with automatic node positioning
  • Colors links based on source node using categorical color scheme
  • Adds interactive tooltips showing flow values and percentages
  • Sets SVG class superset-legacy-chart-sankey-loop for styling
  • Default margins: { top: 0, right: 80, bottom: 0, left: 80 } to accommodate labels

Data Transformation

The transformProps function processes Superset query data into the format expected by the visualization component.

/**
 * Transforms Superset chart props into format expected by SankeyLoop component
 * @param chartProps - Raw props from Superset including query data and form data
 * @returns Transformed props for the visualization component
 */
function transformProps(chartProps: SupersetChartProps): SankeyLoopProps;

interface SupersetChartProps {
  /** Chart dimensions */
  width: number;
  height: number;
  /** Chart configuration from control panel */
  formData: {
    colorScheme: string;
    sliceId: string | number;
  };
  /** Query results from Superset */
  queriesData: Array<{
    data: Array<{
      source: string;
      target: string;
      value: number;
    }>;
  }>;
  /** Chart margins */
  margin: {
    top: number;
    right: number;
    bottom: number;
    left: number;
  };
}

The transformation extracts the first query's data and passes through dimensions, color scheme, and margin settings.

Data Format

The chart expects data in a specific link format for representing flows between nodes.

/**
 * Link data structure for Sankey diagram
 */
interface LinkData {
  /** Source node identifier */
  source: string;
  /** Target node identifier */  
  target: string;
  /** Flow value between source and target */
  value: number;
}

/**
 * Chart props after transformation
 */
interface ChartProps {
  /** Chart width in pixels */
  width: number;
  /** Chart height in pixels */
  height: number;
  /** Array of link data representing flows */
  data: LinkData[];
  /** Color scheme identifier (e.g., 'd3Category10') */
  colorScheme: string;
  /** Chart margins */
  margin: {
    top: number;
    right: number;
    bottom: number;
    left: number;
  };
  /** Slice identifier for color consistency */
  sliceId: string | number;
}

Control Panel Configuration

Control panel sections and options available in Superset UI.

/**
 * Control panel configuration with sections and controls
 */
interface ControlPanelConfig {
  controlPanelSections: Array<{
    label: string;
    expanded: boolean;
    controlSetRows: string[][];
  }>;
  controlOverrides: {
    groupby: {
      label: string;
      description: string;
    };
  };
}

Available Control Sections:

  • Time Range: Legacy time range controls (legacyRegularTime)
  • Query: Core data selection controls
    • groupby: Source and target column selection (labeled "Source / Target")
    • metric: Metric/value column for flow weights
    • adhoc_filters: Additional filtering conditions
    • row_limit: Maximum number of records to process
  • Chart Options: Visual customization
    • color_scheme: Color palette selection for nodes/links

Form Data Structure:

interface FormData {
  /** Source and target columns array */
  groupby: string[];
  /** Metric column for flow values */
  metric: string;
  /** Selected color scheme identifier */
  color_scheme: string;
  /** Maximum number of rows to process */
  row_limit: number;
  /** Additional filter conditions */
  adhoc_filters: AdhocFilter[];
}

Styling and CSS Classes

The chart applies specific CSS classes for customization.

/* Main container class for the entire chart */
.superset-legacy-chart-sankey-loop {
  /* Root SVG container */
}

/* Node rectangle styling */
.superset-legacy-chart-sankey-loop .node rect {
  cursor: move;
  fill-opacity: 0.9;
  shape-rendering: crispEdges;
}

/* Node text label styling */
.superset-legacy-chart-sankey-loop .node text {
  pointer-events: none;
  text-shadow: 0 1px 0 #fff;
}

/* Link default styling */
.superset-legacy-chart-sankey-loop .link {
  fill: none;
  stroke: #000;
  stroke-opacity: 0.2;
}

/* Link hover effects */
.superset-legacy-chart-sankey-loop .link:hover {
  stroke-opacity: 0.5;
}

/* Link path elements */
.superset-legacy-chart-sankey-loop .link path {
  opacity: 0.2;
  stroke-opacity: 0;
}

.superset-legacy-chart-sankey-loop .link:hover path {
  opacity: 0.5;
}

/* Link text labels showing values */
.superset-legacy-chart-sankey-loop .link text {
  fill: #666;
  font-size: 10px;
}

.superset-legacy-chart-sankey-loop .link:hover text {
  opacity: 1;
}

Error Handling

The plugin follows Superset's error handling patterns. Common issues include:

  • Data format errors: Ensure data contains source, target, and value fields
  • Missing dependencies: Verify peer dependencies @superset-ui/core and @superset-ui/chart-controls are installed
  • Registration errors: Ensure plugin is registered before use in charts

Dependencies

/**
 * Required peer dependencies
 */
interface PeerDependencies {
  "@superset-ui/chart-controls": string;
  "@superset-ui/core": string;
}

/**
 * Direct dependencies
 */
interface Dependencies {
  "d3-sankey-diagram": "^0.7.3";
  "d3-selection": "^1.4.0";
  "prop-types": "^15.6.2";
}

Key Features

  • Loop Support: Handles cyclic relationships in data flows unlike traditional Sankey diagrams
  • D3.js Integration: Leverages d3-sankey-diagram for optimized SVG rendering
  • Interactive Tooltips: Hover interactions with value and percentage displays
  • Categorical Colors: Supports Superset's color scheme system
  • Responsive Design: Configurable margins and dimensions
  • Superset Integration: Full compatibility with Superset's dashboard and exploration interface
  • Legacy API Support: Uses Superset's legacy API format for data queries