@harryjwang/simplewordcloud
Version:
A simple word cloud generator supporting English and Chinese text
76 lines • 2.5 kB
TypeScript
import { Language } from './tokenizers';
/**
* Word cloud configuration options
*/
export interface WordCloudOptions {
/** Width of the word cloud in pixels */
width?: number;
/** Height of the word cloud in pixels */
height?: number;
/** Font family to use for the words */
fontFamily?: string;
/** Maximum number of words to include in the cloud */
maxWords?: number;
/** Color scheme to use for the words */
colors?: readonly string[];
/** Padding between words in pixels */
padding?: number;
/** Minimum font size for words */
minFontSize?: number;
/** Maximum font size for words */
maxFontSize?: number;
/** Rotation angles for words (in degrees) */
rotationAngles?: number[];
/** Probability of word rotation */
rotationProbability?: number;
}
/**
* Word cloud generator for English and Chinese text
*/
export declare class WordCloud {
private options;
/**
* Create a new word cloud generator
* @param options Configuration options for the word cloud
*/
constructor(options?: WordCloudOptions);
/**
* Generate a word cloud from text
* @param text The input text
* @param language The language of the text ('english' or 'chinese')
* @returns An SVG element containing the word cloud (in browser) or SVG string (in Node.js)
*/
generate(text: string, language: Language): SVGElement | string;
/**
* Generate a word cloud and return it as an SVG string
* @param text The input text
* @param language The language of the text ('english' or 'chinese')
* @returns A string containing the SVG markup
*/
generateSVG(text: string, language: Language): string;
/**
* Generate SVG string directly (for Node.js environment)
* @param words The words to include in the cloud
* @returns SVG markup as a string
*/
private generateSVGString;
/**
* Scale the font size based on word frequency
* @param count The word count
* @param wordCounts Map of all word counts
* @returns The scaled font size
*/
private scaleFontSize;
/**
* Get a random rotation angle for a word
* @returns The rotation angle in degrees
*/
private getRotation;
/**
* Draw the word cloud on the SVG element (browser only)
* @param words The words to draw
* @param svg The SVG element to draw on
*/
private draw;
}
//# sourceMappingURL=wordcloud.d.ts.map