BoxplotView.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 ChartView from '../../view/Chart.js';
  43. import * as graphic from '../../util/graphic.js';
  44. import { setStatesStylesFromModel, toggleHoverEmphasis } from '../../util/states.js';
  45. import Path from 'zrender/lib/graphic/Path.js';
  46. import { saveOldStyle } from '../../animation/basicTransition.js';
  47. var BoxplotView = /** @class */function (_super) {
  48. __extends(BoxplotView, _super);
  49. function BoxplotView() {
  50. var _this = _super !== null && _super.apply(this, arguments) || this;
  51. _this.type = BoxplotView.type;
  52. return _this;
  53. }
  54. BoxplotView.prototype.render = function (seriesModel, ecModel, api) {
  55. var data = seriesModel.getData();
  56. var group = this.group;
  57. var oldData = this._data;
  58. // There is no old data only when first rendering or switching from
  59. // stream mode to normal mode, where previous elements should be removed.
  60. if (!this._data) {
  61. group.removeAll();
  62. }
  63. var constDim = seriesModel.get('layout') === 'horizontal' ? 1 : 0;
  64. data.diff(oldData).add(function (newIdx) {
  65. if (data.hasValue(newIdx)) {
  66. var itemLayout = data.getItemLayout(newIdx);
  67. var symbolEl = createNormalBox(itemLayout, data, newIdx, constDim, true);
  68. data.setItemGraphicEl(newIdx, symbolEl);
  69. group.add(symbolEl);
  70. }
  71. }).update(function (newIdx, oldIdx) {
  72. var symbolEl = oldData.getItemGraphicEl(oldIdx);
  73. // Empty data
  74. if (!data.hasValue(newIdx)) {
  75. group.remove(symbolEl);
  76. return;
  77. }
  78. var itemLayout = data.getItemLayout(newIdx);
  79. if (!symbolEl) {
  80. symbolEl = createNormalBox(itemLayout, data, newIdx, constDim);
  81. } else {
  82. saveOldStyle(symbolEl);
  83. updateNormalBoxData(itemLayout, symbolEl, data, newIdx);
  84. }
  85. group.add(symbolEl);
  86. data.setItemGraphicEl(newIdx, symbolEl);
  87. }).remove(function (oldIdx) {
  88. var el = oldData.getItemGraphicEl(oldIdx);
  89. el && group.remove(el);
  90. }).execute();
  91. this._data = data;
  92. };
  93. BoxplotView.prototype.remove = function (ecModel) {
  94. var group = this.group;
  95. var data = this._data;
  96. this._data = null;
  97. data && data.eachItemGraphicEl(function (el) {
  98. el && group.remove(el);
  99. });
  100. };
  101. BoxplotView.type = 'boxplot';
  102. return BoxplotView;
  103. }(ChartView);
  104. var BoxPathShape = /** @class */function () {
  105. function BoxPathShape() {}
  106. return BoxPathShape;
  107. }();
  108. var BoxPath = /** @class */function (_super) {
  109. __extends(BoxPath, _super);
  110. function BoxPath(opts) {
  111. var _this = _super.call(this, opts) || this;
  112. _this.type = 'boxplotBoxPath';
  113. return _this;
  114. }
  115. BoxPath.prototype.getDefaultShape = function () {
  116. return new BoxPathShape();
  117. };
  118. BoxPath.prototype.buildPath = function (ctx, shape) {
  119. var ends = shape.points;
  120. var i = 0;
  121. ctx.moveTo(ends[i][0], ends[i][1]);
  122. i++;
  123. for (; i < 4; i++) {
  124. ctx.lineTo(ends[i][0], ends[i][1]);
  125. }
  126. ctx.closePath();
  127. for (; i < ends.length; i++) {
  128. ctx.moveTo(ends[i][0], ends[i][1]);
  129. i++;
  130. ctx.lineTo(ends[i][0], ends[i][1]);
  131. }
  132. };
  133. return BoxPath;
  134. }(Path);
  135. function createNormalBox(itemLayout, data, dataIndex, constDim, isInit) {
  136. var ends = itemLayout.ends;
  137. var el = new BoxPath({
  138. shape: {
  139. points: isInit ? transInit(ends, constDim, itemLayout) : ends
  140. }
  141. });
  142. updateNormalBoxData(itemLayout, el, data, dataIndex, isInit);
  143. return el;
  144. }
  145. function updateNormalBoxData(itemLayout, el, data, dataIndex, isInit) {
  146. var seriesModel = data.hostModel;
  147. var updateMethod = graphic[isInit ? 'initProps' : 'updateProps'];
  148. updateMethod(el, {
  149. shape: {
  150. points: itemLayout.ends
  151. }
  152. }, seriesModel, dataIndex);
  153. el.useStyle(data.getItemVisual(dataIndex, 'style'));
  154. el.style.strokeNoScale = true;
  155. el.z2 = 100;
  156. var itemModel = data.getItemModel(dataIndex);
  157. var emphasisModel = itemModel.getModel('emphasis');
  158. setStatesStylesFromModel(el, itemModel);
  159. toggleHoverEmphasis(el, emphasisModel.get('focus'), emphasisModel.get('blurScope'), emphasisModel.get('disabled'));
  160. }
  161. function transInit(points, dim, itemLayout) {
  162. return zrUtil.map(points, function (point) {
  163. point = point.slice();
  164. point[dim] = itemLayout.initBaseline;
  165. return point;
  166. });
  167. }
  168. export default BoxplotView;