/** * 将数字或字符串格式化为字符串。 * * @param value - 要格式化的值,可以是字符串或数字。 * @returns 格式化后的字符串。如果输入值为字符串,则直接返回该字符串; * 如果输入值为数字,则使用 `intl.format` 方法格式化后返回; * 如果输入值为空或格式化过程中发生错误,则返回原始值。 */ export declare const stringFormatNumber: (value: string | number) => string | number; /** * 防抖函数 * * 创建一个防抖函数,该函数会在调用后等待指定的延迟时间, * 如果在延迟时间内再次调用,则重新开始计时。 * 常用于限制函数调用频率,如搜索输入、窗口调整等场景。 * * @param {Function} func - 要防抖的函数 * @param {number} delay - 延迟时间(毫秒) * @returns {Function} 防抖后的函数,包含以下方法: * - `flush()`: 立即执行函数并清除定时器 * - `cancel()`: 取消延迟执行 * * @example * ```typescript * const debouncedSearch = debounce((query: string) => { * console.log('搜索:', query); * }, 300); * * // 调用防抖函数 * debouncedSearch('hello'); * debouncedSearch('world'); // 只有这个会执行 * * // 立即执行 * debouncedSearch.flush(); * * // 取消执行 * debouncedSearch.cancel(); * ``` * * @since 1.0.0 */ export declare function debounce(func: { (): void; apply?: any; }, delay: number | undefined): { (): void; flush(): void; cancel(): void; }; /** * 图表数据项接口 * * 定义了图表中单个数据项的结构,用于统一各种图表类型的数据格式。 * 支持多种图表类型的数据表示,包括分类、类型、坐标等信息。 * * @interface ChartDataItem * @since 1.0.0 * * @example * ```typescript * const dataItem: ChartDataItem = { * x: '2024-01', * y: 100, * category: '销售', * type: '产品A', * xtitle: '月份', * ytitle: '销售额', * filterLabel: 'Q1' * }; * ``` */ export interface ChartDataItem { /** 数据类别,用于数据分组和筛选 */ category?: string; /** 数据类型,用于区分不同的数据系列 */ type?: string; /** X轴值,可以是数字或字符串 */ x: number | string; /** Y轴值,可以是数字或字符串 */ y: number | string; /** X轴标题,用于显示轴标签 */ xtitle?: string; /** Y轴标题,用于显示轴标签 */ ytitle?: string; /** 筛选标签,用于数据筛选和过滤 */ filterLabel?: string; /** 类目排序键;配置 `sortBy` / `index` 列后用于 X 轴顺序 */ sortBy?: number | string; } /** 未提供 type 时的默认数据序列名(与折线/柱状等图表一致) */ export declare const DEFAULT_CHART_DATASET_TYPE = "\u9ED8\u8BA4"; /** 未配置 sortBy 时,若表格存在该列则自动用于 X 轴排序 */ export declare const CHART_AUTO_SORT_BY_COLUMN = "index"; /** * 雷达图数据项:与 {@link ChartDataItem} 同形。 * - `x`:雷达轴维度(如「产品」「技术」) * - `y`:分值 * - `type`:图例序列名 * - `category`:工具栏筛选项 * * 兼容历史字段 `label` / `score`(分别映射为 x / y)。 */ export type RadarChartDataItem = ChartDataItem & { /** @deprecated 请使用 x */ label?: string; /** @deprecated 请使用 y */ score?: number | string; }; export type RadarChartDataInput = Partial & { label?: string; score?: number | string; }; /** * 解析图表 Y 轴数值(雷达图分值、柱状图高度等) */ export declare const parseChartDataYValue: (value: number | string | null | undefined) => number; /** * 将雷达图入参归一化为 {@link ChartDataItem}(与 LineChart / BarChart 等一致) */ export declare const normalizeRadarChartData: (data: RadarChartDataInput[] | null | undefined) => ChartDataItem[]; /** * 将含「亿元 / 万元 / 元」的人民币口语字符串转为数值(以「元」为数值单位)。 * * - `533亿元` → `533 * 1e8` * - `549万元` → `549 * 1e4` * - `128.5元` → `128.5` * * 不含上述单位且无法识别为纯数字时返回 `null`,避免误解析如 `8%`。 * * @param value - 原始单元格或字段值 * @returns 解析后的有限数字,无法解析则为 `null` */ export declare const parseChineseCurrencyToNumber: (value: unknown) => number | null; /** * 归一化 X 轴值 * * 将字符串数字转换为数字类型,避免重复标签问题。 * 如果输入已经是数字,直接返回;如果是字符串,尝试转换为数字。 * 转换失败时返回原始值。 * * @param {number | string} value - 原始 X 轴值 * @returns {number | string} 归一化后的值 * * @example * ```typescript * normalizeXValue(123); // 123 * normalizeXValue('456'); // 456 * normalizeXValue('abc'); // 'abc' * normalizeXValue(''); // '' * ``` * * @since 1.0.0 */ export declare const normalizeXValue: (value: number | string) => number | string; /** * 比较两个 X 轴值的大小 * * 用于对 X 轴值进行排序,支持数字和字符串的混合比较。 * 比较规则: * 1. 数字优先于字符串 * 2. 数字按数值大小比较 * 3. 字符串按字典序比较 * * @param {number | string} a - 第一个值 * @param {number | string} b - 第二个值 * @returns {number} 比较结果:负数表示 a < b,0 表示 a = b,正数表示 a > b * * @example * ```typescript * compareXValues(1, 2); // -1 * compareXValues('a', 'b'); // -1 * compareXValues(1, 'a'); // -1 (数字优先) * compareXValues('a', 1); // 1 (数字优先) * ``` * * @since 1.0.0 */ export declare const compareXValues: (a: number | string, b: number | string) => number; /** * 解析 X 轴日期/日期区间的排序键;非日期返回 null */ export declare const parseChartXDateSortKey: (value: number | string) => number | null; export declare const isChartXDateOrRange: (value: number | string) => boolean; export declare const areAllChartXDateOrRange: (values: Array) => boolean; /** * 比较两个 X 轴日期/区间;非日期返回 0(不改变相对顺序) */ export declare const compareChartXValues: (a: number | string, b: number | string) => number; /** 按数据出现顺序去重提取 X 值 */ export declare const uniqueChartXValuesPreservingOrder: (data: ChartDataItem[]) => Array; /** * 表格行按 x 字段排序:仅当全部为日期/区间时排序,否则保持原顺序 */ export declare const sortChartDataRowsByXField: >(rows: T[], xField: string) => T[]; /** * 检查两个 X 轴值是否相等 * * 比较两个 X 轴值是否相等,支持数字和字符串的混合比较。 * 先对值进行归一化处理,然后进行比较。 * * @param {number | string} a - 第一个值 * @param {number | string} b - 第二个值 * @returns {boolean} 是否相等 * * @example * ```typescript * isXValueEqual(1, 1); // true * isXValueEqual('1', 1); // true * isXValueEqual('a', 'a'); // true * isXValueEqual(1, 2); // false * ``` * * @since 1.0.0 */ export declare const isXValueEqual: (a: number | string, b: number | string) => boolean; /** * 解析图表排序列名:显式 `sortBy` 优先,否则表格含 `index` 列时自动使用 */ export declare const resolveChartSortByField: (rows: Array> | null | undefined, explicitSortBy?: string, getCellValue?: (row: Record, field: string) => unknown) => string | undefined; /** * 解析 sortBy 排序字段值 */ export declare const parseSortByValue: (value: unknown) => number | string | null; /** * 比较两个 sortBy 值;缺失值排在后面 */ export declare const compareSortByValues: (a: number | string | null, b: number | string | null) => number; /** * 数据是否包含有效的 sortBy 字段 */ export declare const hasChartSortBy: (data: ChartDataItem[]) => boolean; /** * 取某一 x 类目对应的 sortBy(多行取最小值) */ export declare const getSortByForX: (data: ChartDataItem[], xValue: number | string) => number | string | null; /** * 从数据中提取并排序 X 轴值 * * 从图表数据数组中提取所有唯一的 X 轴值。 * 有 sortBy/index 时按 sortBy 排序;否则仅当全部为日期/日期区间时按时间排序,其余保持数据顺序。 * * @param {ChartDataItem[]} data - 图表数据数组 * @returns {Array} 排序后的唯一 X 轴值数组 * * @example * ```typescript * const data = [ * { x: '2024-01', y: 100 }, * { x: '2024-02', y: 200 }, * { x: '2024-01', y: 150 }, // 重复值 * { x: 3, y: 300 } * ]; * const sortedValues = extractAndSortXValues(data); * // ['2024-01', '2024-02', 3] * ``` * * @since 1.0.0 */ export declare const extractAndSortXValues: (data: ChartDataItem[]) => Array; /** * 根据 X 轴值查找对应的数据点 * * 在数据数组中查找指定 X 轴值对应的数据点。 * 可以指定数据类型进行精确匹配。 * * @param {ChartDataItem[]} data - 数据数组 * @param {number | string} xValue - X 轴值 * @param {string} [type] - 数据类型,可选 * @returns {ChartDataItem | undefined} 匹配的数据点,如果未找到返回 undefined * * @example * ```typescript * const data = [ * { x: '2024-01', y: 100, type: 'A' }, * { x: '2024-01', y: 200, type: 'B' }, * { x: '2024-02', y: 300, type: 'A' } * ]; * * // 查找所有类型 * findDataPointByXValue(data, '2024-01'); // 第一个匹配项 * * // 查找指定类型 * findDataPointByXValue(data, '2024-01', 'B'); // { x: '2024-01', y: 200, type: 'B' } * ``` * * @since 1.0.0 */ export declare const findDataPointByXValue: (data: ChartDataItem[], xValue: number | string, type?: string) => ChartDataItem | undefined; /** * 将值转换为数字 * * 安全地将任意值转换为数字类型,转换失败时返回默认值。 * 如果输入已经是有效的数字,直接返回;否则尝试转换。 * 字符串支持「亿元 / 万元 / 元」等人民币口语格式(见 `parseChineseCurrencyToNumber`)。 * * @param {any} val - 要转换的值 * @param {number} fallback - 转换失败时的默认值 * @returns {number} 转换后的数字 * * @example * ```typescript * toNumber('123', 0); // 123 * toNumber(456, 0); // 456 * toNumber('abc', 0); // 0 * toNumber(null, 100); // 100 * ``` * * @since 1.0.0 */ export declare const toNumber: (val: any, fallback: number) => number; /** * 检查值是否不为空 * * 检查值是否不为 null 和 undefined。 * 用于数据验证和条件判断。 * * @param {any} val - 要检查的值 * @returns {boolean} 是否不为空 * * @example * ```typescript * isNotEmpty('hello'); // true * isNotEmpty(0); // true * isNotEmpty(''); // true * isNotEmpty(null); // false * isNotEmpty(undefined); // false * ``` * * @since 1.0.0 */ export declare const isNotEmpty: (val: any) => boolean; /** * 生成数据数组的快速哈希值 * * 用于优化 useMemo 的依赖项比较,避免使用 JSON.stringify 的性能开销。 * 通过比较数组长度和最后一个元素的引用来快速判断数据是否变化。 * 适用于流式数据场景,当数据频繁追加时性能更好。 * * @param {any[]} data - 数据数组 * @returns {string} 哈希值字符串 * * @example * ```typescript * const hash1 = getDataHash([{ x: 1, y: 2 }]); * const hash2 = getDataHash([{ x: 1, y: 2 }, { x: 3, y: 4 }]); * // hash1 !== hash2 * ``` * * @since 1.0.0 */ export declare const getDataHash: (data: any[]) => string; /** * 深度比较两个配置对象的关键字段 * * 用于优化 useMemo 的依赖项比较,只比较配置的关键字段, * 避免对整个配置对象进行深度比较的性能开销。 * * @param {any} config1 - 第一个配置对象 * @param {any} config2 - 第二个配置对象 * @returns {boolean} 是否相等 * * @example * ```typescript * const config1 = { x: 'date', y: 'value', height: 400 }; * const config2 = { x: 'date', y: 'value', height: 400 }; * isConfigEqual(config1, config2); // true * ``` * * @since 1.0.0 */ export declare const isConfigEqual: (config1: any, config2: any) => boolean; /** * 从浏览器 DOM 中解析 CSS 变量的实际颜色值 * * @param {string} cssVar - CSS 变量表达式(如 'var(--color-blue)') * @returns {string} 解析后的颜色值(如 '#1d7afc')或原值 * * @example * ```typescript * resolveCssVariable('var(--color-blue-control-fill-primary)'); // '#1d7afc' * resolveCssVariable('#ff0000'); // '#ff0000' * ``` * * @since 1.0.0 */ export declare const resolveCssVariable: (cssVar: string) => string; /** * 将十六进制颜色或CSS变量转换为带透明度的 RGBA 字符串 * * 支持3位和6位十六进制颜色格式、CSS变量(如 var(--color-name)),并添加透明度。 * * @param {string} color - 颜色值(如 '#ff0000'、'#f00' 或 'var(--color-blue)') * @param {number} alpha - 透明度值(0-1之间) * @returns {string} RGBA 颜色字符串 * * @example * ```typescript * hexToRgba('#ff0000', 0.5); // 'rgba(255, 0, 0, 0.5)' * hexToRgba('#f00', 0.8); // 'rgba(255, 0, 0, 0.8)' * hexToRgba('var(--color-blue)', 0.5); // 'rgba(29, 122, 252, 0.5)' * ``` * * @since 1.0.0 */ export declare const hexToRgba: (color: string, alpha: number) => string; export { registerBarChartComponents, registerChartComponents, registerLineChartComponents, } from './utils/registerChart';