import type { ISparklineGroup } from '@univerjs-pro/sheets-sparkline'; import type { IRange } from '@univerjs/core'; import { SparklineTypeEnum } from '@univerjs-pro/sheets-sparkline'; import { FWorksheet } from '@univerjs/sheets/facade'; import { FSparkline } from './f-sparkline'; import { FSparklineGroup } from './f-sparkline-group'; /** * @ignore */ export interface IFWorksheetSparklineMixin { /** * @description Add sparkline to the worksheet. * @param {IRange[]} sourceRanges Source data location for sparklines * @param {IRange[]} targetRanges Where to place sparklines * @param {SparklineTypeEnum} [type] The chart type. Defaults to a line chart. * @returns {FSparklineGroup | undefined} The group containing all created sparklines, or undefined if creation fails. * * @example * ```ts * const fWorkbook = univerAPI.getActiveWorkbook(); * const fWorksheet = fWorkbook.getSheetByName('Sheet1'); * if (!fWorksheet) return; * * // Create a sparkline in the range A10, with the data source in the range A1:A7. * const sourceRanges = [fWorksheet.getRange('A1:A7').getRange()]; * const targetRanges = [fWorksheet.getRange('A10').getRange()]; * const group = fWorksheet.addSparkline(sourceRanges, targetRanges); * group?.setConfig({ lineWidth: 3 }); * ``` */ addSparkline(sourceRanges: IRange[], targetRanges: IRange[], type?: SparklineTypeEnum): FSparklineGroup | undefined; /** * @description Get all sparklines in the worksheet. * @returns {Map | undefined} - The key is sparkline group id. * * @example * ```ts * const fWorkbook = univerAPI.getActiveWorkbook(); * const fWorksheet = fWorkbook.getSheetByName('Sheet1'); * if (!fWorksheet) return; * * // Get all sparklines in the current worksheet * const allSparkline = fWorksheet.getAllSubSparkline(); * console.log('allSparkline', allSparkline); * ``` */ getAllSubSparkline(): Map | undefined; /** * @description Group the sparklines in the selection into a new sparkline group * @param {IRange[]} ranges - The selection range to be grouped * @returns {void} * * @example * ```ts * const fWorkbook = univerAPI.getActiveWorkbook(); * const fWorksheet = fWorkbook.getSheetByName('Sheet1'); * if (!fWorksheet) return; * * // Create a sparkline in the range A10, with the data source in the range A1:A7. * const firstSparkline = fWorksheet.addSparkline( * [fWorksheet.getRange('A1:A7').getRange()], * [fWorksheet.getRange('A10').getRange()] * ); * // Create a sparkline in the range B10, with the data source in the range B1:B7. * const secondSparkline = fWorksheet.addSparkline( * [fWorksheet.getRange('B1:B7').getRange()], * [fWorksheet.getRange('B10').getRange()] * ); * console.log('debugger', fWorksheet.getAllSubSparkline().size); // 2 * * // Compose the two sparklines into one group after 3 seconds * setTimeout(() => { * fWorksheet.composeSparkline([fWorksheet.getRange('A10:B10').getRange()]); * console.log('debugger', fWorksheet.getAllSubSparkline().size); // 1 * }, 3000); * ``` */ composeSparkline(ranges: IRange[]): void; /** * @description Split the sparkline group within the current selection * @param {IRange[]} ranges - The selection range to be ungrouped * * @example * ```ts * const fWorkbook = univerAPI.getActiveWorkbook(); * const fWorksheet = fWorkbook.getSheetByName('Sheet1'); * if (!fWorksheet) return; * * // Create a sparkline in the range A10, with the data source in the range A1:A7. * const firstSparkline = fWorksheet.addSparkline( * [fWorksheet.getRange('A1:A7').getRange()], * [fWorksheet.getRange('A10').getRange()] * ); * // Create a sparkline in the range B10, with the data source in the range B1:B7. * const secondSparkline = fWorksheet.addSparkline( * [fWorksheet.getRange('B1:B7').getRange()], * [fWorksheet.getRange('B10').getRange()] * ); * * // Compose the two sparklines into one group * fWorksheet.composeSparkline([fWorksheet.getRange('A10:B10').getRange()]); * console.log('debugger', fWorksheet.getAllSubSparkline().size); // 1 * * // Uncompose the sparkline group after 3 seconds * setTimeout(() => { * fWorksheet.unComposeSparkline([fWorksheet.getRange('A10:B10').getRange()]); * console.log('debugger', fWorksheet.getAllSubSparkline().size); // 2 * }, 3000); * ``` */ unComposeSparkline(ranges: IRange[]): void; /** * @description Get the sparkline instance of the current cell * @param {number} row - The row index of the cell, start at 0. * @param {number} col - The column index of the cell, start at 0. * @returns {FSparkline | undefined} Returns the sparkline instance for the next call * * @example * ```ts * const fWorkbook = univerAPI.getActiveWorkbook(); * const fWorksheet = fWorkbook.getSheetByName('Sheet1'); * if (!fWorksheet) return; * * // Create a sparkline in the range A10, with the data source in the range A1:A7. * const sourceRanges = [fWorksheet.getRange('A1:A7').getRange()]; * const targetRanges = [fWorksheet.getRange('A10').getRange()]; * const sparkline = fWorksheet.addSparkline(sourceRanges, targetRanges); * * console.log('Cell A10: ', fWorksheet.getSparklineByCell(9, 0)); * console.log('Cell A11: ', fWorksheet.getSparklineByCell(10, 0)); * ``` */ getSparklineByCell(row: number, col: number): FSparkline | undefined; /** * @description Get the sparkline groups instance of the current cell * @param {number} row - The row index of the cell, start at 0. * @param {number} col - The column index of the cell, start at 0. * @returns {FSparklineGroup | undefined} Returns the sparkline group instance for the next call * * @example * ```ts * const fWorkbook = univerAPI.getActiveWorkbook(); * const fWorksheet = fWorkbook.getSheetByName('Sheet1'); * if (!fWorksheet) return; * * // Create a sparkline in the range A10, with the data source in the range A1:A7. * const firstSparkline = fWorksheet.addSparkline( * [fWorksheet.getRange('A1:A7').getRange()], * [fWorksheet.getRange('A10').getRange()] * ); * // Create a sparkline in the range B10, with the data source in the range B1:B7. * const secondSparkline = fWorksheet.addSparkline( * [fWorksheet.getRange('B1:B7').getRange()], * [fWorksheet.getRange('B10').getRange()] * ); * console.log('Cell A10: ', fWorksheet.getSparklineGroupByCell(9, 0)); * * // Compose the two sparklines into one group after 3 seconds * setTimeout(() => { * fWorksheet.composeSparkline([fWorksheet.getRange('A10:B10').getRange()]); * console.log('Cell A10: ', fWorksheet.getSparklineGroupByCell(9, 0)); * }, 3000); * ``` */ getSparklineGroupByCell(row: number, col: number): FSparklineGroup | undefined; } export declare class FWorksheetSparklineMixin extends FWorksheet implements IFWorksheetSparklineMixin { addSparkline(sourceRanges: IRange[], targetRanges: IRange[], type?: SparklineTypeEnum): FSparklineGroup | undefined; getAllSubSparkline(): Map | undefined; composeSparkline(ranges: IRange[]): void; unComposeSparkline(ranges: IRange[]): void; getSparklineByCell(row: number, col: number): FSparkline | undefined; getSparklineGroupByCell(row: number, col: number): FSparklineGroup | undefined; } declare module '@univerjs/sheets/facade' { interface FWorksheet extends IFWorksheetSparklineMixin { } }