Global.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845
  1. describe('modelAndOptionMapping', function() {
  2. var utHelper = window.utHelper;
  3. var testCase = utHelper.prepare([
  4. 'echarts/src/component/grid',
  5. 'echarts/src/chart/line',
  6. 'echarts/src/chart/pie',
  7. 'echarts/src/chart/bar',
  8. 'echarts/src/component/toolbox',
  9. 'echarts/src/component/dataZoom'
  10. ]);
  11. function getData0(chart, seriesIndex) {
  12. return getSeries(chart, seriesIndex).getData().get('y', 0);
  13. }
  14. function getSeries(chart, seriesIndex) {
  15. return chart.getModel().getComponent('series', seriesIndex);
  16. }
  17. function getModel(chart, type, index) {
  18. return chart.getModel().getComponent(type, index);
  19. }
  20. function countSeries(chart) {
  21. return countModel(chart, 'series');
  22. }
  23. function countModel(chart, type) {
  24. // FIXME
  25. // access private
  26. return chart.getModel()._componentsMap.get(type).length;
  27. }
  28. function getChartView(chart, series) {
  29. return chart._chartsMap[series.__viewId];
  30. }
  31. function countChartViews(chart) {
  32. return chart._chartsViews.length;
  33. }
  34. function saveOrigins(chart) {
  35. var count = countSeries(chart);
  36. var origins = [];
  37. for (var i = 0; i < count; i++) {
  38. var series = getSeries(chart, i);
  39. origins.push({
  40. model: series,
  41. view: getChartView(chart, series)
  42. });
  43. }
  44. return origins;
  45. }
  46. function modelEqualsToOrigin(chart, idxList, origins, boolResult) {
  47. for (var i = 0; i < idxList.length; i++) {
  48. var idx = idxList[i];
  49. expect(origins[idx].model === getSeries(chart, idx)).toEqual(boolResult);
  50. }
  51. }
  52. function viewEqualsToOrigin(chart, idxList, origins, boolResult) {
  53. for (var i = 0; i < idxList.length; i++) {
  54. var idx = idxList[i];
  55. expect(
  56. origins[idx].view === getChartView(chart, getSeries(chart, idx))
  57. ).toEqual(boolResult);
  58. }
  59. }
  60. describe('idNoNameNo', function () {
  61. testCase.createChart()('sameTypeNotMerge', function () {
  62. var option = {
  63. xAxis: {data: ['a']},
  64. yAxis: {},
  65. series: [
  66. {type: 'line', data: [11]},
  67. {type: 'line', data: [22]},
  68. {type: 'line', data: [33]}
  69. ]
  70. };
  71. var chart = this.chart;
  72. chart.setOption(option);
  73. // Not merge
  74. var origins = saveOrigins(chart);
  75. chart.setOption(option, true);
  76. expect(countChartViews(chart)).toEqual(3);
  77. expect(countSeries(chart)).toEqual(3);
  78. modelEqualsToOrigin(chart, [0, 1, 2], origins, false);
  79. viewEqualsToOrigin(chart, [0, 1, 2], origins, true);
  80. });
  81. testCase.createChart()('sameTypeMergeFull', function () {
  82. var option = {
  83. xAxis: {data: ['a']},
  84. yAxis: {},
  85. series: [
  86. {type: 'line', data: [11]},
  87. {type: 'line', data: [22]},
  88. {type: 'line', data: [33]}
  89. ]
  90. };
  91. var chart = this.chart;
  92. chart.setOption(option);
  93. // Merge
  94. var origins = saveOrigins(chart);
  95. chart.setOption({
  96. series: [
  97. {type: 'line', data: [111]},
  98. {type: 'line', data: [222]},
  99. {type: 'line', data: [333]}
  100. ]
  101. });
  102. expect(countSeries(chart)).toEqual(3);
  103. expect(countChartViews(chart)).toEqual(3);
  104. expect(getData0(chart, 0)).toEqual(111);
  105. expect(getData0(chart, 1)).toEqual(222);
  106. expect(getData0(chart, 2)).toEqual(333);
  107. viewEqualsToOrigin(chart, [0, 1, 2], origins, true);
  108. modelEqualsToOrigin(chart, [0, 1, 2], origins, true);
  109. });
  110. testCase.createChart()('sameTypeMergePartial', function () {
  111. var option = {
  112. xAxis: {data: ['a']},
  113. yAxis: {},
  114. series: [
  115. {type: 'line', data: [11]},
  116. {type: 'line', data: [22]},
  117. {type: 'line', data: [33]}
  118. ]
  119. };
  120. var chart = this.chart;
  121. chart.setOption(option);
  122. // Merge
  123. var origins = saveOrigins(chart);
  124. chart.setOption({
  125. series: [
  126. {data: [22222]}
  127. ]
  128. });
  129. expect(countSeries(chart)).toEqual(3);
  130. expect(countChartViews(chart)).toEqual(3);
  131. expect(getData0(chart, 0)).toEqual(22222);
  132. expect(getData0(chart, 1)).toEqual(22);
  133. expect(getData0(chart, 2)).toEqual(33);
  134. viewEqualsToOrigin(chart, [0, 1, 2], origins, true);
  135. modelEqualsToOrigin(chart, [0, 1, 2], origins, true);
  136. });
  137. testCase.createChart()('differentTypeMerge', function () {
  138. var option = {
  139. xAxis: {data: ['a']},
  140. yAxis: {},
  141. series: [
  142. {type: 'line', data: [11]},
  143. {type: 'line', data: [22]},
  144. {type: 'line', data: [33]}
  145. ]
  146. };
  147. var chart = this.chart;
  148. chart.setOption(option);
  149. // Merge
  150. var origins = saveOrigins(chart);
  151. chart.setOption({
  152. series: [
  153. {type: 'line', data: [111]},
  154. {type: 'bar', data: [222]},
  155. {type: 'line', data: [333]}
  156. ]
  157. });
  158. expect(countSeries(chart)).toEqual(3);
  159. expect(countChartViews(chart)).toEqual(3);
  160. expect(getData0(chart, 0)).toEqual(111);
  161. expect(getData0(chart, 1)).toEqual(222);
  162. expect(getData0(chart, 2)).toEqual(333);
  163. expect(getSeries(chart, 1).type === 'series.bar').toEqual(true);
  164. modelEqualsToOrigin(chart, [0, 2], origins, true);
  165. modelEqualsToOrigin(chart, [1], origins, false);
  166. viewEqualsToOrigin(chart, [0, 2], origins, true);
  167. viewEqualsToOrigin(chart, [1], origins, false);
  168. });
  169. });
  170. describe('idSpecified', function () {
  171. testCase.createChart()('sameTypeNotMerge', function () {
  172. var option = {
  173. xAxis: {data: ['a']},
  174. yAxis: {},
  175. series: [
  176. {type: 'line', data: [11]},
  177. {type: 'line', data: [22], id: 20},
  178. {type: 'line', data: [33], id: 30},
  179. {type: 'line', data: [44]},
  180. {type: 'line', data: [55]}
  181. ]
  182. };
  183. var chart = this.chart;
  184. chart.setOption(option);
  185. expect(countSeries(chart)).toEqual(5);
  186. expect(countChartViews(chart)).toEqual(5);
  187. expect(getData0(chart, 0)).toEqual(11);
  188. expect(getData0(chart, 1)).toEqual(22);
  189. expect(getData0(chart, 2)).toEqual(33);
  190. expect(getData0(chart, 3)).toEqual(44);
  191. expect(getData0(chart, 4)).toEqual(55);
  192. var origins = saveOrigins(chart);
  193. chart.setOption(option, true);
  194. expect(countChartViews(chart)).toEqual(5);
  195. expect(countSeries(chart)).toEqual(5);
  196. modelEqualsToOrigin(chart, [0, 1, 2, 3, 4], origins, false);
  197. viewEqualsToOrigin(chart, [0, 1, 2, 3, 4], origins, true);
  198. });
  199. testCase.createChart()('sameTypeMerge', function () {
  200. var option = {
  201. xAxis: {data: ['a']},
  202. yAxis: {},
  203. series: [
  204. {type: 'line', data: [11]},
  205. {type: 'line', data: [22], id: 20},
  206. {type: 'line', data: [33], id: 30},
  207. {type: 'line', data: [44]},
  208. {type: 'line', data: [55]}
  209. ]
  210. };
  211. var chart = this.chart;
  212. chart.setOption(option);
  213. var origins = saveOrigins(chart);
  214. chart.setOption(option);
  215. expect(countChartViews(chart)).toEqual(5);
  216. expect(countSeries(chart)).toEqual(5);
  217. modelEqualsToOrigin(chart, [0, 1, 2, 3, 4], origins, true);
  218. viewEqualsToOrigin(chart, [0, 1, 2, 3, 4], origins, true);
  219. });
  220. testCase.createChart()('differentTypeNotMerge', function () {
  221. var option = {
  222. xAxis: {data: ['a']},
  223. yAxis: {},
  224. series: [
  225. {type: 'line', data: [11]},
  226. {type: 'line', data: [22], id: 20},
  227. {type: 'line', data: [33], id: 30},
  228. {type: 'line', data: [44]},
  229. {type: 'line', data: [55]}
  230. ]
  231. };
  232. var chart = this.chart;
  233. chart.setOption(option);
  234. var origins = saveOrigins(chart);
  235. var option2 = {
  236. xAxis: {data: ['a']},
  237. yAxis: {},
  238. series: [
  239. {type: 'line', data: [11]},
  240. {type: 'bar', data: [22], id: 20},
  241. {type: 'line', data: [33], id: 30},
  242. {type: 'bar', data: [44]},
  243. {type: 'line', data: [55]}
  244. ]
  245. };
  246. chart.setOption(option2, true);
  247. expect(countChartViews(chart)).toEqual(5);
  248. expect(countSeries(chart)).toEqual(5);
  249. modelEqualsToOrigin(chart, [0, 1, 2, 3, 4], origins, false);
  250. viewEqualsToOrigin(chart, [0, 2, 4], origins, true);
  251. viewEqualsToOrigin(chart, [1, 3], origins, false);
  252. });
  253. testCase.createChart()('differentTypeMergeFull', function () {
  254. var option = {
  255. xAxis: {data: ['a']},
  256. yAxis: {},
  257. series: [
  258. {type: 'line', data: [11]},
  259. {type: 'line', data: [22], id: 20},
  260. {type: 'line', data: [33], id: 30, name: 'a'},
  261. {type: 'line', data: [44]},
  262. {type: 'line', data: [55]}
  263. ]
  264. };
  265. var chart = this.chart;
  266. chart.setOption(option);
  267. var origins = saveOrigins(chart);
  268. var option2 = {
  269. series: [
  270. {type: 'line', data: [11]},
  271. {type: 'bar', data: [22], id: 20, name: 'a'},
  272. {type: 'line', data: [33], id: 30},
  273. {type: 'bar', data: [44]},
  274. {type: 'line', data: [55]}
  275. ]
  276. };
  277. chart.setOption(option2);
  278. expect(countChartViews(chart)).toEqual(5);
  279. expect(countSeries(chart)).toEqual(5);
  280. modelEqualsToOrigin(chart, [0, 2, 4], origins, true);
  281. modelEqualsToOrigin(chart, [1, 3], origins, false);
  282. viewEqualsToOrigin(chart, [0, 2, 4], origins, true);
  283. viewEqualsToOrigin(chart, [1, 3], origins, false);
  284. });
  285. testCase.createChart()('differentTypeMergePartial1', function () {
  286. var option = {
  287. xAxis: {data: ['a']},
  288. yAxis: {},
  289. series: [
  290. {type: 'line', data: [11]},
  291. {type: 'line', data: [22], id: 20},
  292. {type: 'line', data: [33]},
  293. {type: 'line', data: [44], id: 40},
  294. {type: 'line', data: [55]}
  295. ]
  296. };
  297. var chart = this.chart;
  298. chart.setOption(option);
  299. var origins = saveOrigins(chart);
  300. var option2 = {
  301. series: [
  302. {type: 'bar', data: [444], id: 40},
  303. {type: 'line', data: [333]},
  304. {type: 'line', data: [222], id: 20}
  305. ]
  306. };
  307. chart.setOption(option2);
  308. expect(countChartViews(chart)).toEqual(5);
  309. expect(countSeries(chart)).toEqual(5);
  310. expect(getData0(chart, 0)).toEqual(333);
  311. expect(getData0(chart, 1)).toEqual(222);
  312. expect(getData0(chart, 2)).toEqual(33);
  313. expect(getData0(chart, 3)).toEqual(444);
  314. expect(getData0(chart, 4)).toEqual(55);
  315. modelEqualsToOrigin(chart, [0, 1, 2, 4], origins, true);
  316. modelEqualsToOrigin(chart, [3], origins, false);
  317. viewEqualsToOrigin(chart, [0, 1, 2, 4], origins, true);
  318. viewEqualsToOrigin(chart, [3], origins, false);
  319. });
  320. testCase.createChart()('differentTypeMergePartial2', function () {
  321. var option = {
  322. xAxis: {data: ['a']},
  323. yAxis: {},
  324. series: [
  325. {type: 'line', data: [11]},
  326. {type: 'line', data: [22], id: 20}
  327. ]
  328. };
  329. var chart = this.chart;
  330. chart.setOption(option);
  331. var option2 = {
  332. series: [
  333. {type: 'bar', data: [444], id: 40},
  334. {type: 'line', data: [333]},
  335. {type: 'line', data: [222], id: 20},
  336. {type: 'line', data: [111]}
  337. ]
  338. };
  339. chart.setOption(option2);
  340. expect(countChartViews(chart)).toEqual(4);
  341. expect(countSeries(chart)).toEqual(4);
  342. expect(getData0(chart, 0)).toEqual(333);
  343. expect(getData0(chart, 1)).toEqual(222);
  344. expect(getData0(chart, 2)).toEqual(444);
  345. expect(getData0(chart, 3)).toEqual(111);
  346. });
  347. testCase.createChart()('mergePartialDoNotMapToOtherId', function () {
  348. var option = {
  349. xAxis: {data: ['a']},
  350. yAxis: {},
  351. series: [
  352. {type: 'line', data: [11], id: 10},
  353. {type: 'line', data: [22], id: 20}
  354. ]
  355. };
  356. var chart = this.chart;
  357. chart.setOption(option);
  358. var option2 = {
  359. series: [
  360. {type: 'bar', data: [444], id: 40}
  361. ]
  362. };
  363. chart.setOption(option2);
  364. expect(countChartViews(chart)).toEqual(3);
  365. expect(countSeries(chart)).toEqual(3);
  366. expect(getData0(chart, 0)).toEqual(11);
  367. expect(getData0(chart, 1)).toEqual(22);
  368. expect(getData0(chart, 2)).toEqual(444);
  369. });
  370. testCase.createChart()('idDuplicate', function () {
  371. var option = {
  372. xAxis: {data: ['a']},
  373. yAxis: {},
  374. series: [
  375. {type: 'line', data: [11], id: 10},
  376. {type: 'line', data: [22], id: 10}
  377. ]
  378. };
  379. var chart = this.chart;
  380. expect(function () {
  381. chart.setOption(option);
  382. }).toThrowError(/duplicate/);
  383. });
  384. testCase.createChart()('nameTheSameButIdNotTheSame', function () {
  385. var chart = this.chart;
  386. var option = {
  387. grid: {},
  388. xAxis: [
  389. {id: 'x1', name: 'a', xxxx: 'x1_a'},
  390. {id: 'x2', name: 'b', xxxx: 'x2_b'}
  391. ],
  392. yAxis: {}
  393. };
  394. chart.setOption(option);
  395. var xAxisModel0 = getModel(chart, 'xAxis', 0);
  396. var xAxisModel1 = getModel(chart, 'xAxis', 1);
  397. expect(xAxisModel0.option.xxxx).toEqual('x1_a');
  398. expect(xAxisModel1.option.xxxx).toEqual('x2_b');
  399. expect(xAxisModel1.option.name).toEqual('b');
  400. var option2 = {
  401. xAxis: [
  402. {id: 'k1', name: 'a', xxxx: 'k1_a'},
  403. {id: 'x2', name: 'a', xxxx: 'x2_a'}
  404. ]
  405. };
  406. chart.setOption(option2);
  407. var xAxisModel0 = getModel(chart, 'xAxis', 0);
  408. var xAxisModel1 = getModel(chart, 'xAxis', 1);
  409. var xAxisModel2 = getModel(chart, 'xAxis', 2);
  410. expect(xAxisModel0.option.xxxx).toEqual('x1_a');
  411. expect(xAxisModel1.option.xxxx).toEqual('x2_a');
  412. expect(xAxisModel1.option.name).toEqual('a');
  413. expect(xAxisModel2.option.xxxx).toEqual('k1_a');
  414. });
  415. });
  416. describe('noIdButNameExists', function () {
  417. testCase.createChart()('sameTypeNotMerge', function () {
  418. var option = {
  419. xAxis: {data: ['a']},
  420. yAxis: {},
  421. series: [
  422. {type: 'line', data: [11]},
  423. {type: 'line', data: [22], name: 'a'},
  424. {type: 'line', data: [33], name: 'b'},
  425. {type: 'line', data: [44]},
  426. {type: 'line', data: [55], name: 'a'}
  427. ]
  428. };
  429. var chart = this.chart;
  430. chart.setOption(option);
  431. expect(getSeries(chart, 1)).not.toEqual(getSeries(chart, 4));
  432. expect(countSeries(chart)).toEqual(5);
  433. expect(countChartViews(chart)).toEqual(5);
  434. expect(getData0(chart, 0)).toEqual(11);
  435. expect(getData0(chart, 1)).toEqual(22);
  436. expect(getData0(chart, 2)).toEqual(33);
  437. expect(getData0(chart, 3)).toEqual(44);
  438. expect(getData0(chart, 4)).toEqual(55);
  439. var origins = saveOrigins(chart);
  440. chart.setOption(option, true);
  441. expect(countChartViews(chart)).toEqual(5);
  442. expect(countSeries(chart)).toEqual(5);
  443. modelEqualsToOrigin(chart, [0, 1, 2, 3, 4], origins, false);
  444. viewEqualsToOrigin(chart, [0, 1, 2, 3, 4], origins, true);
  445. });
  446. testCase.createChart()('sameTypeMerge', function () {
  447. var option = {
  448. xAxis: {data: ['a']},
  449. yAxis: {},
  450. series: [
  451. {type: 'line', data: [11]},
  452. {type: 'line', data: [22], name: 'a'},
  453. {type: 'line', data: [33], name: 'b'},
  454. {type: 'line', data: [44]},
  455. {type: 'line', data: [55], name: 'a'}
  456. ]
  457. };
  458. var chart = this.chart;
  459. chart.setOption(option);
  460. var origins = saveOrigins(chart);
  461. chart.setOption(option);
  462. expect(countChartViews(chart)).toEqual(5);
  463. expect(countSeries(chart)).toEqual(5);
  464. modelEqualsToOrigin(chart, [0, 1, 2, 3, 4], origins, true);
  465. viewEqualsToOrigin(chart, [0, 1, 2, 3, 4], origins, true);
  466. });
  467. testCase.createChart()('differentTypeNotMerge', function () {
  468. var option = {
  469. xAxis: {data: ['a']},
  470. yAxis: {},
  471. series: [
  472. {type: 'line', data: [11]},
  473. {type: 'line', data: [22], name: 'a'},
  474. {type: 'line', data: [33], name: 'b'},
  475. {type: 'line', data: [44]},
  476. {type: 'line', data: [55], name: 'a'}
  477. ]
  478. };
  479. var chart = this.chart;
  480. chart.setOption(option);
  481. var origins = saveOrigins(chart);
  482. var option2 = {
  483. xAxis: {data: ['a']},
  484. yAxis: {},
  485. series: [
  486. {type: 'line', data: [11]},
  487. {type: 'bar', data: [22], name: 'a'},
  488. {type: 'line', data: [33], name: 'b'},
  489. {type: 'bar', data: [44]},
  490. {type: 'line', data: [55], name: 'a'}
  491. ]
  492. };
  493. chart.setOption(option2, true);
  494. expect(countChartViews(chart)).toEqual(5);
  495. expect(countSeries(chart)).toEqual(5);
  496. modelEqualsToOrigin(chart, [0, 1, 2, 3, 4], origins, false);
  497. viewEqualsToOrigin(chart, [0, 2, 4], origins, true);
  498. viewEqualsToOrigin(chart, [1, 3], origins, false);
  499. });
  500. testCase.createChart()('differentTypeMergePartialOneMapTwo', function () {
  501. var option = {
  502. xAxis: {data: ['a']},
  503. yAxis: {},
  504. series: [
  505. {type: 'line', data: [11]},
  506. {type: 'line', data: [22], name: 'a'},
  507. {type: 'line', data: [33]},
  508. {type: 'line', data: [44], name: 'b'},
  509. {type: 'line', data: [55], name: 'a'}
  510. ]
  511. };
  512. var chart = this.chart;
  513. chart.setOption(option);
  514. var origins = saveOrigins(chart);
  515. var option2 = {
  516. series: [
  517. {type: 'bar', data: [444], id: 40},
  518. {type: 'line', data: [333]},
  519. {type: 'bar', data: [222], name: 'a'}
  520. ]
  521. };
  522. chart.setOption(option2);
  523. expect(countChartViews(chart)).toEqual(6);
  524. expect(countSeries(chart)).toEqual(6);
  525. expect(getData0(chart, 0)).toEqual(333);
  526. expect(getData0(chart, 1)).toEqual(222);
  527. expect(getData0(chart, 2)).toEqual(33);
  528. expect(getData0(chart, 3)).toEqual(44);
  529. expect(getData0(chart, 4)).toEqual(55);
  530. expect(getData0(chart, 5)).toEqual(444);
  531. modelEqualsToOrigin(chart, [0, 2, 3, 4], origins, true);
  532. modelEqualsToOrigin(chart, [1], origins, false);
  533. viewEqualsToOrigin(chart, [0, 2, 3, 4], origins, true);
  534. viewEqualsToOrigin(chart, [1], origins, false);
  535. });
  536. testCase.createChart()('differentTypeMergePartialTwoMapOne', function () {
  537. var option = {
  538. xAxis: {data: ['a']},
  539. yAxis: {},
  540. series: [
  541. {type: 'line', data: [11]},
  542. {type: 'line', data: [22], name: 'a'}
  543. ]
  544. };
  545. var chart = this.chart;
  546. chart.setOption(option);
  547. var option2 = {
  548. series: [
  549. {type: 'bar', data: [444], name: 'a'},
  550. {type: 'line', data: [333]},
  551. {type: 'line', data: [222], name: 'a'},
  552. {type: 'line', data: [111]}
  553. ]
  554. };
  555. chart.setOption(option2);
  556. expect(countChartViews(chart)).toEqual(4);
  557. expect(countSeries(chart)).toEqual(4);
  558. expect(getData0(chart, 0)).toEqual(333);
  559. expect(getData0(chart, 1)).toEqual(444);
  560. expect(getData0(chart, 2)).toEqual(222);
  561. expect(getData0(chart, 3)).toEqual(111);
  562. });
  563. testCase.createChart()('mergePartialCanMapToOtherName', function () {
  564. // Consider case: axis.name = 'some label', which can be overwritten.
  565. var option = {
  566. xAxis: {data: ['a']},
  567. yAxis: {},
  568. series: [
  569. {type: 'line', data: [11], name: 10},
  570. {type: 'line', data: [22], name: 20}
  571. ]
  572. };
  573. var chart = this.chart;
  574. chart.setOption(option);
  575. var option2 = {
  576. series: [
  577. {type: 'bar', data: [444], name: 40},
  578. {type: 'bar', data: [999], name: 40},
  579. {type: 'bar', data: [777], id: 70}
  580. ]
  581. };
  582. chart.setOption(option2);
  583. expect(countChartViews(chart)).toEqual(3);
  584. expect(countSeries(chart)).toEqual(3);
  585. expect(getData0(chart, 0)).toEqual(444);
  586. expect(getData0(chart, 1)).toEqual(999);
  587. expect(getData0(chart, 2)).toEqual(777);
  588. });
  589. });
  590. describe('ohters', function () {
  591. testCase.createChart()('aBugCase', function () {
  592. var option = {
  593. series: [
  594. {
  595. type:'pie',
  596. radius: ['20%', '25%'],
  597. center:['20%', '20%'],
  598. avoidLabelOverlap: true,
  599. hoverAnimation :false,
  600. label: {
  601. normal: {
  602. show: true,
  603. position: 'center',
  604. textStyle: {
  605. fontSize: '30',
  606. fontWeight: 'bold'
  607. }
  608. },
  609. emphasis: {
  610. show: true
  611. }
  612. },
  613. data:[
  614. {value:135, name:'视频广告'},
  615. {value:1548}
  616. ]
  617. }
  618. ]
  619. };
  620. var chart = this.chart;
  621. chart.setOption(option);
  622. chart.setOption({
  623. series: [
  624. {
  625. type:'pie',
  626. radius: ['20%', '25%'],
  627. center: ['20%', '20%'],
  628. avoidLabelOverlap: true,
  629. hoverAnimation: false,
  630. label: {
  631. normal: {
  632. show: true,
  633. position: 'center',
  634. textStyle: {
  635. fontSize: '30',
  636. fontWeight: 'bold'
  637. }
  638. }
  639. },
  640. data: [
  641. {value:135, name:'视频广告'},
  642. {value:1548}
  643. ]
  644. },
  645. {
  646. type:'pie',
  647. radius: ['20%', '25%'],
  648. center: ['60%', '20%'],
  649. avoidLabelOverlap: true,
  650. hoverAnimation: false,
  651. label: {
  652. normal: {
  653. show: true,
  654. position: 'center',
  655. textStyle: {
  656. fontSize: '30',
  657. fontWeight: 'bold'
  658. }
  659. }
  660. },
  661. data: [
  662. {value:135, name:'视频广告'},
  663. {value:1548}
  664. ]
  665. }
  666. ]
  667. }, true);
  668. expect(countChartViews(chart)).toEqual(2);
  669. expect(countSeries(chart)).toEqual(2);
  670. });
  671. testCase.createChart()('color', function () {
  672. var option = {
  673. backgroundColor: 'rgba(1,1,1,1)',
  674. xAxis: {data: ['a']},
  675. yAxis: {},
  676. series: [
  677. {type: 'line', data: [11]},
  678. {type: 'line', data: [22]},
  679. {type: 'line', data: [33]}
  680. ]
  681. };
  682. var chart = this.chart;
  683. chart.setOption(option);
  684. expect(chart._model.option.backgroundColor).toEqual('rgba(1,1,1,1)');
  685. // Not merge
  686. chart.setOption({
  687. backgroundColor: '#fff'
  688. }, true);
  689. expect(chart._model.option.backgroundColor).toEqual('#fff');
  690. });
  691. testCase.createChart()('innerId', function () {
  692. var option = {
  693. xAxis: {data: ['a']},
  694. yAxis: {},
  695. toolbox: {
  696. feature: {
  697. dataZoom: {}
  698. }
  699. },
  700. dataZoom: [
  701. {type: 'inside', id: 'a'},
  702. {type: 'slider', id: 'b'}
  703. ],
  704. series: [
  705. {type: 'line', data: [11]},
  706. {type: 'line', data: [22]}
  707. ]
  708. };
  709. var chart = this.chart;
  710. chart.setOption(option);
  711. expect(countModel(chart, 'dataZoom')).toEqual(4);
  712. expect(getModel(chart, 'dataZoom', 0).id).toEqual('a');
  713. expect(getModel(chart, 'dataZoom', 1).id).toEqual('b');
  714. // Merge
  715. chart.setOption({
  716. dataZoom: [
  717. {type: 'slider', id: 'c'},
  718. {type: 'slider', name: 'x'}
  719. ]
  720. });
  721. expect(countModel(chart, 'dataZoom')).toEqual(5);
  722. expect(getModel(chart, 'dataZoom', 0).id).toEqual('a');
  723. expect(getModel(chart, 'dataZoom', 1).id).toEqual('b');
  724. expect(getModel(chart, 'dataZoom', 4).id).toEqual('c');
  725. });
  726. });
  727. });