import type { DataItem } from "../../core/render/Component"; import type { ColorSet } from "../../core/util/ColorSet"; import type { Percent } from "../../core/util/Percent"; import type { IPoint } from "../../core/util/IPoint"; import type { Time } from "../../core/util/Animation"; import { Series, ISeriesSettings, ISeriesDataItem, ISeriesPrivate } from "../../core/render/Series"; import { Label } from "../../core/render/Label"; import { Container } from "../../core/render/Container"; import { Graphics } from "../../core/render/Graphics"; import { ListTemplate } from "../../core/util/List"; import type { Color } from "../../core/util/Color"; export interface IWordCloudDataItem extends ISeriesDataItem { /** * The word. */ category: string; /** * The label that shows the word. */ label: Label; /** * The word's color. */ fill: Color; /** * @ignore */ set: number; /** * @ignore */ angle: number; /** * @ignore */ fontSize: number; } export interface IWordCloudSettings extends ISeriesSettings { /** * Duration, in milliseconds, of words moving to their new places when the * cloud is laid out again, as when the chart resizes. */ animationDuration?: number; /** * Easing of words moving to their new places. * * @see {@link https://www.amcharts.com/docs/v5/concepts/animations/#Easing_functions} for more info * @default am5.ease.out(am5.ease.cubic) */ animationEasing?: (t: Time) => Time; /** * Shrinks all words until every one of them fits. When off, words that * don't fit are left out. * * @default true */ autoFit?: boolean; /** * Layout progress, from `0` to `1`. The layout runs in one pass, so this * turns `1` each time it finishes: watch it to know when words are placed. * * @readonly */ progress?: number; /** * Colors for words with no `fill` in data, one after another. */ colors?: ColorSet; /** * Field in `data` that holds the words. * * @default "category" */ categoryField?: string; /** * Field in `data` that holds a word's color. * * @default "fill" */ fillField?: string; /** * Text to make the cloud from: each word's value is the number of times it * appears. Replaces `data`. */ text?: string; /** * Font size of the words with the lowest value: in pixels, or a share of * the smaller of the cloud's width and height. * * @default am5.percent(2) */ minFontSize?: number | Percent; /** * Font size of the words with the highest value: in pixels, or a share of * the smaller of the cloud's width and height. * * @default am5.percent(15) */ maxFontSize?: number | Percent; /** * Fewest times a word must appear in `text` to be shown. */ minValue?: number; /** * Most words to take from `text`, most frequent first. Doesn't limit * `data`. */ maxCount?: number; /** * Words of `text` to leave out. Case-sensitive. */ excludeWords?: Array; /** * How randomly words are placed, from `0` (from the middle outwards, in * order of value) to `1`. * * @default 0 */ randomness?: number; /** * Fewest characters a word of `text` must have to be shown. * * @default 1 */ minWordLength?: number; /** * Angles, in degrees, that words can be rotated to. * * @default [0, -90] */ angles?: number[]; /** * Gives each word a random angle from `angles`, so the cloud differs on * every layout. When `false`, words take `angles` in turn, which with * `randomness: 0` makes the layout the same every time. * * @since 5.20.1 * @default true */ randomizeAngles?: boolean; /** * Lets small words tuck into the gaps between a bigger word's letters, so * the cloud packs tightly, though the words' boxes overlap. Set to `false` * to keep boxes apart, as for labels with an opaque `background`. * * @since 5.20.1 * @default true */ allowNesting?: boolean; /** * Spacing of the spiral of points that words are tried at. Smaller packs * words more tightly, but takes longer. * * @default 15 */ step?: number; /** * Experimental: an SVG path for the words to fill, scaled to fit the * cloud. * * The fit is approximate. Simple, bold shapes work best; tune * `shapeTolerance`, `maskByShape`, `angles`, `minFontSize` and * `maxFontSize` for a better fill. * * @since 5.20.1 */ svgPath?: string; /** * How many more pixels a word may reach past the `svgPath` outline, on top * of the bit each word overhangs by itself in proportion to its size. A * negative value keeps words further inside. * * Affects placement only, not the drawn `shape`. * * @since 5.20.1 * @default 0 */ shapeTolerance?: number; /** * Clips the words to the `svgPath` shape, cutting off letters that reach * past its edge. * * @since 5.20.1 * @default false */ maskByShape?: boolean; } export interface IWordCloudPrivate extends ISeriesPrivate { /** * The factor `autoFit` scaled font sizes by to fit all words: `1` if it * didn't need to. */ adjustedFontSize: number; } /** * A bit-packed glyph mask of a single word (32 pixels per int), used by the * layout for in-memory collision detection. * * @ignore */ interface IWordSprite { bits: Int32Array; stride: number; bw: number; bh: number; } /** * A computed placement of a single word. No `point` means the word could not * be placed (label gets hidden). * * @ignore */ interface IWordPlacement { dataItem: DataItem; point?: IPoint; angle: number; fontSize: number; } /** * A word cloud: words sized by their values, from `data` or counted in * `text`. * * @see {@link https://www.amcharts.com/docs/v5/charts/word-cloud/} for more info * @important */ export declare class WordCloud extends Series { static className: string; static classNames: Array; _settings: IWordCloudSettings; _privateSettings: IWordCloudPrivate; _dataItemSettings: IWordCloudDataItem; /** * Draws the `svgPath` shape behind the words, while it is set: a faint * silhouette by default. Style it with `series.shape.setAll({ ... })`; its * geometry and visibility are the series'. * * @since 5.20.1 */ readonly shape: Graphics; protected _pointSets: Array>; protected _sets: number; protected _board: Int32Array; protected _boardW: number; protected _boardH: number; protected _boardStride: number; protected _scratchCanvas?: HTMLCanvasElement; protected _scratchContext?: CanvasRenderingContext2D; protected _shapeMask?: Int32Array; protected _shapeMaskKey?: string; protected _shapeCandidates?: Array; protected _labelsContainer: Container; protected _maskApplied: boolean; protected _shapeScale: number; protected _shapeTx: number; protected _shapeTy: number; protected _svgPathWarned: boolean; protected _afterNew(): void; /** * Labels of all words. Configure them through `labels.template`. */ readonly labels: ListTemplate