Skip to content

Commit 92d273b

Browse files
committed
Add tests for initial ranges
1 parent da32318 commit 92d273b

File tree

2 files changed

+117
-19
lines changed

2 files changed

+117
-19
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"data": [{
3+
"x": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49],
4+
"y": [61.54407276195499, 53.01489477283346, 54.27395817178983, 53.55001411571369, 78.9775866748205, 31.884243474727825, 56.77854253236383, 4.735201078365101, 63.12484997271903, 43.09882925106262, 43.724822753247224, 24.844310873420152, 34.89218498332549, 36.0460327216264, 28.2174958198741, 29.273481072578775, 70.89188615102645, 59.76636236708869, 66.76528535512163, 11.281051334701928, 78.37153154211197, 66.08349166666542, 50.09727630364335, 58.04698479499695, 59.74272576303902, 41.86433349552978, 48.22485560857029, 37.70855269433609, 21.119967245011217, 75.10194864698312, 55.48369213601815, 59.735088561204854, 60.42028696627966, 0.10938359086638982, 77.3773017472981, 15.086946383114501, 35.82836446307611, 23.689280033989295, 2.362484581742592, 53.40692073882494, 15.134375465281735, 7.3434664768826075, 54.52433252576499, 35.798885397722806, 38.26472971248782, 17.920068000491725, 37.0479742805594, 45.83239633915396, 43.99138484769564, 69.43228444571429],
5+
"line": {
6+
"shape": "spline",
7+
"smoothing": 1
8+
},
9+
"fill": "tozeroy",
10+
"name": "Bird 1"
11+
}, {
12+
"x": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49],
13+
"y": [42.61173967030771, 77.84512822099697, 55.39613813617828, 4.0231685798691785, 34.55285260557025, 15.153333721685467, 77.54957038861798, 75.64407363993858, 62.12340236506287, 68.02318161065071, 34.816275599609554, 12.97751450053445, 25.16704221023005, 39.27425976595971, 41.98830052124046, 32.88934713126341, 64.3908328308427, 31.152165702544288, 53.28979283850701, 47.831576036783474, 48.46112255786373, 13.019775174742367, 44.95556684431092, 62.13365414186855, 22.796080092935433, 53.88638249610922, 9.378276407428476, 54.87772961864103, 10.622983213205028, 31.428637782080635, 63.81786719853103, 68.85325763593313, 30.412750136966178, 29.161036950263153, 19.125624934754217, 1.7788679495654591, 31.62390207284494, 33.722958647807374, 35.3846908579102, 41.364380830218224, 24.993662278935265, 39.083235916470116, 59.576257951955824, 33.620531907520075, 11.721918308606636, 10.943094423029738, 20.385230482706316, 39.62659948914896, 72.20357742148559, 38.48711164016425],
14+
"name": "Bird 2"
15+
}],
16+
"layout": {
17+
"title": "Seagull Positions",
18+
"xaxis": {
19+
"rangeslider": {
20+
"visible": true,
21+
"thickness": 0.2,
22+
"bgcolor": "#fafafa",
23+
"bordercolor": "black",
24+
"borderwidth": 2,
25+
"range": [20, 30]
26+
},
27+
"title": "Time (Hours)",
28+
"range": [10, 45]
29+
},
30+
"yaxis": {
31+
"title": "Height (ft)"
32+
},
33+
"paper_bgcolor": "#eee",
34+
"height": 500,
35+
"width": 800
36+
}
37+
}

test/jasmine/tests/range_slider_test.js

