You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by ov...@apache.org on 2021/03/17 10:10:08 UTC

[echarts] 06/10: WIP(legend): default symbolSize as 80% itemHeight while it can also inherit

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

ovilia pushed a commit to branch fix-legend
in repository https://gitbox.apache.org/repos/asf/echarts.git

commit 7955fd893c95ae25ede87928afa386b1acdb4d76
Author: Ovilia <zw...@gmail.com>
AuthorDate: Tue Mar 16 16:23:50 2021 +0800

    WIP(legend): default symbolSize as 80% itemHeight while it can also inherit
---
 src/component/legend/LegendModel.ts |  3 +++
 src/component/legend/LegendView.ts  | 26 +++++++++++++++++++-------
 2 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/src/component/legend/LegendModel.ts b/src/component/legend/LegendModel.ts
index b595dc1..c9997cd 100644
--- a/src/component/legend/LegendModel.ts
+++ b/src/component/legend/LegendModel.ts
@@ -123,6 +123,8 @@ export interface LegendStyleOption {
     textStyle?: LabelOption
 
     symbolKeepAspect?: boolean
+
+    symbolSize?: number | 'auto' | 'inherit'
 }
 
 interface DataItem extends LegendStyleOption {
@@ -449,6 +451,7 @@ class LegendModel<Ops extends LegendOption = LegendOption> extends ComponentMode
         itemGap: 10,
         itemWidth: 25,
         itemHeight: 14,
+        symbolSize: 'auto',
 
         inactiveColor: '#ccc',
 
diff --git a/src/component/legend/LegendView.ts b/src/component/legend/LegendView.ts
index 7449414..6f37e72 100644
--- a/src/component/legend/LegendView.ts
+++ b/src/component/legend/LegendView.ts
@@ -184,9 +184,8 @@ class LegendView extends ComponentView {
             !seriesModel.get('legendHoverLink') && excludeSeriesId.push(seriesModel.id);
         });
 
-        each(legendModel.getData(), function (itemModel, dataIndex) {
-            const name = itemModel.get('name');
-            const legendItemStyle = itemModel.getModel('itemStyle').getItemStyle();
+        each(legendModel.getData(), function (legendItemModel, dataIndex) {
+            const name = legendItemModel.get('name');
 
             // Use empty string or \n as a newline string
             if (!this.newlineDisabled && (name === '' || name === '\n')) {
@@ -221,10 +220,13 @@ class LegendView extends ComponentView {
                 // Using rect symbol defaultly
                 const legendSymbolType = data.getVisual('legendSymbol') || 'roundRect';
                 const symbolType = data.getVisual('symbol');
-                const symbolSize = seriesModel.get('symbolSize');
+                const symbolSize = data.getVisual('symbolSize');
+
+                data.getVisual('symbolSize');
+                console.log(symbolSize)
 
                 const itemGroup = this._createItem(
-                    name, dataIndex, itemModel, legendModel,
+                    name, dataIndex, legendItemModel, legendModel,
                     legendSymbolType, symbolType, symbolSize,
                     itemAlign,
                     lineVisualStyle, style, true, selectMode
@@ -257,7 +259,7 @@ class LegendView extends ComponentView {
                         const legendSymbolType = 'roundRect';
 
                         const itemGroup = this._createItem(
-                            name, dataIndex, itemModel, legendModel,
+                            name, dataIndex, legendItemModel, legendModel,
                             legendSymbolType, null, null,
                             itemAlign,
                             {}, style, false, selectMode
@@ -358,8 +360,18 @@ class LegendView extends ComponentView {
         const inactiveBorderColor = itemModel.get('inactiveBorderColor');
         const symbolKeepAspect = itemModel.get('symbolKeepAspect');
 
+        const legendSymbolSize = itemModel.get('symbolSize');
+        if (legendSymbolSize === 'auto') {
+            // auto: 80% itemHeight
+            symbolSize = itemHeight * 0.8;
+        }
+        else if (legendSymbolSize !== 'inherit') {
+            // number: legend.symbolSize
+            symbolSize = Math.min(legendSymbolSize, itemHeight);
+        }
+        // inherit: series.symbolSize, which is passed in by function parameter
+
         const style = getLegendStyle(itemModel, lineVisualStyle, itemVisualStyle, isColorBySeries);
-        console.log(style)
 
         symbolType = symbolType || 'roundRect';
 


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