VisualMapView.js 5.3 KB

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