diff --git a/draftlogs/6414_fix.md b/draftlogs/6414_fix.md new file mode 100644 index 00000000000..8e953c80716 --- /dev/null +++ b/draftlogs/6414_fix.md @@ -0,0 +1 @@ + - Fix auto `backoff` when marker symbols and sizes are arrays [[#6414](https://github.com/plotly/plotly.js/pull/6414)] diff --git a/src/components/drawing/index.js b/src/components/drawing/index.js index ff16be0efea..0472b7fc823 100644 --- a/src/components/drawing/index.js +++ b/src/components/drawing/index.js @@ -1203,7 +1203,13 @@ function applyBackoff(pt, start) { if(trace.type === 'scatter') endI--; // Why we need this hack? var endMarker = end.marker; - b = endMarker ? drawing.symbolBackOffs[drawing.symbolNumber(endMarker.symbol)] * endMarker.size : 0; + var endMarkerSymbol = endMarker.symbol; + if(Lib.isArrayOrTypedArray(endMarkerSymbol)) endMarkerSymbol = endMarkerSymbol[endI]; + + var endMarkerSize = endMarker.size; + if(Lib.isArrayOrTypedArray(endMarkerSize)) endMarkerSize = endMarkerSize[endI]; + + b = endMarker ? drawing.symbolBackOffs[drawing.symbolNumber(endMarkerSymbol)] * endMarkerSize : 0; b += drawing.getMarkerStandoff(d[endI], trace) || 0; } diff --git a/test/image/baselines/z-marker-standoff_auto-backoff2.png b/test/image/baselines/z-marker-standoff_auto-backoff2.png new file mode 100644 index 00000000000..9ba17f625d7 Binary files /dev/null and b/test/image/baselines/z-marker-standoff_auto-backoff2.png differ diff --git a/test/image/mocks/z-marker-standoff_auto-backoff2.json b/test/image/mocks/z-marker-standoff_auto-backoff2.json new file mode 100644 index 00000000000..2a8de6e0d8a --- /dev/null +++ b/test/image/mocks/z-marker-standoff_auto-backoff2.json @@ -0,0 +1,404 @@ +{ + "data": [ + { + "mode": "markers+lines", + "line": { + "width": 5 + }, + "marker": { + "opacity": 1, + "standoff": [5, 20, null, 20, 10], + "angleref": "previous", + "symbol": [null, "arrow", null, null, "arrow-wide"], + "size": [null, 20, null, null, 30] + }, + "x": [ + 1, + 2, + null, + 2, + 3 + ], + "y": [ + 3, + 1, + null, + 1, + 2 + ] + }, + { + "mode": "markers+text", + "marker": { + "opacity": 1, + "size": [10, 40, 20] + }, + "text": [10, 40, 20], + "textposition": ["right", "center", "top"], + "x": [ + 1, + 2, + 3 + ], + "y": [ + 3, + 1, + 2 + ] + }, + { + "type": "scattergeo", + "mode": "markers+lines", + "line": { "width": 5 }, + "marker": { + "opacity": 1, + "standoff": [5, 20, null, 20, 10], + "angleref": "previous", + "symbol": "arrow-wide", + "size": 20 + }, + "lon": [ + -30, + 0, + null, + 0, + 30 + ], + "lat": [ + 20, + -5, + null, + -5, + 10 + ] + }, + { + "type": "scattergeo", + "mode": "markers+text", + "marker": { + "opacity": 1, + "size": [10, 40, 20] + }, + "text": [10, 40, 20], + "textposition": ["right", "center", "top"], + "lon": [ + -30, + 0, + 30 + ], + "lat": [ + 20, + -5, + 10 + ] + }, + { + "type": "scatterternary", + "mode": "markers+lines", + "line": { + "width": 5 + }, + "marker": { + "opacity": 1, + "standoff": [5, 20, null, 20, 10], + "angleref": "previous", + "symbol": [null, "arrow", null, null, "arrow-wide"], + "size": [null, 20, null, null, 30] + }, + "a": [ + 2, + 1, + null, + 1, + 1 + ], + "b": [ + 1, + 2, + null, + 2, + 1 + ], + "c": [ + 1, + 1, + null, + 1, + 2 + ] + }, + { + "type": "scatterternary", + "mode": "markers+text", + "marker": { + "opacity": 1, + "size": [10, 40, 20] + }, + "text": [10, 40, 20], + "textposition": ["right", "center", "top"], + "a": [ + 2, + 1, + 1 + ], + "b": [ + 1, + 2, + 1 + ], + "c": [ + 1, + 1, + 2 + ] + }, + { + "xaxis": "x2", + "yaxis": "y2", + "type": "carpet", + "a": [ 4, 4, 4, 4.5, 4.5, 4.5, 5, 5, 5, 6, 6, 6 ], + "b": [ 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3 ], + "y": [ 2, 3.5, 4, 3, 4.5, 5, 5.5, 6.5, 7.5, 8, 8.5, 10 ], + "aaxis": { + "tickprefix": "a = ", + "ticksuffix": "m", + "smoothing": 1, + "minorgridcount": 9 + }, + "baxis": { + "tickprefix": "b = ", + "ticksuffix": "Pa", + "smoothing": 1, + "minorgridcount": 9 + }, + "carpet": "c0" + }, + { + "xaxis": "x2", + "yaxis": "y2", + "type": "scattercarpet", + "mode": "markers+lines", + "line": { + "width": 5 + }, + "marker": { + "opacity": 1, + "standoff": [5, 20, null, 20, 10], + "angleref": "previous", + "symbol": [null, "arrow", null, null, "arrow-wide"], + "size": [null, 20, null, null, 30] + }, + "a": [ 4, 5, null, 5, 6 ], + "b": [ 2.5, 2.5, null, 2.5, 2.5 ], + "carpet": "c0" + }, + { + "xaxis": "x2", + "yaxis": "y2", + "type": "scattercarpet", + "mode": "markers+text", + "marker": { + "opacity": 1, + "size": [10, 40, 20] + }, + "text": [10, 40, 20], + "textposition": ["right", "center", "top"], + "a": [ 4, 5, 6 ], + "b": [ 2.5, 2.5, 2.5 ], + "carpet": "c0" + }, + { + "subplot": "polar", + "type": "scatterpolar", + "mode": "markers+lines", + "line": { + "width": 5 + }, + "marker": { + "opacity": 1, + "standoff": [5, 20, null, 20, 10], + "angleref": "previous", + "symbol": [null, "arrow", null, null, "arrow-wide"], + "size": [null, 20, null, null, 30] + }, + "r": [ + 1, + 2, + null, + 2, + 3 + ], + "theta": [ + 270, + 90, + null, + 90, + 180 + ] + }, + { + "subplot": "polar", + "type": "scatterpolar", + "mode": "markers+text", + "marker": { + "opacity": 1, + "size": [10, 40, 20] + }, + "text": [10, 40, 20], + "textposition": ["right", "center", "top"], + "r": [ + 1, + 2, + 3 + ], + "theta": [ + 270, + 90, + 180 + ] + }, + { + "subplot": "smith", + "type": "scattersmith", + "mode": "markers+lines", + "line": { + "width": 5 + }, + "marker": { + "opacity": 1, + "standoff": [5, 20, null, 20, 10], + "angleref": "previous", + "symbol": [null, "arrow", null, null, "arrow-wide"], + "size": [null, 20, null, null, 30] + }, + "real": [ + 1, + 2, + null, + 2, + 0.5 + ], + "imag": [ + -0.5, + 1, + null, + 1, + 1 + ] + }, + { + "subplot": "smith", + "type": "scattersmith", + "mode": "markers+text", + "marker": { + "opacity": 1, + "size": [10, 40, 20] + }, + "text": [10, 40, 20], + "textposition": ["right", "center", "top"], + "real": [ + 1, + 2, + 0.5 + ], + "imag": [ + -0.5, + 1, + 1 + ] + } + ], + "layout": { + "xaxis": { + "domain": [ + 0, + 0.3 + ] + }, + "yaxis": { + "domain": [ + 0, + 0.45 + ] + }, + "xaxis2": { + "anchor": "y2", + "domain": [ + 0.35, + 0.65 + ] + }, + "yaxis2": { + "anchor": "x2", + "domain": [ + 0.55, + 1 + ] + }, + "geo": { + "projection": { + "type": "satellite" + }, + "domain": { + "x": [ + 0.35, + 0.65 + ], + "y": [ + 0, + 0.45 + ] + } + }, + "ternary": { + "domain": { + "x": [ + 0, + 0.3 + ], + "y": [ + 0.55, + 1 + ] + }, + "aaxis": { + "title": {"text": "A"} + }, + "baxis": { + "title": {"text": "B"} + }, + "caxis": { + "title": {"text": "C"} + } + }, + "polar": { + "domain": { + "x": [ + 0.7, + 1 + ], + "y": [ + 0, + 0.45 + ] + } + }, + "smith": { + "domain": { + "x": [ + 0.7, + 1 + ], + "y": [ + 0.55, + 1 + ] + } + }, + "height": 900, + "width": 1200, + "legend": { + "orientation": "h" + } + } +}