Skip to content

Commit

Permalink
Release (#1834)
Browse files Browse the repository at this point in the history
* fix: rough canvas rendering error (#1830)

* fix: rough canvas rendering error

* chore: add changeset

* refactor: iterator forEach method now has compatibility

* fix: the size of an unloaded Image is 0 (#1831)

* Version Packages (#1832)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 13, 2024
1 parent dd3e8f2 commit 1d5a167
Show file tree
Hide file tree
Showing 37 changed files with 231 additions and 71 deletions.
42 changes: 36 additions & 6 deletions __tests__/demos/perf/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,49 @@ export async function image(context: { canvas: Canvas; gui: lil.GUI }) {
console.log(canvas);

const group = new Group();

// let image = new GImage({
// style: {
// x: 0,
// y: 0,
// // width: 100,
// // height: 400,
// // src: 'https://gw.alipayobjects.com/mdn/rms_6ae20b/afts/img/A*N4ZMS7gHsUIAAAAAAAAAAABkARQnAQ',
// // src: 'http://mmtcdp.stable.alipay.net/cto_designhubcore/afts/img/g1a5QYkvbcMAAAAAAAAAAAAADgLVAQBr/original',
// src: 'https://mdn.alipayobjects.com/huamei_fr7vu1/afts/img/A*SqloToP7R9QAAAAAAAAAAAAADkn0AQ/original',
// // src: 'https://freepngimg.com/download/svg/animal/10081.svg',
// },
// });

// group.appendChild(image);

const img = new Image();
img.onload = () => {
console.log('onload', img.complete);
// let image = new GImage({
// style: {
// x: 0,
// y: 0,
// src: img,
// },
// });
// group.appendChild(image);
};

let image = new GImage({
style: {
x: 0,
y: 0,
// width: 100,
// height: 400,
// src: 'https://gw.alipayobjects.com/mdn/rms_6ae20b/afts/img/A*N4ZMS7gHsUIAAAAAAAAAAABkARQnAQ',
// src: 'http://mmtcdp.stable.alipay.net/cto_designhubcore/afts/img/g1a5QYkvbcMAAAAAAAAAAAAADgLVAQBr/original',
src: 'https://mdn.alipayobjects.com/huamei_fr7vu1/afts/img/A*SqloToP7R9QAAAAAAAAAAAAADkn0AQ/original',
src: img,
},
});

group.appendChild(image);

// img.src = 'https://freepngimg.com/download/svg/animal/10081.svg';
img.src =
// 'https://gw.alipayobjects.com/mdn/rms_6ae20b/afts/img/A*N4ZMS7gHsUIAAAAAAAAAAABkARQnAQ';
'https://mdn.alipayobjects.com/huamei_fr7vu1/afts/img/A*SqloToP7R9QAAAAAAAAAAAAADkn0AQ/original';

canvas.appendChild(group);

// ---
Expand Down
11 changes: 11 additions & 0 deletions packages/g-canvas/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# @antv/g-canvas

## 2.0.25

### Patch Changes

- Updated dependencies [1de86a88]
- Updated dependencies [abebed9e]
- Updated dependencies [1de86a88]
- @antv/g-plugin-canvas-renderer@2.2.4
- @antv/g-plugin-image-loader@2.1.4
- @antv/g-plugin-canvas-picker@2.1.4

## 2.0.24

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/g-canvas/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-canvas",
"version": "2.0.24",
"version": "2.0.25",
"description": "A renderer implemented by Canvas 2D API",
"keywords": [
"antv",
Expand Down
10 changes: 10 additions & 0 deletions packages/g-canvaskit/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# @antv/g-canvaskit

## 1.0.24

### Patch Changes

- Updated dependencies [abebed9e]
- Updated dependencies [1de86a88]
- @antv/g-plugin-image-loader@2.1.4
- @antv/g-plugin-canvas-picker@2.1.4
- @antv/g-plugin-canvaskit-renderer@2.1.4

## 1.0.23

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/g-canvaskit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-canvaskit",
"version": "1.0.23",
"version": "1.0.24",
"description": "A renderer implemented by CanvasKit",
"keywords": [
"antv",
Expand Down
11 changes: 11 additions & 0 deletions packages/g-mobile-canvas/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# @antv/g-mobile-canvas

## 1.0.22

### Patch Changes

- Updated dependencies [1de86a88]
- Updated dependencies [abebed9e]
- Updated dependencies [1de86a88]
- @antv/g-plugin-canvas-renderer@2.2.4
- @antv/g-plugin-image-loader@2.1.4
- @antv/g-plugin-canvas-picker@2.1.4

## 1.0.21

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/g-mobile-canvas/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-mobile-canvas",
"version": "1.0.21",
"version": "1.0.22",
"description": "A renderer implemented with Canvas2D API in mobile environment",
"keywords": [
"antv",
Expand Down
9 changes: 9 additions & 0 deletions packages/g-mobile-webgl/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# @antv/g-mobile-webgl

## 1.0.29

### Patch Changes

- Updated dependencies [abebed9e]
- Updated dependencies [1de86a88]
- @antv/g-plugin-image-loader@2.1.4
- @antv/g-plugin-device-renderer@2.2.4

## 1.0.28

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/g-mobile-webgl/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-mobile-webgl",
"version": "1.0.28",
"version": "1.0.29",
"description": "A renderer implemented by WebGL1/2 in mobile environment",
"keywords": [
"antv",
Expand Down
6 changes: 6 additions & 0 deletions packages/g-plugin-3d/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @antv/g-plugin-3d

## 2.0.27

### Patch Changes

- @antv/g-plugin-device-renderer@2.2.4

## 2.0.26

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/g-plugin-3d/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-plugin-3d",
"version": "2.0.26",
"version": "2.0.27",
"description": "Provide 3D extension for G",
"keywords": [
"antv",
Expand Down
7 changes: 7 additions & 0 deletions packages/g-plugin-canvas-picker/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @antv/g-plugin-canvas-picker

## 2.1.4

### Patch Changes

- Updated dependencies [1de86a88]
- @antv/g-plugin-canvas-renderer@2.2.4

## 2.1.3

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/g-plugin-canvas-picker/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-plugin-canvas-picker",
"version": "2.1.3",
"version": "2.1.4",
"description": "A G plugin for picking in canvas",
"keywords": [
"antv",
Expand Down
9 changes: 9 additions & 0 deletions packages/g-plugin-canvas-renderer/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# @antv/g-plugin-canvas-renderer

## 2.2.4

### Patch Changes

- 1de86a88: fix: rough canvas rendering error
- Updated dependencies [abebed9e]
- Updated dependencies [1de86a88]
- @antv/g-plugin-image-loader@2.1.4

## 2.2.3

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/g-plugin-canvas-renderer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-plugin-canvas-renderer",
"version": "2.2.3",
"version": "2.2.4",
"description": "A G plugin of renderer implementation with Canvas2D API",
"keywords": [
"antv",
Expand Down
38 changes: 37 additions & 1 deletion packages/g-plugin-canvas-renderer/src/CanvasRendererPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import type {
ContextService,
CanvasContext,
GlobalRuntime,
CSSRGB,
ParsedBaseStyleProps,
} from '@antv/g-lite';
import {
AABB,
Expand All @@ -18,6 +20,7 @@ import {
Node,
} from '@antv/g-lite';
import { mat4, vec3 } from 'gl-matrix';
import { isNil } from '@antv/util';
import type { CanvasRendererPluginOptions } from './interfaces';
import type { Plugin } from '.';

Expand Down Expand Up @@ -599,7 +602,7 @@ export class CanvasRendererPlugin implements RenderingPlugin {
context.save();

// apply attributes to context
styleRenderer.applyAttributesToContext(context, object);
this.applyAttributesToContext(context, object);
}

if (generatePath) {
Expand Down Expand Up @@ -633,6 +636,39 @@ export class CanvasRendererPlugin implements RenderingPlugin {
object.renderable.dirty = false;
}

applyAttributesToContext(
context: CanvasRenderingContext2D,
object: DisplayObject,
) {
const { stroke, fill, opacity, lineDash, lineDashOffset } =
object.parsedStyle as ParsedBaseStyleProps;
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/setLineDash
if (lineDash) {
context.setLineDash(lineDash);
}

// @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/lineDashOffset
if (!isNil(lineDashOffset)) {
context.lineDashOffset = lineDashOffset;
}

if (!isNil(opacity)) {
context.globalAlpha *= opacity;
}

if (
!isNil(stroke) &&
!Array.isArray(stroke) &&
!(stroke as CSSRGB).isNone
) {
context.strokeStyle = object.attributes.stroke as string;
}

if (!isNil(fill) && !Array.isArray(fill) && !(fill as CSSRGB).isNone) {
context.fillStyle = object.attributes.fill as string;
}
}

private convertAABB2Rect(aabb: AABB): Rect {
const min = aabb.getMin();
const max = aabb.getMax();
Expand Down
33 changes: 0 additions & 33 deletions packages/g-plugin-canvas-renderer/src/shapes/styles/Default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,6 @@ import { OptimizedDefaultRenderer, DEFAULT_STYLE } from './OptimizedDefault';
import { getColor, getPattern } from './helper';

export class DefaultRenderer extends OptimizedDefaultRenderer {
applyAttributesToContext(
context: CanvasRenderingContext2D,
object: DisplayObject,
) {
const { stroke, fill, opacity, lineDash, lineDashOffset } =
object.parsedStyle;
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/setLineDash
if (lineDash) {
context.setLineDash(lineDash);
}

// @see https://developer.mozilla.org/zh-CN/docs/Web/API/CanvasRenderingContext2D/lineDashOffset
if (!isNil(lineDashOffset)) {
context.lineDashOffset = lineDashOffset;
}

if (!isNil(opacity)) {
context.globalAlpha *= opacity;
}

if (
!isNil(stroke) &&
!Array.isArray(stroke) &&
!(stroke as CSSRGB).isNone
) {
context.strokeStyle = object.attributes.stroke as string;
}

if (!isNil(fill) && !Array.isArray(fill) && !(fill as CSSRGB).isNone) {
context.fillStyle = object.attributes.fill as string;
}
}

render(
context: CanvasRenderingContext2D,
parsedStyle: ParsedBaseStyleProps,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ export interface StyleRenderer {

// ---

applyAttributesToContext: (
context: CanvasRenderingContext2D,
object: DisplayObject,
) => void;

render: (
context: CanvasRenderingContext2D,
parsedStyle: ParsedBaseStyleProps,
Expand Down
8 changes: 8 additions & 0 deletions packages/g-plugin-canvaskit-renderer/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @antv/g-plugin-canvaskit-renderer

## 2.1.4

### Patch Changes

- Updated dependencies [abebed9e]
- Updated dependencies [1de86a88]
- @antv/g-plugin-image-loader@2.1.4

## 2.1.3

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/g-plugin-canvaskit-renderer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-plugin-canvaskit-renderer",
"version": "2.1.3",
"version": "2.1.4",
"description": "A G plugin of renderer implementation with CanvasKit",
"keywords": [
"antv",
Expand Down
8 changes: 8 additions & 0 deletions packages/g-plugin-device-renderer/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @antv/g-plugin-device-renderer

## 2.2.4

### Patch Changes

- Updated dependencies [abebed9e]
- Updated dependencies [1de86a88]
- @antv/g-plugin-image-loader@2.1.4

## 2.2.3

### Patch Changes
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
@@ -1,6 +1,6 @@
{
"name": "@antv/g-plugin-device-renderer",
"version": "2.2.3",
"version": "2.2.4",
"description": "A G plugin of renderer implementation with GPUDevice",
"keywords": [
"antv",
Expand Down
7 changes: 7 additions & 0 deletions packages/g-plugin-image-loader/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @antv/g-plugin-image-loader

## 2.1.4

### Patch Changes

- abebed9e: fix: the size of an unloaded Image is 0
- 1de86a88: refactor: iterator forEach method now has compatibility

## 2.1.3

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/g-plugin-image-loader/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-plugin-image-loader",
"version": "2.1.3",
"version": "2.1.4",
"description": "A G plugin for loading image",
"keywords": [
"antv",
Expand Down
Loading

0 comments on commit 1d5a167

Please sign in to comment.