Skip to content

Commit ca2e112

Browse files
authored
Merge pull request plotly#1155 from plotly/annotation-category-fix
fix annotation category positioning
2 parents e94b1d1 + 58b91e7 commit ca2e112

File tree

4 files changed

+55
-138
lines changed

4 files changed

+55
-138
lines changed

src/plots/cartesian/axes.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ axes.coercePosition = function(containerOut, gd, coerce, axRef, attr, dflt) {
116116
// if position is given as a category name, convert it to a number
117117
if(typeof pos === 'string' && (ax._categories || []).length) {
118118
newPos = ax._categories.indexOf(pos);
119-
containerOut[attr] = (newPos !== -1) ? dflt : newPos;
119+
containerOut[attr] = (newPos === -1) ? dflt : newPos;
120120
return;
121121
}
122122
}

test/image/baselines/16.png

562 Bytes
Loading

test/image/mocks/16.json

+19-137
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@
3636
"12pm",
3737
"6pm"
3838
],
39-
"name": "trace 0",
40-
"zauto": true,
41-
"zmin": 0.1189977,
42-
"zmax": 0.959744,
4339
"scl": [
4440
[
4541
0,
@@ -87,147 +83,33 @@
8783
],
8884
"layout": {
8985
"title": "User Traffic",
90-
"titlefont": {
91-
"color": "",
92-
"family": "",
93-
"size": 0
94-
},
9586
"font": {
96-
"family": "Arial, sans-serif",
97-
"size": 12,
98-
"color": "#000"
87+
"family": "Arial, sans-serif",
88+
"size": 12,
89+
"color": "#000"
9990
},
100-
"showlegend": false,
10191
"autosize": false,
10292
"width": 600,
10393
"height": 350,
10494
"xaxis": {
105-
"title": "",
106-
"titlefont": {
107-
"color": "",
108-
"family": "",
109-
"size": 16
110-
},
111-
"range": [
112-
-0.5,
113-
4.5
114-
],
115-
"domain": [
116-
0,
117-
1
118-
],
119-
"type": "category",
120-
"rangemode": "normal",
121-
"showgrid": true,
122-
"zeroline": true,
123-
"showline": true,
124-
"autotick": true,
125-
"nticks": 0,
126-
"ticks": "",
127-
"showticklabels": true,
128-
"tick0": 0,
129-
"dtick": 1,
130-
"ticklen": 5,
131-
"tickwidth": 1,
132-
"tickcolor": "#000",
133-
"tickangle": 0,
134-
"tickfont": {
135-
"size": 14,
136-
"color": ""
137-
},
138-
"exponentformat": "e",
139-
"showexponent": "all",
140-
"gridcolor": "#ddd",
141-
"gridwidth": 1,
142-
"zerolinecolor": "#000",
143-
"zerolinewidth": 1,
144-
"linecolor": "rgb(255, 255, 255)",
145-
"linewidth": 0.1,
146-
"anchor": "y",
147-
"position": 0,
148-
"mirror": true,
149-
"overlaying": false,
150-
"autorange": true
95+
"ticks": ""
15196
},
15297
"yaxis": {
153-
"title": "",
154-
"titlefont": {
155-
"color": "",
156-
"family": "",
157-
"size": 16
158-
},
159-
"range": [
160-
-0.5,
161-
2.5
162-
],
163-
"domain": [
164-
0,
165-
1
166-
],
167-
"type": "category",
168-
"rangemode": "normal",
169-
"showgrid": true,
170-
"zeroline": true,
171-
"showline": true,
172-
"autotick": true,
173-
"nticks": 0,
174-
"ticks": "",
175-
"showticklabels": true,
176-
"tick0": 0,
177-
"dtick": 1,
178-
"ticklen": 5,
179-
"tickwidth": 1,
180-
"tickcolor": "#000",
181-
"tickangle": 0,
182-
"tickfont": {
183-
"family": "Arial, sans-serif",
184-
"size": 14,
185-
"color": ""
186-
},
187-
"exponentformat": "e",
188-
"showexponent": "all",
189-
"gridcolor": "#ddd",
190-
"gridwidth": 1,
191-
"zerolinecolor": "#000",
192-
"zerolinewidth": 1,
193-
"linecolor": "rgb(255, 255, 255)",
194-
"linewidth": 0.1,
195-
"anchor": "x",
196-
"position": 0,
197-
"mirror": true,
198-
"overlaying": false,
199-
"autorange": true
200-
},
201-
"legend": {
202-
"x": 0.98,
203-
"y": 0.98,
204-
"traceorder": "normal",
205-
"font": {
206-
"family": "",
207-
"size": 0,
208-
"color": ""
209-
},
210-
"bgcolor": "#fff",
211-
"bordercolor": "#000",
212-
"borderwidth": 1
213-
},
214-
"margin": {
215-
"l": 110,
216-
"r": 200,
217-
"b": 80,
218-
"t": 80,
219-
"pad": 2,
220-
"autoexpand": true
98+
"ticks": ""
22199
},
222-
"paper_bgcolor": "#fff",
223-
"plot_bgcolor": "#fff",
224-
"hovermode": "x",
225-
"dragmode": "zoom",
226-
"barmode": "stack",
227-
"bargap": 0.2,
228-
"bargroupgap": 0,
229-
"boxmode": "overlay",
230-
"separators": ".,",
231-
"hidesources": false
100+
"annotations": [
101+
{
102+
"showarrow": false,
103+
"x": "Wed",
104+
"y": "12pm",
105+
"text": "meeting"
106+
},
107+
{
108+
"showarrow": false,
109+
"x": 0,
110+
"y": 0,
111+
"text": "meeting"
112+
}
113+
]
232114
}
233115
}

test/jasmine/tests/annotations_test.js

+35
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,41 @@ describe('Test annotations', function() {
8787
expect(layoutOut.annotations[0].x).toEqual('2008-07-01');
8888
expect(layoutOut.annotations[0].ax).toEqual('2004-07-01');
8989
});
90+
91+
it('should convert ax/ay category coordinates to linear coords', function() {
92+
var layoutIn = {
93+
annotations: [{
94+
showarrow: true,
95+
axref: 'x',
96+
ayref: 'y',
97+
x: 'c',
98+
ax: 1,
99+
y: 'A',
100+
ay: 3
101+
}]
102+
};
103+
104+
var layoutOut = {
105+
xaxis: {
106+
type: 'category',
107+
_categories: ['a', 'b', 'c'],
108+
range: [-0.5, 2.5] },
109+
yaxis: {
110+
type: 'category',
111+
_categories: ['A', 'B', 'C'],
112+
range: [-0.5, 3]
113+
}
114+
};
115+
Axes.setConvert(layoutOut.xaxis);
116+
Axes.setConvert(layoutOut.yaxis);
117+
118+
_supply(layoutIn, layoutOut);
119+
120+
expect(layoutOut.annotations[0].x).toEqual(2);
121+
expect(layoutOut.annotations[0].ax).toEqual(1);
122+
expect(layoutOut.annotations[0].y).toEqual(0);
123+
expect(layoutOut.annotations[0].ay).toEqual(3);
124+
});
90125
});
91126
});
92127

0 commit comments

Comments
 (0)