Skip to content

Theme Configuration ​

T8 provides a flexible theme configuration system. You can use the theme method to set the text visualization theme style.

Basic Usage ​

ts
const text = new Text('#container');

// Use light theme
text.theme('light');

// Use dark theme
text.theme('dark');

// Custom theme configuration
text.theme('dark', {
  fontSize: 12,
  lineHeight: 20,
  // ... other configurations
});
import "./styles.css";

document.getElementById("app").innerHTML = `
<h1>Hello world</h1>
`;

Configuration Items ​

Basic Configuration ​

Basic configuration items control the basic text styles:

Configuration ItemTypeDefault ValueDescription
fontFamilystring'PingFangSC, sans-serif'Font family
fontSizenumber14Base font size
lineHeightnumber24Base line height
borderColorstring'rgb(199, 199, 199)'Border color

Heading Configuration ​

You can configure the size and line height of different heading levels through fontSizeMultiples and lineHeightMultiples:

ts
{
  // Heading font size multipliers
  fontSizeMultiples: {
    h1: 2,      // 2 times base font size
    h2: 1.72,   // 1.72 times base font size
    h3: 1.4,    // 1.4 times base font size
    h4: 1.15,   // 1.15 times base font size
    h5: 1.08,   // 1.08 times base font size
    h6: 1.08,   // 1.08 times base font size
  },

  // Heading line height multipliers
  lineHeightMultiples: {
    h1: 1.5,    // 1.5 times base line height
    h2: 1.3,    // 1.3 times base line height
    h3: 1.15,   // 1.15 times base line height
    h4: 1,      // 1 times base line height
    h5: 1,      // 1 times base line height
    h6: 1,      // 1 times base line height
  }
}

Color Configuration ​

T8 provides a complete set of preset colors for light and dark themes. Each theme includes the following color configurations:

Configuration ItemDescriptionLight ThemeDark Theme
colorBaseBase text colorrgba(0, 0, 0, 0.65)rgba(255, 255, 255, 0.65)
colorEntityBaseEntity base colorrgba(0, 0, 0, 0.65)rgba(255, 255, 255, 0.65)
colorHeadingBaseHeading base colorrgba(0, 0, 0, 0.85)rgba(255, 255, 255, 0.85)
colorPositivePositive value color#FA541C#FA541C
colorNegativeNegative value color#13A8A8#13A8A8
colorConclusionConclusion color#1F0352#D8C3F3
colorDimensionValueDimension value colorrgba(0, 0, 0, 0.88)rgba(255, 255, 255, 0.88)
colorMetricNameMetric name colorrgba(0, 0, 0, 0.88)rgba(255, 255, 255, 0.88)
colorMetricValueMetric value color#1677FF#4B91FF
colorOtherValueOther value colorrgba(0, 0, 0, 0.88)rgba(255, 255, 255, 0.88)
colorProportionShadowProportion chart shadow#CDDDFD#CDDDFD
colorProportionFillProportion chart fill#3471F9#3471F9
colorLineStrokeLine chart stroke#5B8FF9#5B8FF9

Theme Customization ​

Overriding Preset Theme ​

You can override part of the configuration based on the preset theme:

ts
text.theme('dark', {
  // Override basic configuration
  fontSize: 16,
  lineHeight: 28,

  // Override color configuration
  colorMetricValue: '#1890ff',
  colorPositive: '#52c41a',
  colorNegative: '#ff4d4f',

  // Override heading configuration
  fontSizeMultiples: {
    h1: 2.5,
    h2: 2,
    // ... other heading configurations
  },
});

Complete Example ​

This is a complete example containing all configuration items:

ts
text.theme('dark', {
  // Basic configuration
  fontFamily: 'PingFangSC, sans-serif',
  fontSize: 14,
  lineHeight: 24,
  borderColor: 'rgb(199, 199, 199)',

  // Heading size configuration
  fontSizeMultiples: {
    h1: 2,
    h2: 1.72,
    h3: 1.4,
    h4: 1.15,
    h5: 1.08,
    h6: 1.08,
  },

  // Heading line height configuration
  lineHeightMultiples: {
    h1: 1.5,
    h2: 1.3,
    h3: 1.15,
    h4: 1,
    h5: 1,
    h6: 1,
  },

  // Color configuration
  colorBase: 'rgba(255, 255, 255, 0.65)',
  colorEntityBase: 'rgba(255, 255, 255, 0.65)',
  colorHeadingBase: 'rgba(255, 255, 255, 0.85)',
  colorPositive: '#FA541C',
  colorNegative: '#13A8A8',
  colorConclusion: '#D8C3F3',
  colorDimensionValue: 'rgba(255, 255, 255, 0.88)',
  colorMetricName: 'rgba(255, 255, 255, 0.88)',
  colorMetricValue: '#4B91FF',
  colorOtherValue: 'rgba(255, 255, 255, 0.88)',
  colorProportionShadow: '#CDDDFD',
  colorProportionFill: '#3471F9',
  colorLineStroke: '#5B8FF9',
});