VisualMapView.js 5.3 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 { Rect } from '../../util/graphic.js';
  43. import * as formatUtil from '../../util/format.js';
  44. import * as layout from '../../util/layout.js';
  45. import VisualMapping from '../../visual/VisualMapping.js';
  46. import ComponentView from '../../view/Component.js';
  47. var VisualMapView = /** @class */function (_super) {
  48. __extends(VisualMapView, _super);
  49. function VisualMapView() {
  50. var _this = _super !== null && _super.apply(this, arguments) || this;
  51. _this.type = VisualMapView.type;
  52. _this.autoPositionValues = {
  53. left: 1,
  54. right: 1,
  55. top: 1,
  56. bottom: 1
  57. };
  58. return _this;
  59. }
  60. VisualMapView.prototype.init = function (ecModel, api) {
  61. this.ecModel = ecModel;
  62. this.api = api;
  63. };
  64. /**
  65. * @protected
  66. */
  67. VisualMapView.prototype.render = function (visualMapModel, ecModel, api, payload // TODO: TYPE
  68. ) {
  69. this.visualMapModel = visualMapModel;
  70. if (visualMapModel.get('show') === false) {
  71. this.group.removeAll();
  72. return;
  73. }
  74. this.doRender(visualMapModel, ecModel, api, payload);
  75. };
  76. /**
  77. * @protected
  78. */
  79. VisualMapView.prototype.renderBackground = function (group) {
  80. var visualMapModel = this.visualMapModel;
  81. var padding = formatUtil.normalizeCssArray(visualMapModel.get('padding') || 0);
  82. var rect = group.getBoundingRect();
  83. group.add(new Rect({
  84. z2: -1,
  85. silent: true,
  86. shape: {
  87. x: rect.x - padding[3],
  88. y: rect.y - padding[0],
  89. width: rect.width + padding[3] + padding[1],
  90. height: rect.height + padding[0] + padding[2]
  91. },
  92. style: {
  93. fill: visualMapModel.get('backgroundColor'),
  94. stroke: visualMapModel.get('borderColor'),
  95. lineWidth: visualMapModel.get('borderWidth')
  96. }
  97. }));
  98. };
  99. /**
  100. * @protected
  101. * @param targetValue can be Infinity or -Infinity
  102. * @param visualCluster Only can be 'color' 'opacity' 'symbol' 'symbolSize'
  103. * @param opts
  104. * @param opts.forceState Specify state, instead of using getValueState method.
  105. * @param opts.convertOpacityToAlpha For color gradient in controller widget.
  106. * @return {*} Visual value.
  107. */
  108. VisualMapView.prototype.getControllerVisual = function (targetValue, visualCluster, opts) {
  109. opts = opts || {};
  110. var forceState = opts.forceState;
  111. var visualMapModel = this.visualMapModel;
  112. var visualObj = {};
  113. // Default values.
  114. if (visualCluster === 'color') {
  115. var defaultColor = visualMapModel.get('contentColor');
  116. visualObj.color = defaultColor;
  117. }
  118. function getter(key) {
  119. return visualObj[key];
  120. }
  121. function setter(key, value) {
  122. visualObj[key] = value;
  123. }
  124. var mappings = visualMapModel.controllerVisuals[forceState || visualMapModel.getValueState(targetValue)];
  125. var visualTypes = VisualMapping.prepareVisualTypes(mappings);
  126. zrUtil.each(visualTypes, function (type) {
  127. var visualMapping = mappings[type];
  128. if (opts.convertOpacityToAlpha && type === 'opacity') {
  129. type = 'colorAlpha';
  130. visualMapping = mappings.__alphaForOpacity;
  131. }
  132. if (VisualMapping.dependsOn(type, visualCluster)) {
  133. visualMapping && visualMapping.applyVisual(targetValue, getter, setter);
  134. }
  135. });
  136. return visualObj[visualCluster];
  137. };
  138. VisualMapView.prototype.positionGroup = function (group) {
  139. var model = this.visualMapModel;
  140. var api = this.api;
  141. layout.positionElement(group, model.getBoxLayoutParams(), {
  142. width: api.getWidth(),
  143. height: api.getHeight()
  144. });
  145. };
  146. VisualMapView.prototype.doRender = function (visualMapModel, ecModel, api, payload) {};
  147. VisualMapView.type = 'visualMap';
  148. return VisualMapView;
  149. }(ComponentView);
  150. export default VisualMapView;