Brush.js 5.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. var zrUtil = require("zrender/lib/core/util");
  20. var featureManager = require("../featureManager");
  21. var lang = require("../../../lang");
  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. var brushLang = lang.toolbox.brush;
  41. function Brush(model, ecModel, api) {
  42. this.model = model;
  43. this.ecModel = ecModel;
  44. this.api = api;
  45. /**
  46. * @private
  47. * @type {string}
  48. */
  49. this._brushType;
  50. /**
  51. * @private
  52. * @type {string}
  53. */
  54. this._brushMode;
  55. }
  56. Brush.defaultOption = {
  57. show: true,
  58. type: ['rect', 'polygon', 'lineX', 'lineY', 'keep', 'clear'],
  59. icon: {
  60. /* eslint-disable */
  61. rect: 'M7.3,34.7 M0.4,10V-0.2h9.8 M89.6,10V-0.2h-9.8 M0.4,60v10.2h9.8 M89.6,60v10.2h-9.8 M12.3,22.4V10.5h13.1 M33.6,10.5h7.8 M49.1,10.5h7.8 M77.5,22.4V10.5h-13 M12.3,31.1v8.2 M77.7,31.1v8.2 M12.3,47.6v11.9h13.1 M33.6,59.5h7.6 M49.1,59.5 h7.7 M77.5,47.6v11.9h-13',
  62. // jshint ignore:line
  63. polygon: 'M55.2,34.9c1.7,0,3.1,1.4,3.1,3.1s-1.4,3.1-3.1,3.1 s-3.1-1.4-3.1-3.1S53.5,34.9,55.2,34.9z M50.4,51c1.7,0,3.1,1.4,3.1,3.1c0,1.7-1.4,3.1-3.1,3.1c-1.7,0-3.1-1.4-3.1-3.1 C47.3,52.4,48.7,51,50.4,51z M55.6,37.1l1.5-7.8 M60.1,13.5l1.6-8.7l-7.8,4 M59,19l-1,5.3 M24,16.1l6.4,4.9l6.4-3.3 M48.5,11.6 l-5.9,3.1 M19.1,12.8L9.7,5.1l1.1,7.7 M13.4,29.8l1,7.3l6.6,1.6 M11.6,18.4l1,6.1 M32.8,41.9 M26.6,40.4 M27.3,40.2l6.1,1.6 M49.9,52.1l-5.6-7.6l-4.9-1.2',
  64. // jshint ignore:line
  65. lineX: 'M15.2,30 M19.7,15.6V1.9H29 M34.8,1.9H40.4 M55.3,15.6V1.9H45.9 M19.7,44.4V58.1H29 M34.8,58.1H40.4 M55.3,44.4 V58.1H45.9 M12.5,20.3l-9.4,9.6l9.6,9.8 M3.1,29.9h16.5 M62.5,20.3l9.4,9.6L62.3,39.7 M71.9,29.9H55.4',
  66. // jshint ignore:line
  67. lineY: 'M38.8,7.7 M52.7,12h13.2v9 M65.9,26.6V32 M52.7,46.3h13.2v-9 M24.9,12H11.8v9 M11.8,26.6V32 M24.9,46.3H11.8v-9 M48.2,5.1l-9.3-9l-9.4,9.2 M38.9-3.9V12 M48.2,53.3l-9.3,9l-9.4-9.2 M38.9,62.3V46.4',
  68. // jshint ignore:line
  69. keep: 'M4,10.5V1h10.3 M20.7,1h6.1 M33,1h6.1 M55.4,10.5V1H45.2 M4,17.3v6.6 M55.6,17.3v6.6 M4,30.5V40h10.3 M20.7,40 h6.1 M33,40h6.1 M55.4,30.5V40H45.2 M21,18.9h62.9v48.6H21V18.9z',
  70. // jshint ignore:line
  71. clear: 'M22,14.7l30.9,31 M52.9,14.7L22,45.7 M4.7,16.8V4.2h13.1 M26,4.2h7.8 M41.6,4.2h7.8 M70.3,16.8V4.2H57.2 M4.7,25.9v8.6 M70.3,25.9v8.6 M4.7,43.2v12.6h13.1 M26,55.8h7.8 M41.6,55.8h7.8 M70.3,43.2v12.6H57.2' // jshint ignore:line
  72. /* eslint-enable */
  73. },
  74. // `rect`, `polygon`, `lineX`, `lineY`, `keep`, `clear`
  75. title: zrUtil.clone(brushLang.title)
  76. };
  77. var proto = Brush.prototype; // proto.updateLayout = function (featureModel, ecModel, api) {
  78. /* eslint-disable */
  79. proto.render =
  80. /* eslint-enable */
  81. proto.updateView = function (featureModel, ecModel, api) {
  82. var brushType;
  83. var brushMode;
  84. var isBrushed;
  85. ecModel.eachComponent({
  86. mainType: 'brush'
  87. }, function (brushModel) {
  88. brushType = brushModel.brushType;
  89. brushMode = brushModel.brushOption.brushMode || 'single';
  90. isBrushed |= brushModel.areas.length;
  91. });
  92. this._brushType = brushType;
  93. this._brushMode = brushMode;
  94. zrUtil.each(featureModel.get('type', true), function (type) {
  95. featureModel.setIconStatus(type, (type === 'keep' ? brushMode === 'multiple' : type === 'clear' ? isBrushed : type === brushType) ? 'emphasis' : 'normal');
  96. });
  97. };
  98. proto.getIcons = function () {
  99. var model = this.model;
  100. var availableIcons = model.get('icon', true);
  101. var icons = {};
  102. zrUtil.each(model.get('type', true), function (type) {
  103. if (availableIcons[type]) {
  104. icons[type] = availableIcons[type];
  105. }
  106. });
  107. return icons;
  108. };
  109. proto.onclick = function (ecModel, api, type) {
  110. var brushType = this._brushType;
  111. var brushMode = this._brushMode;
  112. if (type === 'clear') {
  113. // Trigger parallel action firstly
  114. api.dispatchAction({
  115. type: 'axisAreaSelect',
  116. intervals: []
  117. });
  118. api.dispatchAction({
  119. type: 'brush',
  120. command: 'clear',
  121. // Clear all areas of all brush components.
  122. areas: []
  123. });
  124. } else {
  125. api.dispatchAction({
  126. type: 'takeGlobalCursor',
  127. key: 'brush',
  128. brushOption: {
  129. brushType: type === 'keep' ? brushType : brushType === type ? false : type,
  130. brushMode: type === 'keep' ? brushMode === 'multiple' ? 'single' : 'multiple' : brushMode
  131. }
  132. });
  133. }
  134. };
  135. featureManager.register('brush', Brush);
  136. var _default = Brush;
  137. module.exports = _default;