BrushModel.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. var _config = require("../../config");
  20. var __DEV__ = _config.__DEV__;
  21. var echarts = require("../../echarts");
  22. var zrUtil = require("zrender/lib/core/util");
  23. var visualSolution = require("../../visual/visualSolution");
  24. var Model = require("../../model/Model");
  25. /*
  26. * Licensed to the Apache Software Foundation (ASF) under one
  27. * or more contributor license agreements. See the NOTICE file
  28. * distributed with this work for additional information
  29. * regarding copyright ownership. The ASF licenses this file
  30. * to you under the Apache License, Version 2.0 (the
  31. * "License"); you may not use this file except in compliance
  32. * with the License. You may obtain a copy of the License at
  33. *
  34. * http://www.apache.org/licenses/LICENSE-2.0
  35. *
  36. * Unless required by applicable law or agreed to in writing,
  37. * software distributed under the License is distributed on an
  38. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  39. * KIND, either express or implied. See the License for the
  40. * specific language governing permissions and limitations
  41. * under the License.
  42. */
  43. var DEFAULT_OUT_OF_BRUSH_COLOR = ['#ddd'];
  44. var BrushModel = echarts.extendComponentModel({
  45. type: 'brush',
  46. dependencies: ['geo', 'grid', 'xAxis', 'yAxis', 'parallel', 'series'],
  47. /**
  48. * @protected
  49. */
  50. defaultOption: {
  51. // inBrush: null,
  52. // outOfBrush: null,
  53. toolbox: null,
  54. // Default value see preprocessor.
  55. brushLink: null,
  56. // Series indices array, broadcast using dataIndex.
  57. // or 'all', which means all series. 'none' or null means no series.
  58. seriesIndex: 'all',
  59. // seriesIndex array, specify series controlled by this brush component.
  60. geoIndex: null,
  61. //
  62. xAxisIndex: null,
  63. yAxisIndex: null,
  64. brushType: 'rect',
  65. // Default brushType, see BrushController.
  66. brushMode: 'single',
  67. // Default brushMode, 'single' or 'multiple'
  68. transformable: true,
  69. // Default transformable.
  70. brushStyle: {
  71. // Default brushStyle
  72. borderWidth: 1,
  73. color: 'rgba(120,140,180,0.3)',
  74. borderColor: 'rgba(120,140,180,0.8)'
  75. },
  76. throttleType: 'fixRate',
  77. // Throttle in brushSelected event. 'fixRate' or 'debounce'.
  78. // If null, no throttle. Valid only in the first brush component
  79. throttleDelay: 0,
  80. // Unit: ms, 0 means every event will be triggered.
  81. // FIXME
  82. // 试验效果
  83. removeOnClick: true,
  84. z: 10000
  85. },
  86. /**
  87. * @readOnly
  88. * @type {Array.<Object>}
  89. */
  90. areas: [],
  91. /**
  92. * Current activated brush type.
  93. * If null, brush is inactived.
  94. * see module:echarts/component/helper/BrushController
  95. * @readOnly
  96. * @type {string}
  97. */
  98. brushType: null,
  99. /**
  100. * Current brush opt.
  101. * see module:echarts/component/helper/BrushController
  102. * @readOnly
  103. * @type {Object}
  104. */
  105. brushOption: {},
  106. /**
  107. * @readOnly
  108. * @type {Array.<Object>}
  109. */
  110. coordInfoList: [],
  111. optionUpdated: function (newOption, isInit) {
  112. var thisOption = this.option;
  113. !isInit && visualSolution.replaceVisualOption(thisOption, newOption, ['inBrush', 'outOfBrush']);
  114. var inBrush = thisOption.inBrush = thisOption.inBrush || {}; // Always give default visual, consider setOption at the second time.
  115. thisOption.outOfBrush = thisOption.outOfBrush || {
  116. color: DEFAULT_OUT_OF_BRUSH_COLOR
  117. };
  118. if (!inBrush.hasOwnProperty('liftZ')) {
  119. // Bigger than the highlight z lift, otherwise it will
  120. // be effected by the highlight z when brush.
  121. inBrush.liftZ = 5;
  122. }
  123. },
  124. /**
  125. * If ranges is null/undefined, range state remain.
  126. *
  127. * @param {Array.<Object>} [ranges]
  128. */
  129. setAreas: function (areas) {
  130. // If ranges is null/undefined, range state remain.
  131. // This helps user to dispatchAction({type: 'brush'}) with no areas
  132. // set but just want to get the current brush select info from a `brush` event.
  133. if (!areas) {
  134. return;
  135. }
  136. this.areas = zrUtil.map(areas, function (area) {
  137. return generateBrushOption(this.option, area);
  138. }, this);
  139. },
  140. /**
  141. * see module:echarts/component/helper/BrushController
  142. * @param {Object} brushOption
  143. */
  144. setBrushOption: function (brushOption) {
  145. this.brushOption = generateBrushOption(this.option, brushOption);
  146. this.brushType = this.brushOption.brushType;
  147. }
  148. });
  149. function generateBrushOption(option, brushOption) {
  150. return zrUtil.merge({
  151. brushType: option.brushType,
  152. brushMode: option.brushMode,
  153. transformable: option.transformable,
  154. brushStyle: new Model(option.brushStyle).getItemStyle(),
  155. removeOnClick: option.removeOnClick,
  156. z: option.z
  157. }, brushOption, true);
  158. }
  159. var _default = BrushModel;
  160. module.exports = _default;