diff --git a/src/traces/carpet/plot.js b/src/traces/carpet/plot.js index 8d3a5479c14..3f10d5ead3d 100644 --- a/src/traces/carpet/plot.js +++ b/src/traces/carpet/plot.js @@ -173,8 +173,11 @@ function drawAxisLabels(gd, xaxis, yaxis, trace, t, layer, labels, labelClass) { function drawAxisTitles(gd, layer, trace, t, xa, ya, labelOrientationA, labelOrientationB) { var a, b, xy, dxy; - a = 0.5 * (trace.a[0] + trace.a[trace.a.length - 1]); - b = trace.b[0]; + var _a = trace.a.slice().sort(Lib.sorterAsc); + var _b = trace.b.slice().sort(Lib.sorterAsc); + + a = 0.5 * (_a[0] + _a[_a.length - 1]); + b = _b[0]; xy = trace.ab2xy(a, b, true); dxy = trace.dxyda_rough(a, b); if(labelOrientationA.angle === undefined) { @@ -182,8 +185,8 @@ function drawAxisTitles(gd, layer, trace, t, xa, ya, labelOrientationA, labelOri } drawAxisTitle(gd, layer, trace, t, xy, dxy, trace.aaxis, xa, ya, labelOrientationA, 'a-title'); - a = trace.a[0]; - b = 0.5 * (trace.b[0] + trace.b[trace.b.length - 1]); + a = _a[0]; + b = 0.5 * (_b[0] + _b[_b.length - 1]); xy = trace.ab2xy(a, b, true); dxy = trace.dxydb_rough(a, b); if(labelOrientationB.angle === undefined) { diff --git a/test/image/baselines/carpet_ordering-labeling.png b/test/image/baselines/carpet_ordering-labeling.png new file mode 100644 index 00000000000..d19fda41690 Binary files /dev/null and b/test/image/baselines/carpet_ordering-labeling.png differ diff --git a/test/image/mocks/carpet_ordering-labeling.json b/test/image/mocks/carpet_ordering-labeling.json new file mode 100644 index 00000000000..b238485c907 --- /dev/null +++ b/test/image/mocks/carpet_ordering-labeling.json @@ -0,0 +1,47 @@ +{ + "data": [ + { + "type": "carpet", + "a": [3, 2, 1, 3, 2, 1, 3, 2, 1], + "aaxis": { + "title": { "text": "a" } + }, + "b": [3, 3, 3, 2, 2, 2, 1, 1, 1], + "baxis": { + "title": { "text": "b" } + }, + "y": [10, 7, 4, 7, 5, 3, 4, 3, 2] + }, + { + "type": "carpet", + "a": [1, 2, 3, 1, 2, 3, 1, 2, 3], + "aaxis": { + "title": { "text": "a" } + }, + "b": [1, 1, 1, 2, 2, 2, 3, 3, 3], + "baxis": { + "title": { "text": "b" } + }, + "y": [2, 3, 4, 3, 5, 7, 4, 7, 10], + "yaxis": "y2" + } + ], + "layout": { + "grid": { + "rows": 2, + "columns": 1 + }, + "yaxis": { + "title": { + "text": "decreaing a/b ordering" + } + }, + "yaxis2": { + "title": { + "text": "increaing a/b ordering" + } + }, + "width": 600, + "height": 800 + } +}