Skip to content

Commit

Permalink
Merge pull request #6652 from baurt/mapbox-glyphs
Browse files Browse the repository at this point in the history
Fix Non-Mapbox Scatter with text markers
  • Loading branch information
archmoj committed Jul 18, 2023
2 parents e1d8b95 + bf674e1 commit 2effef5
Show file tree
Hide file tree
Showing 14 changed files with 104 additions and 13 deletions.
1 change: 1 addition & 0 deletions draftlogs/6652_fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- fix text markers on non-mapbox styled maps [[#6652](https://github.com/plotly/plotly.js/pull/6652)], with thanks to @baurt for the contribution!
21 changes: 14 additions & 7 deletions src/plots/mapbox/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ var stylesNonMapbox = {
source: 'plotly-osm-tiles',
minzoom: 0,
maxzoom: 22
}]
}],
glyphs: 'https://fonts.openmaptiles.org/{fontstack}/{range}.pbf'
},
'white-bg': {
id: 'white-bg',
Expand All @@ -59,7 +60,8 @@ var stylesNonMapbox = {
paint: {'background-color': '#FFFFFF'},
minzoom: 0,
maxzoom: 22
}]
}],
glyphs: 'https://fonts.openmaptiles.org/{fontstack}/{range}.pbf'
},
'carto-positron': {
id: 'carto-positron',
Expand All @@ -78,7 +80,8 @@ var stylesNonMapbox = {
source: 'plotly-carto-positron',
minzoom: 0,
maxzoom: 22
}]
}],
glyphs: 'https://fonts.openmaptiles.org/{fontstack}/{range}.pbf'
},
'carto-darkmatter': {
id: 'carto-darkmatter',
Expand All @@ -97,7 +100,8 @@ var stylesNonMapbox = {
source: 'plotly-carto-darkmatter',
minzoom: 0,
maxzoom: 22
}]
}],
glyphs: 'https://fonts.openmaptiles.org/{fontstack}/{range}.pbf'
},
'stamen-terrain': {
id: 'stamen-terrain',
Expand All @@ -116,7 +120,8 @@ var stylesNonMapbox = {
source: 'plotly-stamen-terrain',
minzoom: 0,
maxzoom: 22
}]
}],
glyphs: 'https://fonts.openmaptiles.org/{fontstack}/{range}.pbf'
},
'stamen-toner': {
id: 'stamen-toner',
Expand All @@ -135,7 +140,8 @@ var stylesNonMapbox = {
source: 'plotly-stamen-toner',
minzoom: 0,
maxzoom: 22
}]
}],
glyphs: 'https://fonts.openmaptiles.org/{fontstack}/{range}.pbf'
},
'stamen-watercolor': {
id: 'stamen-watercolor',
Expand All @@ -154,7 +160,8 @@ var stylesNonMapbox = {
source: 'plotly-stamen-watercolor',
minzoom: 0,
maxzoom: 22
}]
}],
glyphs: 'https://fonts.openmaptiles.org/{fontstack}/{range}.pbf'
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/traces/scatter/text_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = function(traceIn, traceOut, layout, coerce, opts) {
opts = opts || {};

coerce('textposition');
Lib.coerceFont(coerce, 'textfont', layout.font);
Lib.coerceFont(coerce, 'textfont', opts.font || layout.font);

if(!opts.noSelect) {
coerce('selected.textfont.color');
Expand Down
6 changes: 2 additions & 4 deletions src/traces/scattermapbox/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,8 @@ module.exports = function convert(gd, calcTrace) {
Lib.extendFlat(symbol.layout, {
'text-size': trace.textfont.size,
'text-anchor': textOpts.anchor,
'text-offset': textOpts.offset

// TODO font family
// 'text-font': symbol.textfont.family.split(', '),
'text-offset': textOpts.offset,
'text-font': trace.textfont.family.split(', '),
});

Lib.extendFlat(symbol.paint, {
Expand Down
47 changes: 46 additions & 1 deletion src/traces/scattermapbox/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,44 @@ var handleTextDefaults = require('../scatter/text_defaults');
var handleFillColorDefaults = require('../scatter/fillcolor_defaults');
var attributes = require('./attributes');

// Must use one of the following fonts as the family, else default to 'Open Sans Regular'
// See https://github.com/openmaptiles/fonts/blob/gh-pages/fontstacks.json
var supportedFonts = [
'Metropolis Black Italic',
'Metropolis Black',
'Metropolis Bold Italic',
'Metropolis Bold',
'Metropolis Extra Bold Italic',
'Metropolis Extra Bold',
'Metropolis Extra Light Italic',
'Metropolis Extra Light',
'Metropolis Light Italic',
'Metropolis Light',
'Metropolis Medium Italic',
'Metropolis Medium',
'Metropolis Regular Italic',
'Metropolis Regular',
'Metropolis Semi Bold Italic',
'Metropolis Semi Bold',
'Metropolis Thin Italic',
'Metropolis Thin',
'Open Sans Bold Italic',
'Open Sans Bold',
'Open Sans Extra Bold Italic',
'Open Sans Extra Bold',
'Open Sans Italic',
'Open Sans Light Italic',
'Open Sans Light',
'Open Sans Regular',
'Open Sans Semibold Italic',
'Open Sans Semibold',
'Klokantech Noto Sans Bold',
'Klokantech Noto Sans CJK Bold',
'Klokantech Noto Sans CJK Regular',
'Klokantech Noto Sans Italic',
'Klokantech Noto Sans Regular'
];

module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
function coerce(attr, dflt) {
return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
Expand Down Expand Up @@ -66,7 +104,14 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
coerce('cluster.enabled', clusterEnabledDflt);

if(subTypes.hasText(traceOut)) {
handleTextDefaults(traceIn, traceOut, layout, coerce, {noSelect: true});
handleTextDefaults(traceIn, traceOut, layout, coerce,
{noSelect: true,
font: {
family: supportedFonts.indexOf(layout.font.family) !== -1 ? layout.font.family : 'Open Sans Regular',
size: layout.font.size,
color: layout.font.color
}
});
}

coerce('fill');
Expand Down
Binary file added test/image/baselines/mapbox_carto-text.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/pattern_bars.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/pie_textpad_radial.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/sunburst_inside-text-orientation.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/sunburst_packages_colorscale_novalue.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/sunburst_textpad_radial.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/treemap_sunburst_marker_colors.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/image/baselines/uniformtext_sunburst_treemap.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 40 additions & 0 deletions test/image/mocks/mapbox_carto-text.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"data": [
{
"type": "scattermapbox",
"name": "carto-positron",
"lon": [ 10, 5 ],
"lat": [ 20, 10 ],
"text":["pt1","pt2"],
"mode":"text"

},
{
"type": "scattermapbox",
"name": "carto-darkmatter",
"lon": [ 10, 5 ],
"lat": [ 20, 10 ],
"subplot": "mapbox2",
"mode":"text",
"text":["pt1","pt2"],
"textfont":{"family":"Metropolis Extra Bold Italic","color":"#fff"}
}
],
"layout": {
"grid": {"rows": 1, "columns": 2},

"legend": {
"x": 0,
"y": 1, "yanchor": "bottom"
},

"mapbox": {
"domain": {"row": 0, "column": 0},
"style": "carto-positron"
},
"mapbox2": {
"domain": {"row": 0, "column": 1},
"style": "carto-darkmatter"
}
}
}

0 comments on commit 2effef5

Please sign in to comment.