-
-
Notifications
You must be signed in to change notification settings - Fork 544
insidetextorientation attribute in pie and sunburst #1659
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
23 changes: 23 additions & 0 deletions
23
_posts/plotly_js/basic/pie/2020-01-14-inside-text-orientation.html
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,23 @@ | ||
--- | ||
name: Control text orientation inside Pie slices | ||
language: plotly_js | ||
suite: pie | ||
order: 5 | ||
sitemap: false | ||
arrangement: horizontal | ||
markdown_content: | | ||
The [insidetextorientation](https://plot.ly/javascript/reference/#pie-insidetextorientation) attribute controls the orientation of the texts inside slices. With 'auto' the texts may automatically be rotated to fit with the maximum size inside the slice. The other three options 'horizontal', 'radial', and 'tangential' forces text to be horizontal, radial, and tangential. | ||
--- | ||
var data = [{ | ||
type: "pie", | ||
values: [2, 3, 4, 4], | ||
labels: ["Wages", "Operating expenses", "Cost of sales", "Insurance"], | ||
textinfo: "label+percent", | ||
insidetextorientation: "radial" | ||
}] | ||
var layout = [{ | ||
height: 700, | ||
width: 700 | ||
}] | ||
|
||
Plotly.newPlot('myDiv', data, layout) |
29 changes: 29 additions & 0 deletions
29
_posts/plotly_js/basic/sunburst/2020-01-14-inside-text-orientation.html
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,29 @@ | ||
--- | ||
name: Control text orientation inside Sunburst slices | ||
language: plotly_js | ||
suite: sunburst | ||
order: 6 | ||
sitemap: false | ||
arrangement: horizontal | ||
markdown_content: | | ||
The [insidetextorientation](https://plot.ly/javascript/reference/#sunburst-insidetextorientation) attribute controls the orientation of the texts inside chart sectors. When set to 'auto' the texts may automatically be rotated to fit with the maximum size inside a sector. The other three options 'horizontal', 'radial', and 'tangential' first try to orient text at the 3:00, 6:00, 9:00, and 12:00 hours. If there is no enough room, then the text would be positioned in the middle of the arc. | ||
--- | ||
Plotly.d3.csv('https://raw.githubusercontent.com/plotly/datasets/master/coffee-flavors.csv', function(err, rows){ | ||
function unpack(rows, key) { | ||
return rows.map(function(row) {return row[key]}) | ||
} | ||
|
||
var data = [{ | ||
type: "sunburst", | ||
maxdepth: 2, | ||
ids: unpack(rows, 'ids'), | ||
labels: unpack(rows, 'labels'), | ||
parents: unpack(rows, 'parents'), | ||
textposition: 'inside', | ||
insidetextorientation: 'radial' | ||
}] | ||
|
||
var layout = {margin: {l: 0, r: 0, b: 0, t:0}} | ||
|
||
Plotly.newPlot('myDiv', data, layout) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line as well as some lines above may require indentation. |
||
}) |
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.
Let's add
here to ensure all the text fits inside.
Uh oh!
There was an error while loading. Please reload this page.
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.
Hey Mahdis, this PR is looking really good. I just have a suggestion, which also applies to the sunburst doc in this PR.
I think that text could more explicitly describe these options.
Perhaps something like:
The insidetextorientation attribute controls the orientation of the text inside chart sectors. When set to 'auto', text may be oriented in any direction in order to be as big as possible in the middle of a sector. The 'horizontal' option orients text to be parallel with the bottom of the chart, and will make text smaller in order to achieve that goal. The 'radial' option orients text along the radius of the sector. The 'tangential' option orients text perpendicular to the radius of the sector.
What do you think?
Along with Mojtaba's comments, this looks ready to merge!
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.
Note that if you were to imagine your chart as a clock face, the 'horizontal', 'radial', and 'tangential' options first try to orient text at the the 3:00, 6:00, 9:00, and 12:00 hours. If that is not possible due to space constraints, then they position the text in the middle of the arc. On the other hand the
auto
option always shrinks text to fit in the middle of the arc.