BoxplotView.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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 ChartView from '../../view/Chart.js';
  42. import * as graphic from '../../util/graphic.js';
  43. import { setStatesStylesFromModel, toggleHoverEmphasis } from '../../util/states.js';
  44. import Path from 'zrender/lib/graphic/Path.js';
  45. import { SERIES_TYPE_BOXPLOT } from './BoxplotSeries.js';
  46. import { saveOldStyle } from '../../animation/basicTransition.js';
  47. import { resolveNormalBoxClipping } from '../helper/whiskerBoxCommon.js';
  48. import { createClipPath, SHAPE_CLIP_KIND_FULLY_CLIPPED, SHAPE_CLIP_KIND_NOT_CLIPPED, SHAPE_CLIP_KIND_PARTIALLY_CLIPPED, updateClipPath } from '../helper/createClipPathFromCoordSys.js';
  49. import { map } from 'zrender/lib/core/util.js';
  50. var BoxplotView = /** @class */function (_super) {
  51. __extends(BoxplotView, _super);
  52. function BoxplotView() {
  53. var _this = _super !== null && _super.apply(this, arguments) || this;
  54. _this.type = SERIES_TYPE_BOXPLOT;
  55. return _this;
  56. }
  57. BoxplotView.prototype.render = function (seriesModel, ecModel, api) {
  58. var data = seriesModel.getData();
  59. var group = this.group;
  60. var oldData = this._data;
  61. // There is no old data only when first rendering or switching from
  62. // stream mode to normal mode, where previous elements should be removed.
  63. if (!this._data) {
  64. group.removeAll();
  65. }
  66. var constDim = seriesModel.getWhiskerBoxesLayout() === 'horizontal' ? 1 : 0;
  67. var needClip = seriesModel.get('clip', true);
  68. var coordSys = seriesModel.coordinateSystem;
  69. var clipArea = coordSys.getArea && coordSys.getArea();
  70. var clipPath = needClip && createClipPath(coordSys, false, seriesModel);
  71. data.diff(oldData).add(function (newIdx) {
  72. if (data.hasValue(newIdx)) {
  73. var itemLayout = data.getItemLayout(newIdx);
  74. var clipKind = needClip ? resolveNormalBoxClipping(clipArea, itemLayout) : SHAPE_CLIP_KIND_NOT_CLIPPED;
  75. if (clipKind === SHAPE_CLIP_KIND_FULLY_CLIPPED) {
  76. return;
  77. }
  78. var symbolEl = createNormalBox(itemLayout, data, newIdx, constDim, true);
  79. // One axis tick can corresponds to a group of box items (from different series),
  80. // so it may be visually misleading when a group of items are partially outside
  81. // but no clipping is applied.
  82. // Consider performance of zr Element['clipPath'], only set to partially clipped elements.
  83. updateClipPath(clipKind === SHAPE_CLIP_KIND_PARTIALLY_CLIPPED, symbolEl, clipPath);
  84. data.setItemGraphicEl(newIdx, symbolEl);
  85. group.add(symbolEl);
  86. }
  87. }).update(function (newIdx, oldIdx) {
  88. var symbolEl = oldData.getItemGraphicEl(oldIdx);
  89. // Empty data
  90. if (!data.hasValue(newIdx)) {
  91. group.remove(symbolEl);
  92. return;
  93. }
  94. var itemLayout = data.getItemLayout(newIdx);
  95. var clipKind = needClip ? resolveNormalBoxClipping(clipArea, itemLayout) : SHAPE_CLIP_KIND_NOT_CLIPPED;
  96. if (clipKind === SHAPE_CLIP_KIND_FULLY_CLIPPED) {
  97. group.remove(symbolEl);
  98. return;
  99. }
  100. if (!symbolEl) {
  101. symbolEl = createNormalBox(itemLayout, data, newIdx, constDim);
  102. } else {
  103. saveOldStyle(symbolEl);
  104. updateNormalBoxData(itemLayout, symbolEl, data, newIdx);
  105. }
  106. // See `updateClipPath` in `add`.
  107. updateClipPath(clipKind === SHAPE_CLIP_KIND_PARTIALLY_CLIPPED, symbolEl, clipPath);
  108. group.add(symbolEl);
  109. data.setItemGraphicEl(newIdx, symbolEl);
  110. }).remove(function (oldIdx) {
  111. var el = oldData.getItemGraphicEl(oldIdx);
  112. el && group.remove(el);
  113. }).execute();
  114. this._data = data;
  115. };
  116. BoxplotView.prototype.remove = function (ecModel) {
  117. var group = this.group;
  118. var data = this._data;
  119. this._data = null;
  120. data && data.eachItemGraphicEl(function (el) {
  121. el && group.remove(el);
  122. });
  123. };
  124. BoxplotView.type = SERIES_TYPE_BOXPLOT;
  125. return BoxplotView;
  126. }(ChartView);
  127. var BoxPathShape = /** @class */function () {
  128. function BoxPathShape() {}
  129. return BoxPathShape;
  130. }();
  131. var BoxPath = /** @class */function (_super) {
  132. __extends(BoxPath, _super);
  133. function BoxPath(opts) {
  134. var _this = _super.call(this, opts) || this;
  135. _this.type = 'boxplotBoxPath';
  136. return _this;
  137. }
  138. BoxPath.prototype.getDefaultShape = function () {
  139. return new BoxPathShape();
  140. };
  141. BoxPath.prototype.buildPath = function (ctx, shape) {
  142. var ends = shape.points;
  143. var i = 0;
  144. ctx.moveTo(ends[i][0], ends[i][1]);
  145. i++;
  146. for (; i < 4; i++) {
  147. ctx.lineTo(ends[i][0], ends[i][1]);
  148. }
  149. ctx.closePath();
  150. for (; i < ends.length; i++) {
  151. ctx.moveTo(ends[i][0], ends[i][1]);
  152. i++;
  153. ctx.lineTo(ends[i][0], ends[i][1]);
  154. }
  155. };
  156. return BoxPath;
  157. }(Path);
  158. function createNormalBox(itemLayout, data, dataIndex, constDim, isInit) {
  159. var ends = itemLayout.ends;
  160. var el = new BoxPath({
  161. shape: {
  162. points: isInit ? transInit(ends, constDim, itemLayout) : ends
  163. }
  164. });
  165. updateNormalBoxData(itemLayout, el, data, dataIndex, isInit);
  166. return el;
  167. }
  168. function updateNormalBoxData(itemLayout, el, data, dataIndex, isInit) {
  169. var seriesModel = data.hostModel;
  170. var updateMethod = graphic[isInit ? 'initProps' : 'updateProps'];
  171. updateMethod(el, {
  172. shape: {
  173. points: itemLayout.ends
  174. }
  175. }, seriesModel, dataIndex);
  176. el.useStyle(data.getItemVisual(dataIndex, 'style'));
  177. el.style.strokeNoScale = true;
  178. el.z2 = 100;
  179. var itemModel = data.getItemModel(dataIndex);
  180. var emphasisModel = itemModel.getModel('emphasis');
  181. setStatesStylesFromModel(el, itemModel);
  182. toggleHoverEmphasis(el, emphasisModel.get('focus'), emphasisModel.get('blurScope'), emphasisModel.get('disabled'));
  183. }
  184. function transInit(points, dim, itemLayout) {
  185. return map(points, function (point) {
  186. point = point.slice();
  187. point[dim] = itemLayout.initBaseline;
  188. return point;
  189. });
  190. }
  191. export default BoxplotView;