BoxplotView.js 5.9 KB

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