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/03/31 03:16:45 UTC

[incubator-echarts] branch master updated: feat(scatter): make `symbolRotate` functional for scatter series.

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/incubator-echarts.git


The following commit(s) were added to refs/heads/master by this push:
     new fdf240f  feat(scatter): make `symbolRotate` functional for scatter series.
     new 6f81cbf  Merge pull request #12348 from plainheart/feature/add_function_support_for_scatter_series
fdf240f is described below

commit fdf240f53e598e93b97783debd3c9d569684275e
Author: plainheart <yh...@al-my-life.cn>
AuthorDate: Mon Mar 30 14:56:01 2020 +0800

    feat(scatter): make `symbolRotate` functional for scatter series.
---
 src/chart/helper/Symbol.js |   4 +-
 src/visual/symbol.js       |  13 +++++-
 test/symbol3.html          | 105 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 118 insertions(+), 4 deletions(-)

diff --git a/src/chart/helper/Symbol.js b/src/chart/helper/Symbol.js
index a1a0a94..8d6943f 100644
--- a/src/chart/helper/Symbol.js
+++ b/src/chart/helper/Symbol.js
@@ -248,7 +248,6 @@ symbolProto._updateCommon = function (data, idx, symbolSize, seriesScope) {
 
     var itemStyle = seriesScope && seriesScope.itemStyle;
     var hoverItemStyle = seriesScope && seriesScope.hoverItemStyle;
-    var symbolRotate = seriesScope && seriesScope.symbolRotate;
     var symbolOffset = seriesScope && seriesScope.symbolOffset;
     var labelModel = seriesScope && seriesScope.labelModel;
     var hoverLabelModel = seriesScope && seriesScope.hoverLabelModel;
@@ -264,7 +263,6 @@ symbolProto._updateCommon = function (data, idx, symbolSize, seriesScope) {
         itemStyle = itemModel.getModel(normalStyleAccessPath).getItemStyle(['color']);
         hoverItemStyle = itemModel.getModel(emphasisStyleAccessPath).getItemStyle();
 
-        symbolRotate = itemModel.getShallow('symbolRotate');
         symbolOffset = itemModel.getShallow('symbolOffset');
 
         labelModel = itemModel.getModel(normalLabelAccessPath);
@@ -278,6 +276,8 @@ symbolProto._updateCommon = function (data, idx, symbolSize, seriesScope) {
 
     var elStyle = symbolPath.style;
 
+    var symbolRotate = data.getItemVisual(idx, 'symbolRotate');
+
     symbolPath.attr('rotation', (symbolRotate || 0) * Math.PI / 180 || 0);
 
     if (symbolOffset) {
diff --git a/src/visual/symbol.js b/src/visual/symbol.js
index 8cd7e06..a4c4efd 100644
--- a/src/visual/symbol.js
+++ b/src/visual/symbol.js
@@ -33,12 +33,15 @@ export default function (seriesType, defaultSymbolType, legendSymbol) {
             var symbolType = seriesModel.get('symbol');
             var symbolSize = seriesModel.get('symbolSize');
             var keepAspect = seriesModel.get('symbolKeepAspect');
+            var symbolRotate = seriesModel.get('symbolRotate');
 
             var hasSymbolTypeCallback = isFunction(symbolType);
             var hasSymbolSizeCallback = isFunction(symbolSize);
-            var hasCallback = hasSymbolTypeCallback || hasSymbolSizeCallback;
+            var hasSymbolRotateCallback = isFunction(symbolRotate);
+            var hasCallback = hasSymbolTypeCallback || hasSymbolSizeCallback || hasSymbolRotateCallback;
             var seriesSymbol = (!hasSymbolTypeCallback && symbolType) ? symbolType : defaultSymbolType;
             var seriesSymbolSize = !hasSymbolSizeCallback ? symbolSize : null;
+            var seriesSymbolRotate = !hasSymbolRotateCallback ? seriesSymbolRotate : null;
 
             data.setVisual({
                 legendSymbol: legendSymbol || seriesSymbol,
@@ -48,7 +51,8 @@ export default function (seriesType, defaultSymbolType, legendSymbol) {
                 // some cases but generally it is not recommanded.
                 symbol: seriesSymbol,
                 symbolSize: seriesSymbolSize,
-                symbolKeepAspect: keepAspect
+                symbolKeepAspect: keepAspect,
+                symbolRotate: symbolRotate
             });
 
             // Only visible series has each data be visual encoded
@@ -62,12 +66,14 @@ export default function (seriesType, defaultSymbolType, legendSymbol) {
                     var params = seriesModel.getDataParams(idx);
                     hasSymbolTypeCallback && data.setItemVisual(idx, 'symbol', symbolType(rawValue, params));
                     hasSymbolSizeCallback && data.setItemVisual(idx, 'symbolSize', symbolSize(rawValue, params));
+                    hasSymbolRotateCallback && data.setItemVisual(idx, 'symbolRotate', symbolRotate(rawValue, params));
                 }
 
                 if (data.hasItemOption) {
                     var itemModel = data.getItemModel(idx);
                     var itemSymbolType = itemModel.getShallow('symbol', true);
                     var itemSymbolSize = itemModel.getShallow('symbolSize', true);
+                    var itemSymbolRotate = itemModel.getShallow('symbolRotate', true);
                     var itemSymbolKeepAspect = itemModel.getShallow('symbolKeepAspect', true);
 
                     // If has item symbol
@@ -78,6 +84,9 @@ export default function (seriesType, defaultSymbolType, legendSymbol) {
                         // PENDING Transform symbolSize ?
                         data.setItemVisual(idx, 'symbolSize', itemSymbolSize);
                     }
+                    if (itemSymbolRotate != null) {
+                         data.setItemVisual(idx, 'symbolRotate', itemSymbolRotate);
+                    }
                     if (itemSymbolKeepAspect != null) {
                         data.setItemVisual(idx, 'symbolKeepAspect', itemSymbolKeepAspect);
                     }
diff --git a/test/symbol3.html b/test/symbol3.html
new file mode 100644
index 0000000..7226d75
--- /dev/null
+++ b/test/symbol3.html
@@ -0,0 +1,105 @@
+<!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" />
+        <link rel="stylesheet" href="lib/reset.css" />
+        <script src="lib/esl.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="https://api.map.baidu.com/api?v=3.0&ak=KOmVjPVUAey1G2E8zNhPiuQ6QiEmAwZu&__ec_v__=20200330"></script>
+        <!-- <script src="https://www.echartsjs.com/examples/vendors/echarts/extension/bmap.js?_ec_v__=20200330"></script> -->
+    </head>
+    <body>
+        <div id="main0"></div>
+
+        <script>
+            require([
+                'echarts', 'extension/bmap'
+            ], function (echarts) {
+                var symbolIcon = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAA7CAMAAABbj8oVAAACdlBMVEVHcExroTJqoTFpojN0szdonzJ1tTl3tzhonjJJSSB5uTlspDNysTdaaCNeeihuqDBuqjV1tTlvqTFyrDRfjy91tDllki5onjJqoDJnnjIxAAdnnjRooTJFVR55ujJzsjMyShpHbCJnnjJKPBgxAAdnnjJmnTI0AQlpojNwqTJ+yzxNRhtmji5OWSR9wTxPeigfLxKDyz9VgSoAAAGCyD6O2UIrPRYNEwkOEQproTJxpzMMDwkUFhACAAVjmjFonjIAAAM1TRoVGBIFBAZvpTNknDFpoDEJCghyqjMSFQ49Wx8cHxgtQBYYGxRtozNvqDMwRxl1rzQnKiRupDJmnTEjJx0/Qjt6tzd4szZ0qzNpmy93sDZmoTJbhSl+vDhA [...]
+                var option = {
+                    bmap: {
+                        center: [116, 31],
+                        zoom: 7,
+                        roam: true
+                    },
+                    series: [{
+                        coordinateSystem: 'bmap',
+                        symbol: 'image://' + symbolIcon,
+                        symbolSize: [15, 30],
+                        symbolRotate: function(value, params) {
+                            return -value[2]
+                        },
+                        label: {
+                            show: true,
+                            position: 'top',
+                            distance: 15,
+                            formatter: function(params) {
+                                return params.name + '(' + params.value[2] + 'deg)'
+                            },
+                            verticalAlign: 'middle',
+                            align: 'center',
+                            borderWidth: 1.25,
+                            borderRadius: 2,
+                            borderColor: '#14c4ba',
+                            backgroundColor: '#fff',
+                            padding: [5, 8, 3, 8],
+                            color: '#000'
+                        },
+                        data: [
+                            {
+                                name: 'car1',
+                                value: [121.15, 31.89, 30]
+                            },
+                            {
+                                name: 'car2',
+                                value: [117.781327, 32.608266, 120]
+                            },
+                            {
+                                name: 'car3',
+                                value: [117.5, 30.608266, 90]
+                            },
+                            {
+                                name: 'car4',
+                                value: [115.5, 30.2, 180]
+                            }
+                        ],
+                        encode: {
+                            value: 2
+                        },
+                        type: 'scatter'
+                    }]
+                };
+
+                var chart = testHelper.create(echarts, 'main0', {
+                    title: 'Rotates the symbol as we need',
+                    option: option
+                });
+            });
+        </script>
+
+    </body>
+</html>
\ No newline at end of file


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