legend.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  1. describe('legend', function() {
  2. var uiHelper = window.uiHelper;
  3. var suites = [{
  4. name: 'show',
  5. cases: [{
  6. name: 'should display legend as default',
  7. option: {
  8. series: [{
  9. name: 'a',
  10. type: 'line',
  11. data: [1, 2, 4]
  12. }],
  13. xAxis : [{
  14. type : 'category',
  15. data : ['x','y','z']
  16. }],
  17. yAxis : [{
  18. type : 'value'
  19. }],
  20. legend: {
  21. data: ['a']
  22. }
  23. }
  24. }, {
  25. name: 'should hide legend when show set to be false',
  26. option: {
  27. series: [{
  28. name: 'a',
  29. type: 'line',
  30. data: [1, 2, 4]
  31. }],
  32. xAxis : [{
  33. type : 'category',
  34. data : ['x','y','z']
  35. }],
  36. yAxis : [{
  37. type : 'value'
  38. }],
  39. legend: {
  40. data: ['a'],
  41. show: false
  42. }
  43. }
  44. }]
  45. }, {
  46. name: 'left',
  47. cases: [{
  48. name: 'should display left position',
  49. option: {
  50. series: [{
  51. name: 'a',
  52. type: 'line',
  53. data: [1, 2, 4]
  54. }],
  55. xAxis : [{
  56. type : 'category',
  57. data : ['x','y','z']
  58. }],
  59. yAxis : [{
  60. type : 'value'
  61. }],
  62. legend: {
  63. data: ['a'],
  64. left: 'left'
  65. }
  66. }
  67. }, {
  68. name: 'should display at 20%',
  69. option: {
  70. series: [{
  71. name: 'a',
  72. type: 'line',
  73. data: [1, 2, 4]
  74. }],
  75. xAxis : [{
  76. type : 'category',
  77. data : ['x','y','z']
  78. }],
  79. yAxis : [{
  80. type : 'value'
  81. }],
  82. legend: {
  83. data: ['a'],
  84. left: '20%'
  85. }
  86. }
  87. }, {
  88. name: 'should display at center',
  89. option: {
  90. series: [{
  91. name: 'a',
  92. type: 'line',
  93. data: [1, 2, 4]
  94. }],
  95. xAxis : [{
  96. type : 'category',
  97. data : ['x','y','z']
  98. }],
  99. yAxis : [{
  100. type : 'value'
  101. }],
  102. legend: {
  103. data: ['a'],
  104. left: 'center'
  105. }
  106. }
  107. }, {
  108. name: 'should display at right',
  109. option: {
  110. series: [{
  111. name: 'a',
  112. type: 'line',
  113. data: [1, 2, 4]
  114. }],
  115. xAxis : [{
  116. type : 'category',
  117. data : ['x','y','z']
  118. }],
  119. yAxis : [{
  120. type : 'value'
  121. }],
  122. legend: {
  123. data: ['a'],
  124. left: 'right'
  125. }
  126. }
  127. }]
  128. }, {
  129. name: 'top',
  130. cases: [{
  131. name: 'should display top position',
  132. option: {
  133. series: [{
  134. name: 'a',
  135. type: 'line',
  136. data: [1, 2, 4]
  137. }],
  138. xAxis : [{
  139. type : 'category',
  140. data : ['x','y','z']
  141. }],
  142. yAxis : [{
  143. type : 'value'
  144. }],
  145. legend: {
  146. data: ['a'],
  147. top: 50
  148. }
  149. }
  150. }, {
  151. name: 'should display at 20%',
  152. option: {
  153. series: [{
  154. name: 'a',
  155. type: 'line',
  156. data: [1, 2, 4]
  157. }],
  158. xAxis : [{
  159. type : 'category',
  160. data : ['x','y','z']
  161. }],
  162. yAxis : [{
  163. type : 'value'
  164. }],
  165. legend: {
  166. data: ['a'],
  167. top: '20%'
  168. }
  169. }
  170. }, {
  171. name: 'should display at middle',
  172. option: {
  173. series: [{
  174. name: 'a',
  175. type: 'line',
  176. data: [1, 2, 4]
  177. }],
  178. xAxis : [{
  179. type : 'category',
  180. data : ['x','y','z']
  181. }],
  182. yAxis : [{
  183. type : 'value'
  184. }],
  185. legend: {
  186. data: ['a'],
  187. top: 'middle'
  188. }
  189. }
  190. }, {
  191. name: 'should display at bottom',
  192. option: {
  193. series: [{
  194. name: 'a',
  195. type: 'line',
  196. data: [1, 2, 4]
  197. }],
  198. xAxis : [{
  199. type : 'category',
  200. data : ['x','y','z']
  201. }],
  202. yAxis : [{
  203. type : 'value'
  204. }],
  205. legend: {
  206. data: ['a'],
  207. top: 'bottom'
  208. }
  209. }
  210. }]
  211. }, {
  212. name: 'right',
  213. cases: [{
  214. name: 'should display right position',
  215. option: {
  216. series: [{
  217. name: 'a',
  218. type: 'line',
  219. data: [1, 2, 4]
  220. }],
  221. xAxis : [{
  222. type : 'category',
  223. data : ['x','y','z']
  224. }],
  225. yAxis : [{
  226. type : 'value'
  227. }],
  228. legend: {
  229. data: ['a'],
  230. right: 50
  231. }
  232. }
  233. }]
  234. }, {
  235. name: 'bottom',
  236. cases: [{
  237. name: 'should display bottom position',
  238. option: {
  239. series: [{
  240. name: 'a',
  241. type: 'line',
  242. data: [1, 2, 4]
  243. }],
  244. xAxis : [{
  245. type : 'category',
  246. data : ['x','y','z']
  247. }],
  248. yAxis : [{
  249. type : 'value'
  250. }],
  251. legend: {
  252. data: ['a'],
  253. bottom: 50
  254. }
  255. }
  256. }]
  257. }, {
  258. name: 'left and right',
  259. cases: [{
  260. name: 'are both set',
  261. test: 'equalOption',
  262. option1: {
  263. series: [{
  264. name: 'a',
  265. type: 'line',
  266. data: [1, 2, 4]
  267. }],
  268. xAxis : [{
  269. type : 'category',
  270. data : ['x','y','z']
  271. }],
  272. yAxis : [{
  273. type : 'value'
  274. }],
  275. legend: {
  276. data: ['a'],
  277. left: 50,
  278. right: 50
  279. }
  280. },
  281. option2: {
  282. series: [{
  283. name: 'a',
  284. type: 'line',
  285. data: [1, 2, 4]
  286. }],
  287. xAxis : [{
  288. type : 'category',
  289. data : ['x','y','z']
  290. }],
  291. yAxis : [{
  292. type : 'value'
  293. }],
  294. legend: {
  295. data: ['a'],
  296. left: 50
  297. }
  298. }
  299. }]
  300. }, {
  301. name: 'top and bottom',
  302. cases: [{
  303. name: 'are both set',
  304. test: 'equalOption',
  305. option1: {
  306. series: [{
  307. name: 'a',
  308. type: 'line',
  309. data: [1, 2, 4]
  310. }],
  311. xAxis : [{
  312. type : 'category',
  313. data : ['x','y','z']
  314. }],
  315. yAxis : [{
  316. type : 'value'
  317. }],
  318. legend: {
  319. data: ['a'],
  320. top: 50,
  321. bottom: 50
  322. }
  323. },
  324. option2: {
  325. series: [{
  326. name: 'a',
  327. type: 'line',
  328. data: [1, 2, 4]
  329. }],
  330. xAxis : [{
  331. type : 'category',
  332. data : ['x','y','z']
  333. }],
  334. yAxis : [{
  335. type : 'value'
  336. }],
  337. legend: {
  338. data: ['a'],
  339. top: 50
  340. }
  341. }
  342. }]
  343. }, {
  344. name: 'width',
  345. cases: [{
  346. name: 'should display in seperate lines',
  347. test: 'notEqualOption',
  348. option1: {
  349. series: [{
  350. name: 'this is a',
  351. type: 'line',
  352. data: []
  353. }, {
  354. name: 'this is b',
  355. type: 'line',
  356. data: []
  357. }, {
  358. name: 'this is c',
  359. type: 'line',
  360. data: []
  361. }],
  362. xAxis : [{
  363. type : 'category',
  364. data : ['x','y','z']
  365. }],
  366. yAxis : [{
  367. type : 'value'
  368. }],
  369. legend: {
  370. data: ['this is a', 'this is b',
  371. 'this is c'],
  372. width: 200
  373. }
  374. },
  375. option2: {
  376. series: [{
  377. name: 'this is a',
  378. type: 'line',
  379. data: []
  380. }, {
  381. name: 'this is b',
  382. type: 'line',
  383. data: []
  384. }, {
  385. name: 'this is c',
  386. type: 'line',
  387. data: []
  388. }],
  389. xAxis : [{
  390. type : 'category',
  391. data : ['x','y','z']
  392. }],
  393. yAxis : [{
  394. type : 'value'
  395. }],
  396. legend: {
  397. data: ['this is a', 'this is b',
  398. 'this is c']
  399. }
  400. }
  401. }]
  402. }, {
  403. name: 'hight',
  404. cases: [{
  405. name: 'should display in seperate lines',
  406. test: 'notEqualOption',
  407. option1: {
  408. series: [{
  409. name: 'this is a',
  410. type: 'line',
  411. data: []
  412. }, {
  413. name: 'this is b',
  414. type: 'line',
  415. data: []
  416. }, {
  417. name: 'this is c',
  418. type: 'line',
  419. data: []
  420. }],
  421. xAxis : [{
  422. type : 'category',
  423. data : ['x','y','z']
  424. }],
  425. yAxis : [{
  426. type : 'value'
  427. }],
  428. legend: {
  429. data: ['this is a', 'this is b',
  430. 'this is c'],
  431. height: 50,
  432. orient: 'vertical'
  433. }
  434. },
  435. option2: {
  436. series: [{
  437. name: 'this is a',
  438. type: 'line',
  439. data: []
  440. }, {
  441. name: 'this is b',
  442. type: 'line',
  443. data: []
  444. }, {
  445. name: 'this is c',
  446. type: 'line',
  447. data: []
  448. }],
  449. xAxis : [{
  450. type : 'category',
  451. data : ['x','y','z']
  452. }],
  453. yAxis : [{
  454. type : 'value'
  455. }],
  456. legend: {
  457. data: ['this is a', 'this is b',
  458. 'this is c'],
  459. orient: 'vertical'
  460. }
  461. }
  462. }]
  463. }, {
  464. name: 'orient',
  465. cases: [{
  466. name: 'should display horizontally',
  467. option: {
  468. series: [{
  469. name: 'this is a',
  470. type: 'line',
  471. data: []
  472. }, {
  473. name: 'this is b',
  474. type: 'line',
  475. data: []
  476. }, {
  477. name: 'this is c',
  478. type: 'line',
  479. data: []
  480. }],
  481. xAxis : [{
  482. type : 'category',
  483. data : ['x','y','z']
  484. }],
  485. yAxis : [{
  486. type : 'value'
  487. }],
  488. legend: {
  489. data: ['this is a', 'this is b',
  490. 'this is c'],
  491. orient: 'horizontal'
  492. }
  493. }
  494. }, {
  495. name: 'should display vertically',
  496. option: {
  497. series: [{
  498. name: 'this is a',
  499. type: 'line',
  500. data: []
  501. }, {
  502. name: 'this is b',
  503. type: 'line',
  504. data: []
  505. }, {
  506. name: 'this is c',
  507. type: 'line',
  508. data: []
  509. }],
  510. xAxis : [{
  511. type : 'category',
  512. data : ['x','y','z']
  513. }],
  514. yAxis : [{
  515. type : 'value'
  516. }],
  517. legend: {
  518. data: ['this is a', 'this is b',
  519. 'this is c'],
  520. orient: 'vertical'
  521. }
  522. }
  523. }, {
  524. name: 'should display different with horizontal and vertical',
  525. test: 'notEqualOption',
  526. option1: {
  527. series: [{
  528. name: 'this is a',
  529. type: 'line',
  530. data: []
  531. }, {
  532. name: 'this is b',
  533. type: 'line',
  534. data: []
  535. }, {
  536. name: 'this is c',
  537. type: 'line',
  538. data: []
  539. }],
  540. xAxis : [{
  541. type : 'category',
  542. data : ['x','y','z']
  543. }],
  544. yAxis : [{
  545. type : 'value'
  546. }],
  547. legend: {
  548. data: ['this is a', 'this is b',
  549. 'this is c'],
  550. orient: 'vertical'
  551. }
  552. },
  553. option2: {
  554. series: [{
  555. name: 'this is a',
  556. type: 'line',
  557. data: []
  558. }, {
  559. name: 'this is b',
  560. type: 'line',
  561. data: []
  562. }, {
  563. name: 'this is c',
  564. type: 'line',
  565. data: []
  566. }],
  567. xAxis : [{
  568. type : 'category',
  569. data : ['x','y','z']
  570. }],
  571. yAxis : [{
  572. type : 'value'
  573. }],
  574. legend: {
  575. data: ['this is a', 'this is b',
  576. 'this is c']
  577. }
  578. }
  579. }]
  580. }];
  581. uiHelper.testOptionSpec('legend', suites);
  582. });