Lines changed: 80 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ describe('the range slider', function() {
223223
bgcolor: '#fff',
224224
borderwidth: 0,
225225
bordercolor: '#444'
226-
}
226+
},
227+
_needsExpand: true
227228
},
228229
yaxis: {
229230
fixedrange: true
@@ -248,7 +249,8 @@ describe('the range slider', function() {
248249
bgcolor: '#fff',
249250
borderwidth: 0,
250251
bordercolor: '#444'
251-
}
252+
},
253+
_needsExpand: true
252254
},
253255
yaxis: {
254256
fixedrange: true
@@ -271,34 +273,43 @@ describe('the range slider', function() {
271273
layoutOut = { xaxis: {}, yaxis: {}},
272274
axName = 'xaxis',
273275
counterAxes = ['yaxis'],
274-
expected = { xaxis: { rangeslider: {
275-
visible: true,
276-
thickness: 0.15,
277-
bgcolor: '#fff',
278-
borderwidth: 0,
279-
bordercolor: '#444'
280-
}}, yaxis: {
281-
fixedrange: true
282-
}};
276+
expected = {
277+
xaxis: {
278+
rangeslider: {
279+
visible: true,
280+
thickness: 0.15,
281+
bgcolor: '#fff',
282+
borderwidth: 0,
283+
bordercolor: '#444'
284+
},
285+
_needsExpand: true
286+
},
287+
yaxis: {
288+
fixedrange: true
289+
}
290+
};
283291

284292
RangeSlider.supplyLayoutDefaults(layoutIn, layoutOut, axName, counterAxes);
285293

286294
expect(layoutOut).toEqual(expected);
287295
});
288296

289297
it('should set all counterAxes to fixedrange', function() {
290-
var layoutIn = { xaxis: { rangeslider: true}, yaxis: {}, yaxis2: {}},
298+
var layoutIn = { xaxis: { rangeslider: true }, yaxis: {}, yaxis2: {}},
291299
layoutOut = { xaxis: {}, yaxis: {}, yaxis2: {}},
292300
axName = 'xaxis',
293301
counterAxes = ['yaxis', 'yaxis2'],
294302
expected = {
295-
xaxis: { rangeslider: {
296-
visible: true,
297-
thickness: 0.15,
298-
bgcolor: '#fff',
299-
borderwidth: 0,
300-
bordercolor: '#444'
301-
}},
303+
xaxis: {
304+
rangeslider: {
305+
visible: true,
306+
thickness: 0.15,
307+
bgcolor: '#fff',
308+
borderwidth: 0,
309+
bordercolor: '#444'
310+
},
311+
_needsExpand: true
312+
},
302313
yaxis: { fixedrange: true},
303314
yaxis2: { fixedrange: true }
304315
};
@@ -307,6 +318,56 @@ describe('the range slider', function() {
307318

308319
expect(layoutOut).toEqual(expected);
309320
});
321+
322+
it('should expand the rangeslider range to axis range', function() {
323+
var layoutIn = { xaxis: { rangeslider: { range: [5,6] } }, yaxis: {}},
324+
layoutOut = { xaxis: { range: [1, 10]}, yaxis: {}},
325+
axName = 'xaxis',
326+
counterAxes = ['yaxis'],
327+
expected = {
328+
xaxis: {
329+
rangeslider: {
330+
visible: true,
331+
thickness: 0.15,
332+
bgcolor: '#fff',
333+
borderwidth: 0,
334+
bordercolor: '#444',
335+
range: [1, 10]
336+
},
337+
range: [1, 10]
338+
},
339+
yaxis: { fixedrange: true }
340+
};
341+
342+
RangeSlider.supplyLayoutDefaults(layoutIn, layoutOut, axName, counterAxes);
343+
344+
expect(layoutOut).toEqual(expected);
345+
});
346+
347+
it('should set _needsExpand when an axis range is set', function() {
348+
var layoutIn = { xaxis: { rangeslider: true }, yaxis: {}},
349+
layoutOut = { xaxis: { range: [2, 40]}, yaxis: {}},
350+
axName = 'xaxis',
351+
counterAxes = ['yaxis'],
352+
expected = {
353+
xaxis: {
354+
rangeslider: {
355+
visible: true,
356+
thickness: 0.15,
357+
bgcolor: '#fff',
358+
borderwidth: 0,
359+
bordercolor: '#444'
360+
},
361+
range: [2, 40],
362+
_needsExpand: true
363+
},
364+
yaxis: { fixedrange: true }
365+
};
366+
367+
RangeSlider.supplyLayoutDefaults(layoutIn, layoutOut, axName, counterAxes);
368+
369+
expect(layoutOut).toEqual(expected);
370+
});
310371
});
311372

312373
describe('in general', function() {

0 commit comments

Comments
 (0)