Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2k
Add attribute-based legends (colorlegend, sizelegend, symbollegend)#7656
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Open
Rhoahndur wants to merge2 commits intoplotly:masterChoose a base branch fromRhoahndur:feature/add-attribute-legends
base:master
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
Uh oh!
There was an error while loading.Please reload this page.
Open
Changes fromall commits
Commits
Show all changes
2 commits Select commitHold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletionsdraftlogs/7656_add.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| - Add`colorlegend`,`sizelegend`, and`symbollegend` components for attribute-based legends[[#7656](https://github.com/plotly/plotly.js/pull/7656)] |
171 changes: 171 additions & 0 deletionssrc/components/colorlegend/attributes.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,171 @@ | ||
| 'use strict'; | ||
| var fontAttrs = require('../../plots/font_attributes'); | ||
| var colorAttrs = require('../color/attributes'); | ||
| module.exports = { | ||
| // not really a 'subplot' attribute container, | ||
| // but this is the flag we use to denote attributes that | ||
| // support colorlegend, colorlegend2, colorlegend3, ... counters | ||
| _isSubplotObj: true, | ||
| visible: { | ||
| valType: 'boolean', | ||
| dflt: true, | ||
| editType: 'legend', | ||
| description: 'Determines whether this color legend is visible.' | ||
| }, | ||
| title: { | ||
| text: { | ||
| valType: 'string', | ||
| dflt: '', | ||
| editType: 'legend', | ||
| description: 'Sets the title of the color legend.' | ||
| }, | ||
| font: fontAttrs({ | ||
| editType: 'legend', | ||
| description: 'Sets the font for the color legend title.' | ||
| }), | ||
| side: { | ||
| valType: 'enumerated', | ||
| values: ['top', 'left', 'right'], | ||
| dflt: 'top', | ||
| editType: 'legend', | ||
| description: 'Determines the location of the legend title.' | ||
| }, | ||
| editType: 'legend' | ||
| }, | ||
| // Positioning (same pattern as legend) | ||
| x: { | ||
| valType: 'number', | ||
| dflt: 1.02, | ||
| editType: 'legend', | ||
| description: 'Sets the x position with respect to `xref`.' | ||
| }, | ||
| xref: { | ||
| valType: 'enumerated', | ||
| values: ['container', 'paper'], | ||
| dflt: 'paper', | ||
| editType: 'legend', | ||
| description: 'Sets the container `x` refers to.' | ||
| }, | ||
| xanchor: { | ||
| valType: 'enumerated', | ||
| values: ['auto', 'left', 'center', 'right'], | ||
| dflt: 'left', | ||
| editType: 'legend', | ||
| description: 'Sets the horizontal anchor.' | ||
| }, | ||
| y: { | ||
| valType: 'number', | ||
| dflt: 1, | ||
| editType: 'legend', | ||
| description: 'Sets the y position with respect to `yref`.' | ||
| }, | ||
| yref: { | ||
| valType: 'enumerated', | ||
| values: ['container', 'paper'], | ||
| dflt: 'paper', | ||
| editType: 'legend', | ||
| description: 'Sets the container `y` refers to.' | ||
| }, | ||
| yanchor: { | ||
| valType: 'enumerated', | ||
| values: ['auto', 'top', 'middle', 'bottom'], | ||
| dflt: 'auto', | ||
| editType: 'legend', | ||
| description: 'Sets the vertical anchor.' | ||
| }, | ||
| // Styling | ||
| bgcolor: { | ||
| valType: 'color', | ||
| editType: 'legend', | ||
| description: 'Sets the background color.' | ||
| }, | ||
| bordercolor: { | ||
| valType: 'color', | ||
| dflt: colorAttrs.defaultLine, | ||
| editType: 'legend', | ||
| description: 'Sets the border color.' | ||
| }, | ||
| borderwidth: { | ||
| valType: 'number', | ||
| min: 0, | ||
| dflt: 0, | ||
| editType: 'legend', | ||
| description: 'Sets the border width.' | ||
| }, | ||
| font: fontAttrs({ | ||
| editType: 'legend', | ||
| description: 'Sets the font for legend item text.' | ||
| }), | ||
| // Orientation | ||
| orientation: { | ||
| valType: 'enumerated', | ||
| values: ['v', 'h'], | ||
| dflt: 'v', | ||
| editType: 'legend', | ||
| description: 'Sets the orientation of the legend items.' | ||
| }, | ||
| // Item sizing | ||
| itemsizing: { | ||
| valType: 'enumerated', | ||
| values: ['trace', 'constant'], | ||
| dflt: 'constant', | ||
| editType: 'legend', | ||
| description: [ | ||
| 'Determines if legend items symbols scale with their corresponding data values', | ||
| 'or remain constant.' | ||
| ].join(' ') | ||
| }, | ||
| itemwidth: { | ||
| valType: 'number', | ||
| min: 30, | ||
| dflt: 30, | ||
| editType: 'legend', | ||
| description: 'Sets the width of the legend item symbols.' | ||
| }, | ||
| // Behavior | ||
| itemclick: { | ||
| valType: 'enumerated', | ||
| values: ['toggle', 'toggleothers', false], | ||
| dflt: 'toggle', | ||
| editType: 'legend', | ||
| description: 'Determines the behavior on legend item click.' | ||
| }, | ||
| itemdoubleclick: { | ||
| valType: 'enumerated', | ||
| values: ['toggle', 'toggleothers', false], | ||
| dflt: 'toggleothers', | ||
| editType: 'legend', | ||
| description: 'Determines the behavior on legend item double-click.' | ||
| }, | ||
| // Continuous data binning | ||
| binning: { | ||
| valType: 'enumerated', | ||
| values: ['auto', 'discrete'], | ||
| dflt: 'auto', | ||
| editType: 'calc', | ||
| description: [ | ||
| 'For numeric color data, *auto* creates bins while', | ||
| '*discrete* treats each unique value as a category.' | ||
| ].join(' ') | ||
| }, | ||
| nbins: { | ||
| valType: 'integer', | ||
| min: 1, | ||
| dflt: 5, | ||
| editType: 'calc', | ||
| description: 'Sets the number of bins for continuous data when binning is *auto*.' | ||
| }, | ||
| editType: 'legend' | ||
| }; |
7 changes: 7 additions & 0 deletionssrc/components/colorlegend/constants.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| 'use strict'; | ||
| module.exports = { | ||
| itemGap: 5, | ||
| textGap: 8, | ||
| padding: 10 | ||
| }; |
94 changes: 94 additions & 0 deletionssrc/components/colorlegend/defaults.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| 'use strict'; | ||
| var Lib = require('../../lib'); | ||
| var Template = require('../../plot_api/plot_template'); | ||
| var attributes = require('./attributes'); | ||
| module.exports = function colorlegendDefaults(layoutIn, layoutOut, fullData) { | ||
| var colorlegendIds = findColorlegendIds(fullData); | ||
| layoutOut._colorlegends = []; | ||
| for(var i = 0; i < colorlegendIds.length; i++) { | ||
| var id = colorlegendIds[i]; | ||
| var containerIn = layoutIn[id] || {}; | ||
| var containerOut = Template.newContainer(layoutOut, id); | ||
| handleColorlegendDefaults(containerIn, containerOut, layoutOut, id); | ||
| if(containerOut.visible) { | ||
| containerOut._id = id; | ||
| layoutOut._colorlegends.push(id); | ||
| } | ||
| } | ||
| }; | ||
| function findColorlegendIds(fullData) { | ||
| var ids = []; | ||
| for(var i = 0; i < fullData.length; i++) { | ||
| var trace = fullData[i]; | ||
| if(!trace.visible) continue; | ||
| var marker = trace.marker; | ||
| if(marker && marker.colorlegend) { | ||
| var id = marker.colorlegend; | ||
| if(ids.indexOf(id) === -1) { | ||
| ids.push(id); | ||
| } | ||
| } | ||
| } | ||
| return ids; | ||
| } | ||
| function handleColorlegendDefaults(containerIn, containerOut, layoutOut, id) { | ||
| function coerce(attr, dflt) { | ||
| return Lib.coerce(containerIn, containerOut, attributes, attr, dflt); | ||
| } | ||
| var visible = coerce('visible'); | ||
| if(!visible) return; | ||
| // Title | ||
| coerce('title.text'); | ||
| Lib.coerceFont(coerce, 'title.font', layoutOut.font); | ||
| coerce('title.side'); | ||
| // Orientation first - affects positioning defaults | ||
| var orientation = coerce('orientation'); | ||
| // Positioning - defaults depend on orientation | ||
| var isHorizontal = orientation === 'h'; | ||
| if(isHorizontal) { | ||
| // Horizontal: top-right, outside the chart | ||
| coerce('x', 1.02); | ||
| coerce('xanchor', 'left'); | ||
| coerce('y', 1); | ||
| coerce('yanchor', 'top'); | ||
| } else { | ||
| // Vertical: right side of chart (default from attributes) | ||
| coerce('x'); | ||
| coerce('xanchor'); | ||
| coerce('y'); | ||
| coerce('yanchor'); | ||
| } | ||
| coerce('xref'); | ||
| coerce('yref'); | ||
| // Styling | ||
| coerce('bgcolor', layoutOut.paper_bgcolor); | ||
| coerce('bordercolor'); | ||
| coerce('borderwidth'); | ||
| Lib.coerceFont(coerce, 'font', layoutOut.font); | ||
| coerce('itemsizing'); | ||
| coerce('itemwidth'); | ||
| // Behavior | ||
| coerce('itemclick'); | ||
| coerce('itemdoubleclick'); | ||
| // Binning | ||
| coerce('binning'); | ||
| coerce('nbins'); | ||
| } |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.