BrushModel.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. /**
  20. * AUTO-GENERATED FILE. DO NOT MODIFY.
  21. */
  22. /*
  23. * Licensed to the Apache Software Foundation (ASF) under one
  24. * or more contributor license agreements. See the NOTICE file
  25. * distributed with this work for additional information
  26. * regarding copyright ownership. The ASF licenses this file
  27. * to you under the Apache License, Version 2.0 (the
  28. * "License"); you may not use this file except in compliance
  29. * with the License. You may obtain a copy of the License at
  30. *
  31. * http://www.apache.org/licenses/LICENSE-2.0
  32. *
  33. * Unless required by applicable law or agreed to in writing,
  34. * software distributed under the License is distributed on an
  35. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36. * KIND, either express or implied. See the License for the
  37. * specific language governing permissions and limitations
  38. * under the License.
  39. */
  40. import { __extends } from "tslib";
  41. import * as zrUtil from 'zrender/lib/core/util.js';
  42. import * as visualSolution from '../../visual/visualSolution.js';
  43. import Model from '../../model/Model.js';
  44. import ComponentModel from '../../model/Component.js';
  45. var DEFAULT_OUT_OF_BRUSH_COLOR = '#ddd';
  46. var BrushModel =
  47. /** @class */
  48. function (_super) {
  49. __extends(BrushModel, _super);
  50. function BrushModel() {
  51. var _this = _super !== null && _super.apply(this, arguments) || this;
  52. _this.type = BrushModel.type;
  53. /**
  54. * @readOnly
  55. */
  56. _this.areas = [];
  57. /**
  58. * Current brush painting area settings.
  59. * @readOnly
  60. */
  61. _this.brushOption = {};
  62. return _this;
  63. }
  64. BrushModel.prototype.optionUpdated = function (newOption, isInit) {
  65. var thisOption = this.option;
  66. !isInit && visualSolution.replaceVisualOption(thisOption, newOption, ['inBrush', 'outOfBrush']);
  67. var inBrush = thisOption.inBrush = thisOption.inBrush || {}; // Always give default visual, consider setOption at the second time.
  68. thisOption.outOfBrush = thisOption.outOfBrush || {
  69. color: DEFAULT_OUT_OF_BRUSH_COLOR
  70. };
  71. if (!inBrush.hasOwnProperty('liftZ')) {
  72. // Bigger than the highlight z lift, otherwise it will
  73. // be effected by the highlight z when brush.
  74. inBrush.liftZ = 5;
  75. }
  76. };
  77. /**
  78. * If `areas` is null/undefined, range state remain.
  79. */
  80. BrushModel.prototype.setAreas = function (areas) {
  81. if (process.env.NODE_ENV !== 'production') {
  82. zrUtil.assert(zrUtil.isArray(areas));
  83. zrUtil.each(areas, function (area) {
  84. zrUtil.assert(area.brushType, 'Illegal areas');
  85. });
  86. } // If areas is null/undefined, range state remain.
  87. // This helps user to dispatchAction({type: 'brush'}) with no areas
  88. // set but just want to get the current brush select info from a `brush` event.
  89. if (!areas) {
  90. return;
  91. }
  92. this.areas = zrUtil.map(areas, function (area) {
  93. return generateBrushOption(this.option, area);
  94. }, this);
  95. };
  96. /**
  97. * Set the current painting brush option.
  98. */
  99. BrushModel.prototype.setBrushOption = function (brushOption) {
  100. this.brushOption = generateBrushOption(this.option, brushOption);
  101. this.brushType = this.brushOption.brushType;
  102. };
  103. BrushModel.type = 'brush';
  104. BrushModel.dependencies = ['geo', 'grid', 'xAxis', 'yAxis', 'parallel', 'series'];
  105. BrushModel.defaultOption = {
  106. seriesIndex: 'all',
  107. brushType: 'rect',
  108. brushMode: 'single',
  109. transformable: true,
  110. brushStyle: {
  111. borderWidth: 1,
  112. color: 'rgba(210,219,238,0.3)',
  113. borderColor: '#D2DBEE'
  114. },
  115. throttleType: 'fixRate',
  116. throttleDelay: 0,
  117. removeOnClick: true,
  118. z: 10000
  119. };
  120. return BrushModel;
  121. }(ComponentModel);
  122. function generateBrushOption(option, brushOption) {
  123. return zrUtil.merge({
  124. brushType: option.brushType,
  125. brushMode: option.brushMode,
  126. transformable: option.transformable,
  127. brushStyle: new Model(option.brushStyle).getItemStyle(),
  128. removeOnClick: option.removeOnClick,
  129. z: option.z
  130. }, brushOption, true);
  131. }
  132. export default BrushModel;