Skip to content

Commit 6e26db3

Browse files
Starting to add interact tests for domain referenced objects
1 parent 93284df commit 6e26db3

File tree

4 files changed

+285
-117
lines changed

4 files changed

+285
-117
lines changed

test/image/mocks/domain_ref_base.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@
1818
"layout": {
1919
"xaxis": {
2020
"domain": [0,0.75],
21-
"range": [1, 3]
21+
"range": [1, 4]
2222
},
2323
"yaxis": {
2424
"domain": [0,0.4],
2525
"range": [1, 4]
2626
},
2727
"xaxis2": {
2828
"domain": [0.75,1],
29-
"range": [1, 4],
29+
"range": [1, 5],
3030
"anchor": "y2"
3131
},
3232
"yaxis2": {

test/image/mocks/domain_refs_editable.json

Lines changed: 145 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,150 @@
11
{
2-
"data": [{
3-
"x": [1, 5],
4-
"y": [1, 10],
5-
"type": "scatter"
6-
}, {
7-
"x": [1, 5],
8-
"y": [0.1, 1.0],
9-
"type": "scatter",
10-
"yaxis": "y2"
11-
}],
12-
"layout": {
13-
"title": "Axis domain referenced shape",
14-
"width": 0.3,
15-
"height": 0.2,
16-
"xaxis": {
17-
"domain": [0.2, 0.9]
18-
},
19-
"yaxis": {
20-
"domain": [0.1, 0.8]
21-
},
22-
"yaxis2": {
23-
"overlaying": "y",
24-
"side": "right"
25-
},
26-
"shapes": [{
27-
"type": "rect",
28-
"xref": "x domain",
29-
"yref": "y domain",
30-
"layer": "above",
31-
"x0": 0.1,
32-
"y0": 0.2,
33-
"x1": 0.8,
34-
"y1": 0.5
35-
}]
2+
"data": [
3+
{
4+
"type": "scatter",
5+
"x": [],
6+
"xaxis": "x",
7+
"y": [],
8+
"yaxis": "y"
9+
},
10+
{
11+
"type": "scatter",
12+
"x": [],
13+
"xaxis": "x2",
14+
"y": [],
15+
"yaxis": "y2"
16+
},
17+
{
18+
"type": "scatter",
19+
"x": [],
20+
"xaxis": "x3",
21+
"y": [],
22+
"yaxis": "y3"
23+
},
24+
{
25+
"type": "scatter",
26+
"x": [],
27+
"xaxis": "x4",
28+
"y": [],
29+
"yaxis": "y4"
30+
}
31+
],
32+
"layout": {
33+
"xaxis": {
34+
"anchor": "y",
35+
"domain": [
36+
0.0,
37+
0.45
38+
]
39+
},
40+
"xaxis2": {
41+
"anchor": "y2",
42+
"domain": [
43+
0.55,
44+
1.0
45+
]
46+
},
47+
"xaxis3": {
48+
"anchor": "y3",
49+
"domain": [
50+
0.0,
51+
0.45
52+
],
53+
"range": [
54+
1,
55+
10
56+
]
3657
},
58+
"xaxis4": {
59+
"anchor": "y4",
60+
"domain": [
61+
0.55,
62+
1.0
63+
],
64+
"range": [
65+
0,
66+
1
67+
]
68+
},
69+
"yaxis": {
70+
"anchor": "x",
71+
"domain": [
72+
0.575,
73+
1.0
74+
]
75+
},
76+
"yaxis2": {
77+
"anchor": "x2",
78+
"domain": [
79+
0.575,
80+
1.0
81+
]
82+
},
83+
"yaxis3": {
84+
"anchor": "x3",
85+
"domain": [
86+
0.0,
87+
0.425
88+
],
89+
"range": [
90+
0,
91+
1
92+
]
93+
},
94+
"yaxis4": {
95+
"anchor": "x4",
96+
"domain": [
97+
0.0,
98+
0.425
99+
],
100+
"range": [
101+
1,
102+
10
103+
]
104+
},
105+
"shapes": [{
106+
"type": "rect",
107+
"xref": "x3 domain",
108+
"yref": "y3 domain",
109+
"x0": 0.1,
110+
"y0": 0.2,
111+
"x1": 0.3,
112+
"y1": 0.4,
113+
"line": { "color": "rgb(10, 20, 30)" }
114+
},{
115+
"type": "rect",
116+
"xref": "x4 domain",
117+
"yref": "y4 domain",
118+
"x0": 0.4,
119+
"y0": 0.6,
120+
"x1": 0.5,
121+
"y1": 0.7,
122+
"line": { "color": "rgb(10, 20, 31)" }
123+
}],
124+
"annotations": [{
125+
"text": "A",
126+
"bgcolor": "rgb(100, 200, 232)",
127+
"xref": "x3 domain",
128+
"yref": "y3 domain",
129+
"x": 0.4,
130+
"y": 0.6,
131+
"axref": "x3 domain",
132+
"ayref": "y3 domain",
133+
"ax": 0.5,
134+
"ay": 0.7
135+
},{
136+
"text": "B",
137+
"bgcolor": "rgb(200, 200, 232)",
138+
"xref": "x4 domain",
139+
"yref": "y4 domain",
140+
"x": 0.3,
141+
"y": 0.4,
142+
"axref": "x4 domain",
143+
"ayref": "y4 domain",
144+
"ax": 0.1,
145+
"ay": 0.2
146+
}]
147+
},
37148
"config": {
38149
"editable": true
39150
}

test/jasmine/assets/domain_ref/components.js

Lines changed: 82 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,88 @@ var testMock = require('../../../image/mocks/domain_ref_base.json');
2828
// NOTE: this tolerance is in pixels
2929
var EQUALITY_TOLERANCE = 1e-2;
3030

31+
// some made-up values for testing
32+
// NOTE: The pixel values are intentionally set so that 2*pixel is never greater
33+
// than the mock's margin. This is so that annotations are not unintentionally
34+
// clipped out because they exceed the plotting area. The reason for using twice
35+
// the pixel value is because the annotation test requires plotting 2
36+
// annotations, the second having arrow components twice as long as the first.
37+
var aroPositionsX = [{
38+
// aros referring to data
39+
ref: 'range',
40+
value: [2, 3],
41+
// for objects that need a size (i.e., images)
42+
size: 1.5,
43+
// for the case when annotations specifies arrow in pixels, this value
44+
// is read instead of value[1]
45+
pixel: 25
46+
},
47+
{
48+
// aros referring to domains
49+
ref: 'domain',
50+
value: [0.2, 0.75],
51+
size: 0.3,
52+
pixel: 30
53+
},
54+
{
55+
// aros referring to paper
56+
ref: 'paper',
57+
value: [0.25, 0.8],
58+
size: 0.35,
59+
pixel: 35
60+
},
61+
];
62+
var aroPositionsY = [{
63+
// aros referring to data
64+
ref: 'range',
65+
// two values for rects
66+
value: [1, 2],
67+
pixel: 30,
68+
size: 1.2
69+
},
70+
{
71+
// aros referring to domains
72+
ref: 'domain',
73+
value: [0.25, 0.7],
74+
pixel: 40,
75+
size: 0.2
76+
},
77+
{
78+
// aros referring to paper
79+
ref: 'paper',
80+
value: [0.2, 0.85],
81+
pixel: 45,
82+
size: 0.3
83+
}
84+
];
85+
86+
var axisTypes = ['linear', 'log'];
87+
// Test on 'x', 'y', 'x2', 'y2' axes
88+
// TODO the 'paper' position references are tested twice when once would
89+
// suffice.
90+
var axisPairs = [
91+
['x', 'y'],
92+
['x2', 'y2']
93+
];
94+
// For annotations: if arrow coordinate is in the same coordinate system 's', if
95+
// pixel then 'p'
96+
var arrowAxis = [
97+
['s', 's'],
98+
['p', 's'],
99+
['s', 'p'],
100+
['p', 'p']
101+
];
102+
// only test the shapes line and rect for now
103+
var shapeTypes = ['line', 'rect'];
104+
// anchor positions for images
105+
var xAnchors = ['left', 'center', 'right'];
106+
var yAnchors = ['top', 'middle', 'bottom'];
107+
// this color chosen so it can easily be found with d3
108+
// NOTE: for images color cannot be set but it will be the only image in the
109+
// plot so you can use d3.select('g image').node()
110+
var aroColor = 'rgb(50, 100, 150)';
111+
112+
31113
// acts on an Object representing a aro which could be a line or a rect
32114
// DEPRECATED
33115
function aroFromAROPos(aro, axletter, axnum, aropos) {
@@ -413,87 +495,6 @@ function checkAROPosition(gd, aro) {
413495
return ret;
414496
}
415497

416-
// some made-up values for testing
417-
// NOTE: The pixel values are intentionally set so that 2*pixel is never greater
418-
// than the mock's margin. This is so that annotations are not unintentionally
419-
// clipped out because they exceed the plotting area. The reason for using twice
420-
// the pixel value is because the annotation test requires plotting 2
421-
// annotations, the second having arrow components twice as long as the first.
422-
var aroPositionsX = [{
423-
// aros referring to data
424-
ref: 'range',
425-
value: [2, 3],
426-
// for objects that need a size (i.e., images)
427-
size: 1.5,
428-
// for the case when annotations specifies arrow in pixels, this value
429-
// is read instead of value[1]
430-
pixel: 25
431-
},
432-
{
433-
// aros referring to domains
434-
ref: 'domain',
435-
value: [0.2, 0.75],
436-
size: 0.3,
437-
pixel: 30
438-
},
439-
{
440-
// aros referring to paper
441-
ref: 'paper',
442-
value: [0.25, 0.8],
443-
size: 0.35,
444-
pixel: 35
445-
},
446-
];
447-
var aroPositionsY = [{
448-
// aros referring to data
449-
ref: 'range',
450-
// two values for rects
451-
value: [1, 2],
452-
pixel: 30,
453-
size: 1.2
454-
},
455-
{
456-
// aros referring to domains
457-
ref: 'domain',
458-
value: [0.25, 0.7],
459-
pixel: 40,
460-
size: 0.2
461-
},
462-
{
463-
// aros referring to paper
464-
ref: 'paper',
465-
value: [0.2, 0.85],
466-
pixel: 45,
467-
size: 0.3
468-
}
469-
];
470-
471-
var axisTypes = ['linear', 'log'];
472-
// Test on 'x', 'y', 'x2', 'y2' axes
473-
// TODO the 'paper' position references are tested twice when once would
474-
// suffice.
475-
var axisPairs = [
476-
['x', 'y'],
477-
['x2', 'y2']
478-
];
479-
// For annotations: if arrow coordinate is in the same coordinate system 's', if
480-
// pixel then 'p'
481-
var arrowAxis = [
482-
['s', 's'],
483-
['p', 's'],
484-
['s', 'p'],
485-
['p', 'p']
486-
];
487-
// only test the shapes line and rect for now
488-
var shapeTypes = ['line', 'rect'];
489-
// anchor positions for images
490-
var xAnchors = ['left', 'center', 'right'];
491-
var yAnchors = ['top', 'middle', 'bottom'];
492-
// this color chosen so it can easily be found with d3
493-
// NOTE: for images color cannot be set but it will be the only image in the
494-
// plot so you can use d3.select('g image').node()
495-
var aroColor = 'rgb(50, 100, 150)';
496-
497498
function testShape(
498499
gd,
499500
xAxNum,

0 commit comments

Comments
 (0)