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 2020/06/16 15:15:53 UTC

[incubator-echarts-doc] 02/02: example: can change the option in array like levels/data

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

shenyi pushed a commit to branch live-example
in repository https://gitbox.apache.org/repos/asf/incubator-echarts-doc.git

commit 88e516ee27876e2c0ddff6b5e82b15ea6f509283
Author: pissang <bm...@gmail.com>
AuthorDate: Tue Jun 16 23:15:35 2020 +0800

    example: can change the option in array like levels/data
---
 en/option/series/sunburst.md |  2 +-
 en/option/series/treemap.md  |  2 +-
 src/store.js                 | 25 +++++++++++++++++--------
 zh/option/series/sunburst.md |  2 +-
 zh/option/series/treemap.md  |  5 ++---
 5 files changed, 22 insertions(+), 14 deletions(-)

diff --git a/en/option/series/sunburst.md b/en/option/series/sunburst.md
index 99fece0..8089c3d 100644
--- a/en/option/series/sunburst.md
+++ b/en/option/series/sunburst.md
@@ -286,7 +286,7 @@ If there is no `name`, whether need to render it.
 
 
 
-## levels(Array) = []
+## levels(Array)
 
 **Multiple levels**
 
diff --git a/en/option/series/treemap.md b/en/option/series/treemap.md
index 1273a05..1da1f1b 100644
--- a/en/option/series/treemap.md
+++ b/en/option/series/treemap.md
@@ -110,7 +110,7 @@ The behaviour when clicking a node. Optional values are:
 The treemap will be auto zoomed to a appropriate ratio when a node is clicked (when [nodeClick](~series-treemap.nodeClick) is set as `'zoomToNode'` and no drill down happens). This configuration item indicates the ratio.
 
 
-## levels(Array) = []
+## levels(Array)
 
 **Multiple Levels Configuration**
 
diff --git a/src/store.js b/src/store.js
index c5a51b5..a06862a 100644
--- a/src/store.js
+++ b/src/store.js
@@ -43,8 +43,10 @@ export function isOptionDoc() {
 
 export function changeOption(option, path, value) {
 
-    function changeOptionRecursive(obj, pathParts, objKey) {
+    function changeOptionRecursive(obj, pathParts, objKey, nodePath) {
         const itemStr = pathParts.shift();
+        nodePath = (nodePath ? (nodePath + '.') : '') + itemStr;
+
         if (typeof obj !== 'object' && objKey === 'data') {
             // Convert number to object
             obj = {
@@ -69,29 +71,36 @@ export function changeOption(option, path, value) {
         const key = subtypeItems[0];
         const subtype = subtypeItems[1];
         // TODO: If prop not exists and it should be an array.
-        const prop = obj[key] == null ? {} : obj[key];
+        if (obj[key] == null) {
+            const outlineNode = getOutlineNode(nodePath);
+            obj[key] = (outlineNode && outlineNode.isArray) ? [] : {};
+        }
+        const prop = obj[key];
         if (Array.isArray(prop)) {
             if (key === 'series') { // Only set all on series.
                 obj[key] = prop.map(function (childObj, idx) {
                     if (subtype && childObj.type !== subtype) {
                         return childObj;
                     }
-                    return changeOptionRecursive(childObj, pathParts.slice(), key);
+                    return changeOptionRecursive(childObj, pathParts.slice(), key, nodePath);
                 });
             }
-            // Only change the first one.
-            // TODO: Should be able to choose the index.
-            prop[0] && (prop[0] = changeOptionRecursive(prop[0], pathParts.slice(), key));
+            else {
+                // Only change the first one.
+                // TODO: Should be able to choose the index.
+                obj[key] = prop.slice();
+                obj[key][0] = changeOptionRecursive(obj[key][0] || {}, pathParts.slice(), key, nodePath);
+            }
         }
         else {
             if (subtype && prop.type !== subtype) {
                 obj[key] = prop;
             }
-            obj[key] = changeOptionRecursive(prop, pathParts.slice(), key);
+            obj[key] = changeOptionRecursive(prop, pathParts.slice(), key, nodePath);
         }
 
         return obj;
     }
 
-    return changeOptionRecursive(option, path.split('.'), '');
+    return changeOptionRecursive(option, path.split('.'), '', '');
 }
\ No newline at end of file
diff --git a/zh/option/series/sunburst.md b/zh/option/series/sunburst.md
index 2fbe057..eaf944b 100644
--- a/zh/option/series/sunburst.md
+++ b/zh/option/series/sunburst.md
@@ -464,7 +464,7 @@ function(nodeA, nodeB) {
 
 
 
-## levels(Array) = []
+## levels(Array)
 
 **多层配置**
 
diff --git a/zh/option/series/treemap.md b/zh/option/series/treemap.md
index 37e51e8..9c362d0 100644
--- a/zh/option/series/treemap.md
+++ b/zh/option/series/treemap.md
@@ -200,8 +200,7 @@ const data = [{
 const option = {
     series: {
         type: 'treemap',
-        data: data,
-        levels: [{}, {}, {}]
+        data: data
     }
 };
 
@@ -280,7 +279,7 @@ const option = {
 点击某个节点,会自动放大那个节点到合适的比例(节点占可视区域的面积比例),这个配置项就是这个比例。
 
 
-## levels(Array) = []
+## levels(Array)
 
 **多层配置**
 


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