You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by su...@apache.org on 2020/04/25 21:08:51 UTC

[incubator-echarts] 06/08: test: add test facility.

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

sushuang pushed a commit to branch attached-text
in repository https://gitbox.apache.org/repos/asf/incubator-echarts.git

commit 19bf4d4822677144a1275a64002d27e8b8a36859
Author: 100pah <su...@gmail.com>
AuthorDate: Fri Apr 24 00:46:02 2020 +0800

    test: add test facility.
---
 test/lib/testHelper.js | 40 +++++++++++++++++++++++++++++++++++++++-
 1 file changed, 39 insertions(+), 1 deletion(-)

diff --git a/test/lib/testHelper.js b/test/lib/testHelper.js
index 8aba7d7..d6685d4 100644
--- a/test/lib/testHelper.js
+++ b/test/lib/testHelper.js
@@ -169,7 +169,7 @@
                     var stack = ctx.stack();
                     for (var i = 0; i < stack.length; i++) {
                         var line = stack[i];
-                        content.push(JSON.stringify(line), '\n');
+                        content.push(JSON.stringify(line), ',\n');
                     }
                 });
                 contentAraa.style.display = 'block';
@@ -602,6 +602,44 @@
         console.log(elsStr);
     };
 
+    // opt: {record: JSON, width: number, height: number}
+    testHelper.reproduceCanteen = function (opt) {
+        var canvas = document.createElement('canvas');
+        canvas.style.width = opt.width + 'px';
+        canvas.style.height = opt.height + 'px';
+        var dpr = Math.max(window.devicePixelRatio || 1, 1);
+        canvas.width = opt.width * dpr;
+        canvas.height = opt.height * dpr;
+
+        var ctx = canvas.getContext('2d');
+        var record = opt.record;
+
+        for (var i = 0; i < record.length; i++) {
+            var line = record[i];
+            if (line.attr) {
+                if (!line.hasOwnProperty('val')) {
+                    alertIllegal(line);
+                }
+                ctx[line.attr] = line.val;
+            }
+            else if (line.method) {
+                if (!line.hasOwnProperty('arguments')) {
+                    alertIllegal(line);
+                }
+                ctx[line.method].apply(ctx, line.arguments);
+            }
+            else {
+                alertIllegal(line);
+            }
+        }
+
+        function alertIllegal(line) {
+            throw new Error('Illegal line: ' + JSON.stringify(line));
+        }
+
+        document.body.appendChild(canvas);
+    };
+
     function createDataTableHTML(data, opt) {
         var sourceFormat = detectSourceFormat(data);
         var dataTableLimit = opt.dataTableLimit || DEFAULT_DATA_TABLE_LIMIT;


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