Skip to content

Commit

Permalink
Fix 1458 (#1583)
Browse files Browse the repository at this point in the history
* fix: avoid generating redundant dom structure for document element #1578 (#1580)

* chore: commit changeset

* fix: isBillboard should work on Path

* chore: commit changeset

* feat: add keep aspect ratio in image #1577

* chore: commit changeset
  • Loading branch information
xiaoiver committed Nov 16, 2023
1 parent d3771f1 commit 4fdee19
Show file tree
Hide file tree
Showing 40 changed files with 814 additions and 127 deletions.
6 changes: 6 additions & 0 deletions .changeset/beige-carrots-press.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@antv/g-plugin-image-loader': patch
'@antv/g-lite': patch
---

Keep aspect ration in image.
5 changes: 5 additions & 0 deletions .changeset/chilly-carrots-drive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@antv/g-plugin-svg-renderer': patch
---

Avoid generating redundant dom structure for document element.
11 changes: 11 additions & 0 deletions .changeset/twenty-tables-mate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
'@antv/g-plugin-device-renderer': patch
'@antv/g-plugin-svg-renderer': patch
'@antv/g-mobile-webgl': patch
'@antv/g-plugin-3d': patch
'@antv/g-webgpu': patch
'@antv/g-webgl': patch
'@antv/g-lite': patch
---

Fix picking error when isBillboard enabled.
20 changes: 20 additions & 0 deletions packages/g-lite/src/display-objects/Circle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,38 @@ import { Shape } from '../types';
import { DisplayObject } from './DisplayObject';

export interface CircleStyleProps extends BaseStyleProps {
/**
* X coordinate of the center of the circle.
*/
cx?: number | string | null;
/**
* Y coordinate of the center of the circle.
*/
cy?: number | string | null;
/**
* Z coordinate of the center of the circle.
*/
cz?: number | string | null;
/**
* Radius of the circle.
*/
r: number | string | null;
/**
* Whether the circle is billboard.
*/
isBillboard?: boolean;
/**
* Whether the circle is size attenuation.
*/
isSizeAttenuation?: boolean;
}
export interface ParsedCircleStyleProps extends ParsedBaseStyleProps {
cx: number;
cy: number;
cz?: number;
r: number;
isBillboard?: boolean;
isSizeAttenuation?: boolean;
}
export class Circle extends DisplayObject<
CircleStyleProps,
Expand Down
16 changes: 15 additions & 1 deletion packages/g-lite/src/display-objects/Image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,22 @@ export interface ImageStyleProps extends BaseStyleProps {
src?: string | HTMLImageElement;
width?: number | string;
height?: number | string;
/**
* Whether the circle is billboard.
*/
isBillboard?: boolean;
billboardRotation?: number;
/**
* When isBillboard enabled, whether the circle is size attenuation.
*/
isSizeAttenuation?: boolean;
/**
* When isBillboard enabled, the rotation.
*/
billboardRotation?: number;
/**
* Whether to keep the aspect ratio of the image, under such circumstances, either the width or height can be omitted.
*/
keepAspectRatio?: boolean;
}
export interface ParsedImageStyleProps extends ParsedBaseStyleProps {
x: number;
Expand All @@ -27,6 +40,7 @@ export interface ParsedImageStyleProps extends ParsedBaseStyleProps {
isBillboard?: boolean;
billboardRotation?: number;
isSizeAttenuation?: boolean;
keepAspectRatio?: boolean;
}
export class Image extends DisplayObject<
ImageStyleProps,
Expand Down
27 changes: 26 additions & 1 deletion packages/g-lite/src/display-objects/Line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,38 @@ import { Shape } from '../types';
import { DisplayObject, isDisplayObject } from './DisplayObject';

export interface LineStyleProps extends BaseStyleProps {
/**
* X coordinate of the start of the line.
*/
x1: number;
/**
* Y coordinate of the start of the line.
*/
y1: number;
/**
* X coordinate of the end of the line.
*/
x2: number;
/**
* Y coordinate of the end of the line.
*/
y2: number;
/**
* Z coordinate of the start of the line.
*/
z1?: number;
/**
* Z coordinate of the end of the line.
*/
z2?: number;
/**
* Whether the line is billboard.
*/
isBillboard?: boolean;
/**
* Whether the line is size attenuation.
*/
isSizeAttenuation?: boolean;
/**
* marker will be positioned at x1/y1
*/
Expand Down Expand Up @@ -44,6 +69,7 @@ export interface ParsedLineStyleProps extends ParsedBaseStyleProps {
defX: number;
defY: number;
isBillboard?: boolean;
isSizeAttenuation?: boolean;
markerStart?: DisplayObject | null;
markerEnd?: DisplayObject | null;
markerStartOffset?: number;
Expand All @@ -70,7 +96,6 @@ export class Line extends DisplayObject<LineStyleProps, ParsedLineStyleProps> {
y2: 0,
z1: 0,
z2: 0,
isBillboard: false,
...style,
},
...rest,
Expand Down
8 changes: 8 additions & 0 deletions packages/g-lite/src/display-objects/Path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,14 @@ export interface PathStyleProps extends BaseStyleProps {
*/
markerEndOffset?: number;

/**
* Whether the circle is billboard.
*/
isBillboard?: boolean;
/**
* Whether the circle is size attenuation.
*/
isSizeAttenuation?: boolean;
}

export interface PathSegmentBBox {
Expand Down Expand Up @@ -108,6 +115,7 @@ export interface ParsedPathStyleProps extends ParsedBaseStyleProps {
markerStartOffset?: number;
markerEndOffset?: number;
isBillboard?: boolean;
isSizeAttenuation?: boolean;
}
export class Path extends DisplayObject<PathStyleProps, ParsedPathStyleProps> {
private markerStartAngle = 0;
Expand Down
7 changes: 7 additions & 0 deletions packages/g-lite/src/display-objects/Polyline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ export interface PolylineStyleProps extends BaseStyleProps {
* offset relative to original position
*/
markerEndOffset?: number;
/**
* Whether the circle is billboard.
*/
isBillboard?: boolean;
/**
* Whether the circle is size attenuation.
*/
isSizeAttenuation?: boolean;
}
export interface ParsedPolylineStyleProps extends ParsedBaseStyleProps {
points: {
Expand Down
2 changes: 1 addition & 1 deletion packages/g-mobile-webgl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"@antv/g-plugin-html-renderer": "workspace:*",
"@antv/g-plugin-image-loader": "workspace:*",
"@antv/g-plugin-mobile-interaction": "workspace:*",
"@antv/g-device-api": "^1.3.0",
"@antv/g-device-api": "^1.3.6",
"@antv/util": "^3.3.4",
"tslib": "^2.5.3"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/g-plugin-3d/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"@antv/g-lite": "workspace:*",
"@antv/g-plugin-device-renderer": "workspace:*",
"@antv/g-shader-components": "workspace:*",
"@antv/g-device-api": "^1.3.0",
"@antv/g-device-api": "^1.3.6",
"gl-matrix": "^3.4.3",
"tslib": "^2.5.3"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/g-plugin-device-renderer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"@antv/g-plugin-image-loader": "workspace:*",
"@antv/g-shader-components": "workspace:*",
"@antv/util": "^3.3.4",
"@antv/g-device-api": "^1.3.0",
"@antv/g-device-api": "^1.3.6",
"@webgpu/types": "^0.1.6",
"earcut": "^2.2.3",
"eventemitter3": "^5.0.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/g-plugin-device-renderer/src/PickingPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ export class PickingPlugin implements RenderingPlugin {
},
{
name: SceneUniform.VIEWPORT,
value: [canvasWidth, canvasHeight],
value: [width, height],
},
{
name: SceneUniform.IS_ORTHO,
Expand Down
36 changes: 30 additions & 6 deletions packages/g-plugin-device-renderer/src/drawcalls/InstancedLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ export class InstancedLineDrawcall extends Instanced {
markerStartOffset,
markerEndOffset,
isBillboard,
// @ts-ignore
isSizeAttenuation,
} = (object as Polyline).parsedStyle;
parsedLineStyleProps = {
x1: points[0][0],
Expand All @@ -193,6 +195,7 @@ export class InstancedLineDrawcall extends Instanced {
lineDash,
lineDashOffset,
isBillboard,
isSizeAttenuation,
markerStart,
markerEnd,
markerStartOffset,
Expand All @@ -212,6 +215,7 @@ export class InstancedLineDrawcall extends Instanced {
markerStartOffset,
markerEndOffset,
isBillboard,
isSizeAttenuation,
} = (object as Path).parsedStyle;
let mSegmentCount = 0;
let mCommandIndex = 0;
Expand Down Expand Up @@ -239,6 +243,7 @@ export class InstancedLineDrawcall extends Instanced {
lineDash,
lineDashOffset,
isBillboard,
isSizeAttenuation,
markerStart,
markerEnd,
markerStartOffset,
Expand All @@ -247,8 +252,19 @@ export class InstancedLineDrawcall extends Instanced {
totalLength = (object as Path).getTotalLength();
}

const { x1, y1, x2, y2, z1, z2, defX, defY, lineCap, isBillboard } =
parsedLineStyleProps;
const {
x1,
y1,
x2,
y2,
z1,
z2,
defX,
defY,
lineCap,
isBillboard,
isSizeAttenuation,
} = parsedLineStyleProps;

const { startOffsetX, startOffsetY, endOffsetX, endOffsetY } =
this.calcOffset(parsedLineStyleProps);
Expand All @@ -263,8 +279,8 @@ export class InstancedLineDrawcall extends Instanced {
dashOffset,
dashSegmentPercent,
dashRatioInEachSegment,
// isBillboard
isBillboard ? 1 : 0,
// isSizeAttenuation
isBillboard || isSizeAttenuation ? 1 : 0,
);

interleaved.push(
Expand Down Expand Up @@ -399,6 +415,8 @@ export class InstancedLineDrawcall extends Instanced {
markerStartOffset,
markerEndOffset,
isBillboard,
// @ts-ignore
isSizeAttenuation,
} = (object as Polyline).parsedStyle;
parsedLineStyleProps = {
x1: points[0][0],
Expand All @@ -410,6 +428,7 @@ export class InstancedLineDrawcall extends Instanced {
defX,
defY,
lineCap,
isSizeAttenuation,
isBillboard,
markerStart,
markerEnd,
Expand All @@ -427,6 +446,7 @@ export class InstancedLineDrawcall extends Instanced {
markerStartOffset,
markerEndOffset,
isBillboard,
isSizeAttenuation,
} = (object as Path).parsedStyle;
parsedLineStyleProps = {
x1: absolutePath[0][1],
Expand All @@ -439,6 +459,7 @@ export class InstancedLineDrawcall extends Instanced {
defY,
lineCap,
isBillboard,
isSizeAttenuation,
markerStart,
markerEnd,
markerStartOffset,
Expand Down Expand Up @@ -468,6 +489,7 @@ export class InstancedLineDrawcall extends Instanced {
} else if (
name === 'lineDashOffset' ||
name === 'lineDash' ||
name === 'isSizeAttenuation' ||
name === 'isBillboard'
) {
const packed: number[] = [];
Expand All @@ -479,8 +501,10 @@ export class InstancedLineDrawcall extends Instanced {
packed.push(
dashOffset,
dashSegmentPercent,
dashRatioInEachSegment, // isBillboard
object.parsedStyle.isBillboard ? 1 : 0,
dashRatioInEachSegment,
object.parsedStyle.isBillboard || object.parsedStyle.isSizeAttenuation
? 1
: 0, // isSizeAttenuation
);
});

Expand Down
Loading

0 comments on commit 4fdee19

Please sign in to comment.