Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion src/plots/cartesian/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
Binary file modified test/image/baselines/16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
156 changes: 19 additions & 137 deletions test/image/mocks/16.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@
"12pm",
"6pm"
],
"name": "trace 0",
"zauto": true,
"zmin": 0.1189977,
"zmax": 0.959744,
"scl": [
[
0,
Expand Down Expand Up @@ -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"
}
]
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, you read my mind by covering numbers and categories as coordinates.

}
35 changes: 35 additions & 0 deletions test/jasmine/tests/annotations_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});

Expand Down