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

feat: 对比值无波动时也显示灰色 #2351

Merged
merged 5 commits into from
Sep 14, 2023
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
35 changes: 35 additions & 0 deletions packages/s2-core/__tests__/unit/utils/text-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
getEmptyPlaceholder,
getContentAreaForMultiData,
isZeroOrEmptyValue,
isUnchangedValue,
} from '@/utils/text';

const isHD = window.devicePixelRatio >= 2;
Expand Down Expand Up @@ -306,3 +307,37 @@ describe('isZeroOrEmptyValue', () => {
expect(isZeroOrEmptyValue(undefined)).toBe(true);
});
});

describe('isUnchangedValue', () => {
test('should return true for zero values', () => {
expect(isUnchangedValue(0, 123)).toBeTruthy();
expect(isUnchangedValue('0', 'abc')).toBeTruthy();
});

test('should return true for empty values', () => {
expect(isUnchangedValue('', 'abc')).toBeTruthy();
expect(isUnchangedValue(null, 123)).toBeTruthy();
expect(isUnchangedValue(undefined, 123)).toBeTruthy();
});

test('should return true for unchanged values', () => {
expect(isUnchangedValue('test', 'test')).toBeTruthy();
expect(isUnchangedValue(123, 123)).toBeTruthy();
});

test('should return true for numberless changed values', () => {
expect(isUnchangedValue('test', 'abc')).toBeTruthy();
});

test('should return false for numeric changed values', () => {
expect(isUnchangedValue(123, 456)).toBeFalsy();
});

test('should return true for negative zero', () => {
expect(isUnchangedValue(-0, 123)).toBeTruthy();
});

test('should return false for negative values', () => {
expect(isUnchangedValue(-123, 123)).toBeFalsy();
});
});
13 changes: 13 additions & 0 deletions packages/s2-core/src/utils/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,19 @@ export const isZeroOrEmptyValue = (value: number | string): boolean => {
);
};

/**
* Determines whether the data is actually equal to 0 or empty or nil or equals to compareValue
* example: "0.00%" => true
* @param value
* @param compareValue
*/
export const isUnchangedValue = (
value: number | string,
compareValue: number | string,
): boolean => {
return isZeroOrEmptyValue(value) || value === compareValue;
lijinke666 marked this conversation as resolved.
Show resolved Hide resolved
};

/**
* 根据单元格对齐方式计算文本的 x 坐标
* @param x 单元格的 x 坐标
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
type MultiData,
type SimpleDataItem,
type ViewMeta,
isZeroOrEmptyValue,
isUnchangedValue,
} from '@antv/s2';
import cls from 'classnames';
import { first, get, isEmpty, isFunction, isNil } from 'lodash';
Expand Down Expand Up @@ -69,7 +69,10 @@ export const StrategySheetDataTooltip: React.FC<CustomTooltipProps> = ({
<div className={tooltipCls('divider')} />
<ul className={tooltipCls('derived-values')}>
{derivedValues.map((derivedValue: SimpleDataItem, i) => {
const isUnchanged = isZeroOrEmptyValue(derivedValue);
const isUnchanged = isUnchangedValue(
lijinke666 marked this conversation as resolved.
Show resolved Hide resolved
derivedValue,
value as SimpleDataItem,
);
const isUp =
!isUnchanged && isUpDataValue(derivedValue as string);
const isDown = !isUnchanged && !isUp;
Expand Down