BrushModel.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. var _config = require("../../config");
  2. var __DEV__ = _config.__DEV__;
  3. var echarts = require("../../echarts");
  4. var zrUtil = require("zrender/lib/core/util");
  5. var visualSolution = require("../../visual/visualSolution");
  6. var Model = require("../../model/Model");
  7. var DEFAULT_OUT_OF_BRUSH_COLOR = ['#ddd'];
  8. var BrushModel = echarts.extendComponentModel({
  9. type: 'brush',
  10. dependencies: ['geo', 'grid', 'xAxis', 'yAxis', 'parallel', 'series'],
  11. /**
  12. * @protected
  13. */
  14. defaultOption: {
  15. // inBrush: null,
  16. // outOfBrush: null,
  17. toolbox: null,
  18. // Default value see preprocessor.
  19. brushLink: null,
  20. // Series indices array, broadcast using dataIndex.
  21. // or 'all', which means all series. 'none' or null means no series.
  22. seriesIndex: 'all',
  23. // seriesIndex array, specify series controlled by this brush component.
  24. geoIndex: null,
  25. //
  26. xAxisIndex: null,
  27. yAxisIndex: null,
  28. brushType: 'rect',
  29. // Default brushType, see BrushController.
  30. brushMode: 'single',
  31. // Default brushMode, 'single' or 'multiple'
  32. transformable: true,
  33. // Default transformable.
  34. brushStyle: {
  35. // Default brushStyle
  36. borderWidth: 1,
  37. color: 'rgba(120,140,180,0.3)',
  38. borderColor: 'rgba(120,140,180,0.8)'
  39. },
  40. throttleType: 'fixRate',
  41. // Throttle in brushSelected event. 'fixRate' or 'debounce'.
  42. // If null, no throttle. Valid only in the first brush component
  43. throttleDelay: 0,
  44. // Unit: ms, 0 means every event will be triggered.
  45. // FIXME
  46. // 试验效果
  47. removeOnClick: true,
  48. z: 10000
  49. },
  50. /**
  51. * @readOnly
  52. * @type {Array.<Object>}
  53. */
  54. areas: [],
  55. /**
  56. * Current activated brush type.
  57. * If null, brush is inactived.
  58. * see module:echarts/component/helper/BrushController
  59. * @readOnly
  60. * @type {string}
  61. */
  62. brushType: null,
  63. /**
  64. * Current brush opt.
  65. * see module:echarts/component/helper/BrushController
  66. * @readOnly
  67. * @type {Object}
  68. */
  69. brushOption: {},
  70. /**
  71. * @readOnly
  72. * @type {Array.<Object>}
  73. */
  74. coordInfoList: [],
  75. optionUpdated: function (newOption, isInit) {
  76. var thisOption = this.option;
  77. !isInit && visualSolution.replaceVisualOption(thisOption, newOption, ['inBrush', 'outOfBrush']);
  78. thisOption.inBrush = thisOption.inBrush || {}; // Always give default visual, consider setOption at the second time.
  79. thisOption.outOfBrush = thisOption.outOfBrush || {
  80. color: DEFAULT_OUT_OF_BRUSH_COLOR
  81. };
  82. },
  83. /**
  84. * If ranges is null/undefined, range state remain.
  85. *
  86. * @param {Array.<Object>} [ranges]
  87. */
  88. setAreas: function (areas) {
  89. // If ranges is null/undefined, range state remain.
  90. // This helps user to dispatchAction({type: 'brush'}) with no areas
  91. // set but just want to get the current brush select info from a `brush` event.
  92. if (!areas) {
  93. return;
  94. }
  95. this.areas = zrUtil.map(areas, function (area) {
  96. return generateBrushOption(this.option, area);
  97. }, this);
  98. },
  99. /**
  100. * see module:echarts/component/helper/BrushController
  101. * @param {Object} brushOption
  102. */
  103. setBrushOption: function (brushOption) {
  104. this.brushOption = generateBrushOption(this.option, brushOption);
  105. this.brushType = this.brushOption.brushType;
  106. }
  107. });
  108. function generateBrushOption(option, brushOption) {
  109. return zrUtil.merge({
  110. brushType: option.brushType,
  111. brushMode: option.brushMode,
  112. transformable: option.transformable,
  113. brushStyle: new Model(option.brushStyle).getItemStyle(),
  114. removeOnClick: option.removeOnClick,
  115. z: option.z
  116. }, brushOption, true);
  117. }
  118. var _default = BrushModel;
  119. module.exports = _default;