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/11/05 09:59:31 UTC

[incubator-echarts] branch bundle-dts updated: fix(sunburst): add an abstraction between callback params and inner structure

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

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


The following commit(s) were added to refs/heads/bundle-dts by this push:
     new 663af17  fix(sunburst): add an abstraction between callback params and inner structure
663af17 is described below

commit 663af17e790289cbd93f89cbe0ff542b7a52fd22
Author: pissang <bm...@gmail.com>
AuthorDate: Thu Nov 5 17:58:42 2020 +0800

    fix(sunburst): add an abstraction between callback params and inner structure
---
 src/chart/sunburst/SunburstSeries.ts |  9 ++++++++-
 src/chart/sunburst/sunburstLayout.ts | 21 ++++++++++++++++++++-
 2 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/src/chart/sunburst/SunburstSeries.ts b/src/chart/sunburst/SunburstSeries.ts
index c3e04de..ecd68c8 100644
--- a/src/chart/sunburst/SunburstSeries.ts
+++ b/src/chart/sunburst/SunburstSeries.ts
@@ -95,6 +95,13 @@ export interface SunburstSeriesLevelOption extends SunburstStateOption, StatesOp
         label?: SunburstLabelOption
     }
 }
+
+interface SortParam {
+    dataIndex: number
+    depth: number
+    height: number
+    getValue(): number
+}
 export interface SunburstSeriesOption extends
     SeriesOption<SunburstStateOption, ExtraStateOption>, SunburstStateOption,
     CircleLayoutOptionMixin {
@@ -123,7 +130,7 @@ export interface SunburstSeriesOption extends
 
     animationType?: 'expansion' | 'scale'
 
-    sort?: 'desc' | 'asc' | ((a: TreeNode, b: TreeNode) => number)
+    sort?: 'desc' | 'asc' | ((a: SortParam, b: SortParam) => number)
 }
 
 interface SunburstSeriesModel {
diff --git a/src/chart/sunburst/sunburstLayout.ts b/src/chart/sunburst/sunburstLayout.ts
index db59ec0..67f9a9c 100644
--- a/src/chart/sunburst/sunburstLayout.ts
+++ b/src/chart/sunburst/sunburstLayout.ts
@@ -23,6 +23,7 @@ import GlobalModel from '../../model/Global';
 import ExtensionAPI from '../../ExtensionAPI';
 import SunburstSeriesModel, { SunburstSeriesNodeItemOption, SunburstSeriesOption } from './SunburstSeries';
 import { TreeNode } from '../../data/Tree';
+import { valueToNode } from '@babel/types';
 
 // let PI2 = Math.PI * 2;
 const RADIAN = Math.PI / 180;
@@ -202,7 +203,25 @@ function initChildren(node: TreeNode, sortOrder?: SunburstSeriesOption['sort'])
  */
 function sort(children: TreeNode[], sortOrder: SunburstSeriesOption['sort']) {
     if (typeof sortOrder === 'function') {
-        return children.sort(sortOrder);
+        const sortTargets = zrUtil.map(children, (child, idx) => {
+            const value = child.getValue() as number;
+            return {
+                params: {
+                    depth: child.depth,
+                    height: child.height,
+                    dataIndex: child.dataIndex,
+                    getValue: () => value
+                },
+                index: idx
+            };
+        });
+        sortTargets.sort((a, b) => {
+            return sortOrder(a.params, b.params);
+        });
+
+        return zrUtil.map(sortTargets, (target) => {
+            return children[target.index];
+        });
     }
     else {
         const isAsc = sortOrder === 'asc';


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