UNPKG

drizzle-cube

Version:

Drizzle ORM-first semantic layer with Cube.js compatibility. Type-safe analytics and dashboards with SQL injection protection.

65 lines (64 loc) 2.88 kB
import { ChartType, ChartAxisConfig } from '../types'; import { MetricItem, BreakdownItem } from '../components/AnalysisBuilder/types'; /** * Result of smart chart defaults calculation */ export interface SmartChartDefaults { /** The recommended chart type */ chartType: ChartType; /** The auto-configured chart axis settings */ chartConfig: ChartAxisConfig; } /** * Availability status for a chart type */ export interface ChartAvailability { /** Whether the chart type can be used with current selections */ available: boolean; /** Reason why the chart is unavailable (for tooltip) */ reason?: string; } /** * Map of chart type availability statuses */ export type ChartAvailabilityMap = Record<ChartType, ChartAvailability>; /** * Check if a specific chart type is available given current selections */ export declare function getChartAvailability(chartType: ChartType, metrics: MetricItem[], breakdowns: BreakdownItem[]): ChartAvailability; /** * Get availability for all chart types */ export declare function getAllChartAvailability(metrics: MetricItem[], breakdowns: BreakdownItem[]): ChartAvailabilityMap; /** * Select the best chart type based on current metrics and breakdowns * * Priority order: * 1. If current chart type is still valid, keep it (preserve user intent) * 2. If current chart becomes invalid, switch to best alternative: * - Has time dimension → line * - Has dimension + measure → bar * - Has measures only → bar (or kpiNumber if single measure + no breakdowns) * - No fields → keep current */ export declare function selectBestChartType(metrics: MetricItem[], breakdowns: BreakdownItem[], currentChartType: ChartType): ChartType; /** * Get smart default chart configuration based on chart type and selections */ export declare function getSmartChartDefaults(metrics: MetricItem[], breakdowns: BreakdownItem[], currentChartType: ChartType): SmartChartDefaults; /** * Determine if chart type should be auto-switched based on selections change * * Returns the new chart type if a switch is recommended, or null if no change needed. * * @param metrics - Current metrics selection * @param breakdowns - Current breakdowns selection * @param currentChartType - Current chart type * @param userManuallySelected - Whether user manually selected the current chart type */ export declare function shouldAutoSwitchChartType(metrics: MetricItem[], breakdowns: BreakdownItem[], currentChartType: ChartType, userManuallySelected: boolean): ChartType | null; /** * Merge existing chart config with smart defaults * Only fills in missing or invalid fields, preserves valid existing config */ export declare function mergeChartConfigWithDefaults(existingConfig: ChartAxisConfig, smartDefaults: ChartAxisConfig, metrics: MetricItem[], breakdowns: BreakdownItem[]): ChartAxisConfig;