helper.js 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. describe('dataZoom/helper', function() {
  2. var utHelper = window.utHelper;
  3. var helper;
  4. beforeAll(function (done) { // jshint ignore:line
  5. window.requireES(['echarts/src/component/dataZoom/helper'], function (h) {
  6. helper = h;
  7. done();
  8. });
  9. });
  10. function makeRecords(result) {
  11. var o = {};
  12. helper.eachAxisDim(function (dimNames) {
  13. o[dimNames.name] = {};
  14. var r = result[dimNames.name] || [];
  15. for (var i = 0; i < r.length; i++) {
  16. o[dimNames.name][r[i]] = true;
  17. }
  18. });
  19. return o;
  20. }
  21. describe('findLinkedNodes', function () {
  22. function forEachModel(models, callback) {
  23. for (var i = 0; i < models.length; i++) {
  24. callback(models[i]);
  25. }
  26. }
  27. function axisIndicesGetter(model, dimNames) {
  28. return model[dimNames.axisIndex];
  29. }
  30. it('findLinkedNodes_base', function (done) {
  31. var models = [
  32. {xAxisIndex: [1, 2], yAxisIndex: [0]},
  33. {xAxisIndex: [3], yAxisIndex: [1]},
  34. {xAxisIndex: [5], yAxisIndex: []},
  35. {xAxisIndex: [2, 5], yAxisIndex: []}
  36. ];
  37. var result = helper.createLinkedNodesFinder(
  38. utHelper.curry(forEachModel, models),
  39. helper.eachAxisDim,
  40. axisIndicesGetter
  41. )(models[0]);
  42. expect(result).toEqual({
  43. nodes: [models[0], models[3], models[2]],
  44. records: makeRecords({x: [1, 2, 5], y: [0]})
  45. });
  46. done();
  47. });
  48. it('findLinkedNodes_crossXY', function (done) {
  49. var models = [
  50. {xAxisIndex: [1, 2], yAxisIndex: [0]},
  51. {xAxisIndex: [3], yAxisIndex: [3, 0]},
  52. {xAxisIndex: [6, 3], yAxisIndex: [9]},
  53. {xAxisIndex: [5, 3], yAxisIndex: []},
  54. {xAxisIndex: [8], yAxisIndex: [4]}
  55. ];
  56. var result = helper.createLinkedNodesFinder(
  57. utHelper.curry(forEachModel, models),
  58. helper.eachAxisDim,
  59. axisIndicesGetter
  60. )(models[0]);
  61. expect(result).toEqual({
  62. nodes: [models[0], models[1], models[2], models[3]],
  63. records: makeRecords({x: [1, 2, 3, 5, 6], y: [0, 3, 9]})
  64. });
  65. done();
  66. });
  67. it('findLinkedNodes_emptySourceModel', function (done) {
  68. var models = [
  69. {xAxisIndex: [1, 2], yAxisIndex: [0]},
  70. {xAxisIndex: [3], yAxisIndex: [3, 0]},
  71. {xAxisIndex: [6, 3], yAxisIndex: [9]},
  72. {xAxisIndex: [5, 3], yAxisIndex: []},
  73. {xAxisIndex: [8], yAxisIndex: [4]}
  74. ];
  75. var result = helper.createLinkedNodesFinder(
  76. utHelper.curry(forEachModel, models),
  77. helper.eachAxisDim,
  78. axisIndicesGetter
  79. )();
  80. expect(result).toEqual({
  81. nodes: [],
  82. records: makeRecords({x: [], y: []})
  83. });
  84. done();
  85. });
  86. });
  87. });