Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: 优化链接跳转自定义标记文档 close #2914 #2918

Merged
merged 1 commit into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions s2-site/docs/manual/advanced/interaction/link-jump.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ s2.on(S2Event.GLOBAL_LINK_FIELD_JUMP, (data) => {

## 透视表

支持将行头 `rows`, 列头 `columns`, 数值 `values` 标记为链接样式。
支持将行头 `rows`, 列头 `columns`, 数值 `values` 标记为链接样式。[查看示例](/examples/interaction/advanced/#pivot-link-jump)

```ts | pure
import { S2Event } from '@antv/s2'
Expand Down Expand Up @@ -93,7 +93,7 @@ const s2Options = {

## 明细表

支持将列头 `columns` 和对应的数值标记为链接样式。
支持将列头 `columns` 和对应的数值标记为链接样式。[查看示例](/examples/interaction/advanced/#table-link-jump)

:::warning{title="注意"}
由于明细表单列头的特殊性,为和透视表保持一致,同时兼容多列头的场景,明细表的标记会对列头和数值**同时生效**.
Expand Down Expand Up @@ -134,20 +134,30 @@ await s2.render();

## 自定义标记

除了配置行头/列头/数值字段外,支持根据单元格信息自定义标记,满足更多使用场景。
除了配置 `行头/列头/数值` 字段外,支持根据单元格信息自定义标记,满足更多使用场景。[查看示例](/examples/interaction/advanced/#custom-link-jump)

:::warning{title="注意"}
数值和表头的单元格数据结构不同,请注意区分,`meta` 对应关系如下:

1. 数值单元格对应 [ViewMeta](/api/general/s2-options#viewmeta)
2. 表头单元格对应 [Node](/api/basic-class/node)

:::

```ts
import { Node } from '@antv/s2'

const s2Options = {
width: 600,
height: 600,
interaction: {
linkFields: (meta) => {
// 不标记列头
if (meta?.belongsCell?.cellType === 'colCell') {
if (meta instanceof Node) {
return false;
}

// 根据指标值动态标记
// 根据数值动态标记
return meta?.fieldValue === '浙江' || meta?.fieldValue >= 10;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { S2DataConfig, S2Event, S2Options, TableSheet } from '@antv/s2';
import { Node, S2DataConfig, S2Event, S2Options, TableSheet } from '@antv/s2';

fetch('https://assets.antv.antgroup.com/s2/basic-table-mode.json')
.then((res) => res.json())
Expand Down Expand Up @@ -39,11 +39,11 @@ fetch('https://assets.antv.antgroup.com/s2/basic-table-mode.json')
interaction: {
linkFields: (meta) => {
// 不标记列头
if (meta?.belongsCell?.cellType === 'colCell') {
if (meta instanceof Node) {
return false;
wjgogogo marked this conversation as resolved.
Show resolved Hide resolved
}

// 根据指标值动态标记
// 根据数值动态标记
return meta?.fieldValue === '浙江' || meta?.fieldValue >= 10;
},
},
Expand Down
4 changes: 4 additions & 0 deletions s2-site/examples/interaction/advanced/demo/table-link-jump.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ fetch('https://assets.antv.antgroup.com/s2/basic-table-mode.json')
width: 600,
height: 480,
interaction: {
/**
* 由于明细表单列头的特殊性,为和透视表保持一致,同时兼容多列头的场景,明细表的标记会对列头和数值**同时生效**.
* 如希望标记只对数值生效,可以参考自定义标记示例: https://s2.antv.antgroup.com/examples/interaction/advanced/#custom-link-jump
*/
linkFields: ['type', 'province', 'price'],
},
};
Expand Down
Loading