Loading...
S2 comes with field tagging feature. Users can set different rendering logics based on business semantics to mark and analyze key data. Field tag types include:
The figure below visually shows the form of the four field tags:
The S2
field marking feature is configured by configuring the Conditions
attribute in s2Options
.
// 构建 optionsconst s2Options = {width: 600,height: 600,// 通过配置 conditions 实现字段标记conditions: {text: [{field: "price",mapping(fieldValue, data) {return {// fill 是文本字段标记下唯一必须的字段,用于指定文本颜色fill: "#5B8FF9",};},},],},};
The Conditions attribute can configure four different fields, corresponding to four different field tags.
text
, background
and interval
are all of Condition array type
field
and mapping
two fieldsicon
is slightly different, it is IconCondition array type
position
field is used to specify the position of the icon relative to the textFocus on explaining the two fields of field
and mapping
:
field
is used to specify which fields to apply the field mark to, and its value range will vary depending on the form of the table:
field
value range or regular matching range is values
, and the scope of action is the row header, column header, corner header and data cellsfield
value range or regular matching range is columns
, and the range of action is the data cellpivot mode |
|
table mode |
|
mapping
is a callback function that handles field marking:
parameter | illustrate | type | Defaults | required |
---|---|---|---|---|
fieldValue | The value of the corresponding field of the cell | number | string | null | - | |
data | The entire row of data corresponding to the cell | object | - | ✓ |
return value | illustrate | type | Defaults | required |
---|---|---|---|---|
fill | When used as a text field tag, it represents the text fill color <br data-mdast="html">When it is used as a background field tag, it represents the cell background fill color <br data-mdast="html">It is used as a column When the graph field is marked, it represents the fill color of the histogram <br data-mdast="html">When it is used for the icon field mark, it represents the icon fill color | string | - | ✓ |
icon | For icon field tags only, specifies the icon type | string | - | |
isCompare | Only used for histogram field marking, when true , you can customize the maximum and minimum values of the histogram | boolean | - | |
minValue | It is only used when the histogram field is marked and isCompare is true , and the minimum value of the histogram can be customized | number | - | |
maxValue | Only used when the histogram field is marked and isCompare is true , customize the maximum value of the histogram | number | - | |
fieldValue | Only used when the histogram field is marked and isCompare is true , customize the length of the histogram | number | - |
If the return value of the
mapping
function is empty, it means that the field mark of the cell is not rendered
S2
currently has a list of built-in icons:
icon name | icon icon | Functional description | icon name | icon icon | Functional description |
---|---|---|---|---|---|
Cell Down | ![]() | YoY decline | ExpandColIcon | ![]() | Schedule HideExpand |
CellUp | ![]() | YoY rise | Plus | ![]() | tree form expansion |
GlobalAsc | ![]() | global ascending | Minus | ![]() | Tree form collapsed |
GlobalDesc | ![]() | global descending | SortDown | ![]() | Schedule descending |
GroupAsc | ![]() | ascending order within group | SortDownSelected | ![]() | Schedule descending selection status |
GroupDesc | ![]() | descending order within group | SortUp | ![]() | Schedule Ascending |
trend | ![]() | Trend | SortUpSelected | ![]() | Schedule ascending selection status |
ArrowUp | ![]() | indicator rises | ArrowDown | ![]() | indicators drop |
DrillDownIcon | ![]() | drill down |
🎨 field mark detailed configuration refer to Conditions API documentation.
By setting the position
attribute in the icon
field tag, you can set whether the icon is on the left or right of the text. (Currently, header cells do not support switching)
The icon for the price
field is to the right of the text, and the icon for the cost
field is to the left of the text:
You can customize the interval range of the histogram by displaying the return value of the mapping
attribute in the specified interval
field tag and setting the value of the isCompare
attribute to true
, and specifying the values of maxValue
and minValue
.
If the value of the
isCompare
attribute in the return value of themapping 函数
isfalse
or the attribute is not returned. At this timemaxValue
andminValue
will use the maximum and minimum values of the field in all chart data as interval ranges
The price
field uses a custom schema, and the cost
field uses the default schema:
When the interval of the histogram has positive and negative points, and with the fill
attribute of the return value of the mapping
function, a positive and negative two-way histogram with different colors can be drawn:
📊 See more field markup examples .
The underlying graphic drawing of S2
uses the AntV/g rendering engine. With its powerful drawing capabilities, the fill
field is not only a color attribute, but also gradient colors , textures , etc. can be used.
The price
field uses a gradient color:
📊 See more field markup examples .
By displaying the return value of the mapping
function in the specified background
field tag
the intelligentReverseTextColor
attribute value is true
. When the mark background color is dark and the text color and background color combination does not meet the Level AA standards of the WCAG2.0 guidelines, the text color
will change to white. When the marker background color is bright, the text color defaults to black.
Priority: intelligentReverseTextColor
of background condition
< fill
of text condition
📊 See more field markup examples .