Skip to content

Fix Non-Mapbox Scatter with text markers #6652

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 5 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)]
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: 'http://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: 'http://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: 'http://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: 'http://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: 'http://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: 'http://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: 'http://fonts.openmaptiles.org/{fontstack}/{range}.pbf'
}
};

Expand Down
8 changes: 5 additions & 3 deletions src/traces/scatter/text_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ var Lib = require('../../lib');
*/
module.exports = function(traceIn, traceOut, layout, coerce, opts) {
opts = opts || {};

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

if(opts.font) {
Lib.coerceFont(coerce, 'textfont', opts.font);
} else {
Lib.coerceFont(coerce, 'textfont', layout.font);
}
if(!opts.noSelect) {
coerce('selected.textfont.color');
coerce('unselected.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
9 changes: 8 additions & 1 deletion src/traces/scattermapbox/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,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: '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
Loading
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"
}
}
}