Skip to content

API Reference ​

Text ​

constructor ​

typescript
constructor(container: string | HTMLElement);
ParameterTypeRequiredDescription
containerstring | HTMLElementYesContainer element, can be a DOM selector or DOM element

theme ​

ParameterTypeRequiredDescription
theme'dark' | 'light'YesTheme name
seedTokenPartial<SeedTokenOptions>NoTheme token config

Return Value

TypeDescription
TextText instance, supports method chaining

registerPlugin ​

ParameterTypeRequiredDescription
pluginPluginType | PluginType[]YesSingle plugin or array of plugins

Return Value

TypeDescription
TextText instance, supports method chaining

render ​

Renders the narrative text visualization with a T8 syntax string.

ParameterTypeRequiredDescription
t8SyntaxstringNoT8 syntax string to render

Return Value

TypeDescription
functionUnmount function to remove the visualization

Usage Example

typescript
// Render with T8 syntax string
text.theme('light').render(`
  # Sales Report
  Total sales are [ÂĨ1,234,567](metric_value).
`);

clear ​

Clears the visualization by unmounting it.

ParameterTypeRequiredDescription
(none)

unmount ​

Unmounts the visualization component.

ParameterTypeRequiredDescription
(none)

Schema ​

NarrativeTextSpec ​

typescript
interface NarrativeTextSpec {
  headline?: HeadlineSpec;
  sections?: SectionSpec[];
}
PropertyTypeRequiredDescription
headlineHeadlineSpecNoHeadline spec
sectionsSectionSpec[]NoArray of sections

SectionSpec ​

typescript
type SectionSpec = (StandardSectionSpec | CustomBlockElement) & CommonProps;
PropertyTypeRequiredDescription
paragraphsParagraphSpec[]NoArray of paragraphs
customTypestringNoCustom block type
stylesRecord<string, any>NoStyle object
classNamestringNoClass name

ParagraphSpec ​

typescript
type ParagraphSpec = HeadingParagraphSpec | TextParagraphSpec | BulletsParagraphSpec | CustomBlockElement;

enum ParagraphType {
  HEADING1 = 'heading1',
  HEADING2 = 'heading2',
  HEADING3 = 'heading3',
  HEADING4 = 'heading4',
  HEADING5 = 'heading5',
  HEADING6 = 'heading6',
  NORMAL = 'normal',
  BULLETS = 'bullets',
}
PropertyTypeRequiredDescription
typeParagraphTypeYesParagraph type
phrasesPhraseSpec[]YesArray of phrases
bulletsBulletItemSpec[]NoArray of bullet items (only for BULLETS type)
customTypestringNoCustom block type (only for custom blocks)

PhraseSpec ​

typescript
type PhraseSpec = TextPhraseSpec | EntityPhraseSpec | CustomPhraseSpec<CustomMetaData>;

enum PhraseType {
  TEXT = 'text',
  ENTITY = 'entity',
  CUSTOM = 'custom',
}
PropertyTypeRequiredDescription
typePhraseTypeYesPhrase type
valuestringYesPhrase content
metadataEntityMetaData | CustomMetaDataNoMetadata

EntityType ​

typescript
type EntityType =
  | 'metric_name' // Metric name, e.g., DAU
  | 'metric_value' // Metric value, e.g., 1.23 million
  | 'other_metric_value' // Other metric value
  | 'contribute_ratio' // Contribution ratio, e.g., 23%
  | 'delta_value' // Delta value, e.g., -1.2
  | 'ratio_value' // Ratio value, e.g., +23%
  | 'trend_desc' // Trend description, e.g., up/down
  | 'dim_value' // Dimension value, e.g., sex = man
  | 'time_desc' // Time description, e.g., 2021-11-19
  | 'proportion'; // Proportion, e.g., 20%

Plugin System ​

PluginManager ​

typescript
class PluginManager {
  constructor(plugins?: PluginType[]);
  protected entities: Partial<Record<EntityType, PhraseDescriptor<EntityMetaData>>>;
  protected customPhrases: Record<string, PhraseDescriptor<any>>;
  protected customBlocks: Record<string, BlockDescriptor<any>>;
}

constructor ​

ParameterTypeRequiredDescription
pluginsPluginType[]NoArray of plugins

PhraseDescriptor ​

