Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"comment": "fix: respect explicit label smart invert settings",
"type": "patch",
"packageName": "@visactor/vchart"
}
],
"packageName": "@visactor/vchart",
"email": "biukam.w@gmail.com"
}
45 changes: 45 additions & 0 deletions packages/vchart/__tests__/unit/component/label/label-util.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { barLabel, pieLabel } from '../../../../src/component/label/util';

const createLabelInfo = (labelSpec: Record<string, unknown>) =>
({
labelSpec,
series: {
direction: 'vertical',
getMeasureField: () => ['value'],
getYAxisHelper: (): undefined => undefined
}
} as any);

describe('label util', () => {
describe('barLabel', () => {
it('preserves disabled smart invert for inside labels', () => {
const result = barLabel(createLabelInfo({ position: 'inside', smartInvert: false }));

expect(result.smartInvert).toBe(false);
});

it('preserves explicit smart invert options for inside labels', () => {
const smartInvert = {
fillStrategy: 'invertBase',
strokeStrategy: 'similarBase'
};
const result = barLabel(createLabelInfo({ position: 'inside', smartInvert }));

expect(result.smartInvert).toBe(smartInvert);
});

it('enables smart invert by default for inside labels', () => {
const result = barLabel(createLabelInfo({ position: 'inside' }));

expect(result.smartInvert).toBe(true);
});
});

describe('pieLabel', () => {
it('preserves disabled smart invert for inside labels', () => {
const result = pieLabel(createLabelInfo({ position: 'inside', smartInvert: false }));

expect(result.smartInvert).toBe(false);
});
});
});
12 changes: 2 additions & 10 deletions packages/vchart/src/component/label/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,7 @@ export function barLabel(labelInfo: ILabelInfo) {
}

// encode smartInvert
let smartInvert = false;
if (isString(originPosition) && originPosition.includes('inside')) {
smartInvert = true;
}
const smartInvert = labelSpec.smartInvert ?? (isString(originPosition) && originPosition.includes('inside'));

return { position, overlap, smartInvert };
}
Expand Down Expand Up @@ -240,12 +237,7 @@ export function pieLabel(labelInfo: ILabelInfo) {
const position = labelPosition as BaseLabelAttrs['position'];

// encode smartInvert
let smartInvert;
if (labelSpec.smartInvert) {
smartInvert = labelSpec.smartInvert;
} else {
smartInvert = isString(labelPosition) && labelPosition.includes('inside');
}
const smartInvert = labelSpec.smartInvert ?? (isString(labelPosition) && labelPosition.includes('inside'));

return { position, smartInvert };
}
Expand Down
Loading