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

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


The following commit(s) were added to refs/heads/aggregate-transform by this 
push:
     new e69a6f4  fix(transform): fix count aggregate. clean codes
e69a6f4 is described below

commit e69a6f4f332b28519e44909d5bba1a931c2b4389
Author: pissang <[email protected]>
AuthorDate: Fri Mar 25 17:16:06 2022 +0800

    fix(transform): fix count aggregate. clean codes
---
 src/component/transform/aggregateTransform.ts |   2 +-
 src/component/transform/idTransform.ts        |  14 ++-
 src/component/transform/sortTransform.ts      |   7 --
 src/data/SeriesData.ts                        |   2 +-
 src/processor/dataSample.ts                   |   2 +-
 test/data-transform-aggregate2.html           | 142 ++++++++++++++++++++++++++
 6 files changed, 151 insertions(+), 18 deletions(-)

diff --git a/src/component/transform/aggregateTransform.ts 
b/src/component/transform/aggregateTransform.ts
index 51b16c6..9bab9f0 100644
--- a/src/component/transform/aggregateTransform.ts
+++ b/src/component/transform/aggregateTransform.ts
@@ -369,7 +369,7 @@ const methods: {
     },
     COUNT: {
         init: () => 1,
-        add: (prev: number) => prev++
+        add: (prev: number) => prev + 1
     },
     FIRST: {
         init: identity,
diff --git a/src/component/transform/idTransform.ts 
b/src/component/transform/idTransform.ts
index 8c01628..0366d8f 100644
--- a/src/component/transform/idTransform.ts
+++ b/src/component/transform/idTransform.ts
@@ -71,13 +71,11 @@ export const idTransform: 
ExternalDataTransform<IdTransformOption> = {
     type: 'echarts:id',
 
     transform: function (params) {
-        const upstream = params.upstream;
-        const config = params.config;
-        const dimensionIndex = config.dimensionIndex;
-        const dimensionName = config.dimensionName;
+        const {upstream, config} = params;
+        const {dimensionIndex, dimensionName} = config;
 
-        const dimsDef = upstream.cloneAllDimensionInfo() as 
DimensionDefinitionLoose[];
-        dimsDef[dimensionIndex] = dimensionName;
+        const dimensions = upstream.cloneAllDimensionInfo() as 
DimensionDefinitionLoose[];
+        dimensions[dimensionIndex] = dimensionName;
 
         const data = upstream.cloneRawData() as OptionSourceDataArrayRows;
 
@@ -88,8 +86,8 @@ export const idTransform: 
ExternalDataTransform<IdTransformOption> = {
         }
 
         return {
-            dimensions: dimsDef,
-            data: data
+            dimensions,
+            data
         };
     }
 };
\ No newline at end of file
diff --git a/src/component/transform/sortTransform.ts 
b/src/component/transform/sortTransform.ts
index dbe246c..5442964 100644
--- a/src/component/transform/sortTransform.ts
+++ b/src/component/transform/sortTransform.ts
@@ -114,13 +114,6 @@ export const sortTransform: 
ExternalDataTransform<SortTransformOption> = {
                 throwError(errMsg);
             }
 
-            if (order !== 'asc' && order !== 'desc') {
-                if (__DEV__) {
-                    errMsg = 'Sort transform config must has "order" 
specified.' + sampleLog;
-                }
-                throwError(errMsg);
-            }
-
             if (incomparable && (incomparable !== 'min' && incomparable !== 
'max')) {
                 let errMsg = '';
                 if (__DEV__) {
diff --git a/src/data/SeriesData.ts b/src/data/SeriesData.ts
index 83421cc..b1565c2 100644
--- a/src/data/SeriesData.ts
+++ b/src/data/SeriesData.ts
@@ -473,7 +473,7 @@ class SeriesData<
     private _initGetDimensionInfo(needsHasOwn: boolean): void {
         const dimensionInfos = this._dimInfos;
         this._getDimInfo = needsHasOwn
-            ? dimName => (dimensionInfos.hasOwnProperty(dimName) ? 
dimensionInfos[dimName] : undefined)
+            ? dimName => ((zrUtil.hasOwn, dimName) ? dimensionInfos[dimName] : 
undefined)
             : dimName => dimensionInfos[dimName];
     }
 
diff --git a/src/processor/dataSample.ts b/src/processor/dataSample.ts
index 28579a6..7695def 100644
--- a/src/processor/dataSample.ts
+++ b/src/processor/dataSample.ts
@@ -22,7 +22,7 @@ import { Dictionary } from 'zrender/src/core/types';
 import SeriesModel from '../model/Series';
 import { isFunction, isString } from 'zrender/src/core/util';
 
-
+// TODO Merge with methods in aggregate transform
 type Sampler = (frame: ArrayLike<number>) => number;
 const samplers: Dictionary<Sampler> = {
     average: function (frame) {
diff --git a/test/data-transform-aggregate2.html 
b/test/data-transform-aggregate2.html
new file mode 100644
index 0000000..f2ffb6a
--- /dev/null
+++ b/test/data-transform-aggregate2.html
@@ -0,0 +1,142 @@
+<!DOCTYPE html>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+
+<html>
+    <head>
+        <meta charset="utf-8">
+        <meta name="viewport" content="width=device-width, initial-scale=1" />
+        <script src="lib/simpleRequire.js"></script>
+        <script src="lib/config.js"></script>
+        <script src="lib/jquery.min.js"></script>
+        <script src="lib/facePrint.js"></script>
+        <script src="lib/testHelper.js"></script>
+        <!-- <script src="ut/lib/canteen.js"></script> -->
+        <link rel="stylesheet" href="lib/reset.css" />
+    </head>
+    <body>
+        <style>
+            .chart {
+                width: 260px;
+                height: 150px;
+                display: inline-block;
+            }
+        </style>
+
+
+
+        <div id="main"></div>
+
+
+
+
+
+
+        <script>
+        require([
+            'echarts'
+        ], function (echarts) {
+            var option;
+
+            var dataset = [
+                ['Group', 'Name', 'Year', 'Value'],
+                ['A', 'A1', '2020', 10],
+                ['A', 'A2', '2020', 12],
+                ['A', 'A3', '2020', 15],
+                ['A', 'A1', '2021', 8],
+                ['A', 'A2', '2021', 5],
+                ['A', 'A3', '2021', 9],
+                ['B', 'B1', '2020', 5],
+                ['B', 'B2', '2020', 9],
+                ['B', 'B3', '2020', 2],
+                ['B', 'B1', '2021', 15],
+                ['B', 'B2', '2021', 18],
+                ['B', 'B3', '2021', 3],
+            ]
+
+            function createOption(groupBy, method) {
+                return option = {
+                    animation: false,
+                    grid: {
+                        top: 10,
+                        bottom: 20,
+                        containLabel: true,
+                        left: 5,
+                        right: 5
+                    },
+                    title: {
+                        text: groupBy + ', ' + method,
+                        left: 'center',
+                        top: 0,
+                        textStyle: {
+                            fontSize: 10
+                        }
+                    },
+                    dataset: [
+                        {
+                            source: dataset
+                        },
+                        {
+                            fromDatasetIndex: 0,
+                            transform: [{
+                                type: 'aggregate',
+                                config: {
+                                    output: [
+                                        { from: 'Group' },
+                                        { from: 'Name' },
+                                        { from: 'Year' },
+                                        { from: 'Value', method }
+                                    ],
+                                    groupBy
+                                }
+                            }]
+                        }
+                    ],
+                    xAxis: {type: 'category'},
+                    yAxis: {},
+                    series: {
+                        type: 'bar',
+                        datasetIndex: 1,
+                        encode: {
+                            x: groupBy,
+                            y: 'Value',
+                            itemName: groupBy
+                        }
+                    }
+                };
+            }
+
+            ['Group', 'Year'].forEach(groupBy => {
+                ['count', 'sum', 'first', 'min', 'max', 'average', 'Q1', 'Q2', 
'Q3', 'median'].forEach(method => {
+                    const dom = document.createElement('div');
+                    dom.className = 'chart';
+                    const option = createOption(groupBy, method);
+                    document.querySelector('#main').appendChild(dom);
+                    const chart = echarts.init(dom);
+                    chart.setOption(option);
+                });
+            });
+        });
+        </script>
+
+
+    </body>
+</html>
+

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to