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

S2中明细表或者透视表设置背景柱状图最小值不生效?🐛 #2819

Closed
3 tasks
Zhaohanqi12 opened this issue Jul 15, 2024 · 9 comments
Closed
3 tasks
Assignees

Comments

@Zhaohanqi12
Copy link

🏷 Version

S2中明细表或者透视表设置背景柱状图最小的那个值无论是多少背景柱状图都不生效?

Package Version
@antv/s2 1.5.0
@antv/s2-react 1.3.3

Sheet Type

  • [ √] PivotSheet
  • [ √] TableSheet
  • GridAnalysisSheet
  • StrategySheet
  • EditableSheet

🖋 Description

⌨️ Code Snapshots

🔗 Reproduce Link

image
复现demo地址
https://codesandbox.io/p/sandbox/flamboyant-greider-z9zhfg?file=%2Fsrc%2Findex.ts%3A27%2C17

@lijinke666
Copy link
Member

lijinke666 commented Jul 15, 2024

是的, 因为需要考虑双向柱状图, 数值可能为负数, 所以基准值不是从 0 开始的, 而是你的数据最小值, 此时 1220 等价, 所以看起来不生效, 你可以手动设置 minValue0

      {
        field: "number",
        mapping(value, record, cell) {
          const defaultValueRange = cell.valueRangeByField;

          return {
            fill: "#80BFFF",
            isCompare: true,
            minValue: 0,
            maxValue: defaultValueRange.maxValue,
          };
        },
      },

@lijinke666 lijinke666 self-assigned this Jul 15, 2024
@Zhaohanqi12
Copy link
Author

Zhaohanqi12 commented Jul 15, 2024 via email

@lijinke666
Copy link
Member

cell.valueRangeByField 不就能获取最大值和最小值吗, 两个版本一样的, 你动态判断最小值是不是负数, 动态改变 isCompare 不就行了

@Zhaohanqi12
Copy link
Author

Zhaohanqi12 commented Jul 15, 2024 via email

@lijinke666
Copy link
Member

哦哦, 1.x 版本没有传入第三个参数, 你是两个版本都在用? 你提供的 demo 又是 2.x 版本的

@Zhaohanqi12
Copy link
Author

Zhaohanqi12 commented Jul 15, 2024 via email

@lijinke666
Copy link
Member

1.x 版本中这样改写一下吧, 自定义 dataCell 重写 mappingValue, 额外注入第三个参数, mapping 使用方式不变

public mappingValue(condition: Condition): MappingResult {
const value = this.meta.fieldValue as unknown as number;
const rowDataInfo = this.spreadsheet.isTableMode()
? this.spreadsheet.dataSet.getCellData({
query: { rowIndex: this.meta.rowIndex },
})
: this.meta.data;
return condition?.mapping(value, rowDataInfo);
}

import { DataCell } from '@antv/s2'

class CustomDataCell extends DataCell {
  mappingValue(condition) {
    const value = this.meta.fieldValue
    const rowDataInfo = this.spreadsheet.isTableMode()
      ? this.spreadsheet.dataSet.getCellData({
          query: { rowIndex: this.meta.rowIndex },
        })
      : this.meta.data;

    // 注入第三个参数
    return condition?.mapping(value, rowDataInfo, this);
  }
}

const s2Options = {
  dataCell: (viewMeta) => new CustomDataCell(viewMeta, viewMeta?.spreadsheet),
}

@lijinke666
Copy link
Member

lijinke666 commented Jul 15, 2024

PS:

valueRangeByField 这块缺失文档, 2.x 后续版本中应该会将 cell.valueRangeByField 改成 cell.getValueRange(), 后续如果升级了版本请注意.

@Zhaohanqi12
Copy link
Author

Zhaohanqi12 commented Jul 15, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants