CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-superset-ui--plugin-chart-pivot-table

Superset Chart - Pivot Table provides comprehensive pivot table chart plugin for Apache Superset with interactive data visualization and summarization capabilities.

Pending
Overview
Eval results
Files

pivot-table-engine.mddocs/

Internal Architecture Details

This document describes the internal implementation architecture of the pivot table plugin. These components are internal implementation details and are not part of the public API of @superset-ui/plugin-chart-pivot-table.

Important: The components described here should not be imported or used directly. All functionality is available through the public PivotTableChartPlugin API.

Capabilities

PivotTable Component

Core pivot table rendering component from the internal react-pivottable library.

/**
 * Internal pivot table rendering component
 * Handles the actual pivot table display and interaction
 * Note: This is an internal component, not exported from the public API
 */
// Internal: PivotTable component from react-pivottable library

Aggregation Templates

Comprehensive set of built-in aggregation functions for data summarization.

/**
 * Internal collection of aggregation function templates
 * Each template returns a configured aggregation function
 * Note: This is internal to the plugin, not exported from the public API
 */
// Internal: aggregatorTemplates from react-pivottable utilities

interface AggregatorTemplates {
  /** Count of non-null values */
  count: (formatter: NumberFormatter) => AggregatorFunction;
  /** Count of unique values */
  countUnique: (formatter: NumberFormatter) => AggregatorFunction;
  /** List unique values separated by delimiter */
  listUnique: (separator: string, formatter: NumberFormatter) => AggregatorFunction;
  /** Sum of numeric values */
  sum: (formatter: NumberFormatter) => AggregatorFunction;
  /** Average of numeric values */
  average: (formatter: NumberFormatter) => AggregatorFunction;
  /** Median of numeric values */
  median: (formatter: NumberFormatter) => AggregatorFunction;
  /** Sample variance calculation */
  var: (ddof: number, formatter: NumberFormatter) => AggregatorFunction;
  /** Sample standard deviation calculation */
  stdev: (ddof: number, formatter: NumberFormatter) => AggregatorFunction;
  /** Minimum value */
  min: (formatter: NumberFormatter) => AggregatorFunction;
  /** Maximum value */
  max: (formatter: NumberFormatter) => AggregatorFunction;
  /** First non-null value */
  first: (formatter: NumberFormatter) => AggregatorFunction;
  /** Last non-null value */ 
  last: (formatter: NumberFormatter) => AggregatorFunction;
  /** Fraction calculations relative to total, row, or column */
  fractionOf: (
    numeratorAgg: AggregatorFunction,
    denominatorType: 'total' | 'row' | 'col',
    formatter: NumberFormatter
  ) => AggregatorFunction;
}

Usage Example:

import { aggregatorTemplates } from "@superset-ui/plugin-chart-pivot-table/src/react-pivottable";
import { getNumberFormatter } from "@superset-ui/core";

const formatter = getNumberFormatter('.2f');

// Create specific aggregation functions
const aggregators = {
  'Count': aggregatorTemplates.count(formatter),
  'Sum': aggregatorTemplates.sum(formatter),
  'Average': aggregatorTemplates.average(formatter),
  'Sum as % of Total': aggregatorTemplates.fractionOf(
    aggregatorTemplates.sum(),
    'total',
    formatter
  ),
};

Sorting Utilities

Utility functions for data sorting within the pivot table.

/**
 * Sorting utility function
 * Provides natural sorting for pivot table data
 */
export const sortAs: SortFunction;

type SortFunction = (order: string[]) => (a: string, b: string) => number;

Usage Example:

import { sortAs } from "@superset-ui/plugin-chart-pivot-table/src/react-pivottable";

// Create custom sort order
const customSort = sortAs(['High', 'Medium', 'Low']);
const sortedData = data.sort((a, b) => customSort(a.priority, b.priority));

Built-in Aggregation Functions

The pivot table engine provides a comprehensive factory for creating aggregation functions.

