LinesView.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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 LineDraw from '../helper/LineDraw.js';
  42. import EffectLine from '../helper/EffectLine.js';
  43. import Line from '../helper/Line.js';
  44. import Polyline from '../helper/Polyline.js';
  45. import EffectPolyline from '../helper/EffectPolyline.js';
  46. import LargeLineDraw from '../helper/LargeLineDraw.js';
  47. import linesLayout from './linesLayout.js';
  48. import { createClipPath } from '../helper/createClipPathFromCoordSys.js';
  49. import ChartView from '../../view/Chart.js';
  50. var LinesView = /** @class */function (_super) {
  51. __extends(LinesView, _super);
  52. function LinesView() {
  53. var _this = _super !== null && _super.apply(this, arguments) || this;
  54. _this.type = LinesView.type;
  55. return _this;
  56. }
  57. LinesView.prototype.render = function (seriesModel, ecModel, api) {
  58. var data = seriesModel.getData();
  59. var lineDraw = this._updateLineDraw(data, seriesModel);
  60. var zlevel = seriesModel.get('zlevel');
  61. var trailLength = seriesModel.get(['effect', 'trailLength']);
  62. var zr = api.getZr();
  63. // Avoid the drag cause ghost shadow
  64. // FIXME Better way ?
  65. // SVG doesn't support
  66. var isSvg = zr.painter.getType() === 'svg';
  67. if (!isSvg) {
  68. zr.painter.getLayer(zlevel).clear(true);
  69. }
  70. // Config layer with motion blur
  71. if (this._lastZlevel != null && !isSvg) {
  72. zr.configLayer(this._lastZlevel, {
  73. motionBlur: false
  74. });
  75. }
  76. if (this._showEffect(seriesModel) && trailLength > 0) {
  77. if (!isSvg) {
  78. zr.configLayer(zlevel, {
  79. motionBlur: true,
  80. lastFrameAlpha: Math.max(Math.min(trailLength / 10 + 0.9, 1), 0)
  81. });
  82. } else if (process.env.NODE_ENV !== 'production') {
  83. console.warn('SVG render mode doesn\'t support lines with trail effect');
  84. }
  85. }
  86. lineDraw.updateData(data);
  87. var clipPath = seriesModel.get('clip', true) && createClipPath(seriesModel.coordinateSystem, false, seriesModel);
  88. if (clipPath) {
  89. this.group.setClipPath(clipPath);
  90. } else {
  91. this.group.removeClipPath();
  92. }
  93. this._lastZlevel = zlevel;
  94. this._finished = true;
  95. };
  96. LinesView.prototype.incrementalPrepareRender = function (seriesModel, ecModel, api) {
  97. var data = seriesModel.getData();
  98. var lineDraw = this._updateLineDraw(data, seriesModel);
  99. lineDraw.incrementalPrepareUpdate(data);
  100. this._clearLayer(api);
  101. this._finished = false;
  102. };
  103. LinesView.prototype.incrementalRender = function (taskParams, seriesModel, ecModel) {
  104. this._lineDraw.incrementalUpdate(taskParams, seriesModel.getData());
  105. this._finished = taskParams.end === seriesModel.getData().count();
  106. };
  107. LinesView.prototype.eachRendered = function (cb) {
  108. this._lineDraw && this._lineDraw.eachRendered(cb);
  109. };
  110. LinesView.prototype.updateTransform = function (seriesModel, ecModel, api) {
  111. var data = seriesModel.getData();
  112. var pipelineContext = seriesModel.pipelineContext;
  113. if (!this._finished || pipelineContext.large || pipelineContext.progressiveRender) {
  114. // TODO Don't have to do update in large mode. Only do it when there are millions of data.
  115. return {
  116. update: true
  117. };
  118. } else {
  119. // TODO Use same logic with ScatterView.
  120. // Manually update layout
  121. var res = linesLayout.reset(seriesModel, ecModel, api);
  122. if (res.progress) {
  123. res.progress({
  124. start: 0,
  125. end: data.count(),
  126. count: data.count()
  127. }, data);
  128. }
  129. // Not in large mode
  130. this._lineDraw.updateLayout();
  131. this._clearLayer(api);
  132. }
  133. };
  134. LinesView.prototype._updateLineDraw = function (data, seriesModel) {
  135. var lineDraw = this._lineDraw;
  136. var hasEffect = this._showEffect(seriesModel);
  137. var isPolyline = !!seriesModel.get('polyline');
  138. var pipelineContext = seriesModel.pipelineContext;
  139. var isLargeDraw = pipelineContext.large;
  140. if (process.env.NODE_ENV !== 'production') {
  141. if (hasEffect && isLargeDraw) {
  142. console.warn('Large lines not support effect');
  143. }
  144. }
  145. if (!lineDraw || hasEffect !== this._hasEffet || isPolyline !== this._isPolyline || isLargeDraw !== this._isLargeDraw) {
  146. if (lineDraw) {
  147. lineDraw.remove();
  148. }
  149. lineDraw = this._lineDraw = isLargeDraw ? new LargeLineDraw() : new LineDraw(isPolyline ? hasEffect ? EffectPolyline : Polyline : hasEffect ? EffectLine : Line);
  150. this._hasEffet = hasEffect;
  151. this._isPolyline = isPolyline;
  152. this._isLargeDraw = isLargeDraw;
  153. }
  154. this.group.add(lineDraw.group);
  155. return lineDraw;
  156. };
  157. LinesView.prototype._showEffect = function (seriesModel) {
  158. return !!seriesModel.get(['effect', 'show']);
  159. };
  160. LinesView.prototype._clearLayer = function (api) {
  161. // Not use motion when dragging or zooming
  162. var zr = api.getZr();
  163. var isSvg = zr.painter.getType() === 'svg';
  164. if (!isSvg && this._lastZlevel != null) {
  165. zr.painter.getLayer(this._lastZlevel).clear(true);
  166. }
  167. };
  168. LinesView.prototype.remove = function (ecModel, api) {
  169. this._lineDraw && this._lineDraw.remove();
  170. this._lineDraw = null;
  171. // Clear motion when lineDraw is removed
  172. this._clearLayer(api);
  173. };
  174. LinesView.prototype.dispose = function (ecModel, api) {
  175. this.remove(ecModel, api);
  176. };
  177. LinesView.type = 'lines';
  178. return LinesView;
  179. }(ChartView);
  180. export default LinesView;