diff --git a/src/plots/mapbox/index.js b/src/plots/mapbox/index.js index 9411950b870..7f9e0d38633 100644 --- a/src/plots/mapbox/index.js +++ b/src/plots/mapbox/index.js @@ -15,6 +15,7 @@ var getSubplotCalcData = require('../../plots/get_data').getSubplotCalcData; var xmlnsNamespaces = require('../../constants/xmlns_namespaces'); var d3 = require('d3'); var Drawing = require('../../components/drawing'); +var svgTextUtils = require('../../lib/svg_text_utils'); var Mapbox = require('./mapbox'); @@ -170,21 +171,41 @@ exports.toSVG = function(gd) { 'font-family': 'Arial', 'color': 'rgba(0, 0, 0, 0.75)', 'text-anchor': 'end', - 'data-unformatted': attributions, - x: size.l + size.w * domain.x[1] - 3, - y: size.t + size.h * (1 - domain.y[0]) - 4 + 'data-unformatted': attributions }); var bBox = Drawing.bBox(attributionText.node()); + + // Break into multiple lines twice larger than domain + var maxWidth = size.w * (domain.x[1] - domain.x[0]); + if((bBox.width > maxWidth / 2)) { + var multilineAttributions = attributions.split('|').join('
'); + attributionText + .text(multilineAttributions) + .attr('data-unformatted', multilineAttributions) + .call(svgTextUtils.convertToTspans, gd); + + bBox = Drawing.bBox(attributionText.node()); + } + attributionText.attr('transform', 'translate(-3, ' + (-bBox.height + 8) + ')'); + + // Draw white rectangle behind text attributionGroup .insert('rect', '.static-attribution') .attr({ - x: size.l + size.w * domain.x[1] - bBox.width - 6, - y: size.t + size.h * (1 - domain.y[0]) - (bBox.height + 3), + x: -bBox.width - 6, + y: -bBox.height - 3, width: bBox.width + 6, height: bBox.height + 3, fill: 'rgba(255, 255, 255, 0.75)' }); + + // Scale down if larger than domain + var scaleRatio = 1; + if((bBox.width + 6) > maxWidth) scaleRatio = maxWidth / (bBox.width + 6); + + var offset = [(size.l + size.w * domain.x[1]), (size.t + size.h * (1 - domain.y[0]))]; + attributionGroup.attr('transform', 'translate(' + offset[0] + ',' + offset[1] + ') scale(' + scaleRatio + ')'); } }; diff --git a/test/image/baselines/mapbox_0.png b/test/image/baselines/mapbox_0.png index ad2fe772a46..89e0ff40d97 100644 Binary files a/test/image/baselines/mapbox_0.png and b/test/image/baselines/mapbox_0.png differ diff --git a/test/image/baselines/mapbox_angles.png b/test/image/baselines/mapbox_angles.png index 3d4dd88f938..ce0eacf07e7 100644 Binary files a/test/image/baselines/mapbox_angles.png and b/test/image/baselines/mapbox_angles.png differ diff --git a/test/image/baselines/mapbox_bubbles-text.png b/test/image/baselines/mapbox_bubbles-text.png index 9b7153f9ad4..131a38dd2ab 100644 Binary files a/test/image/baselines/mapbox_bubbles-text.png and b/test/image/baselines/mapbox_bubbles-text.png differ diff --git a/test/image/baselines/mapbox_bubbles.png b/test/image/baselines/mapbox_bubbles.png index 52dcd920b86..58e177e6be8 100644 Binary files a/test/image/baselines/mapbox_bubbles.png and b/test/image/baselines/mapbox_bubbles.png differ diff --git a/test/image/baselines/mapbox_choropleth-multiple.png b/test/image/baselines/mapbox_choropleth-multiple.png index c4b86115596..86fd49833af 100644 Binary files a/test/image/baselines/mapbox_choropleth-multiple.png and b/test/image/baselines/mapbox_choropleth-multiple.png differ diff --git a/test/image/baselines/mapbox_choropleth-raw-geojson.png b/test/image/baselines/mapbox_choropleth-raw-geojson.png index ae40b65cc32..9e4870d95bc 100644 Binary files a/test/image/baselines/mapbox_choropleth-raw-geojson.png and b/test/image/baselines/mapbox_choropleth-raw-geojson.png differ diff --git a/test/image/baselines/mapbox_choropleth0.png b/test/image/baselines/mapbox_choropleth0.png index 8e871370cc5..8a9bd27be48 100644 Binary files a/test/image/baselines/mapbox_choropleth0.png and b/test/image/baselines/mapbox_choropleth0.png differ diff --git a/test/image/baselines/mapbox_connectgaps.png b/test/image/baselines/mapbox_connectgaps.png index 67dcb6fc51a..4de11c88590 100644 Binary files a/test/image/baselines/mapbox_connectgaps.png and b/test/image/baselines/mapbox_connectgaps.png differ diff --git a/test/image/baselines/mapbox_custom-style.png b/test/image/baselines/mapbox_custom-style.png index d0a8ff92dd8..179f0ae9037 100644 Binary files a/test/image/baselines/mapbox_custom-style.png and b/test/image/baselines/mapbox_custom-style.png differ diff --git a/test/image/baselines/mapbox_density-mulitple.png b/test/image/baselines/mapbox_density-mulitple.png index 828cf6f29ed..a98fb7e64d9 100644 Binary files a/test/image/baselines/mapbox_density-mulitple.png and b/test/image/baselines/mapbox_density-mulitple.png differ diff --git a/test/image/baselines/mapbox_density0.png b/test/image/baselines/mapbox_density0.png index 38410c5f4b4..265c2cea77e 100644 Binary files a/test/image/baselines/mapbox_density0.png and b/test/image/baselines/mapbox_density0.png differ diff --git a/test/image/baselines/mapbox_earthquake-density.png b/test/image/baselines/mapbox_earthquake-density.png index 1d72d151ead..85ac1719ae4 100644 Binary files a/test/image/baselines/mapbox_earthquake-density.png and b/test/image/baselines/mapbox_earthquake-density.png differ diff --git a/test/image/baselines/mapbox_fill.png b/test/image/baselines/mapbox_fill.png index 98b4b382a7d..6f1188fd2fa 100644 Binary files a/test/image/baselines/mapbox_fill.png and b/test/image/baselines/mapbox_fill.png differ diff --git a/test/image/baselines/mapbox_geojson-attributes.png b/test/image/baselines/mapbox_geojson-attributes.png index ab86940f700..cd98ff31107 100644 Binary files a/test/image/baselines/mapbox_geojson-attributes.png and b/test/image/baselines/mapbox_geojson-attributes.png differ diff --git a/test/image/baselines/mapbox_layers.png b/test/image/baselines/mapbox_layers.png index 384f9b042cd..c9d49e9fe83 100644 Binary files a/test/image/baselines/mapbox_layers.png and b/test/image/baselines/mapbox_layers.png differ diff --git a/test/image/baselines/mapbox_osm-style.png b/test/image/baselines/mapbox_osm-style.png index 7f6981034f1..bfd9fd6bc54 100644 Binary files a/test/image/baselines/mapbox_osm-style.png and b/test/image/baselines/mapbox_osm-style.png differ diff --git a/test/image/baselines/mapbox_symbol-text.png b/test/image/baselines/mapbox_symbol-text.png index dbaeddf583f..dce3a47b815 100644 Binary files a/test/image/baselines/mapbox_symbol-text.png and b/test/image/baselines/mapbox_symbol-text.png differ