/**
 * Factory function that creates all available aggregation functions
 * @param formatter - Number formatter for displaying aggregated values
 * @returns Object containing all aggregation functions
 */
const aggregatorsFactory = (formatter: NumberFormatter) => ({
  /** Count of non-null values */
  'Count': AggregatorFunction;
  /** Count of unique values */
  'Count Unique Values': AggregatorFunction;
  /** List unique values with comma separation */
  'List Unique Values': AggregatorFunction;
  /** Sum of numeric values */
  'Sum': AggregatorFunction;
  /** Average of numeric values */
  'Average': AggregatorFunction;
  /** Median of numeric values */
  'Median': AggregatorFunction;
  /** Sample variance */
  'Sample Variance': AggregatorFunction;
  /** Sample standard deviation */
  'Sample Standard Deviation': AggregatorFunction;
  /** Minimum value */
  'Minimum': AggregatorFunction;
  /** Maximum value */
  'Maximum': AggregatorFunction;
  /** First non-null value */
  'First': AggregatorFunction;
  /** Last non-null value */
  'Last': AggregatorFunction;
  /** Sum as fraction of total */
  'Sum as Fraction of Total': AggregatorFunction;
  /** Sum as fraction of row total */
  'Sum as Fraction of Rows': AggregatorFunction;
  /** Sum as fraction of column total */
  'Sum as Fraction of Columns': AggregatorFunction;
  /** Count as fraction of total */
  'Count as Fraction of Total': AggregatorFunction;
  /** Count as fraction of row total */
  'Count as Fraction of Rows': AggregatorFunction;
  /** Count as fraction of column total */
  'Count as Fraction of Columns': AggregatorFunction;
});

AggregatorFunction Type

Type definition for aggregation functions used in the pivot table.

type AggregatorFunction = {
  /** Function to process and aggregate data values */
  (data: DataRecord[], rowKey: string[], colKey: string[]): {
    /** Aggregated numeric value */
    value: number;
    /** Formatted display string */
    format: (value: number) => string;
  };
};

NumberFormatter Type

Number formatting interface for displaying aggregated values.

interface NumberFormatter {
  /** Format a number for display */
  (value: number): string;
  /** Formatter ID */
  id: string;
}

Advanced Aggregation Usage

Custom Aggregation Configuration:

import { 
  aggregatorTemplates, 
  PivotTable 
} from "@superset-ui/plugin-chart-pivot-table/src/react-pivottable";
import { getNumberFormatter } from "@superset-ui/core";

const percentFormatter = getNumberFormatter('.1%');
const currencyFormatter = getNumberFormatter('$,.2f');

// Configure pivot table with custom aggregations
const pivotConfig = {
  data: salesData,
  rows: ['region'],
  cols: ['quarter'],
  aggregatorName: 'Sum',
  aggregators: {
    'Sum': aggregatorTemplates.sum(currencyFormatter),
    'Average': aggregatorTemplates.average(currencyFormatter),
    '% of Total': aggregatorTemplates.fractionOf(
      aggregatorTemplates.sum(),
      'total',
      percentFormatter
    ),
  },
  vals: ['amount']
};

Table Renderers

The engine supports various table rendering modes for different display requirements.

interface TableRenderer {
  /** Standard table renderer */
  'Table': ReactComponent;
  /** Table with bars for visual representation */
  'Table Barchart': ReactComponent;
  /** Heatmap table renderer */
  'Table Heatmap': ReactComponent;
  /** Row heatmap renderer */
  'Table Row Heatmap': ReactComponent;
  /** Column heatmap renderer */
  'Table Col Heatmap': ReactComponent;
}

Install with Tessl CLI

npx tessl i tessl/npm-superset-ui--plugin-chart-pivot-table

docs

chart-component.md

configuration-types.md

index.md

pivot-table-engine.md

plugin-registration.md

props-transformation.md

query-building.md

tile.json