typescript
interface PhraseDescriptor<MetaData> {
  key: string;
  isEntity: boolean;
  render?: ((value: string, metadata: MetaData) => HTMLElement) | HTMLElement;
  tooltip?:
    | false
    | (Omit<TooltipProps, 'children' | 'title'> & {
        title: ((value: string, metadata: MetaData) => HTMLElement | string | number) | HTMLElement | string | number;
      });
  classNames?: string[] | ((value: string, metadata: MetaData) => string[]);
  style?: CSSProperties | ((value: string, metadata: MetaData, themeSeedToken: SeedTokenOptions) => CSSProperties);
  onHover?: (value: string, metadata: MetaData) => string;
  onClick?: (value: string, metadata: MetaData) => string;
  getText?: (value: string, metadata: MetaData) => string;
  getMarkdown?: (value: string, metadata: MetaData) => string;
}
PropertyTypeRequiredDescription
keystringYesUnique plugin identifier
isEntitybooleanYesWhether it's an entity phrase
renderfunction | HTMLElementNoRender function or element
tooltipfalse | objectNoTooltip configuration
classNamesstring[] | functionNoClass names array or function
styleCSSProperties | functionNoStyle object or function
onHoverfunctionNoHover event handler
onClickfunctionNoClick event handler
getTextfunctionNoGet plain text content function
getMarkdownfunctionNoGet Markdown content function

BlockDescriptor ​

typescript
interface BlockDescriptor<CustomBlockSpec> {
  key: string;
  isBlock: true;
  className?: string | ((spec: CustomBlockSpec) => string);
  style?: CSSProperties | ((spec: CustomBlockSpec) => CSSProperties);
  render?: (spec: CustomBlockSpec) => HTMLElement;
  getText?: (spec: CustomBlockSpec) => string;
  getMarkdown?: (spec: CustomBlockSpec) => string;
}
PropertyTypeRequiredDescription
keystringYesUnique plugin identifier
isBlocktrueYesIdentifies as a block plugin
classNamestring | functionNoClass name or function
styleCSSProperties | functionNoStyle object or function
renderfunctionNoRender function
getTextfunctionNoGet plain text content function
getMarkdownfunctionNoGet Markdown content function

Preset Plugin Factory Functions ​

typescript
function createMetricName(
  customDescriptor?: SpecificEntityPhraseDescriptor,
  mode?: CustomEntityMode,
): PhraseDescriptor<EntityMetaData>;
ParameterTypeRequiredDescription
customDescriptorSpecificEntityPhraseDescriptorNoCustom descriptor
modeCustomEntityModeNoMerge mode, 'merge' or 'overwrite'

Return Value

TypeDescription
PhraseDescriptor<EntityMetaData>Entity phrase plugin descriptor

Note: Other preset plugin factory functions (createMetricValue, createDeltaValue, etc.) have the same parameters and return values as createMetricName.

Theme System ​

SeedTokenOptions ​

typescript
interface SeedTokenOptions {
  // Base configuration
  fontSize: number;
  lineHeight: number;
  fontFamily: string;

  // Color system
  colorBase: string; // Base text color
  colorEntityBase: string; // Entity base color
  colorHeadingBase: string; // Heading base color
  colorPositive: string; // Positive color
  colorNegative: string; // Negative color
  colorConclusion: string; // Conclusion color
  colorDimensionValue: string; // Dimension value color
  colorMetricName: string; // Metric name color
  colorMetricValue: string; // Metric value color
  colorOtherValue: string; // Other value color
  colorProportionShadow: string; // Proportion chart shadow color
  colorProportionFill: string; // Proportion chart fill color
  colorLineStroke: string; // Line chart stroke color
}
PropertyTypeRequiredDescription
fontSizenumberYesBase font size
lineHeightnumberYesBase line height
fontFamilystringYesFont family
colorBasestringYesBase text color
colorEntityBasestringYesEntity base color
colorHeadingBasestringYesHeading base color
colorPositivestringYesPositive color
colorNegativestringYesNegative color
colorConclusionstringYesConclusion color
colorDimensionValuestringYesDimension value color
colorMetricNamestringYesMetric name color
colorMetricValuestringYesMetric value color
colorOtherValuestringYesOther value color
colorProportionShadowstringYesProportion chart shadow color
colorProportionFillstringYesProportion chart fill color
colorLineStrokestringYesLine chart stroke color