AxisModel.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. var zrUtil = require("zrender/lib/core/util");
  2. var ComponentModel = require("../../model/Component");
  3. var makeStyleMapper = require("../../model/mixin/makeStyleMapper");
  4. var axisModelCreator = require("../axisModelCreator");
  5. var numberUtil = require("../../util/number");
  6. var axisModelCommonMixin = require("../axisModelCommonMixin");
  7. var AxisModel = ComponentModel.extend({
  8. type: 'baseParallelAxis',
  9. /**
  10. * @type {module:echarts/coord/parallel/Axis}
  11. */
  12. axis: null,
  13. /**
  14. * @type {Array.<Array.<number>}
  15. * @readOnly
  16. */
  17. activeIntervals: [],
  18. /**
  19. * @return {Object}
  20. */
  21. getAreaSelectStyle: function () {
  22. return makeStyleMapper([['fill', 'color'], ['lineWidth', 'borderWidth'], ['stroke', 'borderColor'], ['width', 'width'], ['opacity', 'opacity']])(this.getModel('areaSelectStyle'));
  23. },
  24. /**
  25. * The code of this feature is put on AxisModel but not ParallelAxis,
  26. * because axisModel can be alive after echarts updating but instance of
  27. * ParallelAxis having been disposed. this._activeInterval should be kept
  28. * when action dispatched (i.e. legend click).
  29. *
  30. * @param {Array.<Array<number>>} intervals interval.length === 0
  31. * means set all active.
  32. * @public
  33. */
  34. setActiveIntervals: function (intervals) {
  35. var activeIntervals = this.activeIntervals = zrUtil.clone(intervals); // Normalize
  36. if (activeIntervals) {
  37. for (var i = activeIntervals.length - 1; i >= 0; i--) {
  38. numberUtil.asc(activeIntervals[i]);
  39. }
  40. }
  41. },
  42. /**
  43. * @param {number|string} [value] When attempting to detect 'no activeIntervals set',
  44. * value can not be input.
  45. * @return {string} 'normal': no activeIntervals set,
  46. * 'active',
  47. * 'inactive'.
  48. * @public
  49. */
  50. getActiveState: function (value) {
  51. var activeIntervals = this.activeIntervals;
  52. if (!activeIntervals.length) {
  53. return 'normal';
  54. }
  55. if (value == null) {
  56. return 'inactive';
  57. }
  58. for (var i = 0, len = activeIntervals.length; i < len; i++) {
  59. if (activeIntervals[i][0] <= value && value <= activeIntervals[i][1]) {
  60. return 'active';
  61. }
  62. }
  63. return 'inactive';
  64. }
  65. });
  66. var defaultOption = {
  67. type: 'value',
  68. /**
  69. * @type {Array.<number>}
  70. */
  71. dim: null,
  72. // 0, 1, 2, ...
  73. // parallelIndex: null,
  74. areaSelectStyle: {
  75. width: 20,
  76. borderWidth: 1,
  77. borderColor: 'rgba(160,197,232)',
  78. color: 'rgba(160,197,232)',
  79. opacity: 0.3
  80. },
  81. realtime: true,
  82. // Whether realtime update view when select.
  83. z: 10
  84. };
  85. zrUtil.merge(AxisModel.prototype, axisModelCommonMixin);
  86. function getAxisType(axisName, option) {
  87. return option.type || (option.data ? 'category' : 'value');
  88. }
  89. axisModelCreator('parallel', AxisModel, getAxisType, defaultOption);
  90. var _default = AxisModel;
  91. module.exports = _default;