Loading...
There are 3 out-of-the-box theme configurations built into S2, and powerful theme customization functions are also provided. View APIs
In the color usage of S2, we will first select a theme color, and use the theme color to generate a set of标准色板
:
白
5 lighter colors, placed on index 0~5黑
to generate 5 darker colors and place them on indexes 6~11The following is an example of using #0A78F4 and #FF5500 different theme colors to generate a standard color palette:
The swatch is defined as Palette , from which the color will be taken when the theme schema is generated, and its color comes from the standard swatch. The key properties of Palette are:
basicColors[1]
will be takenbasicColors[1]
is the color of index 0 in the standard swatches.Thus S2 guarantees that all the colors used in drawing come from the theme color or the derived color of the theme color. In this way, the color of the table interface is unified, and it is also convenient for users to generate personalized themes according to the theme colors they need.
The theme schema is defined as S2Theme , which describes the theme style of cells and interactions in detail, and its attributes include color, line thickness, text size, text alignment, etc. Throughout the schema, all colors will be taken from the Palette :
const s2 = new PivotSheet(container, s2DataConfig, s2Options);s2.setTheme({background: {color: '#353c59',},});s2.render(false);
The setThemeCfg
method on the s2 instance is the entry point for all theme configurations. This method receives a parameter of type ThemeCfg . You can:
You can use the corresponding theme by specifying the theme name:
const s2 = new PivotSheet(container, s2DataConfig, s2Options);// name 可为 default, colorful, grays2.setThemeCfg({ name: 'colorful' });s2.render(false);
S2 has 3 built-in theme effects:
Default | ![]() |
Colorful blue | ![]() |
Simple gray | ![]() |
📊 See more theme examples .
If the built-in themes do not meet your requirements, you can override specific configurations by customizing the schema
.
At this point you can call s2.setTheme
or s2.setThemeCfg()
to configure the theme
object. View the complete schema configuration :
const s2 = new PivotSheet(container, s2DataConfig, s2Options);const customTheme = {background: {color: '#353c59',},};// s2.setThemeCfg({ theme: customTheme })s2.setTheme(customTheme)s2.render(false);
View details and full API
s2.setTheme({rowCell: {text: {textAlign: 'left',},bolderText: {textAlign: 'left',},},});
View full API
s2.setTheme({rowCell: {cell: {backgroundColor: '#dcdcdc',},},});
View full API
s2.setTheme({scrollBar: {thumbColor: '#666',thumbHorizontalMinSize: 20,thumbVerticalMinSize: 20,},});
Although the custom schema
is flexible, it has a heavy mental burden and requires a more detailed understanding of the schema
structure. Therefore, we also provide a custom color palette function. At this time, you need to configure the palette
object for setThemeCfg
. View full swatch configuration :
You can refer to the built-in swatches to personalize basicColors
and semanticColors
. The selected colors will be used to draw different parts of the table. For the relationship between colors, please refer to the swatch comparison table below .
In addition, in order to facilitate the deployment of exclusive color palettes, S2 officially provides a self-service color palette tool , which helps you quickly adjust color palettes, copy and paste them into projects for use with one click.
const s2 = new PivotSheet(container, s2DataConfig, s2Options);const s2Palette = {// 基础配色色板basicColors: ['#FFFFFF','#F8F5FE','#EDE1FD','#873BF4','#7232CF','#AB76F7','#FFFFFF','#DDC7FC','#9858F5','#B98EF8','#873BF4','#282B33','#121826',],// 语义化色板semanticColors: {red: '#FF4D4F',green: '#29A294',},};s2.setThemeCfg({ palette: s2Palette });s2.render(false);
There is a large degree of freedom in the deployment of self- selected swatch colors , but each color needs to be determined individually, and the overall process is relatively complicated. To meet users' general theme demands, S2 also provides the function of generating color palettes based on theme colors.
import { getPalette, generatePalette, PivotSheet } from '@antv/s2';const s2 = new PivotSheet(container, s2DataConfig, s2Options);// 主题色const themeColor = '#EA1720';// 使用内置的 colorful 色板作为参考色板// 根据风格差异,你也可以选择 default、gray 作为参考色板const palette = getPalette('colorful');// 使用参考色板 & 主题色值生成新色板const newPalette = generatePalette({ ...palette, brandColor: themeColor });// 使用新色板设置主题s2.setThemeCfg({palette: newPalette,});s2.render(false);
Swatches | Coverage | corresponds to the key of the schema | ||
Basic color - basicColors | ||||
default | simple gray | colorful blue | ||
#000000 | #000000 | #FFFFFF | Corner header cell bold text color | cornerCell.bolderText.fill |
Corner header cell text color | cornerCell.text.fill | |||
Corner header cell icon color | cornerCell.icon.fill | |||
Row header cell icon color | rowCell.cell.icon.fill | |||
Column header cell bold text color | colCell.bolderText.fill | |||
column header cell text color | colCell.text.fill | |||
column header cell icon color | colCell.icon.fill | |||
data cell icon color | dataCell.icon.fill | |||
#F5F8FE | #FAFBFB | #F5F8FF | Row header cell background fill color | rowCell.cell.backgroundColor |
Data cell background fill color | dataCell.cell.backgroundColor | |||
#E0E9FD | #F0F2F4 | #E1EAFE | The background fill color of the mouse hover state of the row header cell | rowCell.interactionState.hover.backgroundColor |
The background fill color of the mouse-selected state of the row header cell | rowCell.interactionState.selected.backgroundColor | |||
Data cell mouse hover background fill color | dataCell.interactionState.hover.backgroundColor | |||
Data cell mouse hover focus state background fill color | dataCell.interactionState.hoverFocus.backgroundColor | |||
Data cell mouse selected background fill color | dataCell.interactionState.selected.backgroundColor | |||
#E0E9FD | #F0F2F4 | #3471F9 | Corner header cell background fill color | cornerCell.cell.backgroundColor |
Column header cell background fill color | colCell.cell.backgroundColor | |||
#CCDBFC | #E7E9ED | #2C60D4 | Column header cell mouse hover background fill color | colCell.cell.interactionState.hover.backgroundColor |
The background fill color of the mouse selected state of the column header cell | colCell.cell.interactionState.selected.backgroundColor | |||
#234DAB | #6E757F | #2C60D4 | Brush the background fill color of the pre-selected state mask | prepareSelectMask.backgroundColor |
#326EF4 | #565C64 | #2C60D4 | Row header cell link text color | rowCell.text.linkTextFill |
#326EF4 | #9DA7B6 | #3471F9 | Data cell histogram fill color | dataCell.cell.miniBarChartFillColor |
resize mask background color | resizeArea.background | |||
resize hotspot guide color | resizeArea.guideLineColor | |||
resize background color of hotspot hover state | resizeArea.interactionState.hover. backgroundColor | |||
#FFFFFF | #FFFFFF | #FFFFFF | Data cell background fill color | dataCell.cell.backgroundColor |
table background fill color | background.color | |||
#E0E9FD | #F0F2F4 | #E1EAFE | Row header cell horizontal border color | rowCell.cell.horizontalBorderColor |
Row header cell vertical border color | rowCell.cell.verticalBorderColor | |||
Data cell horizontal border color | dataCell.cell.horizontalBorderColor | |||
Data cell vertical border color | dataCell.cell.verticalBorderColor | |||
#CCDBFC | #E7E9ED | #5286FA | Horizontal border color of corner header cells | cornerCell.cell.horizontalBorderColor |
Corner header cell vertical border color | cornerCell.cell.verticalBorderColor | |||
Column header cell horizontal border color | colCell.cell.horizontalBorderColor | |||
Column header cell vertical border color | colCell.cell.verticalBorderColor | |||
#326EF4 | #BAC1CC | #5286FA | The horizontal border color of the table body (level one horizontal dividing line) | splitLine.verticalBorderColor |
#326EF4 | #BAC1CC | #3471F9 | The vertical border color of the table body (first-level vertical dividing line) | splitLine.horizontalBorderColor |
#000000 | #000000 | #000000 | Data cell bold text color | dataCell.bolderText.fill |
data cell text color | dataCell.text.fill | |||
#000000 | #000000 | #000000 | Row header cell bold text color | rowCell.bolderText.fill |
Row header cell bold link text color | rowCell.bolderText.linkTextFill | |||
Row header cell link text color | rowCell.text.linkTextFill | |||
Data cell mouse hover focused state border color | dataCell.interactionState.hoverFocus.borderColor | |||
The border color of the data cell mouse selection pre-center state | dataCell.interactionState.prepareSelect.borderColor | |||
Semantic Colors - semanticColors | ||||
red: #FF4D4F | red: #FF4D4F | red: #FF4D4F | Color of the arrow icon on the data cell | dataCell.icon.downIconColor |
green: #29A294 | green: #29A294 | green: #29A294 | Data cell down arrow icon color | dataCell.icon.upIconColor |