Skip to content

Commit

Permalink
Release (#1633)
Browse files Browse the repository at this point in the history
* feat: support size attenuation in annotation plugin (#1631)

* feat: support size attenuation in annotation plugin

* chore: commit changeset

* chore(release): bump version (#1632)

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 committed Feb 23, 2024
1 parent 76b373f commit a43c19a
Show file tree
Hide file tree
Showing 122 changed files with 1,124 additions and 169 deletions.
413 changes: 386 additions & 27 deletions __tests__/demos/plugin/annotation.ts

Large diffs are not rendered by default.

45 changes: 45 additions & 0 deletions __tests__/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,51 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>G: Preview</title>
<style>
.lil-gui.root {
position: absolute;
top: 0;
right: 0;
z-index: 1;
background: black;
}

.lil-gui.main li {
margin-left: 0 !important;
padding-left: 0 !important;
list-style-type: none !important;
}

.lil-gui li.title {
padding-left: 16px !important;
}

.lil-gui .c select {
color: black;
}

@keyframes animated-size {
0% {
width: 10px;
height: 500px;
}
50% {
width: 800px;
height: 500px;
}
100% {
width: 10px;
height: 500px;
}
}

.animatedCanvasSize {
animation-duration: 3s;
animation-iteration-count: infinite;
animation-name: animated-size;
animation-timing-function: ease;
}
</style>
</head>
<body>
<div id="app"></div>
Expand Down
57 changes: 54 additions & 3 deletions __tests__/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Canvas } from '../packages/g';
import * as lil from 'lil-gui';
import { Canvas, CanvasEvent } from '../packages/g';
import { Renderer as CanvasRenderer } from '../packages/g-canvas';
import { Renderer as CanvaskitRenderer } from '../packages/g-canvaskit';
import { Renderer as SVGRenderer } from '../packages/g-svg';
Expand Down Expand Up @@ -52,7 +53,11 @@ selectChart.style.margin = '1em';
renderOptions();
selectChart.onchange = () => {
const { value } = selectChart;
history.pushState({ value }, '', `?name=${value}`);
history.pushState(
{ value },
'',
`?name=${value}&renderer=${selectRenderer.value}`,
);
plot();
};
document.onkeydown = (event) => {
Expand Down Expand Up @@ -86,6 +91,12 @@ const selectRenderer = document.createElement('select');
selectRenderer.style.margin = '1em';
selectRenderer.append(...Object.keys(renderers).map(createOption));
selectRenderer.onchange = () => {
const { value } = selectRenderer;
history.pushState(
{ value },
'',
`?name=${selectChart.value}&renderer=${value}`,
);
plot();
};

Expand All @@ -111,7 +122,12 @@ addEventListener('popstate', (event) => {

// @ts-ignore
const initialValue = new URL(location).searchParams.get('name') as string;
// @ts-ignore
const initialRenderer = new URL(location).searchParams.get(
'renderer',
) as string;
if (tests[initialValue]) selectChart.value = initialValue;
if (renderers[initialRenderer]) selectRenderer.value = initialRenderer;
app.append(selectChart);
app.append(searchInput);
app.append(selectRenderer);
Expand Down Expand Up @@ -167,8 +183,14 @@ function createSpecRender(object) {
],
// Used for WebGPU renderer
shaderCompilerPath: '/glsl_wgsl_compiler_bg.wasm',
// enableDirtyRectangleRendering: false,
// enableDirtyRectangleRenderingDebug: true,
});

if (generate.initRenderer) {
generate.initRenderer(renderer, selectRenderer.value);
}

renderer.registerPlugin(
new DragAndDropPlugin({ dragstartDistanceThreshold: 1 }),
);
Expand All @@ -184,7 +206,36 @@ function createSpecRender(object) {
// @ts-ignore
window.__g_instances__ = [canvas];

await generate({ canvas, renderer, container: $div });
// GUI
const gui = new lil.GUI({ autoPlace: false });
$div.appendChild(gui.domElement);

await generate({ canvas, renderer, container: $div, gui });

if (
selectRenderer.value === 'canvas' &&
renderer.getConfig().enableDirtyRectangleRendering &&
renderer.getConfig().enableDirtyRectangleRenderingDebug
) {
// display dirty rectangle
const $dirtyRectangle = document.createElement('div');
$dirtyRectangle.style.cssText = `
position: absolute;
pointer-events: none;
background: rgba(255, 0, 0, 0.5);
`;
$div.appendChild($dirtyRectangle);
canvas.addEventListener(CanvasEvent.DIRTY_RECTANGLE, (e) => {
const { dirtyRect } = e.detail;
const { x, y, width, height } = dirtyRect;
const dpr = window.devicePixelRatio;
// convert from canvas coords to viewport
$dirtyRectangle.style.left = `${x / dpr}px`;
$dirtyRectangle.style.top = `${y / dpr}px`;
$dirtyRectangle.style.width = `${width / dpr}px`;
$dirtyRectangle.style.height = `${height / dpr}px`;
});
}

container.append($div);
};
Expand Down
7 changes: 7 additions & 0 deletions packages/g-camera-api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @antv/g-camera-api

## 1.2.23

### Patch Changes

- Updated dependencies [11d23f39]
- @antv/g-lite@1.2.22

## 1.2.22

### 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": "1.2.22",
"version": "1.2.23",
"description": "A simple implementation of Camera API.",
"keywords": [
"antv",
Expand Down
13 changes: 13 additions & 0 deletions packages/g-canvas/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# @antv/g-canvas

## 1.11.27

### Patch Changes

- Updated dependencies [11d23f39]
- @antv/g-lite@1.2.22
- @antv/g-plugin-canvas-path-generator@1.3.22
- @antv/g-plugin-canvas-picker@1.10.24
- @antv/g-plugin-canvas-renderer@1.9.24
- @antv/g-plugin-dom-interaction@1.9.22
- @antv/g-plugin-html-renderer@1.9.25
- @antv/g-plugin-image-loader@1.3.22

## 1.11.26

### 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": "1.11.26",
"version": "1.11.27",
"description": "A renderer implemented by Canvas 2D API",
"keywords": [
"antv",
Expand Down
13 changes: 13 additions & 0 deletions packages/g-canvaskit/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# @antv/g-canvaskit

## 0.10.27

### Patch Changes

- Updated dependencies [11d23f39]
- @antv/g-lite@1.2.22
- @antv/g-plugin-canvas-path-generator@1.3.22
- @antv/g-plugin-canvas-picker@1.10.24
- @antv/g-plugin-canvaskit-renderer@1.3.23
- @antv/g-plugin-dom-interaction@1.9.22
- @antv/g-plugin-html-renderer@1.9.25
- @antv/g-plugin-image-loader@1.3.22

## 0.10.26

### 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": "0.10.26",
"version": "0.10.27",
"description": "A renderer implemented by CanvasKit",
"keywords": [
"antv",
Expand Down
7 changes: 7 additions & 0 deletions packages/g-components/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @antv/g-components

## 1.9.22

### Patch Changes

- Updated dependencies [11d23f39]
- @antv/g-lite@1.2.22

## 1.9.21

### 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": "1.9.21",
"version": "1.9.22",
"description": "Components for g",
"keywords": [
"antv",
Expand Down
7 changes: 7 additions & 0 deletions packages/g-dom-mutation-observer-api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @antv/g-dom-mutation-observer-api

## 1.2.22

### Patch Changes

- Updated dependencies [11d23f39]
- @antv/g-lite@1.2.22

## 1.2.21

### 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": "1.2.21",
"version": "1.2.22",
"description": "A simple implementation of DOM MutationObserver API.",
"keywords": [
"antv",
Expand Down
7 changes: 7 additions & 0 deletions packages/g-gesture/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @antv/g-gesture

## 2.2.25

### Patch Changes

- Updated dependencies [11d23f39]
- @antv/g-lite@1.2.22

## 2.2.24

### 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": "2.2.24",
"version": "2.2.25",
"description": "G Gesture",
"keywords": [
"antv",
Expand Down
7 changes: 7 additions & 0 deletions packages/g-image-exporter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @antv/g-image-exporter

## 0.7.22

### Patch Changes

- Updated dependencies [11d23f39]
- @antv/g-lite@1.2.22

## 0.7.21

### 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": "0.7.21",
"version": "0.7.22",
"description": "A image exporter for G using DOM API",
"keywords": [
"antv",
Expand Down
6 changes: 6 additions & 0 deletions packages/g-lite/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @antv/g-lite

## 1.2.22

### Patch Changes

- 11d23f39: Support size attenuation.

## 1.2.21

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/g-lite/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/g-lite",
"version": "1.2.21",
"version": "1.2.22",
"description": "A core module for rendering engine implements DOM API.",
"keywords": [
"antv",
Expand Down
1 change: 1 addition & 0 deletions packages/g-lite/src/AbstractRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export class AbstractRenderer implements IRenderer {
*/
enableDirtyRectangleRendering: true,
enableDirtyRectangleRenderingDebug: false,
enableSizeAttenuation: true,
...config,
};
}
Expand Down
24 changes: 19 additions & 5 deletions packages/g-lite/src/Canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import { FrustumCullingStrategy } from './plugins/FrustumCullingStrategy';
import { PrepareRendererPlugin } from './plugins/PrepareRendererPlugin';
import { EventService, RenderReason, RenderingService } from './services';
import type { PointLike } from './shapes';
import type {
CanvasConfig,
ClipSpaceNearZ,
Cursor,
InteractivePointerEvent,
import {
type CanvasConfig,
type ClipSpaceNearZ,
type Cursor,
type InteractivePointerEvent,
} from './types';
import {
caf,
Expand Down Expand Up @@ -293,12 +293,26 @@ export class Canvas extends EventTarget implements ICanvas {
this.context.renderingContext.renderReasons.add(
RenderReason.CAMERA_CHANGED,
);

if (
runtime.enableSizeAttenuation &&
this.getConfig().renderer.getConfig().enableSizeAttenuation
) {
this.updateSizeAttenuation();
}
});

// bind camera
this.context.camera = camera;
}

private updateSizeAttenuation() {
const zoom = this.getCamera().getZoom();
this.document.documentElement.forEach((node: DisplayObject) => {
runtime.styleValueRegistry.updateSizeAttenuation(node, zoom);
});
}

getConfig() {
return this.context.config;
}
Expand Down
Loading

0 comments on commit a43c19a

Please sign in to comment.