diff --git a/src/traces/bar/plot.js b/src/traces/bar/plot.js index d99a7194c69..78728914a92 100644 --- a/src/traces/bar/plot.js +++ b/src/traces/bar/plot.js @@ -442,6 +442,9 @@ function toMoveInsideBar(x0, x1, y0, y1, textBB, opts) { var anchor = opts.anchor || 'end'; var isEnd = anchor === 'end'; var isStart = anchor === 'start'; + var leftToRight = opts.leftToRight || 0; // left: -1, center: 0, right: 1 + var toRight = (leftToRight + 1) / 2; + var toLeft = 1 - toRight; var textWidth = textBB.width; var textHeight = textBB.height; @@ -479,9 +482,15 @@ function toMoveInsideBar(x0, x1, y0, y1, textBB, opts) { } // compute text and target positions - var textX = (textBB.left + textBB.right) / 2; + var textX = ( + textBB.left * toLeft + + textBB.right * toRight + ); var textY = (textBB.top + textBB.bottom) / 2; - var targetX = (x0 + x1) / 2; + var targetX = ( + (x0 + TEXTPAD) * toLeft + + (x1 - TEXTPAD) * toRight + ); var targetY = (y0 + y1) / 2; var anchorX = 0; var anchorY = 0; diff --git a/src/traces/treemap/plot.js b/src/traces/treemap/plot.js index 10f2a4d3523..4f2deb49b33 100644 --- a/src/traces/treemap/plot.js +++ b/src/traces/treemap/plot.js @@ -299,16 +299,6 @@ function plotOne(gd, cd, element, transitionOpts) { var y1 = pt.y1; var textBB = pt.textBB; - if(x0 === x1) { - x0 -= TEXTPAD; - x1 += TEXTPAD; - } - - if(y0 === y1) { - y0 -= TEXTPAD; - y1 += TEXTPAD; - } - var hasFlag = function(f) { return trace.textposition.indexOf(f) !== -1; }; var hasBottom = hasFlag('bottom'); @@ -321,14 +311,9 @@ function plotOne(gd, cd, element, transitionOpts) { var hasRight = hasFlag('right'); var hasLeft = hasFlag('left') || opts.onPathbar; - var offsetDir = - hasLeft ? 'left' : - hasRight ? 'right' : 'center'; - - if(opts.onPathbar || !opts.isHeader) { - x0 += hasLeft ? TEXTPAD : 0; - x1 -= hasRight ? TEXTPAD : 0; - } + var leftToRight = + hasLeft ? -1 : + hasRight ? 1 : 0; var pad = trace.marker.pad; if(opts.isHeader) { @@ -336,8 +321,8 @@ function plotOne(gd, cd, element, transitionOpts) { x1 -= pad.r - TEXTPAD; if(x0 >= x1) { var mid = (x0 + x1) / 2; - x0 = mid - TEXTPAD; - x1 = mid + TEXTPAD; + x0 = mid; + x1 = mid; } // limit the drawing area for headers @@ -356,33 +341,29 @@ function plotOne(gd, cd, element, transitionOpts) { isHorizontal: false, constrained: true, angle: 0, - anchor: anchor + anchor: anchor, + leftToRight: leftToRight }); transform.fontSize = opts.fontSize; - if(offsetDir !== 'center') { - var deltaX = (x1 - x0) / 2 - transform.scale * (textBB.right - textBB.left) / 2; - if(opts.isHeader) deltaX -= TEXTPAD; - - if(offsetDir === 'left') transform.targetX -= deltaX; - else if(offsetDir === 'right') transform.targetX += deltaX; - } - - transform.targetX = viewMapX(transform.targetX - transform.anchorX * transform.scale); - transform.targetY = viewMapY(transform.targetY - transform.anchorY * transform.scale); - transform.anchorX = 0; - transform.anchorY = 0; + transform.targetX = viewMapX(transform.targetX); + transform.targetY = viewMapY(transform.targetY); if(isNaN(transform.targetX) || isNaN(transform.targetY)) { return {}; } - recordMinTextSize(trace.type, transform, fullLayout); + if(x0 !== x1 && y0 !== y1) { + recordMinTextSize(trace.type, transform, fullLayout); + } + return { scale: transform.scale, rotate: transform.rotate, textX: transform.textX, textY: transform.textY, + anchorX: transform.anchorX, + anchorY: transform.anchorY, targetX: transform.targetX, targetY: transform.targetY }; @@ -495,13 +476,18 @@ function plotOne(gd, cd, element, transitionOpts) { } var transform = pt.transform; - recordMinTextSize(trace.type, transform, fullLayout); + if(pt.x0 !== pt.x1 && pt.y0 !== pt.y1) { + recordMinTextSize(trace.type, transform, fullLayout); + } + return d3.interpolate(prev, { transform: { scale: transform.scale, rotate: transform.rotate, textX: transform.textX, textY: transform.textY, + anchorX: transform.anchorX, + anchorY: transform.anchorY, targetX: transform.targetX, targetY: transform.targetY } @@ -534,11 +520,16 @@ function plotOne(gd, cd, element, transitionOpts) { var strTransform = function(d) { var transform = d.transform; - recordMinTextSize(trace.type, transform, fullLayout); + + if(d.x0 !== d.x1 && d.y0 !== d.y1) { + recordMinTextSize(trace.type, transform, fullLayout); + } return Lib.getTextTransform({ textX: transform.textX, textY: transform.textY, + anchorX: transform.anchorX, + anchorY: transform.anchorY, targetX: transform.targetX, targetY: transform.targetY, scale: transform.scale, @@ -561,6 +552,8 @@ function plotOne(gd, cd, element, transitionOpts) { prevLookupPathbar[getKey(pt)].transform = { textX: pt.transform.textX, textY: pt.transform.textY, + anchorX: pt.transform.anchorX, + anchorY: pt.transform.anchorY, targetX: pt.transform.targetX, targetY: pt.transform.targetY, scale: pt.transform.scale, @@ -581,6 +574,8 @@ function plotOne(gd, cd, element, transitionOpts) { prevLookupSlices[getKey(pt)].transform = { textX: pt.transform.textX, textY: pt.transform.textY, + anchorX: pt.transform.anchorX, + anchorY: pt.transform.anchorY, targetX: pt.transform.targetX, targetY: pt.transform.targetY, scale: pt.transform.scale, diff --git a/test/image/baselines/treemap_coffee.png b/test/image/baselines/treemap_coffee.png index 3b07932be1c..d283751e01c 100644 Binary files a/test/image/baselines/treemap_coffee.png and b/test/image/baselines/treemap_coffee.png differ diff --git a/test/image/baselines/treemap_flare.png b/test/image/baselines/treemap_flare.png index 9b7703e6273..88260664e8e 100644 Binary files a/test/image/baselines/treemap_flare.png and b/test/image/baselines/treemap_flare.png differ diff --git a/test/image/baselines/treemap_level-depth.png b/test/image/baselines/treemap_level-depth.png index 6f2aa4ac87b..15ba3e01597 100644 Binary files a/test/image/baselines/treemap_level-depth.png and b/test/image/baselines/treemap_level-depth.png differ diff --git a/test/image/baselines/treemap_packages_colorscale_allone.png b/test/image/baselines/treemap_packages_colorscale_allone.png index ed977d1e687..f6d337f0105 100644 Binary files a/test/image/baselines/treemap_packages_colorscale_allone.png and b/test/image/baselines/treemap_packages_colorscale_allone.png differ diff --git a/test/image/baselines/treemap_packages_colorscale_novalue.png b/test/image/baselines/treemap_packages_colorscale_novalue.png index 6473503b5f9..a602dda326b 100644 Binary files a/test/image/baselines/treemap_packages_colorscale_novalue.png and b/test/image/baselines/treemap_packages_colorscale_novalue.png differ diff --git a/test/image/baselines/treemap_packings.png b/test/image/baselines/treemap_packings.png index 2891ea6cb32..5db4df1644d 100644 Binary files a/test/image/baselines/treemap_packings.png and b/test/image/baselines/treemap_packings.png differ diff --git a/test/image/baselines/treemap_pad_mirror.png b/test/image/baselines/treemap_pad_mirror.png index 7fb51301e03..3aba2a27a29 100644 Binary files a/test/image/baselines/treemap_pad_mirror.png and b/test/image/baselines/treemap_pad_mirror.png differ diff --git a/test/image/baselines/treemap_pad_transpose.png b/test/image/baselines/treemap_pad_transpose.png index f215e78005c..460f2cc7be2 100644 Binary files a/test/image/baselines/treemap_pad_transpose.png and b/test/image/baselines/treemap_pad_transpose.png differ diff --git a/test/image/baselines/treemap_sunburst_marker_colors.png b/test/image/baselines/treemap_sunburst_marker_colors.png index 0790bca81df..ab85b17e709 100644 Binary files a/test/image/baselines/treemap_sunburst_marker_colors.png and b/test/image/baselines/treemap_sunburst_marker_colors.png differ diff --git a/test/image/baselines/treemap_textfit.png b/test/image/baselines/treemap_textfit.png index 3d8660f2007..d9e7ce156e6 100644 Binary files a/test/image/baselines/treemap_textfit.png and b/test/image/baselines/treemap_textfit.png differ diff --git a/test/image/baselines/treemap_textposition.png b/test/image/baselines/treemap_textposition.png index 67835c5498c..82a137dc35b 100644 Binary files a/test/image/baselines/treemap_textposition.png and b/test/image/baselines/treemap_textposition.png differ diff --git a/test/image/baselines/treemap_values.png b/test/image/baselines/treemap_values.png index 2be823d8aef..45367d7f913 100644 Binary files a/test/image/baselines/treemap_values.png and b/test/image/baselines/treemap_values.png differ diff --git a/test/image/baselines/treemap_values_colorscale.png b/test/image/baselines/treemap_values_colorscale.png index 2954e59110a..d9e890e853f 100644 Binary files a/test/image/baselines/treemap_values_colorscale.png and b/test/image/baselines/treemap_values_colorscale.png differ diff --git a/test/image/baselines/treemap_with-without_values.png b/test/image/baselines/treemap_with-without_values.png index b6cedec1971..cc64ab5d577 100644 Binary files a/test/image/baselines/treemap_with-without_values.png and b/test/image/baselines/treemap_with-without_values.png differ diff --git a/test/image/baselines/treemap_with-without_values_template.png b/test/image/baselines/treemap_with-without_values_template.png index d1905dc32b6..64e6082af74 100644 Binary files a/test/image/baselines/treemap_with-without_values_template.png and b/test/image/baselines/treemap_with-without_values_template.png differ diff --git a/test/image/baselines/uniformtext_sunburst_treemap.png b/test/image/baselines/uniformtext_sunburst_treemap.png index 96d3d7227a3..62925d71461 100644 Binary files a/test/image/baselines/uniformtext_sunburst_treemap.png and b/test/image/baselines/uniformtext_sunburst_treemap.png differ diff --git a/test/image/baselines/uniformtext_treemap.png b/test/image/baselines/uniformtext_treemap.png index 43723137e15..644243ea876 100644 Binary files a/test/image/baselines/uniformtext_treemap.png and b/test/image/baselines/uniformtext_treemap.png differ diff --git a/test/image/baselines/uniformtext_treemap_coffee-maxdepth3.png b/test/image/baselines/uniformtext_treemap_coffee-maxdepth3.png new file mode 100644 index 00000000000..052da9fc349 Binary files /dev/null and b/test/image/baselines/uniformtext_treemap_coffee-maxdepth3.png differ diff --git a/test/image/mocks/uniformtext_treemap_coffee-maxdepth3.json b/test/image/mocks/uniformtext_treemap_coffee-maxdepth3.json new file mode 100644 index 00000000000..7b09cc062c9 --- /dev/null +++ b/test/image/mocks/uniformtext_treemap_coffee-maxdepth3.json @@ -0,0 +1,320 @@ +{ + "data": [ + { + "type": "treemap", + "tiling": { + "packing": "slice-dice" + }, + "pathbar": { + "visible": false + }, + "maxdepth": 3, + "textinfo": "label+percent parent", + "ids": [ + "Aromas", + "Tastes", + "Aromas-Enzymatic", + "Aromas-Sugar Browning", + "Aromas-Dry Distillation", + "Tastes-Bitter", + "Tastes-Salt", + "Tastes-Sweet", + "Tastes-Sour", + "Enzymatic-Flowery", + "Enzymatic-Fruity", + "Enzymatic-Herby", + "Sugar Browning-Nutty", + "Sugar Browning-Carmelly", + "Sugar Browning-Chocolatey", + "Dry Distillation-Resinous", + "Dry Distillation-Spicy", + "Dry Distillation-Carbony", + "Bitter-Pungent", + "Bitter-Harsh", + "Salt-Sharp", + "Salt-Bland", + "Sweet-Mellow", + "Sweet-Acidy", + "Sour-Winey", + "Sour-Soury", + "Flowery-Floral", + "Flowery-Fragrant", + "Fruity-Citrus", + "Fruity-Berry-like", + "Herby-Alliaceous", + "Herby-Leguminous", + "Nutty-Nut-like", + "Nutty-Malt-like", + "Carmelly-Candy-like", + "Carmelly-Syrup-like", + "Chocolatey-Chocolate-like", + "Chocolatey-Vanilla-like", + "Resinous-Turpeny", + "Resinous-Medicinal", + "Spicy-Warming", + "Spicy-Pungent", + "Carbony-Smokey", + "Carbony-Ashy", + "Pungent-Creosol", + "Pungent-Phenolic", + "Harsh-Caustic", + "Harsh-Alkaline", + "Sharp-Astringent", + "Sharp-Rough", + "Bland-Neutral", + "Bland-Soft", + "Mellow-Delicate", + "Mellow-Mild", + "Acidy-Nippy", + "Acidy-Piquant", + "Winey-Tangy", + "Winey-Tart", + "Soury-Hard", + "Soury-Acrid", + "Floral-Coffee Blossom", + "Floral-Tea Rose", + "Fragrant-Cardamon Caraway", + "Fragrant-Coriander Seeds", + "Citrus-Lemon", + "Citrus-Apple", + "Berry-like-Apricot", + "Berry-like-Blackberry", + "Alliaceous-Onion", + "Alliaceous-Garlic", + "Leguminous-Cucumber", + "Leguminous-Garden Peas", + "Nut-like-Roasted Peanuts", + "Nut-like-Walnuts", + "Malt-like-Balsamic Rice", + "Malt-like-Toast", + "Candy-like-Roasted Hazelnut", + "Candy-like-Roasted Almond", + "Syrup-like-Honey", + "Syrup-like-Maple Syrup", + "Chocolate-like-Bakers", + "Chocolate-like-Dark Chocolate", + "Vanilla-like-Swiss", + "Vanilla-like-Butter", + "Turpeny-Piney", + "Turpeny-Blackcurrant-like", + "Medicinal-Camphoric", + "Medicinal-Cineolic", + "Warming-Cedar", + "Warming-Pepper", + "Pungent-Clove", + "Pungent-Thyme", + "Smokey-Tarry", + "Smokey-Pipe Tobacco", + "Ashy-Burnt", + "Ashy-Charred" + ], + "labels": [ + "Aromas", + "Tastes", + "Enzymatic", + "Sugar Browning", + "Dry Distillation", + "Bitter", + "Salt", + "Sweet", + "Sour", + "Flowery", + "Fruity", + "Herby", + "Nutty", + "Carmelly", + "Chocolatey", + "Resinous", + "Spicy", + "Carbony", + "Pungent", + "Harsh", + "Sharp", + "Bland", + "Mellow", + "Acidy", + "Winey", + "Soury", + "Floral", + "Fragrant", + "Citrus", + "Berry-like", + "Alliaceous", + "Leguminous", + "Nut-like", + "Malt-like", + "Candy-like", + "Syrup-like", + "Chocolate-like", + "Vanilla-like", + "Turpeny", + "Medicinal", + "Warming", + "Pungent", + "Smokey", + "Ashy", + "Creosol", + "Phenolic", + "Caustic", + "Alkaline", + "Astringent", + "Rough", + "Neutral", + "Soft", + "Delicate", + "Mild", + "Nippy", + "Piquant", + "Tangy", + "Tart", + "Hard", + "Acrid", + "Coffee Blossom", + "Tea Rose", + "Cardamon Caraway", + "Coriander Seeds", + "Lemon", + "Apple", + "Apricot", + "Blackberry", + "Onion", + "Garlic", + "Cucumber", + "Garden Peas", + "Roasted Peanuts", + "Walnuts", + "Balsamic Rice", + "Toast", + "Roasted Hazelnut", + "Roasted Almond", + "Honey", + "Maple Syrup", + "Bakers", + "Dark Chocolate", + "Swiss", + "Butter", + "Piney", + "Blackcurrant-like", + "Camphoric", + "Cineolic", + "Cedar", + "Pepper", + "Clove", + "Thyme", + "Tarry", + "Pipe Tobacco", + "Burnt", + "Charred" + ], + "parents": [ + "", + "", + "Aromas", + "Aromas", + "Aromas", + "Tastes", + "Tastes", + "Tastes", + "Tastes", + "Aromas-Enzymatic", + "Aromas-Enzymatic", + "Aromas-Enzymatic", + "Aromas-Sugar Browning", + "Aromas-Sugar Browning", + "Aromas-Sugar Browning", + "Aromas-Dry Distillation", + "Aromas-Dry Distillation", + "Aromas-Dry Distillation", + "Tastes-Bitter", + "Tastes-Bitter", + "Tastes-Salt", + "Tastes-Salt", + "Tastes-Sweet", + "Tastes-Sweet", + "Tastes-Sour", + "Tastes-Sour", + "Enzymatic-Flowery", + "Enzymatic-Flowery", + "Enzymatic-Fruity", + "Enzymatic-Fruity", + "Enzymatic-Herby", + "Enzymatic-Herby", + "Sugar Browning-Nutty", + "Sugar Browning-Nutty", + "Sugar Browning-Carmelly", + "Sugar Browning-Carmelly", + "Sugar Browning-Chocolatey", + "Sugar Browning-Chocolatey", + "Dry Distillation-Resinous", + "Dry Distillation-Resinous", + "Dry Distillation-Spicy", + "Dry Distillation-Spicy", + "Dry Distillation-Carbony", + "Dry Distillation-Carbony", + "Bitter-Pungent", + "Bitter-Pungent", + "Bitter-Harsh", + "Bitter-Harsh", + "Salt-Sharp", + "Salt-Sharp", + "Salt-Bland", + "Salt-Bland", + "Sweet-Mellow", + "Sweet-Mellow", + "Sweet-Acidy", + "Sweet-Acidy", + "Sour-Winey", + "Sour-Winey", + "Sour-Soury", + "Sour-Soury", + "Flowery-Floral", + "Flowery-Floral", + "Flowery-Fragrant", + "Flowery-Fragrant", + "Fruity-Citrus", + "Fruity-Citrus", + "Fruity-Berry-like", + "Fruity-Berry-like", + "Herby-Alliaceous", + "Herby-Alliaceous", + "Herby-Leguminous", + "Herby-Leguminous", + "Nutty-Nut-like", + "Nutty-Nut-like", + "Nutty-Malt-like", + "Nutty-Malt-like", + "Carmelly-Candy-like", + "Carmelly-Candy-like", + "Carmelly-Syrup-like", + "Carmelly-Syrup-like", + "Chocolatey-Chocolate-like", + "Chocolatey-Chocolate-like", + "Chocolatey-Vanilla-like", + "Chocolatey-Vanilla-like", + "Resinous-Turpeny", + "Resinous-Turpeny", + "Resinous-Medicinal", + "Resinous-Medicinal", + "Spicy-Warming", + "Spicy-Warming", + "Spicy-Pungent", + "Spicy-Pungent", + "Carbony-Smokey", + "Carbony-Smokey", + "Carbony-Ashy", + "Carbony-Ashy" + ] + } + ], + "layout": { + "uniformtext": { + "mode": "hide" + }, + "margin": {"l": 0, "r": 0, "b": 0, "t": 0}, + "width": 400, + "height": 400, + "shapes": [ + { "type": "rect", "layer": "below", "x0": 0, "x1": 1, "y0": 0, "y1": 1 } + ] + } +} diff --git a/test/jasmine/tests/treemap_test.js b/test/jasmine/tests/treemap_test.js index f8d87bbcfa2..45297d53d85 100644 --- a/test/jasmine/tests/treemap_test.js +++ b/test/jasmine/tests/treemap_test.js @@ -1445,7 +1445,7 @@ describe('Test treemap tweening:', function() { 'M284.375,188.5L548.375,188.5L548.375,308.5L284.375,308.5Z' ); _assert('move B text to new position', 'transform', 'B', [221.25, 126], 3); - _assert('enter b text to new position', 'transform', 'b', [286.63, 196.35]); + _assert('enter b text to new position', 'transform', 'b', [287.625, 192]); }) .catch(failTest) .then(done);