Skip to content

Relates to #3735, adds itemsymbol: 'constant' legend option, which uses a circle symbol for all legend entries. #5475

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/components/legend/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var fontAttrs = require('../../plots/font_attributes');
var colorAttrs = require('../color/attributes');

var Drawing = require('../drawing');

module.exports = {
bgcolor: {
Expand Down Expand Up @@ -77,6 +77,16 @@ module.exports = {
'or remain *constant* independent of the symbol size on the graph.'
].join(' ')
},
itemsymbol: {
valType: 'enumerated',
values: ['trace'].concat(Drawing.symbolList),
dflt: 'trace',
editType: 'legend',
description: [
'Determines if the legend items symbols use the symbol of the first point in each *trace*',
'or the specified symbol name.'
].join(' ')
},
itemwidth: {
valType: 'number',
min: 30,
Expand Down
1 change: 1 addition & 0 deletions src/components/legend/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
5 changes: 5 additions & 0 deletions src/components/legend/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 customItemSymbol = legend.itemsymbol && legend.itemsymbol !== 'trace';
var itemWidth = legend.itemwidth;
var centerPos = (itemWidth + constants.itemGap * 2) / 2;
var centerTransform = strTranslate(centerPos, 0);
Expand Down Expand Up @@ -204,6 +205,10 @@ module.exports = function style(s, gd, legend) {
valToBound = cst;
}

if(customItemSymbol && attrIn === 'marker.symbol') {
valToBound = legend.itemsymbol;
}

if(bounds) {
if(valToBound < bounds[0]) return bounds[0];
else if(valToBound > bounds[1]) return bounds[1];
Expand Down