model.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. describe('util/model', function() {
  2. var utHelper = window.utHelper;
  3. var modelUtil;
  4. beforeAll(function (done) { // jshint ignore:line
  5. utHelper.resetPackageLoader(function () {
  6. window.require(['echarts/util/model'], function (h) {
  7. modelUtil = h;
  8. done();
  9. });
  10. });
  11. });
  12. function makeRecords(result) {
  13. var o = {};
  14. modelUtil.eachAxisDim(function (dimNames) {
  15. o[dimNames.name] = {};
  16. var r = result[dimNames.name] || [];
  17. for (var i = 0; i < r.length; i++) {
  18. o[dimNames.name][r[i]] = true;
  19. }
  20. });
  21. return o;
  22. }
  23. describe('compressBatches', function () {
  24. function item(seriesId, dataIndex) {
  25. return {seriesId: seriesId, dataIndex: dataIndex};
  26. }
  27. it('base', function (done) {
  28. // Remove dupliate between A and B
  29. expect(modelUtil.compressBatches(
  30. [item(3, 4), item(3, 5), item(4, 5)],
  31. [item(4, 6), item(4, 5), item(3, 3), item(3, 4)]
  32. )).toEqual([
  33. [item('3', [5])],
  34. [item('3', [3]), item('4', [6])]
  35. ]);
  36. // Compress
  37. expect(modelUtil.compressBatches(
  38. [item(3, 4), item(3, 6), item(3, 5), item(4, 5)],
  39. [item(4, 6), item(4, 5), item(3, 3), item(3, 4), item(4, 7)]
  40. )).toEqual([
  41. [item('3', [5, 6])],
  42. [item('3', [3]), item('4', [6, 7])]
  43. ]);
  44. // Remove duplicate in themselves
  45. expect(modelUtil.compressBatches(
  46. [item(3, 4), item(3, 6), item(3, 5), item(4, 5)],
  47. [item(4, 6), item(4, 5), item(3, 3), item(3, 4), item(4, 7), item(4, 6)]
  48. )).toEqual([
  49. [item('3', [5, 6])],
  50. [item('3', [3]), item('4', [6, 7])]
  51. ]);
  52. // dataIndex is array
  53. expect(modelUtil.compressBatches(
  54. [item(3, [4, 5, 8]), item(4, 4), item(3, [5, 7, 7])],
  55. [item(3, [8, 9])]
  56. )).toEqual([
  57. [item('3', [4, 5, 7]), item('4', [4])],
  58. [item('3', [9])]
  59. ]);
  60. // empty
  61. expect(modelUtil.compressBatches(
  62. [item(3, [4, 5, 8]), item(4, 4), item(3, [5, 7, 7])],
  63. []
  64. )).toEqual([
  65. [item('3', [4, 5, 7, 8]), item('4', [4])],
  66. []
  67. ]);
  68. expect(modelUtil.compressBatches(
  69. [],
  70. [item(3, [4, 5, 8]), item(4, 4), item(3, [5, 7, 7])]
  71. )).toEqual([
  72. [],
  73. [item('3', [4, 5, 7, 8]), item('4', [4])]
  74. ]);
  75. // should not has empty array
  76. expect(modelUtil.compressBatches(
  77. [item(3, [4, 5, 8])],
  78. [item(3, [4, 5, 8])]
  79. )).toEqual([
  80. [],
  81. []
  82. ]);
  83. done();
  84. });
  85. });
  86. });