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

Release #1870

Merged
merged 7 commits into from
Dec 20, 2024
Merged

Release #1870

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
1 change: 0 additions & 1 deletion __tests__/demos/bugfix/1677.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export async function shadowroot_offset(context) {
width: 500,
height: 500,
renderer: new Renderer(),
supportsCSSTransform: true,
});

const circle = new Circle({
Expand Down
12 changes: 6 additions & 6 deletions __tests__/demos/event/dblClick.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Circle, Text } from '@antv/g';
import { Circle, Text, Canvas } from '@antv/g';

export async function dblClick(context) {
export async function dblClick(context: { canvas: Canvas }) {
const { canvas } = context;
await canvas.ready;

let DELAY = 200;
canvas.dblClickSpeed = DELAY;
canvas.getConfig().dblClickSpeed = DELAY;

const circle0 = new Circle({
style: {
Expand Down Expand Up @@ -43,7 +43,7 @@ export async function dblClick(context) {

circle0.addEventListener('mouseenter', () => {
DELAY = 200;
canvas.dblClickSpeed = DELAY;
canvas.getConfig().dblClickSpeed = DELAY;

text0.attr({ text: `current dblclick delay: ${DELAY}ms` });
text1.attr({
Expand All @@ -52,7 +52,7 @@ export async function dblClick(context) {
});
circle1.addEventListener('mouseenter', () => {
DELAY = 500;
canvas.dblClickSpeed = DELAY;
canvas.getConfig().dblClickSpeed = DELAY;

text0.attr({ text: `current dblclick delay: ${DELAY}ms` });
text1.attr({
Expand All @@ -61,7 +61,7 @@ export async function dblClick(context) {
});
circle2.addEventListener('mouseenter', () => {
DELAY = 1000;
canvas.dblClickSpeed = DELAY;
canvas.getConfig().dblClickSpeed = DELAY;

text0.attr({ text: `current dblclick delay: ${DELAY}ms` });
text1.attr({
Expand Down
93 changes: 93 additions & 0 deletions __tests__/demos/perf/event.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import {
Canvas,
ElementEvent,
Rect,
Group,
CustomEvent,
EventTarget,
} from '@antv/g';
import * as tinybench from 'tinybench';

export async function event(context: { canvas: Canvas }) {
const { canvas } = context;
console.log(canvas);

await canvas.ready;

const { width, height } = canvas.getConfig();
const root = new Group();
let count = 2e4;
let rects = [];
let eventTargets = [];

function render() {
root.destroyChildren();
rects = [];

for (let i = 0; i < count; i++) {
const x = Math.random() * width;
const y = Math.random() * height;
const size = 10 + Math.random() * 40;
const speed = 1 + Math.random();

const rect = new Rect({
style: {
x,
y,
width: size,
height: size,
fill: 'white',
stroke: '#000',
lineWidth: 1,
},
});
root.appendChild(rect);
rects[i] = { x, y, size, speed, el: rect };

// ---
const eventTarge = new EventTarget();
eventTargets.push(eventTarge);
eventTarge.addEventListener(ElementEvent.BOUNDS_CHANGED, () => {
//
});
}
}

render();
canvas.appendChild(root);

// benchmark
// ----------
const boundsChangedEvent = new CustomEvent(ElementEvent.BOUNDS_CHANGED);
boundsChangedEvent.detail = { affectChildren: true };

const bench = new tinybench.Bench({ name: 'event benchmark', time: 1e2 });

bench.add('Iterating trigger events', async () => {
root.forEach((el) => {
el.dispatchEvent(boundsChangedEvent);
});
});
bench.add('Iterating trigger events without propagate', async () => {
root.forEach((el) => {
el.dispatchEvent(boundsChangedEvent, true);
});
});
bench.add('Iterating over trigger events on empty objects', async () => {
eventTargets.forEach((el) => {
el.dispatchEvent(boundsChangedEvent);
});
});
bench.add('Batch triggering events', async () => {
canvas.dispatchEvent(boundsChangedEvent, true);
});

await bench.run();

console.log(bench.name);
console.table(bench.table());
console.log(bench.results);
console.log(bench.tasks);

// ----------
}
10 changes: 10 additions & 0 deletions packages/g-camera-api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# @antv/g-camera-api

## 2.0.29

### Patch Changes

- Updated dependencies [244d6dd]
- Updated dependencies [9ebc16b]
- Updated dependencies [2d71558]
- Updated dependencies [fad9325]
- @antv/[email protected]

## 2.0.28

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/g-camera-api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-camera-api",
"version": "2.0.28",
"version": "2.0.29",
"description": "A simple implementation of Camera API.",
"keywords": [
"antv",
Expand Down
17 changes: 17 additions & 0 deletions packages/g-canvas/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# @antv/g-canvas

## 2.0.33

### Patch Changes

- 244d6dd: refactor: reduce global redundant code
- Updated dependencies [244d6dd]
- Updated dependencies [9ebc16b]
- Updated dependencies [2d71558]
- Updated dependencies [fad9325]
- @antv/[email protected]
- @antv/[email protected]
- @antv/[email protected]
- @antv/[email protected]
- @antv/[email protected]
- @antv/[email protected]
- @antv/[email protected]

## 2.0.32

### 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.32",
"version": "2.0.33",
"description": "A renderer implemented by Canvas 2D API",
"keywords": [
"antv",
Expand Down
8 changes: 2 additions & 6 deletions packages/g-canvas/src/Canvas2DContextService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
CanvasConfig,
ContextService,
} from '@antv/g-lite';
import { RenderReason, isBrowser, setDOMSize } from '@antv/g-lite';
import { RenderReason, setDOMSize } from '@antv/g-lite';
import { isString } from '@antv/util';

export class Canvas2DContextService
Expand Down Expand Up @@ -92,11 +92,7 @@ export class Canvas2DContextService
}

resize(width: number, height: number) {
const { devicePixelRatio } = this.canvasConfig;

// use user-defined dpr first
let dpr = devicePixelRatio || (isBrowser && window.devicePixelRatio) || 1;
dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
const { devicePixelRatio: dpr } = this.canvasConfig;
this.dpr = dpr;

if (this.$canvas) {
Expand Down
17 changes: 17 additions & 0 deletions packages/g-canvaskit/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# @antv/g-canvaskit

## 1.0.32

### Patch Changes

- 244d6dd: refactor: reduce global redundant code
- Updated dependencies [244d6dd]
- Updated dependencies [9ebc16b]
- Updated dependencies [2d71558]
- Updated dependencies [fad9325]
- @antv/[email protected]
- @antv/[email protected]
- @antv/[email protected]
- @antv/[email protected]
- @antv/[email protected]
- @antv/[email protected]
- @antv/[email protected]

## 1.0.31

### 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.31",
"version": "1.0.32",
"description": "A renderer implemented by CanvasKit",
"keywords": [
"antv",
Expand Down
7 changes: 2 additions & 5 deletions packages/g-canvaskit/src/CanvasKitContextService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
CanvasConfig,
ContextService,
} from '@antv/g-lite';
import { isBrowser, setDOMSize } from '@antv/g-lite';
import { setDOMSize } from '@antv/g-lite';
import type * as CanvaskitRenderer from '@antv/g-plugin-canvaskit-renderer';
import type { CanvasKitContext } from '@antv/g-plugin-canvaskit-renderer';
import { isString } from '@antv/util';
Expand Down Expand Up @@ -40,7 +40,7 @@ export class CanvasKitContextService
}

async initAsync() {
const { container, canvas, devicePixelRatio } = this.canvasConfig;
const { container, canvas, devicePixelRatio: dpr } = this.canvasConfig;

if (canvas) {
this.$canvas = canvas;
Expand Down Expand Up @@ -71,9 +71,6 @@ export class CanvasKitContextService
}
}

// use user-defined dpr first
let dpr = devicePixelRatio || (isBrowser && window.devicePixelRatio) || 1;
dpr = dpr >= 1 ? Math.ceil(dpr) : 1;
this.dpr = dpr;
this.resize(this.canvasConfig.width, this.canvasConfig.height);

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

## 2.0.26

### Patch Changes

- Updated dependencies [244d6dd]
- Updated dependencies [9ebc16b]
- Updated dependencies [2d71558]
- Updated dependencies [fad9325]
- @antv/[email protected]

## 2.0.25

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/g-components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-components",
"version": "2.0.25",
"version": "2.0.26",
"description": "Components for g",
"keywords": [
"antv",
Expand Down
10 changes: 10 additions & 0 deletions packages/g-dom-mutation-observer-api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# @antv/g-dom-mutation-observer-api

## 2.0.26

### Patch Changes

- Updated dependencies [244d6dd]
- Updated dependencies [9ebc16b]
- Updated dependencies [2d71558]
- Updated dependencies [fad9325]
- @antv/[email protected]

## 2.0.25

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/g-dom-mutation-observer-api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-dom-mutation-observer-api",
"version": "2.0.25",
"version": "2.0.26",
"description": "A simple implementation of DOM MutationObserver API.",
"keywords": [
"antv",
Expand Down
10 changes: 10 additions & 0 deletions packages/g-gesture/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# @antv/g-gesture

## 3.0.26

### Patch Changes

- Updated dependencies [244d6dd]
- Updated dependencies [9ebc16b]
- Updated dependencies [2d71558]
- Updated dependencies [fad9325]
- @antv/[email protected]

## 3.0.25

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/g-gesture/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-gesture",
"version": "3.0.25",
"version": "3.0.26",
"description": "G Gesture",
"keywords": [
"antv",
Expand Down
11 changes: 11 additions & 0 deletions packages/g-image-exporter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# @antv/g-image-exporter

## 1.0.26

### Patch Changes

- 244d6dd: refactor: reduce global redundant code
- Updated dependencies [244d6dd]
- Updated dependencies [9ebc16b]
- Updated dependencies [2d71558]
- Updated dependencies [fad9325]
- @antv/[email protected]

## 1.0.25

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/g-image-exporter/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-image-exporter",
"version": "1.0.25",
"version": "1.0.26",
"description": "A image exporter for G using DOM API",
"keywords": [
"antv",
Expand Down
11 changes: 2 additions & 9 deletions packages/g-image-exporter/src/ImageExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,16 +188,9 @@ export class ImageExporter {
}

private getOrCreateImage(src: string): Promise<HTMLImageElement> {
// @see https://github.com/antvis/g/issues/938
const { createImage } = this.options.canvas.getConfig();

return new Promise((resolve, reject) => {
let image: HTMLImageElement;
if (createImage) {
image = createImage(src);
} else if (isBrowser) {
image = new window.Image();
}
// @see https://github.com/antvis/g/issues/938
const image = this.options.canvas.getConfig().createImage();

if (image) {
image.onload = () => {
Expand Down
Loading
Loading