Skip to content

Commit f965d29

Browse files
authored
Merge pull request #166 from VisActor/feat/docs
feat(docs): update export video/gif docs
2 parents 11edc4a + f8b9589 commit f965d29

2 files changed

Lines changed: 86 additions & 21 deletions

File tree

docs/assets/guide/en/Getting_Started.md

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -184,24 +184,56 @@ The generated chart is as follows:
184184
## Export GIF and Video
185185

186186
VMind supports exporting the generated chart as a GIF animation and video, which can be shared anytime and anywhere.
187-
In order to implement the video export function, you need to additionally introduce VChart and FFMPEG into the project and pass them in as objects to VMind. The following will show how to get the ObjectURL of the chart GIF and video:
187+
In order to implement the video export function, you need to additionally include VChart, FFMPEG, canvas related content in your project and pass them as objects to VMind. The following will show how to get the ObjectURL of the chart GIF and video:
188188

189-
First install VChart and FFMPEG:
189+
First, install VChart, FFMPEG, and canvas-related content:
190190
```bash
191191
# Install with npm
192192
npm install @visactor/vchart
193-
npm install @ffmpeg/ffmpeg
194-
npm install @ffmpeg/util
193+
npm install @visactor/vrender-core
194+
npm install @ffmpeg/ffmpeg^0.11.6
195+
npm install canvas^2.11.2
195196
```
196-
197+
Ensure that the vrender-core version matches the vchart dependency version, for example: `"@visactor/vchart": "1.12.7"` should correspond to `"@visactor/vrender-core": "0.20.7"`.
198+
Usage is as follows:
197199
```typescript
198-
import VChart from '@visactor/vchart';
199-
import { FFmpeg } from "@ffmpeg/ffmpeg";
200-
import { fetchFile } from "@ffmpeg/util";
201-
//Export video
202-
const videoSrc = await vmind.exportVideo(spec, time, VChart, FFmpeg, fetchFile); //Pass in chart spec and video duration, return ObjectURL
203-
//Export GIF image
204-
const gifSrc = await vmind.exportGIF(spec, time, VChart, FFmpeg, fetchFile); //Pass in chart spec and GIF duration, return ObjectURL
200+
import VChart from "@visactor/vchart";
201+
import { ManualTicker, defaultTimeline } from "@visactor/vrender-core";
202+
import { createFFmpeg, fetchFile } from '@ffmpeg/ffmpeg/dist/ffmpeg.min.js'
203+
import { createCanvas } from "canvas";
204+
import VMind from "@visactor/vmind";
205+
206+
// Initialize vmind and ffmpeg
207+
const vmind = new VMind({});
208+
const ffmpeg = createFFmpeg({
209+
log: true,
210+
});
211+
const loadFFmpeg = async () => {
212+
if (!ffmpeg.isLoaded()) {
213+
await ffmpeg.load();
214+
}
215+
};
216+
// Ensure ffmpeg is loaded before using the export feature
217+
await loadFFmpeg();
218+
// Export video
219+
// Pass in the chart spec, video duration, and necessary parameters for video creation, and return the ObjectURL
220+
const videoSrc = await vmind.exportVideo(spec, time, {
221+
VChart,
222+
FFmpeg: ffmpeg,
223+
fetchFile,
224+
ManualTicker,
225+
defaultTimeline,
226+
createCanvas,
227+
});
228+
// Export GIF image
229+
const gifSrc = await vmind.exportGIF(spec, time, {
230+
VChart,
231+
FFmpeg: ffmpeg,
232+
fetchFile,
233+
ManualTicker,
234+
defaultTimeline,
235+
createCanvas
236+
});
205237
```
206238

207239
Once you get the ObjectURL of the chart, we can save it as a file. Take saving the video file as an example:

docs/assets/guide/zh/Getting_Started.md

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -184,24 +184,57 @@ const { spec, time } = await vmind.generateChart(userPrompt, fieldInfo, dataset)
184184
## 导出 GIF 和视频
185185

186186
VMind 支持将生成的图表导出为 GIF 格式的动画和视频,随时随地进行分享。
187-
为了实现视频导出功能,你需要在项目中额外引入VChart和FFMPEG,并将其作为对象传入VMind。下面将展示如何获得图表 GIF 和视频的 ObjectURL:
187+
为了实现视频导出功能,你需要在项目中额外引入`VChart, FFMPEG, canvas`相关内容,并将其作为对象传入VMind。下面将展示如何获得图表 GIF 和视频的 ObjectURL:
188188

189-
首先安装VChart和FFMPEG
189+
首先安装VChart,FFMPEG以及canvas相关内容
190190
```bash
191191
# 使用 npm 安装
192192
npm install @visactor/vchart
193-
npm install @ffmpeg/ffmpeg
194-
npm install @ffmpeg/util
193+
npm install @visactor/vrender-core
194+
npm install @ffmpeg/ffmpeg^0.11.6
195+
npm install canvas^2.11.2
195196
```
197+
同时确保vrender-core版本与vchart依赖版本一致,如:`"@visactor/vchart": "1.12.7"`对应的版本应该为,`"@visactor/vrender-core": "0.20.7"`
198+
具体使用如下:
196199

197200
```typescript
198-
import VChart from '@visactor/vchart';
199-
import { FFmpeg } from "@ffmpeg/ffmpeg";
200-
import { fetchFile } from "@ffmpeg/util";
201+
import VChart from "@visactor/vchart";
202+
import { ManualTicker, defaultTimeline } from "@visactor/vrender-core";
203+
import { createFFmpeg, fetchFile } from '@ffmpeg/ffmpeg/dist/ffmpeg.min.js'
204+
import { createCanvas } from "canvas";
205+
import VMind from "@visactor/vmind";
206+
207+
// 初始化vmind和ffmpeg
208+
const vmind = new VMind({});
209+
const ffmpeg = createFFmpeg({
210+
log: true,
211+
});
212+
const loadFFmpeg = async () => {
213+
if (!ffmpeg.isLoaded()) {
214+
await ffmpeg.load();
215+
}
216+
};
217+
// 确保在使用导出功能前已经加载了ffmpeg
218+
await loadFFmpeg();
201219
//导出视频
202-
const videoSrc = await vmind.exportVideo(spec, time, VChart, FFmpeg, fetchFile); //传入图表spec和视频时长,返回ObjectURL
220+
//传入图表spec,视频时长和视频化必要参数,返回ObjectURL
221+
const videoSrc = await vmind.exportVideo(spec, time, {
222+
VChart,
223+
FFmpeg: ffmpeg,
224+
fetchFile,
225+
ManualTicker,
226+
defaultTimeline,
227+
createCanvas,
228+
});
203229
//导出GIF图片
204-
const gifSrc = await vmind.exportGIF(spec, time, VChart, FFmpeg, fetchFile); //传入图表spec和GIF时长,返回ObjectURL
230+
const gifSrc = await vmind.exportGIF(spec, time, {
231+
VChart,
232+
FFmpeg: ffmpeg,
233+
fetchFile,
234+
ManualTicker,
235+
defaultTimeline,
236+
createCanvas
237+
});
205238
```
206239

207240
一旦获得图表的 ObjectURL,我们可以将其保存为文件。以保存视频文件为例:

0 commit comments

Comments
 (0)