model.js 3.2 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('findLinkedNodes', function () {
  24. function forEachModel(models, callback) {
  25. for (var i = 0; i < models.length; i++) {
  26. callback(models[i]);
  27. }
  28. }
  29. function axisIndicesGetter(model, dimNames) {
  30. return model[dimNames.axisIndex];
  31. }
  32. it('findLinkedNodes_base', function (done) {
  33. var models = [
  34. {xAxisIndex: [1, 2], yAxisIndex: [0]},
  35. {xAxisIndex: [3], yAxisIndex: [1]},
  36. {xAxisIndex: [5], yAxisIndex: []},
  37. {xAxisIndex: [2, 5], yAxisIndex: []}
  38. ];
  39. var result = modelUtil.createLinkedNodesFinder(
  40. utHelper.curry(forEachModel, models),
  41. modelUtil.eachAxisDim,
  42. axisIndicesGetter
  43. )(models[0]);
  44. expect(result).toEqual({
  45. nodes: [models[0], models[3], models[2]],
  46. records: makeRecords({x: [1, 2, 5], y: [0]})
  47. });
  48. done();
  49. });
  50. it('findLinkedNodes_crossXY', function (done) {
  51. var models = [
  52. {xAxisIndex: [1, 2], yAxisIndex: [0]},
  53. {xAxisIndex: [3], yAxisIndex: [3, 0]},
  54. {xAxisIndex: [6, 3], yAxisIndex: [9]},
  55. {xAxisIndex: [5, 3], yAxisIndex: []},
  56. {xAxisIndex: [8], yAxisIndex: [4]}
  57. ];
  58. var result = modelUtil.createLinkedNodesFinder(
  59. utHelper.curry(forEachModel, models),
  60. modelUtil.eachAxisDim,
  61. axisIndicesGetter
  62. )(models[0]);
  63. expect(result).toEqual({
  64. nodes: [models[0], models[1], models[2], models[3]],
  65. records: makeRecords({x: [1, 2, 3, 5, 6], y: [0, 3, 9]})
  66. });
  67. done();
  68. });
  69. it('findLinkedNodes_emptySourceModel', function (done) {
  70. var models = [
  71. {xAxisIndex: [1, 2], yAxisIndex: [0]},
  72. {xAxisIndex: [3], yAxisIndex: [3, 0]},
  73. {xAxisIndex: [6, 3], yAxisIndex: [9]},
  74. {xAxisIndex: [5, 3], yAxisIndex: []},
  75. {xAxisIndex: [8], yAxisIndex: [4]}
  76. ];
  77. var result = modelUtil.createLinkedNodesFinder(
  78. utHelper.curry(forEachModel, models),
  79. modelUtil.eachAxisDim,
  80. axisIndicesGetter
  81. )();
  82. expect(result).toEqual({
  83. nodes: [],
  84. records: makeRecords({x: [], y: []})
  85. });
  86. done();
  87. });
  88. });
  89. });