Skip to content

Commit

Permalink
chore: fix test case for stdlib
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoiver committed Aug 18, 2023
1 parent be64342 commit 90d1458
Show file tree
Hide file tree
Showing 11 changed files with 237 additions and 119 deletions.
2 changes: 1 addition & 1 deletion __tests__/plots/api/chart-render-3d-scatter-plot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function chartRender3dScatterPlot(context) {
// Add a directional light into scene.
const light = new DirectionalLight({
style: {
intensity: 3,
intensity: 2.5,
fill: 'white',
direction: [-1, 0, 1],
},
Expand Down
6 changes: 0 additions & 6 deletions __tests__/unit/lib/std.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
Theta,
Radial,
Radar,
Cartesian3D,
} from '../../../src/coordinate';
import { Constant, Field, Transform, Column } from '../../../src/encode';
import {
Expand Down Expand Up @@ -43,7 +42,6 @@ import {
Gauge,
Density as DensityGeometry,
Heatmap,
Point3D,
} from '../../../src/mark';
import { Category10, Category20 } from '../../../src/palette';
import {
Expand All @@ -66,7 +64,6 @@ import { Classic, ClassicDark, Academy } from '../../../src/theme';
import {
AxisX,
AxisY,
AxisZ,
AxisArc,
AxisLinear,
AxisRadar,
Expand Down Expand Up @@ -231,7 +228,6 @@ describe('stdlib', () => {
'transform.sample': Sample,
'transform.filter': FilterTransform,
'coordinate.cartesian': Cartesian,
'coordinate.cartesian3D': Cartesian3D,
'coordinate.polar': Polar,
'coordinate.helix': Helix,
'coordinate.transpose': Transpose,
Expand All @@ -248,7 +244,6 @@ describe('stdlib', () => {
'mark.rect': Rect,
'mark.line': Line,
'mark.point': PointGeometry,
'mark.point3D': Point3D,
'mark.text': TextGeometry,
'mark.cell': Cell,
'mark.area': AreaGeometry,
Expand Down Expand Up @@ -297,7 +292,6 @@ describe('stdlib', () => {
'theme.academy': Academy,
'component.axisX': AxisX,
'component.axisY': AxisY,
'component.axisZ': AxisZ,
'component.axisArc': AxisArc,
'component.axisLinear': AxisLinear,
'component.axisRadar': AxisRadar,
Expand Down
4 changes: 2 additions & 2 deletions site/.dumirc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ export default defineConfig({
order: 14,
},
{
slug: 'spec/3d',
slug: 'spec/threed',
title: {
zh: '3D 图表 - 3D Charts',
en: '3D',
Expand Down Expand Up @@ -338,7 +338,7 @@ export default defineConfig({
icon: 'other',
},
{
slug: '3d',
slug: 'threed',
title: {
zh: '3D 可视化',
en: '3D Charts',
Expand Down
2 changes: 1 addition & 1 deletion site/docs/api/chart.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ chart.render();

### `chart.point3D`

添加 point3D 图形,具体见 [3d](/spec/3d/point3-d)
添加 point3D 图形,具体见 [3d](/spec/threed/point-threed)

## 设置属性

Expand Down
69 changes: 67 additions & 2 deletions site/docs/manual/extra-topics/3d-charts.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ renderer.registerPlugin(new ControlPlugin());

## 扩展 threedlib

由于 3D 相关的功能代码体积巨大,我们将其分离到 `threedlib` 中,在运行时扩展它并自定义 Chart 对象:
由于 3D 相关的功能代码体积巨大,我们将其分离到 [threedlib](/manual/extra-topics/bundle#g2threedlib) 中,在运行时扩展它并自定义 Chart 对象:

```ts
import { Runtime, corelib, threedlib, extend } from '@antv/g2';
Expand All @@ -60,7 +60,7 @@ const chart = new Chart({
});
```

我们使用 [point3D](/spec/3d/point3-d) Mark 并选择 cube 作为 shape 进行绘制。
我们使用 [point3D](/spec/threed/point-threed) Mark 并选择 cube 作为 shape 进行绘制。
随后设置 z 通道、比例尺和坐标轴。

```ts
Expand Down Expand Up @@ -115,6 +115,8 @@ chart.render().then(() => {
const chart = new Chart({
theme: 'classic',
renderer,
width: 500,
height: 500,
depth: 400,
});

Expand Down Expand Up @@ -178,6 +180,8 @@ camera.rotate(-20, -20, 0);
const chart = new Chart({
theme: 'classic',
renderer,
width: 500,
height: 500,
depth: 400,
});

Expand Down Expand Up @@ -240,6 +244,67 @@ const light = new DirectionalLight({
canvas.appendChild(light);
```

我们可以通过 `intensity` 增大光源的强度:

```js | ob { pin: false }
(() => {
const renderer = new gWebgl.Renderer();
renderer.registerPlugin(new gPluginControl.Plugin());
renderer.registerPlugin(new gPlugin3d.Plugin());

const Chart = G2.extend(G2.Runtime, { ...G2.corelib(), ...G2.threedlib() });

// 初始化图表实例
const chart = new Chart({
theme: 'classic',
renderer,
width: 500,
height: 500,
depth: 400,
});

chart
.point3D()
.data({
type: 'fetch',
value:
'https://gw.alipayobjects.com/os/bmw-prod/2c813e2d-2276-40b9-a9af-cf0a0fb7e942.csv',
})
.encode('x', 'Horsepower')
.encode('y', 'Miles_per_Gallon')
.encode('z', 'Weight_in_lbs')
.encode('color', 'Cylinders')
.encode('shape', 'cube')
.coordinate({ type: 'cartesian3D' })
.scale('x', { nice: true })
.scale('y', { nice: true })
.scale('z', { nice: true })
.legend(false)
.axis('x', { gridLineWidth: 2 })
.axis('y', { gridLineWidth: 2, titleBillboardRotation: -Math.PI / 2 })
.axis('z', { gridLineWidth: 2 });

chart.render().then(() => {
const { canvas } = chart.getContext();
const camera = canvas.getCamera();
camera.setPerspective(0.1, 5000, 45, 500 / 500);
camera.setType(g.CameraType.ORBITING);

// Add a directional light into scene.
const light = new gPlugin3d.DirectionalLight({
style: {
intensity: 5,
fill: 'white',
direction: [0, 0, 1],
},
});
canvas.appendChild(light);
});

return chart.getContainer();
})();
```

## 使用相机交互

3D 场景下的交互和 2D 场景有很大的不同,[g-plugin-control](https://g.antv.antgroup.com/plugins/control) 提供了 3D 场景下基于相机的交互。当我们拖拽画布时,会控制相机绕视点进行旋转操作,而鼠标滚轮的缩放会让相机进行 dolly 操作。
Expand Down
5 changes: 3 additions & 2 deletions site/docs/manual/extra-topics/bundle.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ chart.auto(); // Auto Mark

> 开发中,预计 10 月底上线
返回 3D 分析库,提供 3D 可视化的能力。该 library 不会包含在 [G2.stdlib](#g2stdlib) 里面,同样不能单独使用,需要配合 [G2.corelib](#g2corelib) 使用。
返回 3D 分析库,提供 3D 可视化的能力。该 library 不会包含在 [G2.stdlib](#g2stdlib) 里面,同样不能单独使用,需要配合 [G2.corelib](#g2corelib) 使用。[示例](/manual/extra-topics/3d-charts)

```js
import { Runtime, extend, threedlib, corelib } from '@antv/g2';
Expand All @@ -267,9 +267,10 @@ const Chart = extend(Runtime, {
const chart = new Chart({
theme: 'classic',
renderer: new Renderer(), //使用 webgl 渲染器
depth: 400, // 设置深度
});

chart.interval3d();
chart.point3D();
```

## 未来工作
Expand Down
6 changes: 0 additions & 6 deletions site/docs/spec/3d/point3D.en.md

This file was deleted.

96 changes: 0 additions & 96 deletions site/docs/spec/3d/point3D.zh.md

This file was deleted.

6 changes: 6 additions & 0 deletions site/docs/spec/threed/pointThreed.en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: point3D
order: 1
---

<embed src="@/docs/spec/threed/pointThreed.zh.md"></embed>
Loading

0 comments on commit 90d1458

Please sign in to comment.