From 6e63b970da353a7ccc231e3cbf716a008e191f4f Mon Sep 17 00:00:00 2001 From: Jinke Li Date: Fri, 13 Dec 2024 10:00:31 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=9C=A8=E7=BB=B4?= =?UTF-8?q?=E5=80=BC=E7=BC=BA=E5=A4=B1=E5=9C=BA=E6=99=AF=E4=B8=8B=E5=AF=BC?= =?UTF-8?q?=E5=87=BA=E6=95=B0=E6=8D=AE=E5=8D=A0=E4=BD=8D=E7=AC=A6=E6=9C=AA?= =?UTF-8?q?=E8=A7=A3=E6=9E=90=E7=9A=84=E9=97=AE=E9=A2=98=20(#3027)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../miss-dimension-values-spec.ts.snap | 10 +++++----- .../unit/data-set/pivot-data-set-spec.ts | 2 ++ .../s2-core/__tests__/unit/utils/text-spec.ts | 19 ++++++++++++++++++- .../s2-core/src/data-set/base-data-set.ts | 8 ++++++-- packages/s2-core/src/utils/export/method.ts | 4 +++- 5 files changed, 34 insertions(+), 9 deletions(-) diff --git a/packages/s2-core/__tests__/spreadsheet/__snapshots__/miss-dimension-values-spec.ts.snap b/packages/s2-core/__tests__/spreadsheet/__snapshots__/miss-dimension-values-spec.ts.snap index 3c0793b6c4..7bfa7ddc92 100644 --- a/packages/s2-core/__tests__/spreadsheet/__snapshots__/miss-dimension-values-spec.ts.snap +++ b/packages/s2-core/__tests__/spreadsheet/__snapshots__/miss-dimension-values-spec.ts.snap @@ -21,19 +21,19 @@ exports[`Miss Dimension Values Tests should replace empty dimension value placeh exports[`Miss Dimension Values Tests should replace empty dimension value placeholder when copy original data 1`] = ` "first second third number -总计 $$empty_field_value$$ $$empty_field_value$$ 1732771 +总计 - - 1732771 维值-1 维值-2 维度-3 12222 维值-1 维值-3 维值-3 11111 维值-1 维值-3 维度-3 11111 维值-1 维值-3 小计 维值-1 小计 456 测试-1 测试-2 维度-3 4444567 -测试-1 测试-3 $$empty_field_value$$ 785222 +测试-1 测试-3 - 785222 测试-1 测试-4 维度-3 6455644 测试-1 测试-5 维度-3 1111 测试-1 小计 125555 -测试-6 测试-x $$empty_field_value$$ 111111 -测试-6 测试-7 $$empty_field_value$$ 67878 -测试-6 测试-8 $$empty_field_value$$ 456.464 +测试-6 测试-x - 111111 +测试-6 测试-7 - 67878 +测试-6 测试-8 - 456.464 测试-6 小计 123.416" `; diff --git a/packages/s2-core/__tests__/unit/data-set/pivot-data-set-spec.ts b/packages/s2-core/__tests__/unit/data-set/pivot-data-set-spec.ts index f9ae37178e..55568e80e5 100644 --- a/packages/s2-core/__tests__/unit/data-set/pivot-data-set-spec.ts +++ b/packages/s2-core/__tests__/unit/data-set/pivot-data-set-spec.ts @@ -26,6 +26,7 @@ import { totalData as drillDownTotalData, } from 'tests/data/mock-drill-down-dataset.json'; import { assembleDataCfg } from 'tests/util'; +import { EMPTY_FIELD_VALUE } from '../../../src'; jest.mock('@/sheet-type'); @@ -510,6 +511,7 @@ describe('Pivot Dataset Test', () => { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore expect(dataSet.getFieldName(['1'])).toEqual(['1']); + expect(dataSet.getFieldName(EMPTY_FIELD_VALUE)).toStrictEqual('-'); }); test('should return correct field meta', () => { diff --git a/packages/s2-core/__tests__/unit/utils/text-spec.ts b/packages/s2-core/__tests__/unit/utils/text-spec.ts index 960a86fae7..aa084ce7a9 100644 --- a/packages/s2-core/__tests__/unit/utils/text-spec.ts +++ b/packages/s2-core/__tests__/unit/utils/text-spec.ts @@ -1,4 +1,4 @@ -import { ELLIPSIS_SYMBOL } from '@/common'; +import { ELLIPSIS_SYMBOL, EMPTY_FIELD_VALUE } from '@/common'; import { drawCustomContent, getCellWidth, @@ -8,6 +8,7 @@ import { isUnchangedValue, isUpDataValue, isZeroOrEmptyValue, + replaceEmptyFieldValue, } from '@/utils/text'; import { createFakeSpreadSheet, @@ -385,3 +386,19 @@ describe('getDisplayText', () => { expect(getDisplayText(value, '@')).toEqual(result); }); }); + +describe('replaceEmptyFieldValue', () => { + test.each` + value | result + ${'value'} | ${'value'} + ${EMPTY_FIELD_VALUE} | ${'-'} + ${undefined} | ${undefined} + ${0} | ${0} + ${NaN} | ${NaN} + `( + 'should get correct empty field display value for $value', + ({ value, result }) => { + expect(replaceEmptyFieldValue(value)).toEqual(result); + }, + ); +}); diff --git a/packages/s2-core/src/data-set/base-data-set.ts b/packages/s2-core/src/data-set/base-data-set.ts index ae29e5e356..7287273809 100644 --- a/packages/s2-core/src/data-set/base-data-set.ts +++ b/packages/s2-core/src/data-set/base-data-set.ts @@ -37,7 +37,11 @@ import { } from '../utils/condition/state-controller'; import { generateExtraFieldMeta } from '../utils/dataset/pivot-data-set'; import type { Indexes } from '../utils/indexes'; -import { getDisplayText, getEmptyPlaceholder } from '../utils/text'; +import { + getDisplayText, + getEmptyPlaceholder, + replaceEmptyFieldValue, +} from '../utils/text'; import type { GetCellMultiDataParams } from './index'; import type { GetCellDataParams, Query } from './interface'; @@ -145,7 +149,7 @@ export abstract class BaseDataSet { return get( this.getFieldMeta(realField, this.meta), 'name', - defaultValue ?? realDefaultValue, + replaceEmptyFieldValue(defaultValue ?? realDefaultValue), ); } diff --git a/packages/s2-core/src/utils/export/method.ts b/packages/s2-core/src/utils/export/method.ts index 16a7e8bb50..1437cb3f18 100644 --- a/packages/s2-core/src/utils/export/method.ts +++ b/packages/s2-core/src/utils/export/method.ts @@ -14,6 +14,7 @@ import { import type { Node } from '../../facet/layout/node'; import type { SpreadSheet } from '../../sheet-type'; import { resolveNillString } from '../layout'; +import { replaceEmptyFieldValue } from '../text'; export function keyEqualTo(key: string, compareKey: string) { if (!key || !compareKey) { @@ -64,8 +65,9 @@ export const getHeaderMeasureFieldNames = ( } // https://github.com/antvis/S2/issues/2688 + // https://github.com/antvis/S2/pull/2829 if (!formatHeader) { - return resolveNillString(field); + return replaceEmptyFieldValue(resolveNillString(field)!); } return spreadsheet.dataSet.getFieldName(field); From 001573f2dedbf069c996deb1579bcc9525f5efa8 Mon Sep 17 00:00:00 2001 From: Jinke Li Date: Fri, 13 Dec 2024 10:01:25 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=A1=8C=E5=A4=B4?= =?UTF-8?q?=E5=9C=88=E9=80=89=E5=A4=8D=E5=88=B6=E6=97=B6=E9=83=A8=E5=88=86?= =?UTF-8?q?=E5=9C=BA=E6=99=AF=E4=B8=8B=E6=95=B0=E6=8D=AE=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=20close=20#2975=20(#3029)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 修复行头圈选复制时部分场景下数据重复 close #2975 * chore: 还原 --- .../brush-selection/base-brush-selection.ts | 7 +++++-- s2-site/docs/manual/migration-v2.zh.md | 13 +++++++++++++ s2-site/examples/basic/pivot/demo/grid.ts | 10 +++++++--- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/packages/s2-core/src/interaction/brush-selection/base-brush-selection.ts b/packages/s2-core/src/interaction/brush-selection/base-brush-selection.ts index c90f19f0bf..fb70510a8e 100644 --- a/packages/s2-core/src/interaction/brush-selection/base-brush-selection.ts +++ b/packages/s2-core/src/interaction/brush-selection/base-brush-selection.ts @@ -158,8 +158,11 @@ export class BaseBrushSelection let newX = this.endBrushPoint?.x + x; let newY = this.endBrushPoint?.y + y; - let needScrollForX = true; - let needScrollForY = true; + // 有滚动条才需要滚动 + let needScrollForX = isRowHeader + ? !!facet.hRowScrollBar + : !!facet.hScrollBar; + let needScrollForY = !!facet.vScrollBar; const vScrollBarWidth = facet.vScrollBar?.getBBox()?.width; // 额外加缩进,保证 getShape 在 panelBox 内 const extraPixel = 2; diff --git a/s2-site/docs/manual/migration-v2.zh.md b/s2-site/docs/manual/migration-v2.zh.md index 8c4a327f44..167b224adc 100644 --- a/s2-site/docs/manual/migration-v2.zh.md +++ b/s2-site/docs/manual/migration-v2.zh.md @@ -1016,6 +1016,19 @@ splitLine: { } ``` +#### 自定义 hook 变更 + +1. 原 `layoutDataPosition` 废弃,新增 `layoutCellMeta` 用于自定义单元格元数据。 + +```diff +const s2Options = { +- layoutDataPosition: (s2, getCellData) => {} ++ layoutCellMeta: (cellMeta) => {} +} +``` + +具体请查看 [自定义单元格元数据](/examples/custom/custom-layout/#custom-layout-cell-meta) 相关示例。 + ### 组件层 (s2-react) @antv/s2-react #### 移除 Ant Design 组件库依赖 diff --git a/s2-site/examples/basic/pivot/demo/grid.ts b/s2-site/examples/basic/pivot/demo/grid.ts index 78c599dcbf..d01777f692 100644 --- a/s2-site/examples/basic/pivot/demo/grid.ts +++ b/s2-site/examples/basic/pivot/demo/grid.ts @@ -43,10 +43,14 @@ fetch( width: 600, height: 480, hierarchyType: 'grid', + // 数值挂行头时, 自定义角头虚拟数值字段文本, 默认 "数值" + cornerExtraFieldText: '自定义', interaction: { - copy: { enable: true }, - withFormat: true, - withHeader: true, + copy: { + enable: true, + withFormat: true, + withHeader: true, + }, }, // 显示序号 // seriesNumber: {