import { ChartLocation } from '../../common/utils/helper'; import { Chart } from '../chart'; import { Size, Rect } from '@syncfusion/ej2-svg-base'; import { BorderModel, FontModel } from '../../common/model/base-model'; import { DataLabelSettingsModel } from '../series/chart-series-model'; import { Series, Points } from './chart-series'; /** * Metadata captured for one data label instance during Smart Labels Pass 1 (series rendering). * Nothing is drawn when this is created - Pass 2 (renderSmartLabels) consumes these once every * series, marker and series-element bound on the chart is known. * * @private */ interface SmartLabelPendingInfo { series: Series; point: Points; dataLabel: DataLabelSettingsModel; text: string; /** Resolved final text color (argsData.font.color, else the same contrast-based fallback the normal path uses). */ color: string; /** The label's background/shape fill (argsData.color - may differ from dataLabel.fill via the textRender event). */ backgroundFill: string; /** The label's border (argsData.border - may differ from dataLabel.border via the textRender event). */ border: BorderModel; /** The label's font (argsData.font - may differ from dataLabel.font via the textRender event). */ font: FontModel; /** Whether this label draws a background shape at all (this.isShape, snapshotted per-label). */ isShape: boolean; textSize: Size; /** The rect the legacy (non-smart) positioning logic would have used, in chart/plot-area space. */ desiredRect: Rect; /** The point's symbol location, in chart/plot-area space. */ anchor: ChartLocation; /** The point's own series-element bounds (column/bar/candle rect, etc.), in chart/plot-area space. */ ownRegion: Rect | null; labelIndex: number; /** The series clip rect, kept so Pass 2 can convert absolute chart-space rects back to clip-relative * coordinates when drawing (drawSmartLabelElement / drawConnectorLine re-apply this offset). */ clip: Rect; } /** * A rendered, non-relocated data label that must be hidden if it overlaps a series element. * * @private */ interface SeriesOverlapLabel { series: Series; point: Points; rect: Rect; textElement: Element; shapeId: string; } /** * The `DataLabel` module is used to render data labels for data points. */ export declare class DataLabel { private chart; private margin; private isShape; private locationX; private locationY; private fontBackground; private borderWidth; private markerHeight; commonId: string; private yAxisInversed; private inverted; private errorHeight; private chartBackground; private extraSpace; /** * Stores the resolved label position selected during automatic * collision resolution. * * @private */ private actualPosition; /** @private */ dataLabelRectCollection: { [id: string]: Rect; }; /** @private */ repositionedLabels: Rect[]; /** Keys (label text + point location) of labels already rendered, used by `showDuplicateLabels`. */ private renderedLabelKeys; private keyCollectionOwner; /** * Smart Labels (enableSmartLabels) Pass 1 storage: one entry per data label instance whose * placement has been deferred to Pass 2 (renderSmartLabels). Cleared at the end of Pass 2. * * @private */ pendingSmartLabels: SmartLabelPendingInfo[]; /** * Labels rendered while `seriesOverlapAction` is 'Hide', checked once all series elements exist. * * @private */ seriesOverlapLabels: SeriesOverlapLabel[]; /** Series element geometry used while Smart Labels are placed; null when not required. */ private seriesElementBounds; /** * Constructor for the data label module. * * @private */ constructor(chart: Chart); private initPrivateVariables; private calculateErrorHeight; private isRectSeries; /** * Render the data label for series. * * @param {Series} series - The series to render. * @param {Chart} chart - The parent chart. * @param {DataLabelSettingsModel} dataLabel - The settings for data labels. * @returns {void} * @private */ render(series: Series, chart: Chart, dataLabel: DataLabelSettingsModel): void; /** * Checks whether a label with the same text has already been rendered at the same point location, * and registers the label otherwise. * * @param {Points} point - The point being rendered. * @param {number} index - The label index of the point. * @param {string} text - The label text. * @returns {boolean} true if an identical label already exists at this location. */ private isDuplicateLabel; renderDataLabel(series: Series, point: Points, element: HTMLElement, dataLabel: DataLabelSettingsModel): Element[]; /** * Renders the stack labels for the chart. * * This method is responsible for displaying cumulative total values on stacked chart segments. * * @returns {void} */ renderStackLabels(): void; /** * This method is responsible for positioning the cumulative sum of stacking column series. * * @param {Object} positivePoints - The positive points of the stacking series. * @param {Object} negativePoints - The negative points of the stacking series. * @param {Object} zeroPoints - The zero points of the stacking series. * @param {Series[]} seriesInGroup - The array of series in group. * @param {Element} stackLabelGroup - The stack label group element. * @param {number} stackLabelIndex - The index of the stack label. * @returns {number} - The number of stack labels. */ calculateStackLabel(positivePoints: { [xValue: string]: Points; }, negativePoints: { [xValue: string]: Points; }, zeroPoints: { [xValue: string]: Points; }, seriesInGroup: Series[], stackLabelGroup: Element, stackLabelIndex: number): number; /** * Retrieves the points of a rectangle. * * @param {Rect} rect - The rectangle whose points are to be retrieved. * @returns {ChartLocation[]} - The points of the rectangle. */ private getRectanglePoints; private isDataLabelOverlapWithChartBound; /** * Creates a template for data labels. * * @param {HTMLElement} parentElement - The parent element to which the template will be appended. * @param {Series} series - The series associated with the data label. * @param {DataLabelSettingsModel} dataLabel - The settings for the data label. * @param {Points} point - The data point to which the data label is associated. * @param {ITextRenderEventArgs} data - The event data associated with rendering the data label. * @param {number} labelIndex - The index of the data label. * @param {boolean} redraw - Specifies whether to redraw the template. * @param {number} angle - Specifies the angle of rotation. * @returns {void} */ private createDataLabelTemplate; calculateTemplateLabelSize(parentElement: HTMLElement, childElement: HTMLElement, point: Points, series: Series, dataLabel: DataLabelSettingsModel, labelIndex: number, clip: Rect, redraw: boolean, isReactCallback?: boolean, angle?: number): void; private calculateTextPosition; private calculatePolarRectPosition; /** * Gets the location for the data label. * * @param {Points} point - The data point associated with the label. * @param {Series} series - The series associated with the data label. * @param {Size} textSize - The size of the text to be displayed in the data label. * @param {number} labelIndex - The index of the data label. * @returns {ChartLocation} - The location for the data label. */ private getLabelLocation; private calculateRectPosition; private calculatePathPosition; private isDataLabelShape; private calculateRectActualPosition; private calculateAlignment; private calculateTopAndOuterPosition; /** * Updates the location of the data label. * * @param {LabelPosition} position - The position of the data label. * @param {number} location - The initial location of the data label. * @param {number} extraSpace - Extra space to adjust the label position. * @param {MarginModel} margin - The margin for the chart. * @param {Rect} rect - The rectangle associated with the data label. * @param {boolean} top - Indicates whether the label is positioned at the top. * @param {boolean} inside - Indicates whether the label is inside the chart area. * @returns {number} The updated location of the data label. */ private updateLabelLocation; private calculatePathActualPosition; /** * Draws a connector line from the repositioned label to the data point. * * @param {ChartLocation} labelLocation - The location of the repositioned label. * @param {ChartLocation} pointLocation - The location of the data point. * @param {Series} series - The series associated with the data label. * @param {Points} point - The data point to which the data label is associated. * @param {DataLabelSettingsModel} dataLabel - The data label settings. * @param {number} labelIndex - The index of the label within the point (0 for the primary label). * @returns {void} * @private */ private drawConnectorLine; private getConnectorId; /** * Draws a pointer shape at the connection point. * * @param {ChartLocation} labelLocation - The location of the repositioned label. * @param {ChartLocation} pointLocation - The location of the data point. * @param {Series} series - The series associated with the data label. * @param {Points} point - The data point to which the data label is associated. * @param {DataLabelSettingsModel} dataLabel - The data label settings. * @param {string} color - The color of the pointer. * @param {number} opacity - The opacity of the pointer. * @param {number} labelIndex - The index of the label within the point (0 for the primary label). * @returns {void} * @private */ private drawPointerShape; /** * Initiates the animation for data labels. * * @param {Series} series - The series associated with the data labels. * @param {Element} [element] - The element to animate. * @returns {void} * @private */ doDataLabelAnimation(series: Series, element?: Element): void; private getPosition; private collectSmartLabel; /** * Pass 1: places every pending Smart Label one by one (spec section 8), each validated against * chart bounds, series markers, series elements (own and other series) and every label already * placed in this pass, using a Top/Bottom/Left/Right/Outer/Inner search with progressively * increasing offset (spec sections 2-4), drawing a connector line only when the label actually * moved off its point (spec section 5). * * @returns {void} * @private */ renderSmartLabels(): void; /** * Hides every label rendered with `seriesOverlapAction` that overlaps a series element. * Runs once all series are rendered, because the elements of later series do not exist while an * earlier series renders its labels. Labels are never moved here. * * @returns {void} * @private */ hideLabelsOverlappingSeriesElements(): void; private hidesOnSeriesOverlap; /** * Collects the rendered geometry of every visible series: the regions of rectangular series and the * path (sampled to a polyline) of line, area and trendline series. * * @returns {SeriesElementBounds[]} - chart/plot-area space geometry per series. * @private */ private collectElementBounds; /** * Converts an SVG path (absolute M, L, H, V, C, S, Q, T, A, Z commands) into polylines, sampling curves. * * @param {string} direction - The `d` attribute of the path. * @param {Rect} clip - The series clip rect used to shift the vertices. * @returns {ChartLocation[]} - Array of polylines (each sub path as an array of points). * @private */ private parsePath; /** * Checks whether a label rect overlaps any series element. The rectangular element of the label's own * point is ignored, and so is the filled region of the label's own area series. * * @param {Rect} rect - The label rect in chart/plot-area space. * @param {SeriesElementBounds[]} elements - The collected series geometry. * @param {Series} ownSeries - The series the label belongs to. * @param {Points} ownPoint - The point the label belongs to. * @returns {boolean} - True when the label overlaps a series element. * @private */ private overlapsSeriesElement; private segmentIntersectsRect; private isInsidePolygon; /** * Builds marker collision regions from every visible point's `symbolLocations`, sized by that * series' own configured marker width/height. Only series with a visible marker contribute * blockers, since an invisible marker occupies no drawn space to avoid. * * @returns {Rect[]} - chart/plot-area-space bounds for every rendered marker. * @private */ private collectMarkerBounds; private buildSmartLabelCandidates; private getRangeSmartLabelSide; private buildRangeSmartLabelRect; private clampCandidateToClipRect; private placeSmartLabel; private drawSmartLabelElement; /** * Get module name. * * @returns {string} - Returns the module name. */ protected getModuleName(): string; /** * To destroy the dataLabel for series. * * @returns {void} * @private */ destroy(): void; } export {};