jquery.flot.navigate.Test.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820
  1. /* eslint-disable */
  2. /* global $, describe, it, xit, xdescribe, after, afterEach, expect*/
  3. describe("flot navigate plugin", function () {
  4. var placeholder, plot, options;
  5. beforeEach(function () {
  6. placeholder = setFixtures('<div id="test-container" style="width: 600px;height: 400px">')
  7. .find('#test-container');
  8. options = {
  9. xaxes: [{ autoScale: 'exact' }],
  10. yaxes: [{ autoScale: 'exact' }],
  11. zoom: { interactive: true, active: true, amount: 10 },
  12. pan: { interactive: true, active: true, frameRate: -1 }
  13. };
  14. });
  15. it('provides a zoom, zoomOut, pan, smartPan functions', function () {
  16. plot = $.plot(placeholder, [
  17. []
  18. ], options);
  19. expect(typeof plot.zoom).toBe('function');
  20. expect(typeof plot.zoomOut).toBe('function');
  21. expect(typeof plot.pan).toBe('function');
  22. expect(typeof plot.smartPan).toBe('function');
  23. });
  24. describe('zoom', function () {
  25. it('uses the provided amount', function () {
  26. var xaxis, yaxis;
  27. plot = $.plot(placeholder, [
  28. [
  29. [0, 0],
  30. [10, 10]
  31. ]
  32. ], options);
  33. xaxis = plot.getXAxes()[0];
  34. yaxis = plot.getYAxes()[0];
  35. plot.zoom({
  36. amount: 2
  37. });
  38. expect(xaxis.min).toBe(2.5);
  39. expect(xaxis.max).toBe(7.5);
  40. expect(yaxis.min).toBeCloseTo(2.5, 7);
  41. expect(yaxis.max).toBeCloseTo(7.5, 7);
  42. });
  43. it('works with autoScale', function () {
  44. var xaxis, yaxis,
  45. opts = {
  46. xaxes: [{ autoScale: 'sliding-window' , min: 0, max: 100}],
  47. yaxes: [{ autoScale: 'loose' }],
  48. zoom: { interactive: true, amount: 10 },
  49. pan: { interactive: true, frameRate: -1 }
  50. };
  51. plot = $.plot(placeholder, [
  52. [
  53. [0, 0],
  54. [10, 10]
  55. ]
  56. ], opts);
  57. xaxis = plot.getXAxes()[0];
  58. yaxis = plot.getYAxes()[0];
  59. plot.zoom({
  60. amount: 4,
  61. center: {
  62. left: 0,
  63. top: plot.height()/2
  64. }
  65. });
  66. expect(xaxis.min).toBe(0);
  67. expect(xaxis.max).toBe(25);
  68. expect(yaxis.min).toBeCloseTo(4.4, 7);
  69. expect(yaxis.max).toBeCloseTo(5.8, 7);
  70. plot.zoom({
  71. amount: -2,
  72. center: {
  73. left: plot.width()/2,
  74. top: plot.height()/2
  75. }
  76. });
  77. expect(xaxis.min).toBeCloseTo(6.25, 2);
  78. expect(xaxis.max).toBe(18.75);
  79. expect(yaxis.min).toBeCloseTo(4.8, 7);
  80. expect(yaxis.max).toBe(5.4);
  81. });
  82. it('uses the amount configured in the plot if none is provided', function () {
  83. var xaxis, yaxis;
  84. plot = $.plot(placeholder, [
  85. [
  86. [0, 0],
  87. [10, 10]
  88. ]
  89. ], options);
  90. xaxis = plot.getXAxes()[0];
  91. yaxis = plot.getYAxes()[0];
  92. plot.zoom();
  93. expect(xaxis.min).toBe(4.5);
  94. expect(xaxis.max).toBe(5.5);
  95. expect(yaxis.min).toBeCloseTo(4.5, 7);
  96. expect(yaxis.max).toBeCloseTo(5.5, 7);
  97. });
  98. it('uses the provided center', function () {
  99. var xaxis, yaxis;
  100. plot = $.plot(placeholder, [
  101. [
  102. [0, 0],
  103. [10, 10]
  104. ]
  105. ], options);
  106. plot.zoom({
  107. amount: 2,
  108. center: {
  109. left: 0,
  110. top: plot.height()
  111. }
  112. });
  113. xaxis = plot.getXAxes()[0];
  114. yaxis = plot.getYAxes()[0];
  115. expect(xaxis.min).toBe(0);
  116. expect(xaxis.max).toBe(5);
  117. expect(yaxis.min).toBe(0);
  118. expect(yaxis.max).toBe(5);
  119. });
  120. it('uses the provided axes', function () {
  121. var xaxis, yaxis;
  122. plot = $.plot(placeholder, [
  123. [
  124. [0, 0],
  125. [10, 10]
  126. ]
  127. ], options);
  128. plot.zoom({
  129. amount: 2,
  130. center: {
  131. left: 0,
  132. top: plot.height()
  133. },
  134. axes: plot.getXAxes()
  135. });
  136. xaxis = plot.getXAxes()[0];
  137. yaxis = plot.getYAxes()[0];
  138. expect(xaxis.min).toBe(0);
  139. expect(xaxis.max).toBe(5);
  140. expect(yaxis.min).toBe(0);
  141. expect(yaxis.max).toBe(10);
  142. });
  143. it ('doesn\'t got to Infinity and beyond', function () {
  144. var xaxis, yaxis;
  145. plot = $.plot(placeholder, [
  146. [
  147. [-1, -10e200 ],
  148. [1, 10e200]
  149. ]
  150. ], options);
  151. plot.zoom({
  152. amount: 10e-200
  153. });
  154. yaxis = plot.getYAxes()[0];
  155. expect(yaxis.min).not.toBe(-Infinity);
  156. expect(yaxis.max).not.toBe(Infinity);
  157. });
  158. it('generates subunitary ticks for X axis', function () {
  159. var xaxis, ticks, middle;
  160. plot = $.plot(placeholder, [
  161. [
  162. [3, 0],
  163. [9, 10]
  164. ]
  165. ], options);
  166. plot.zoom({
  167. amount: 4,
  168. center: {
  169. left: 0,
  170. top: plot.height()
  171. }
  172. });
  173. xaxis = plot.getXAxes()[0];
  174. expect(xaxis.min).toBe(3);
  175. expect(xaxis.max).toBe(4.5);
  176. ticks = xaxis.ticks;
  177. middle = Math.floor(ticks.length / 2);
  178. expect(ticks[middle- 1].v).toBe(3.6);
  179. expect(ticks[middle].v).toBe(3.8);
  180. expect(ticks[middle + 1].v).toBe(4);
  181. });
  182. it('does not zoom for active false', function () {
  183. plot = $.plot(placeholder, [
  184. [
  185. [0, 0],
  186. [10, 10]
  187. ]
  188. ], {
  189. xaxes: [{ autoScale: 'exact' }],
  190. yaxes: [{ autoScale: 'exact' }],
  191. zoom: { interactive: true, active: false, amount: 10 },
  192. pan: { interactive: true, active: false, frameRate: -1 }
  193. });
  194. var eventHolder = plot.getEventHolder(),
  195. xaxis = plot.getXAxes()[0],
  196. yaxis = plot.getYAxes()[0],
  197. initialCoords = [
  198. {x: 3, y: 5},
  199. {x:7, y:9}
  200. ],
  201. finalCoords = [
  202. {x: 2, y: 4},
  203. {x: 8, y: 10}
  204. ],
  205. midPointCoords = {
  206. x: (xaxis.c2p(finalCoords[0].x - plot.offset().left) + xaxis.c2p(finalCoords[1].x - plot.offset().left)) / 2,
  207. y: (yaxis.c2p(finalCoords[0].y - plot.offset().top) + yaxis.c2p(finalCoords[1].y - plot.offset().top)) / 2
  208. };
  209. simulate.sendTouchEvents(initialCoords, eventHolder, 'touchstart');
  210. simulate.sendTouchEvents(finalCoords, eventHolder, 'touchmove');
  211. simulate.sendTouchEvents(finalCoords, eventHolder, 'touchend');
  212. expect(xaxis.min).toBe(0);
  213. expect(xaxis.max).toBe(10);
  214. expect(yaxis.min).toBe(0);
  215. expect(yaxis.max).toBe(10);
  216. });
  217. describe('with large numbers', function() {
  218. it ('limits the navigation offsets', function () {
  219. var yaxis;
  220. plot = $.plot(placeholder, [
  221. [
  222. [0, -1e308],
  223. [1000, 1e308]
  224. ]
  225. ], options);
  226. yaxis = plot.getYAxes()[0];
  227. plot.zoom({
  228. amount: 10e-20
  229. });
  230. expect(yaxis.min).toBe(-Number.MAX_VALUE);
  231. expect(yaxis.max).toBe(Number.MAX_VALUE);
  232. expect(isFinite(plot.navigationState().yaxis.navigationOffset.below)).toBe(true);
  233. expect(isFinite(plot.navigationState().yaxis.navigationOffset.above)).toBe(true);
  234. });
  235. })
  236. });
  237. describe('zoomOut', function () {
  238. it('uses the provided amount', function () {
  239. var xaxis, yaxis;
  240. plot = $.plot(placeholder, [
  241. [
  242. [0, 0],
  243. [10, 10]
  244. ]
  245. ], options);
  246. xaxis = plot.getXAxes()[0];
  247. yaxis = plot.getYAxes()[0];
  248. plot.zoomOut({
  249. amount: 0.5
  250. });
  251. expect(xaxis.min).toBe(2.5);
  252. expect(xaxis.max).toBe(7.5);
  253. expect(yaxis.min).toBeCloseTo(2.5, 7);
  254. expect(yaxis.max).toBeCloseTo(7.5, 7);
  255. });
  256. it('uses the amount configured in the plot if none is provided', function () {
  257. var xaxis, yaxis;
  258. plot = $.plot(placeholder, [
  259. [
  260. [0, 0],
  261. [10, 10]
  262. ]
  263. ], options);
  264. xaxis = plot.getXAxes()[0];
  265. yaxis = plot.getYAxes()[0];
  266. plot.zoom();
  267. expect(xaxis.min).toBe(4.5);
  268. expect(xaxis.max).toBe(5.5);
  269. expect(yaxis.min).toBeCloseTo(4.5, 7);
  270. expect(yaxis.max).toBeCloseTo(5.5, 7);
  271. });
  272. it('uses the provided center', function () {
  273. var xaxis, yaxis;
  274. plot = $.plot(placeholder, [
  275. [
  276. [0, 0],
  277. [10, 10]
  278. ]
  279. ], options);
  280. plot.zoomOut({
  281. amount: 0.5,
  282. center: {
  283. left: 0,
  284. top: plot.height()
  285. }
  286. });
  287. xaxis = plot.getXAxes()[0];
  288. yaxis = plot.getYAxes()[0];
  289. expect(xaxis.min).toBe(0);
  290. expect(xaxis.max).toBe(5);
  291. expect(yaxis.min).toBe(0);
  292. expect(yaxis.max).toBe(5);
  293. });
  294. it ('doesn\'t got to Infinity and beyond', function () {
  295. var xaxis, yaxis;
  296. plot = $.plot(placeholder, [
  297. [
  298. [-1, -10e200 ],
  299. [1, 10e200]
  300. ]
  301. ], options);
  302. plot.zoomOut({
  303. amount: 10e200
  304. });
  305. yaxis = plot.getYAxes()[0];
  306. expect(yaxis.min).not.toBe(-Infinity);
  307. expect(yaxis.max).not.toBe(Infinity);
  308. });
  309. it ('can be disabled per axis for zoom on plot', function () {
  310. var xaxis, yaxis;
  311. plot = $.plot(placeholder, [
  312. [
  313. [0, 0],
  314. [10, 10]
  315. ]
  316. ], options);
  317. xaxis = plot.getXAxes()[0];
  318. yaxis = plot.getYAxes()[0];
  319. xaxis.options.plotZoom = false;
  320. plot.zoomOut({
  321. amount: 0.5
  322. });
  323. expect(xaxis.min).toBe(0);
  324. expect(xaxis.max).toBe(10);
  325. expect(yaxis.min).toBeCloseTo(2.5, 7);
  326. expect(yaxis.max).toBeCloseTo(7.5, 7);
  327. });
  328. it ('can be disabled per axis for zoom on axis', function () {
  329. var xaxis, yaxis;
  330. plot = $.plot(placeholder, [
  331. [
  332. [0, 0],
  333. [10, 10]
  334. ]
  335. ], options);
  336. xaxis = plot.getXAxes()[0];
  337. yaxis = plot.getYAxes()[0];
  338. xaxis.options.axisZoom = false;
  339. plot.zoomOut({
  340. amount: 0.5,
  341. axes: [xaxis]
  342. });
  343. expect(xaxis.min).toBe(0);
  344. expect(xaxis.max).toBe(10);
  345. expect(yaxis.min).toBe(0);
  346. expect(yaxis.max).toBe(10);
  347. });
  348. });
  349. describe('smartPan', function () {
  350. it('uses the provided x delta', function () {
  351. var xaxis, yaxis;
  352. plot = $.plot(placeholder, [
  353. [
  354. [0, 0],
  355. [10, 10]
  356. ]
  357. ], options);
  358. xaxis = plot.getXAxes()[0];
  359. yaxis = plot.getYAxes()[0];
  360. plot.smartPan({
  361. x: -plot.width(),
  362. y: 0
  363. }, plot.navigationState());
  364. expect(xaxis.min).toBe(-10);
  365. expect(xaxis.max).toBe(0);
  366. expect(yaxis.min).toBe(0);
  367. expect(yaxis.max).toBe(10);
  368. });
  369. it('uses the provided y delta', function () {
  370. var xaxis, yaxis;
  371. plot = $.plot(placeholder, [
  372. [
  373. [0, 0],
  374. [10, 10]
  375. ]
  376. ], options);
  377. xaxis = plot.getXAxes()[0];
  378. yaxis = plot.getYAxes()[0];
  379. plot.smartPan({
  380. x: 0,
  381. y: plot.height(),
  382. }, plot.navigationState());
  383. expect(xaxis.min).toBe(0);
  384. expect(xaxis.max).toBe(10);
  385. expect(yaxis.min).toBe(-10);
  386. expect(yaxis.max).toBe(0);
  387. });
  388. it('snaps to the x direction when delta y is small', function () {
  389. var xaxis, yaxis;
  390. plot = $.plot(placeholder, [
  391. [
  392. [0, 0],
  393. [10, 10]
  394. ]
  395. ], options);
  396. xaxis = plot.getXAxes()[0];
  397. yaxis = plot.getYAxes()[0];
  398. plot.smartPan({
  399. x: -plot.width(),
  400. y: 1
  401. }, plot.navigationState());
  402. expect(xaxis.min).toBe(-10);
  403. expect(xaxis.max).toBe(0);
  404. expect(yaxis.min).toBe(0);
  405. expect(yaxis.max).toBe(10);
  406. });
  407. it('snaps to the y direction when delta x is small', function () {
  408. var xaxis, yaxis;
  409. plot = $.plot(placeholder, [
  410. [
  411. [0, 0],
  412. [10, 10]
  413. ]
  414. ], options);
  415. xaxis = plot.getXAxes()[0];
  416. yaxis = plot.getYAxes()[0];
  417. plot.smartPan({
  418. x: 1,
  419. y: plot.height(),
  420. }, plot.navigationState());
  421. expect(xaxis.min).toBe(0);
  422. expect(xaxis.max).toBe(10);
  423. expect(yaxis.min).toBe(-10);
  424. expect(yaxis.max).toBe(0);
  425. });
  426. it('restore xaxis offset on snap on y direction if returns from diagonal snap', function () {
  427. var xaxis, yaxis;
  428. plot = $.plot(placeholder, [
  429. [
  430. [0, 0],
  431. [10, 10]
  432. ]
  433. ], options);
  434. xaxis = plot.getXAxes()[0];
  435. yaxis = plot.getYAxes()[0];
  436. var initialState = plot.navigationState(0, 0);
  437. plot.smartPan({
  438. x: plot.width(),
  439. y: plot.height(),
  440. }, initialState);
  441. expect(xaxis.min).toBe(10);
  442. expect(xaxis.max).toBe(20);
  443. expect(yaxis.min).toBe(-10);
  444. expect(yaxis.max).toBe(0);
  445. plot.smartPan({
  446. x: plot.width(),
  447. y: 2,
  448. }, initialState);
  449. expect(yaxis.min).toBe(0);
  450. expect(yaxis.max).toBe(10);
  451. });
  452. it ('can be disabled per axis for panning the etire plot', function () {
  453. var xaxis, yaxis;
  454. plot = $.plot(placeholder, [
  455. [
  456. [0, 0],
  457. [10, 10]
  458. ]
  459. ], options);
  460. xaxis = plot.getXAxes()[0];
  461. yaxis = plot.getYAxes()[0];
  462. xaxis.options.plotPan = false;
  463. plot.smartPan({
  464. x: plot.width(),
  465. y: plot.height(),
  466. }, plot.navigationState());
  467. expect(xaxis.min).toBe(0);
  468. expect(xaxis.max).toBe(10);
  469. expect(yaxis.min).toBe(-10);
  470. expect(yaxis.max).toBe(0);
  471. });
  472. it ('can be disabled per axis for pan on that axis', function () {
  473. var xaxis, yaxis;
  474. plot = $.plot(placeholder, [
  475. [
  476. [0, 0],
  477. [10, 10]
  478. ]
  479. ], options);
  480. xaxis = plot.getXAxes()[0];
  481. yaxis = plot.getYAxes()[0];
  482. xaxis.options.axisPan = false;
  483. plot.smartPan({
  484. x: plot.width(),
  485. y: plot.height(),
  486. }, plot.navigationState(), [xaxis]);
  487. expect(xaxis.min).toBe(0);
  488. expect(xaxis.max).toBe(10);
  489. expect(yaxis.min).toBe(0);
  490. expect(yaxis.max).toBe(10);
  491. });
  492. it('can pan close to 0 for logaxis', function () {
  493. var xaxis, yaxis;
  494. plot = $.plot(placeholder, [
  495. [
  496. [0, 0],
  497. [10, 10]
  498. ]
  499. ], {
  500. xaxes: [{ autoScale: 'exact', mode : 'log'}],
  501. yaxes: [{ autoScale: 'exact' }],
  502. zoom: { interactive: true, active: true, amount: 10 },
  503. pan: { interactive: true, active: true, frameRate: -1 }
  504. });
  505. xaxis = plot.getXAxes()[0];
  506. yaxis = plot.getYAxes()[0];
  507. expect(xaxis.min).toBe(0.1);
  508. expect(xaxis.max).toBe(10);
  509. plot.smartPan({
  510. x: -plot.width(),
  511. y: 0
  512. }, plot.navigationState());
  513. expect(xaxis.min).toBeCloseTo(0.001, 4);
  514. expect(xaxis.max).toBeCloseTo(0.1, 4);
  515. expect(yaxis.min).toBe(0);
  516. expect(yaxis.max).toBe(10);
  517. });
  518. describe('with large numbers', function() {
  519. it ('limits the navigation offsets', function () {
  520. var yaxis;
  521. plot = $.plot(placeholder, [
  522. [
  523. [0, -1e308],
  524. [1000, 1e308]
  525. ]
  526. ], options);
  527. yaxis = plot.getYAxes()[0];
  528. plot.smartPan({
  529. x: 0,
  530. y: plot.height(),
  531. }, plot.navigationState());
  532. expect(yaxis.min).toBe(-1e308);
  533. expect(yaxis.max).toBeLessThan(0);
  534. expect(isFinite(plot.navigationState().yaxis.navigationOffset.below)).toBe(true);
  535. expect(isFinite(plot.navigationState().yaxis.navigationOffset.above)).toBe(true);
  536. });
  537. })
  538. });
  539. describe('mousePan', function() {
  540. it ('pans on xaxis only', function () {
  541. plot = $.plot(placeholder, [
  542. [
  543. [0, 0],
  544. [10, 10]
  545. ]
  546. ], options);
  547. var xaxis = plot.getXAxes()[0],
  548. yaxis = plot.getYAxes()[0],
  549. initialXmin = xaxis.min,
  550. initialXmax = xaxis.max,
  551. eventHolder = plot.getEventHolder(),
  552. pointCoords = [
  553. { x: xaxis.p2c(4), y: xaxis.box.top + plot.offset().top + 10 },
  554. { x: xaxis.p2c(5), y: xaxis.box.top + plot.offset().top + 15 }
  555. ];
  556. simulate.mouseDown(eventHolder, pointCoords[0].x, pointCoords[0].y);
  557. simulate.mouseMove(eventHolder, pointCoords[0].x, pointCoords[0].y);
  558. simulate.mouseMove(eventHolder, pointCoords[1].x, pointCoords[1].y);
  559. simulate.mouseUp(eventHolder, pointCoords[1].x, pointCoords[1].y);
  560. expect(xaxis.min).toBeCloseTo(xaxis.c2p(xaxis.p2c(initialXmin) + (pointCoords[0].x - pointCoords[1].x)), 0);
  561. expect(xaxis.max).toBeCloseTo(xaxis.c2p(xaxis.p2c(initialXmax) + (pointCoords[0].x - pointCoords[1].x)), 0);
  562. expect(yaxis.min).toBe(0);
  563. expect(yaxis.max).toBe(10);
  564. });
  565. it ('pans on yaxis only', function () {
  566. plot = $.plot(placeholder, [
  567. [
  568. [0, 0],
  569. [10, 10]
  570. ]
  571. ], options);
  572. var xaxis = plot.getXAxes()[0],
  573. yaxis = plot.getYAxes()[0],
  574. initialYmin = yaxis.min,
  575. initialYmax = yaxis.max,
  576. eventHolder = plot.getEventHolder(),
  577. pointCoords = [
  578. { x: xaxis.box.left - 10, y: yaxis.p2c(4) },
  579. { x: yaxis.p2c(3), y: yaxis.p2c(8) }
  580. ];
  581. simulate.mouseDown(eventHolder, pointCoords[0].x, pointCoords[0].y);
  582. simulate.mouseMove(eventHolder, pointCoords[0].x, pointCoords[0].y);
  583. simulate.mouseMove(eventHolder, pointCoords[1].x, pointCoords[1].y);
  584. simulate.mouseUp(eventHolder, pointCoords[1].x, pointCoords[1].y);
  585. expect(xaxis.min).toBe(0);
  586. expect(xaxis.max).toBe(10);
  587. expect(yaxis.min).toBeCloseTo(yaxis.c2p(yaxis.p2c(initialYmin) + (pointCoords[0].y - pointCoords[1].y)), 0);
  588. expect(yaxis.max).toBeCloseTo(yaxis.c2p(yaxis.p2c(initialYmax) + (pointCoords[0].y - pointCoords[1].y)), 0);
  589. });
  590. });
  591. describe('click', function(){
  592. it('on plot activates plot\'s zoom and pan active propriety', function() {
  593. plot = $.plot(placeholder, [
  594. [
  595. [0, 0],
  596. [10, 10]
  597. ]
  598. ], {
  599. zoom: { interactive: true, active: false, amount: 10 },
  600. pan: { interactive: true, active: false}
  601. });
  602. var eventHolder = plot.getEventHolder(),
  603. pointCoords = { x: 0, y: plot.height() };
  604. simulate.click(eventHolder, pointCoords.x, pointCoords.y);
  605. expect(plot.getOptions().pan.active).toBe(true);
  606. expect(plot.getOptions().zoom.active).toBe(true);
  607. });
  608. });
  609. describe('mouse dblclick', function(){
  610. it('on plot activates plot\'s zoom and pan active propriety', function() {
  611. plot = $.plot(placeholder, [
  612. [
  613. [0, 0],
  614. [10, 10]
  615. ]
  616. ], {
  617. zoom: { interactive: true, active: false, amount: 10 },
  618. pan: { interactive: true, active: false}
  619. });
  620. var eventHolder = plot.getEventHolder(),
  621. pointCoords = { x: 0, y: plot.height() };
  622. simulate.dblclick(eventHolder, pointCoords.x, pointCoords.y);
  623. expect(plot.getOptions().pan.active).toBe(true);
  624. expect(plot.getOptions().zoom.active).toBe(true);
  625. });
  626. it('sends touched axis for double click on axis', function(){
  627. plot = $.plot(placeholder, [
  628. [
  629. [-1, 2],
  630. [11, 12]
  631. ]
  632. ], options);
  633. var eventHolder = plot.getEventHolder(),
  634. xaxis = plot.getXAxes()[0],
  635. coords = { x: xaxis.p2c(4), y: xaxis.box.top + 10 };
  636. var spyRecenter = jasmine.createSpy('spy');
  637. $(plot.getPlaceholder()).on('re-center', spyRecenter);
  638. simulate.dblclick(eventHolder, coords.x, coords.y);
  639. expect(spyRecenter).toHaveBeenCalled();
  640. expect(spyRecenter.calls.all()[0].args[0].detail.axisTouched).toEqual(xaxis);
  641. });
  642. });
  643. });