BrushModel.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 = /** @class */function (_super) {
  47. __extends(BrushModel, _super);
  48. function BrushModel() {
  49. var _this = _super !== null && _super.apply(this, arguments) || this;
  50. _this.type = BrushModel.type;
  51. /**
  52. * @readOnly
  53. */
  54. _this.areas = [];
  55. /**
  56. * Current brush painting area settings.
  57. * @readOnly
  58. */
  59. _this.brushOption = {};
  60. return _this;
  61. }
  62. BrushModel.prototype.optionUpdated = function (newOption, isInit) {
  63. var thisOption = this.option;
  64. !isInit && visualSolution.replaceVisualOption(thisOption, newOption, ['inBrush', 'outOfBrush']);
  65. var inBrush = thisOption.inBrush = thisOption.inBrush || {};
  66. // Always give default visual, consider setOption at the second time.
  67. thisOption.outOfBrush = thisOption.outOfBrush || {
  68. color: DEFAULT_OUT_OF_BRUSH_COLOR
  69. };
  70. if (!inBrush.hasOwnProperty('liftZ')) {
  71. // Bigger than the highlight z lift, otherwise it will
  72. // be effected by the highlight z when brush.
  73. inBrush.liftZ = 5;
  74. }
  75. };
  76. /**
  77. * If `areas` is null/undefined, range state remain.
  78. */
  79. BrushModel.prototype.setAreas = function (areas) {
  80. if (process.env.NODE_ENV !== 'production') {
  81. zrUtil.assert(zrUtil.isArray(areas));
  82. zrUtil.each(areas, function (area) {
  83. zrUtil.assert(area.brushType, 'Illegal areas');
  84. });
  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;