-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
pie : add Pattern #6601
Merged
Merged
pie : add Pattern #6601
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
342bd09
pie : add Pattern
thierryVergult 1cce254
piePattern : add md & fix reference to colors
thierryVergult fedbe67
Update src/traces/pie/defaults.js
thierryVergult c24ae98
piePattern : use the old point color when no shape present
thierryVergult e40e078
piePattern : rework styleOne in case no colors defined
thierryVergult a683c2a
piePattern : extra check on trace.marker.pattern
thierryVergult 49319de
piePattern : fix broken tests
thierryVergult 8cd2c97
piePattern : add mock
thierryVergult 5d809b6
piePattern : rework the index of legend items
thierryVergult a422094
piePattern : lint fix & d3 call style
thierryVergult f376b63
piePattern : call pointStyle outside the d3 s.style construction
thierryVergult File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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 pattern to pie trace type [[#6601](https://github.com/plotly/plotly.js/pull/6601)] |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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,89 @@ | ||
{ | ||
"data": [ | ||
{ | ||
"labels": [ "giraffe", "orangutan", "monkey"], | ||
"values": [ 30, 20, 50], | ||
"type": "pie", | ||
"marker": { | ||
"colors": [ "red", "green", "red"], | ||
"line": { | ||
"color": "lightgrey", | ||
"width": 4 | ||
}, | ||
"pattern": { | ||
"shape": [ "+", "", "-"], | ||
"fgcolor": [ "darksalmon", "black", "steelblue"], | ||
"bgcolor": "lightgrey" | ||
} | ||
}, | ||
"textfont": { "color": ["black", "white", "black"]}, | ||
"sort": false, | ||
"domain": {"x": [0.81, 0.99]} | ||
}, { | ||
"labels": [ "giraffe", "orangutan", "monkey"], | ||
"values": [ 30, 20, 50], | ||
"type": "pie", | ||
"marker": { | ||
"colors": [ "red", "green", "blue"], | ||
"line": { | ||
"color": "lightgrey", | ||
"width": 4 | ||
}, | ||
"pattern": { | ||
"shape": [ "+", "", "-"], | ||
"fgcolor": [ "darksalmon", "black", "steelblue"] | ||
} | ||
}, | ||
"textfont": { "color": ["black", "white", "black"]}, | ||
"sort": false, | ||
"domain": {"x": [0.61, 0.79]} | ||
}, { | ||
"labels": [ "giraffe", "orangutan", "monkey"], | ||
"values": [ 30, 20, 50], | ||
"type": "pie", | ||
"marker": { | ||
"colors": [ "red", "green", "blue"], | ||
"line": { | ||
"color": "lightgrey", | ||
"width": 4 | ||
}, | ||
"pattern": { | ||
"shape": [ "+", "", "-"] | ||
} | ||
}, | ||
"textfont": { "color": "black"}, | ||
"sort": false, | ||
"domain": {"x": [0.41, 0.59]} | ||
}, { | ||
"labels": [ "giraffe", "orangutan", "monkey"], | ||
"values": [ 30, 20, 50], | ||
"type": "pie", | ||
"marker": { | ||
"colors": [ "red", "green", "blue"], | ||
"line": { | ||
"color": "lightgrey", | ||
"width": 4 | ||
} | ||
}, | ||
"sort": false, | ||
"domain": {"x": [0.21, 0.39]} | ||
}, { | ||
"labels": [ "giraffe", "orangutan", "monkey"], | ||
"values": [ 30, 20, 50], | ||
"type": "pie", | ||
"marker": { | ||
"colors": ["steelblue", "steelblue", "steelblue"], | ||
"line": { | ||
"color": "lightgrey", | ||
"width": 4 | ||
} | ||
}, | ||
"sort": false, | ||
"domain": {"x": [0.01, 0.19]} | ||
} | ||
], | ||
"layout": { | ||
"title": { "text": "pie chart with pattern"}, | ||
"width": 800 | ||
} | ||
} |
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we can get this to be the default result for inside text? This would particularly help in the cases where we don't know whether the text will end up inside or outside. Maybe if the pattern solidity <0.5 we contrast with the bgcolor, >0.5 we contrast with the fgcolor? Here's where this auto color is chosen (
Color.contrast
picks either black or white, whichever is farther from the given color):plotly.js/src/traces/pie/plot.js
Line 531 in 0919988
Note I haven't looked but wonder if we want to do the same for bars:
plotly.js/src/traces/bar/style.js
Line 124 in 0919988
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked similar cases for bar trace and scatter trace, see attached. Scatter trace with area filled with a pattern seems a special case anyway, but also the actual bar trace is deciding on the color of the text inside the bar by evaluating the base color of the bar, without taking into account pattern attributes.
And even flipping the text color to black inside the bar / slice will give a distortion effect, probably as bad as the actual situation. Patterns with text inside is probably never a very good idea ..
I would prefer to add a pattern to a few other trace types first (funnelarea, sunburst, ..) and to handle the color of the text inside a pattern eventually later via a separate PR.

zz-pattern_textfont_color.json.txt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm OK - I guess it's not so clear that any color we choose here will actually be usable, for a lot of situations neither black nor white would really work and (given that this is often used in black&white contexts) we don't want to consider any other colors. So the recommendation I guess would be to use
textposition='outside'
when you have patterns.