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,54 @@
import { AABBBounds } from '@visactor/vutils';
import { Area } from '../../src/graphic/area';
import { Line } from '../../src/graphic/line';

function expectBounds(bounds: AABBBounds) {
expect(bounds.x1).toBe(0);
expect(bounds.y1).toBe(0);
expect(bounds.x2).toBe(10);
expect(bounds.y2).toBe(10);
}

describe('invalid defined points', () => {
test('line bounds exclude invalid points when connecting the remaining points', () => {
const points = [
{ x: 0, y: 0 },
{ x: 500, y: 500, defined: false },
{ x: 10, y: 10 }
];
const line = new Line({ points, connectedType: 'connect' });

const pointBounds = new AABBBounds();
(line as any).updateLineAABBBoundsByPoints(line.attribute, { points }, pointBounds);
expectBounds(pointBounds);

const segmentBounds = new AABBBounds();
(line as any).updateLineAABBBoundsBySegments(
{ segments: [{ points }], connectedType: 'connect' },
{ segments: [{ points }] },
segmentBounds
);
expectBounds(segmentBounds);
});

test('area bounds exclude both coordinates of invalid points', () => {
const points = [
{ x: 0, y: 0, y1: 2 },
{ x: 500, y: 500, y1: -500, defined: false },
{ x: 10, y: 10, y1: 4 }
];
const area = new Area({ points, connectedType: 'connect' });

const pointBounds = new AABBBounds();
(area as any).updateAreaAABBBoundsByPoints(area.attribute, { points }, pointBounds);
expectBounds(pointBounds);

const segmentBounds = new AABBBounds();
(area as any).updateAreaAABBBoundsBySegments(
{ segments: [{ points }], connectedType: 'connect' },
{ segments: [{ points }] },
segmentBounds
);
expectBounds(segmentBounds);
});
});
6 changes: 6 additions & 0 deletions packages/vrender-core/src/graphic/area.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ export class Area extends Graphic<IAreaGraphicAttribute> implements IArea {
const { points = areaTheme.points } = attribute;
const b = aabbBounds;
points.forEach(p => {
if (p.defined === false) {
return;
}
b.add(p.x, p.y);
b.add(p.x1 ?? p.x, p.y1 ?? p.y); //面积图特殊性:由三个值构成,横向面积图,x1会省略;纵向面积图,y1会省略
});
Expand All @@ -103,6 +106,9 @@ export class Area extends Graphic<IAreaGraphicAttribute> implements IArea {
const b = aabbBounds;
segments.forEach(s => {
s.points.forEach(p => {
if (p.defined === false) {
return;
}
b.add(p.x, p.y);
b.add(p.x1 ?? p.x, p.y1 ?? p.y); //面积图特殊性:由三个值构成,横向面积图,x1会省略;纵向面积图,y1会省略
});
Expand Down
8 changes: 4 additions & 4 deletions packages/vrender-core/src/graphic/line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ export class Line extends Graphic<ILineGraphicAttribute> implements ILine {
aabbBounds: IAABBBounds,
graphic?: ILine
): IAABBBounds {
const { points = lineTheme.points, connectedType } = attribute;
const { points = lineTheme.points } = attribute;
const b = aabbBounds;
points.forEach(p => {
if (p.defined !== false || connectedType === 'connect') {
if (p.defined !== false) {
b.add(p.x, p.y);
}
});
Expand All @@ -97,11 +97,11 @@ export class Line extends Graphic<ILineGraphicAttribute> implements ILine {
aabbBounds: IAABBBounds,
graphic?: ILine
): IAABBBounds {
const { segments = lineTheme.segments, connectedType } = attribute;
const { segments = lineTheme.segments } = attribute;
const b = aabbBounds;
segments.forEach(s => {
s.points.forEach(p => {
if (p.defined !== false || connectedType === 'connect') {
if (p.defined !== false) {
b.add(p.x, p.y);
}
});
Expand Down
Loading