diff --git a/src/plots/cartesian/axes.js b/src/plots/cartesian/axes.js index 27359e06df9..bd86bb76b06 100644 --- a/src/plots/cartesian/axes.js +++ b/src/plots/cartesian/axes.js @@ -116,7 +116,7 @@ axes.coercePosition = function(containerOut, gd, coerce, axRef, attr, dflt) { // if position is given as a category name, convert it to a number if(typeof pos === 'string' && (ax._categories || []).length) { newPos = ax._categories.indexOf(pos); - containerOut[attr] = (newPos !== -1) ? dflt : newPos; + containerOut[attr] = (newPos === -1) ? dflt : newPos; return; } } diff --git a/test/image/baselines/16.png b/test/image/baselines/16.png index 446891b07b4..edce238d560 100644 Binary files a/test/image/baselines/16.png and b/test/image/baselines/16.png differ diff --git a/test/image/mocks/16.json b/test/image/mocks/16.json index b73a41d13e2..24e9b09e702 100644 --- a/test/image/mocks/16.json +++ b/test/image/mocks/16.json @@ -36,10 +36,6 @@ "12pm", "6pm" ], - "name": "trace 0", - "zauto": true, - "zmin": 0.1189977, - "zmax": 0.959744, "scl": [ [ 0, @@ -87,147 +83,33 @@ ], "layout": { "title": "User Traffic", - "titlefont": { - "color": "", - "family": "", - "size": 0 - }, "font": { - "family": "Arial, sans-serif", - "size": 12, - "color": "#000" + "family": "Arial, sans-serif", + "size": 12, + "color": "#000" }, - "showlegend": false, "autosize": false, "width": 600, "height": 350, "xaxis": { - "title": "", - "titlefont": { - "color": "", - "family": "", - "size": 16 - }, - "range": [ - -0.5, - 4.5 - ], - "domain": [ - 0, - 1 - ], - "type": "category", - "rangemode": "normal", - "showgrid": true, - "zeroline": true, - "showline": true, - "autotick": true, - "nticks": 0, - "ticks": "", - "showticklabels": true, - "tick0": 0, - "dtick": 1, - "ticklen": 5, - "tickwidth": 1, - "tickcolor": "#000", - "tickangle": 0, - "tickfont": { - "size": 14, - "color": "" - }, - "exponentformat": "e", - "showexponent": "all", - "gridcolor": "#ddd", - "gridwidth": 1, - "zerolinecolor": "#000", - "zerolinewidth": 1, - "linecolor": "rgb(255, 255, 255)", - "linewidth": 0.1, - "anchor": "y", - "position": 0, - "mirror": true, - "overlaying": false, - "autorange": true + "ticks": "" }, "yaxis": { - "title": "", - "titlefont": { - "color": "", - "family": "", - "size": 16 - }, - "range": [ - -0.5, - 2.5 - ], - "domain": [ - 0, - 1 - ], - "type": "category", - "rangemode": "normal", - "showgrid": true, - "zeroline": true, - "showline": true, - "autotick": true, - "nticks": 0, - "ticks": "", - "showticklabels": true, - "tick0": 0, - "dtick": 1, - "ticklen": 5, - "tickwidth": 1, - "tickcolor": "#000", - "tickangle": 0, - "tickfont": { - "family": "Arial, sans-serif", - "size": 14, - "color": "" - }, - "exponentformat": "e", - "showexponent": "all", - "gridcolor": "#ddd", - "gridwidth": 1, - "zerolinecolor": "#000", - "zerolinewidth": 1, - "linecolor": "rgb(255, 255, 255)", - "linewidth": 0.1, - "anchor": "x", - "position": 0, - "mirror": true, - "overlaying": false, - "autorange": true - }, - "legend": { - "x": 0.98, - "y": 0.98, - "traceorder": "normal", - "font": { - "family": "", - "size": 0, - "color": "" - }, - "bgcolor": "#fff", - "bordercolor": "#000", - "borderwidth": 1 - }, - "margin": { - "l": 110, - "r": 200, - "b": 80, - "t": 80, - "pad": 2, - "autoexpand": true + "ticks": "" }, - "paper_bgcolor": "#fff", - "plot_bgcolor": "#fff", - "hovermode": "x", - "dragmode": "zoom", - "barmode": "stack", - "bargap": 0.2, - "bargroupgap": 0, - "boxmode": "overlay", - "separators": ".,", - "hidesources": false + "annotations": [ + { + "showarrow": false, + "x": "Wed", + "y": "12pm", + "text": "meeting" + }, + { + "showarrow": false, + "x": 0, + "y": 0, + "text": "meeting" + } + ] } } diff --git a/test/jasmine/tests/annotations_test.js b/test/jasmine/tests/annotations_test.js index f771fdcca6c..cf6e282f6da 100644 --- a/test/jasmine/tests/annotations_test.js +++ b/test/jasmine/tests/annotations_test.js @@ -87,6 +87,41 @@ describe('Test annotations', function() { expect(layoutOut.annotations[0].x).toEqual('2008-07-01'); expect(layoutOut.annotations[0].ax).toEqual('2004-07-01'); }); + + it('should convert ax/ay category coordinates to linear coords', function() { + var layoutIn = { + annotations: [{ + showarrow: true, + axref: 'x', + ayref: 'y', + x: 'c', + ax: 1, + y: 'A', + ay: 3 + }] + }; + + var layoutOut = { + xaxis: { + type: 'category', + _categories: ['a', 'b', 'c'], + range: [-0.5, 2.5] }, + yaxis: { + type: 'category', + _categories: ['A', 'B', 'C'], + range: [-0.5, 3] + } + }; + Axes.setConvert(layoutOut.xaxis); + Axes.setConvert(layoutOut.yaxis); + + _supply(layoutIn, layoutOut); + + expect(layoutOut.annotations[0].x).toEqual(2); + expect(layoutOut.annotations[0].ax).toEqual(1); + expect(layoutOut.annotations[0].y).toEqual(0); + expect(layoutOut.annotations[0].ay).toEqual(3); + }); }); });