You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by sh...@apache.org on 2022/02/22 04:52:13 UTC

[echarts-bar-racing] branch master updated: exporting progress with higher precision

This is an automated email from the ASF dual-hosted git repository.

shenyi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/echarts-bar-racing.git


The following commit(s) were added to refs/heads/master by this push:
     new 64d0d1d  exporting progress with higher precision
64d0d1d is described below

commit 64d0d1da4d6b4ba7f302d109e376d76edf0bb423
Author: pissang <bm...@gmail.com>
AuthorDate: Tue Feb 22 12:52:03 2022 +0800

    exporting progress with higher precision
---
 src/components/BChart.vue | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/src/components/BChart.vue b/src/components/BChart.vue
index a1cec57..f56b291 100644
--- a/src/components/BChart.vue
+++ b/src/components/BChart.vue
@@ -7,7 +7,7 @@
             </a>
         </div>
         <div v-else slot="header" class="text-base flex items-center">
-            <el-progress width="30" class="mr-5" type="circle" :show-text="false" :percentage="exportingProgress"></el-progress>
+            <el-progress :width="30" class="mr-5" type="circle" :show-text="false" :percentage="exportingProgress"></el-progress>
             {{$t('exporting')}} {{exportingProgress.toFixed(0) + '%'}}
             <el-button @click="cancelDownload()" size="mini" icon="el-icon-close" class="ml-5">
                 {{$t('cancel')}}
@@ -86,7 +86,7 @@ export default defineComponent({
                 }
 
                 recorder = new WebMWriter({
-                    frameRate: fps || 30,
+                    frameRate: fps,
                     transparent: true
                 });
 
@@ -97,7 +97,7 @@ export default defineComponent({
 
                 const title = this.title || this.$t('toolName') || 'bar-racing';
 
-                await this.doRun((curr, total) => {
+                await this.doRun(fps, (curr, total) => {
                     this.exportingProgress = curr / total * 100;
                 });
                 // Canceld
@@ -225,7 +225,7 @@ export default defineComponent({
             catch (e) {}
         },
 
-        async doRun(onProgress?: (curr: number, total: number) => void) {
+        async doRun(fps = 60, onProgress?: (curr: number, total: number) => void) {
             if (!this.chartData || this.chartData.length < headerLength) {
                 return;
             }
@@ -248,6 +248,7 @@ export default defineComponent({
                     }]
                 });
 
+
                 return new Promise((resolve) => {
                     setTimeout(() => {
                         resolve(undefined);
@@ -255,16 +256,29 @@ export default defineComponent({
                 })
             }
 
+            let frameCount = 0;
+            let totalFrames = fps * this.animationDuration / 1000 * dataCnt;
+            function frameCounter() {
+                frameCount++;
+                onProgress && onProgress(frameCount, totalFrames);
+            }
+
+            if (onProgress) {
+                chart.getZr().animation.on('frame', frameCounter);
+            }
+
             for (let i = 0; i < dataCnt; ++i) {
                 onProgress && onProgress(i, dataCnt);
                 // Cancled.
                 if (!this.isExportingVideo) {
+                    chart.getZr().animation.off('frame', frameCounter);
                     return;
                 }
                 const row = that.chartData[headerLength + i + 1] as string[];
                 await step(row);
             }
 
+            chart.getZr().animation.off('frame', frameCounter);
             onProgress && onProgress(dataCnt, dataCnt);
         }
     }

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org