Skip to content

Commit 7246537

Browse files
authored
Merge pull request #4519 from plotly/pie-add-textpad
Improve pie and sunburst inside text pad
2 parents 80262b5 + 056eed3 commit 7246537

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+210
-12
lines changed

src/traces/pie/plot.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ var svgTextUtils = require('../../lib/svg_text_utils');
1919
var uniformText = require('../bar/uniform_text');
2020
var recordMinTextSize = uniformText.recordMinTextSize;
2121
var clearMinTextSize = uniformText.clearMinTextSize;
22+
var TEXTPAD = require('../bar/constants').TEXTPAD;
2223

2324
var helpers = require('./helpers');
2425
var eventData = require('./event_data');
@@ -684,6 +685,8 @@ function isCrossing(pt, angle) {
684685
}
685686

686687
function calcRadTransform(textBB, r, ring, halfAngle, midAngle) {
688+
r = Math.max(0, r - 2 * TEXTPAD);
689+
687690
// max size if text is rotated radially
688691
var a = textBB.width / textBB.height;
689692
var s = calcMaxHalfSize(a, halfAngle, r, ring);
@@ -695,6 +698,8 @@ function calcRadTransform(textBB, r, ring, halfAngle, midAngle) {
695698
}
696699

697700
function calcTanTransform(textBB, r, ring, halfAngle, midAngle) {
701+
r = Math.max(0, r - 2 * TEXTPAD);
702+
698703
// max size if text is rotated tangentially
699704
var a = textBB.height / textBB.width;
700705
var s = calcMaxHalfSize(a, halfAngle, r, ring);
@@ -1148,11 +1153,7 @@ function computeTransform(
11481153
transform, // inout
11491154
textBB // in
11501155
) {
1151-
var rotate = transform.rotate;
1152-
var scale = transform.scale;
1153-
if(scale > 1) scale = 1;
1154-
1155-
var a = rotate * Math.PI / 180;
1156+
var a = transform.rotate * Math.PI / 180;
11561157
var cosA = Math.cos(a);
11571158
var sinA = Math.sin(a);
11581159
var midX = (textBB.left + textBB.right) / 2;
-88 Bytes
76 Bytes

test/image/baselines/mathjax.png

-9 Bytes
-4 Bytes

test/image/baselines/pie_fonts.png

-238 Bytes
-879 Bytes
-87 Bytes
16.7 KB
16.9 KB
-232 Bytes
-214 Bytes
-703 Bytes
-1.09 KB
15.6 KB
-1.27 KB
-76 Bytes

test/image/baselines/texttemplate.png

-397 Bytes
-671 Bytes
-5.27 KB
-14 Bytes

test/image/mocks/pie_fonts.json

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"inherit from<br><b>global...</b>",
1010
"font"
1111
],
12+
"textposition": ["outside", "inside"],
1213
"type": "pie",
1314
"domain": {
1415
"x": [0, 0.4],
+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"data": [
3+
{
4+
"type": "pie",
5+
"hole": 0.5,
6+
"labels": [
7+
"a",
8+
"b",
9+
"c",
10+
"d"
11+
],
12+
"values": [
13+
20,
14+
10,
15+
2,
16+
1
17+
],
18+
"textposition": "inside",
19+
"insidetextorientation": "radial",
20+
"marker": {
21+
"colors": [
22+
"pink",
23+
"lightgreen",
24+
"skyblue",
25+
"orange"
26+
],
27+
"line": {
28+
"width": 3,
29+
"color": [
30+
"red",
31+
"green",
32+
"blue",
33+
"grey"
34+
]
35+
}
36+
}
37+
}
38+
],
39+
"layout": {
40+
"width": 300,
41+
"height": 300,
42+
"title": {
43+
"text": "should provide some pad<br>before fiting & printing text"
44+
}
45+
}
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"data": [
3+
{
4+
"type": "pie",
5+
"hole": 0.5,
6+
"labels": [
7+
"a",
8+
"b",
9+
"c",
10+
"d"
11+
],
12+
"values": [
13+
20,
14+
10,
15+
2,
16+
1
17+
],
18+
"textposition": "inside",
19+
"insidetextorientation": "tangential",
20+
"marker": {
21+
"colors": [
22+
"pink",
23+
"lightgreen",
24+
"skyblue",
25+
"orange"
26+
],
27+
"line": {
28+
"width": 3,
29+
"color": [
30+
"red",
31+
"green",
32+
"blue",
33+
"grey"
34+
]
35+
}
36+
}
37+
}
38+
],
39+
"layout": {
40+
"width": 300,
41+
"height": 300,
42+
"title": {
43+
"text": "should provide some pad<br>before fiting & printing text"
44+
}
45+
}
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"data": [
3+
{
4+
"type": "sunburst",
5+
"parents": [
6+
"",
7+
"",
8+
"",
9+
"",
10+
"Alpha",
11+
"Bravo",
12+
"Charlie",
13+
"Delta"
14+
],
15+
"labels": [
16+
"Alpha",
17+
"Bravo",
18+
"Charlie",
19+
"Delta",
20+
"Echo",
21+
"Foxtrot",
22+
"Golf",
23+
"Hotel"
24+
],
25+
"branchvalues": "total",
26+
"values": [
27+
20,
28+
10,
29+
2,
30+
1,
31+
20,
32+
10,
33+
2,
34+
1
35+
],
36+
"textposition": "inside",
37+
"insidetextorientation": "radial",
38+
"marker": {
39+
"line": {
40+
"width": 3
41+
}
42+
}
43+
}
44+
],
45+
"layout": {
46+
"width": 300,
47+
"height": 300,
48+
"title": {
49+
"text": "should provide some pad<br>before fiting & printing text"
50+
}
51+
}
52+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"data": [
3+
{
4+
"type": "sunburst",
5+
"parents": [
6+
"",
7+
"",
8+
"",
9+
"",
10+
"Alpha",
11+
"Bravo",
12+
"Charlie",
13+
"Delta"
14+
],
15+
"labels": [
16+
"Alpha",
17+
"Bravo",
18+
"Charlie",
19+
"Delta",
20+
"Echo",
21+
"Foxtrot",
22+
"Golf",
23+
"Hotel"
24+
],
25+
"branchvalues": "total",
26+
"values": [
27+
20,
28+
10,
29+
2,
30+
1,
31+
20,
32+
10,
33+
2,
34+
1
35+
],
36+
"textposition": "inside",
37+
"insidetextorientation": "tangential",
38+
"marker": {
39+
"line": {
40+
"width": 3
41+
}
42+
}
43+
}
44+
],
45+
"layout": {
46+
"width": 300,
47+
"height": 300,
48+
"title": {
49+
"text": "should provide some pad<br>before fiting & printing text"
50+
}
51+
}
52+
}

test/jasmine/tests/pie_test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -2010,15 +2010,15 @@ describe('pie uniformtext', function() {
20102010
Plotly.plot(gd, fig)
20112011
.then(assertTextSizes('without uniformtext', {
20122012
fontsizes: [12, 12, 12, 12, 12, 12, 12, 12],
2013-
scales: [1, 1, 1, 1, 1, 1, 1, 0.58],
2013+
scales: [1, 1, 1, 1, 1, 1, 1, 0.52],
20142014
}))
20152015
.then(function() {
20162016
fig.layout.uniformtext = {mode: 'hide'}; // default with minsize=0
20172017
return Plotly.react(gd, fig);
20182018
})
20192019
.then(assertTextSizes('using mode: "hide"', {
20202020
fontsizes: [12, 12, 12, 12, 12, 12, 12, 12],
2021-
scales: [0.58, 0.58, 0.58, 0.58, 0.58, 0.58, 0.58, 0.58],
2021+
scales: [0.52, 0.52, 0.52, 0.52, 0.52, 0.52, 0.52, 0.52],
20222022
}))
20232023
.then(function() {
20242024
fig.layout.uniformtext.minsize = 9; // set a minsize less than trace font size
@@ -2058,7 +2058,7 @@ describe('pie uniformtext', function() {
20582058
})
20592059
.then(assertTextSizes('clear uniformtext', {
20602060
fontsizes: [12, 12, 12, 12, 12, 12, 12, 12],
2061-
scales: [1, 1, 1, 1, 1, 1, 1, 0.58],
2061+
scales: [1, 1, 1, 1, 1, 1, 1, 0.52],
20622062
}))
20632063
.catch(failTest)
20642064
.then(done);

test/jasmine/tests/sunburst_test.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1975,7 +1975,7 @@ describe('sunburst inside text orientation', function() {
19751975
return Plotly.react(gd, fig);
19761976
})
19771977
.then(assertTextRotations('using "tangential"', {
1978-
rotations: [0, 0, -42, -78]
1978+
rotations: [0, 30, -42, -78]
19791979
}))
19801980
.then(function() {
19811981
fig.data[0].insidetextorientation = 'auto';
@@ -2060,15 +2060,15 @@ describe('sunburst uniformtext', function() {
20602060
Plotly.plot(gd, fig)
20612061
.then(assertTextSizes('without uniformtext', {
20622062
fontsizes: [12, 12, 12, 12, 12, 12, 12, 12, 12, 12],
2063-
scales: [1, 1, 1, 1, 1, 1, 1, 1, 1, 0.58],
2063+
scales: [1, 1, 1, 1, 1, 1, 1, 1, 1, 0.52],
20642064
}))
20652065
.then(function() {
20662066
fig.layout.uniformtext = {mode: 'hide'}; // default with minsize=0
20672067
return Plotly.react(gd, fig);
20682068
})
20692069
.then(assertTextSizes('using mode: "hide"', {
20702070
fontsizes: [12, 12, 12, 12, 12, 12, 12, 12, 12, 12],
2071-
scales: [0.58, 0.58, 0.58, 0.58, 0.58, 0.58, 0.58, 0.58, 0.58, 0.58],
2071+
scales: [0.52, 0.52, 0.52, 0.52, 0.52, 0.52, 0.52, 0.52, 0.52, 0.52],
20722072
}))
20732073
.then(function() {
20742074
fig.layout.uniformtext.minsize = 9; // set a minsize less than trace font size
@@ -2108,7 +2108,7 @@ describe('sunburst uniformtext', function() {
21082108
})
21092109
.then(assertTextSizes('clear uniformtext', {
21102110
fontsizes: [12, 12, 12, 12, 12, 12, 12, 12, 12, 12],
2111-
scales: [1, 1, 1, 1, 1, 1, 1, 1, 1, 0.58],
2111+
scales: [1, 1, 1, 1, 1, 1, 1, 1, 1, 0.52],
21122112
}))
21132113
.catch(failTest)
21142114
.then(done);

0 commit comments

Comments
 (0)