From 173bb1dc19391e9db7d5b975dc2a9a420845a18a Mon Sep 17 00:00:00 2001 From: "brian.kotek" Date: Fri, 5 Feb 2021 14:20:25 -0500 Subject: [PATCH 1/5] Relates to #3735, adds `itemsymbol: 'constant'` legend option, which uses a circle symbol for all legend entries. --- src/components/legend/attributes.js | 10 ++++++++++ src/components/legend/defaults.js | 1 + src/components/legend/style.js | 5 +++++ 3 files changed, 16 insertions(+) diff --git a/src/components/legend/attributes.js b/src/components/legend/attributes.js index 7179f99bcce..7fa22ff76db 100644 --- a/src/components/legend/attributes.js +++ b/src/components/legend/attributes.js @@ -77,6 +77,16 @@ module.exports = { 'or remain *constant* independent of the symbol size on the graph.' ].join(' ') }, + itemsymbol: { + valType: 'enumerated', + values: ['trace', 'constant'], + dflt: 'trace', + editType: 'legend', + description: [ + 'Determines if the legend items symbols use the symbol of the first point in each *trace*', + 'or use a *constant* circle symbol.' + ].join(' ') + }, itemwidth: { valType: 'number', min: 30, diff --git a/src/components/legend/defaults.js b/src/components/legend/defaults.js index f1e434d8b6f..3dfc6507a7b 100644 --- a/src/components/legend/defaults.js +++ b/src/components/legend/defaults.js @@ -105,6 +105,7 @@ module.exports = function legendDefaults(layoutIn, layoutOut, fullData) { if(helpers.isGrouped(layoutOut.legend)) coerce('tracegroupgap'); coerce('itemsizing'); + coerce('itemsymbol'); coerce('itemwidth'); coerce('itemclick'); diff --git a/src/components/legend/style.js b/src/components/legend/style.js index 0ef881e9af4..f9c32212bef 100644 --- a/src/components/legend/style.js +++ b/src/components/legend/style.js @@ -25,6 +25,7 @@ module.exports = function style(s, gd, legend) { var fullLayout = gd._fullLayout; if(!legend) legend = fullLayout.legend; var constantItemSizing = legend.itemsizing === 'constant'; + var constantItemSymbol = legend.itemsymbol === 'constant'; var itemWidth = legend.itemwidth; var centerPos = (itemWidth + constants.itemGap * 2) / 2; var centerTransform = strTranslate(centerPos, 0); @@ -203,6 +204,10 @@ module.exports = function style(s, gd, legend) { if(constantItemSizing && valToBound && cst !== undefined) { valToBound = cst; } + + if(constantItemSymbol && attrIn === 'marker.symbol') { + valToBound = 'circle'; + } if(bounds) { if(valToBound < bounds[0]) return bounds[0]; From 9ff8ecfc38030a512e019a395b6c8706c7b105a7 Mon Sep 17 00:00:00 2001 From: "brian.kotek" Date: Fri, 5 Feb 2021 14:32:37 -0500 Subject: [PATCH 2/5] Remove trailing spaces --- src/components/legend/style.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/legend/style.js b/src/components/legend/style.js index f9c32212bef..a77293ece3d 100644 --- a/src/components/legend/style.js +++ b/src/components/legend/style.js @@ -204,7 +204,7 @@ module.exports = function style(s, gd, legend) { if(constantItemSizing && valToBound && cst !== undefined) { valToBound = cst; } - + if(constantItemSymbol && attrIn === 'marker.symbol') { valToBound = 'circle'; } From fbbcf912796e4484923d931419ebd16e4b7db223 Mon Sep 17 00:00:00 2001 From: "brian.kotek" Date: Thu, 11 Feb 2021 16:38:55 -0500 Subject: [PATCH 3/5] Relates to #3735, switch to 'circle' option, but under the hood in theory the user could now specify any valid symbol name. --- src/components/legend/attributes.js | 4 ++-- src/components/legend/style.js | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/components/legend/attributes.js b/src/components/legend/attributes.js index 7fa22ff76db..05493e48d77 100644 --- a/src/components/legend/attributes.js +++ b/src/components/legend/attributes.js @@ -79,12 +79,12 @@ module.exports = { }, itemsymbol: { valType: 'enumerated', - values: ['trace', 'constant'], + values: ['trace', 'circle'], dflt: 'trace', editType: 'legend', description: [ 'Determines if the legend items symbols use the symbol of the first point in each *trace*', - 'or use a *constant* circle symbol.' + 'or use a circle symbol.' ].join(' ') }, itemwidth: { diff --git a/src/components/legend/style.js b/src/components/legend/style.js index a77293ece3d..e7332de610a 100644 --- a/src/components/legend/style.js +++ b/src/components/legend/style.js @@ -25,7 +25,7 @@ module.exports = function style(s, gd, legend) { var fullLayout = gd._fullLayout; if(!legend) legend = fullLayout.legend; var constantItemSizing = legend.itemsizing === 'constant'; - var constantItemSymbol = legend.itemsymbol === 'constant'; + var customItemSymbol = legend.itemsymbol && legend.itemsymbol !== 'trace'; var itemWidth = legend.itemwidth; var centerPos = (itemWidth + constants.itemGap * 2) / 2; var centerTransform = strTranslate(centerPos, 0); @@ -205,8 +205,8 @@ module.exports = function style(s, gd, legend) { valToBound = cst; } - if(constantItemSymbol && attrIn === 'marker.symbol') { - valToBound = 'circle'; + if(customItemSymbol && attrIn === 'marker.symbol') { + valToBound = legend.itemsymbol; } if(bounds) { From 8ba0712cc6662f7a15d30f5bc9b603f0d80cb951 Mon Sep 17 00:00:00 2001 From: "brian.kotek" Date: Thu, 11 Feb 2021 17:08:53 -0500 Subject: [PATCH 4/5] Add options for all symbols to itemsymbol attribute options list. --- src/components/legend/attributes.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/legend/attributes.js b/src/components/legend/attributes.js index 05493e48d77..d2853c0d8cc 100644 --- a/src/components/legend/attributes.js +++ b/src/components/legend/attributes.js @@ -2,7 +2,7 @@ var fontAttrs = require('../../plots/font_attributes'); var colorAttrs = require('../color/attributes'); - +var Drawing = require('../drawing'); module.exports = { bgcolor: { @@ -79,12 +79,12 @@ module.exports = { }, itemsymbol: { valType: 'enumerated', - values: ['trace', 'circle'], + values: ['trace', ...Drawing.symbolList], dflt: 'trace', editType: 'legend', description: [ 'Determines if the legend items symbols use the symbol of the first point in each *trace*', - 'or use a circle symbol.' + 'or the specified symbol name.' ].join(' ') }, itemwidth: { From 181de00c58bbb734a4fec593e239e20994a3ec97 Mon Sep 17 00:00:00 2001 From: "brian.kotek" Date: Mon, 22 Feb 2021 15:52:16 -0500 Subject: [PATCH 5/5] Use array concat instead of spread operator. --- src/components/legend/attributes.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/legend/attributes.js b/src/components/legend/attributes.js index d2853c0d8cc..73544f6d9c0 100644 --- a/src/components/legend/attributes.js +++ b/src/components/legend/attributes.js @@ -79,7 +79,7 @@ module.exports = { }, itemsymbol: { valType: 'enumerated', - values: ['trace', ...Drawing.symbolList], + values: ['trace'].concat(Drawing.symbolList), dflt: 'trace', editType: 'legend', description: [