Skip to content

Commit c338b60

Browse files
committed
always fall back to circle icon in legend for scattermap
1 parent 292acf8 commit c338b60

2 files changed

Lines changed: 45 additions & 1 deletion

File tree

src/components/legend/style.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,12 @@ module.exports = function style(s, gd, legend) {
207207

208208
if (showMarker) {
209209
dEdit.mc = boundVal('marker.color', pickFirst);
210-
dEdit.mx = boundVal('marker.symbol', pickFirst);
210+
// Scattermap traces use marker.symbol to specify the Maki icon used in
211+
// the map itself, which usually doesn't correspond to a valid
212+
// Plotly symbol. Always draw a circle so the swatch is consistent
213+
// across symbols rather than silently mismatched.
214+
var isScattermapTrace = trace.type === 'scattermap' || trace.type === 'scattermapbox';
215+
dEdit.mx = isScattermapTrace ? 'circle' : boundVal('marker.symbol', pickFirst);
211216
dEdit.mo = boundVal('marker.opacity', Lib.mean, [0.2, 1]);
212217
dEdit.mlc = boundVal('marker.line.color', pickFirst);
213218
dEdit.mlw = boundVal('marker.line.width', Lib.mean, [0, 5], CST_MARKER_LINE_WIDTH);

test/jasmine/tests/scattermap_test.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,6 +1248,45 @@ describe('Test plotly events on a scattermap plot when css transform is present:
12481248
});
12491249
});
12501250

1251+
describe('scattermap legend', function() {
1252+
var gd;
1253+
1254+
beforeEach(function() {
1255+
Plotly.setPlotConfig({});
1256+
gd = createGraphDiv();
1257+
});
1258+
1259+
afterEach(function() {
1260+
Plotly.purge(gd);
1261+
destroyGraphDiv();
1262+
});
1263+
1264+
it('@gl should always draw a circle swatch regardless of marker.symbol', function(done) {
1265+
// marker.symbol on map traces is a Maki/sprite icon name that the SVG
1266+
// legend can't reproduce, so the swatch should consistently be a circle.
1267+
// The circle symbol path is the only one using an arc ('A') command;
1268+
// square/triangle/etc. use only straight (H/V/L) segments.
1269+
Plotly.newPlot(gd, {
1270+
data: [
1271+
{ type: 'scattermap', lat: [0], lon: [0], mode: 'markers', name: 'square', marker: { symbol: 'square' } },
1272+
{ type: 'scattermap', lat: [1], lon: [1], mode: 'markers', name: 'tri', marker: { symbol: 'triangle-stroked' } }
1273+
],
1274+
layout: {
1275+
map: { style: 'open-street-map', zoom: 6, center: { lat: 0.5, lon: 0.5 } },
1276+
showlegend: true
1277+
}
1278+
}).then(function() {
1279+
var swatches = gd.querySelectorAll('.legend .legendpoints path.scatterpts');
1280+
expect(swatches.length).toBe(2, 'one swatch per trace');
1281+
swatches.forEach(function(node) {
1282+
var d = node.getAttribute('d');
1283+
expect(d.indexOf('A')).toBeGreaterThan(-1, 'swatch is a circle (has arc): ' + d);
1284+
expect(d.indexOf('NaN')).toBe(-1, 'swatch path has no NaN: ' + d);
1285+
});
1286+
}).then(done, done.fail);
1287+
});
1288+
});
1289+
12511290
describe('scattermap restyle', function() {
12521291
var gd;
12531292

0 commit comments

Comments
 (0)