LineDraw.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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 * as graphic from '../../util/graphic.js';
  41. import LineGroup from './Line.js';
  42. import { getLabelStatesModels } from '../../label/labelStyle.js';
  43. var LineDraw = /** @class */function () {
  44. function LineDraw(LineCtor) {
  45. this.group = new graphic.Group();
  46. this._LineCtor = LineCtor || LineGroup;
  47. }
  48. LineDraw.prototype.updateData = function (lineData) {
  49. var _this = this;
  50. // Remove progressive els.
  51. this._progressiveEls = null;
  52. var lineDraw = this;
  53. var group = lineDraw.group;
  54. var oldLineData = lineDraw._lineData;
  55. lineDraw._lineData = lineData;
  56. // There is no oldLineData only when first rendering or switching from
  57. // stream mode to normal mode, where previous elements should be removed.
  58. if (!oldLineData) {
  59. group.removeAll();
  60. }
  61. var seriesScope = makeSeriesScope(lineData);
  62. lineData.diff(oldLineData).add(function (idx) {
  63. _this._doAdd(lineData, idx, seriesScope);
  64. }).update(function (newIdx, oldIdx) {
  65. _this._doUpdate(oldLineData, lineData, oldIdx, newIdx, seriesScope);
  66. }).remove(function (idx) {
  67. group.remove(oldLineData.getItemGraphicEl(idx));
  68. }).execute();
  69. };
  70. ;
  71. LineDraw.prototype.updateLayout = function () {
  72. var lineData = this._lineData;
  73. // Do not support update layout in incremental mode.
  74. if (!lineData) {
  75. return;
  76. }
  77. lineData.eachItemGraphicEl(function (el, idx) {
  78. el.updateLayout(lineData, idx);
  79. }, this);
  80. };
  81. ;
  82. LineDraw.prototype.incrementalPrepareUpdate = function (lineData) {
  83. this._seriesScope = makeSeriesScope(lineData);
  84. this._lineData = null;
  85. this.group.removeAll();
  86. };
  87. ;
  88. LineDraw.prototype.incrementalUpdate = function (taskParams, lineData) {
  89. this._progressiveEls = [];
  90. function updateIncrementalAndHover(el) {
  91. if (!el.isGroup && !isEffectObject(el)) {
  92. el.incremental = true;
  93. el.ensureState('emphasis').hoverLayer = true;
  94. }
  95. }
  96. for (var idx = taskParams.start; idx < taskParams.end; idx++) {
  97. var itemLayout = lineData.getItemLayout(idx);
  98. if (lineNeedsDraw(itemLayout)) {
  99. var el = new this._LineCtor(lineData, idx, this._seriesScope);
  100. el.traverse(updateIncrementalAndHover);
  101. this.group.add(el);
  102. lineData.setItemGraphicEl(idx, el);
  103. this._progressiveEls.push(el);
  104. }
  105. }
  106. };
  107. ;
  108. LineDraw.prototype.remove = function () {
  109. this.group.removeAll();
  110. };
  111. ;
  112. LineDraw.prototype.eachRendered = function (cb) {
  113. graphic.traverseElements(this._progressiveEls || this.group, cb);
  114. };
  115. LineDraw.prototype._doAdd = function (lineData, idx, seriesScope) {
  116. var itemLayout = lineData.getItemLayout(idx);
  117. if (!lineNeedsDraw(itemLayout)) {
  118. return;
  119. }
  120. var el = new this._LineCtor(lineData, idx, seriesScope);
  121. lineData.setItemGraphicEl(idx, el);
  122. this.group.add(el);
  123. };
  124. LineDraw.prototype._doUpdate = function (oldLineData, newLineData, oldIdx, newIdx, seriesScope) {
  125. var itemEl = oldLineData.getItemGraphicEl(oldIdx);
  126. if (!lineNeedsDraw(newLineData.getItemLayout(newIdx))) {
  127. this.group.remove(itemEl);
  128. return;
  129. }
  130. if (!itemEl) {
  131. itemEl = new this._LineCtor(newLineData, newIdx, seriesScope);
  132. } else {
  133. itemEl.updateData(newLineData, newIdx, seriesScope);
  134. }
  135. newLineData.setItemGraphicEl(newIdx, itemEl);
  136. this.group.add(itemEl);
  137. };
  138. return LineDraw;
  139. }();
  140. function isEffectObject(el) {
  141. return el.animators && el.animators.length > 0;
  142. }
  143. function makeSeriesScope(lineData) {
  144. var hostModel = lineData.hostModel;
  145. var emphasisModel = hostModel.getModel('emphasis');
  146. return {
  147. lineStyle: hostModel.getModel('lineStyle').getLineStyle(),
  148. emphasisLineStyle: emphasisModel.getModel(['lineStyle']).getLineStyle(),
  149. blurLineStyle: hostModel.getModel(['blur', 'lineStyle']).getLineStyle(),
  150. selectLineStyle: hostModel.getModel(['select', 'lineStyle']).getLineStyle(),
  151. emphasisDisabled: emphasisModel.get('disabled'),
  152. blurScope: emphasisModel.get('blurScope'),
  153. focus: emphasisModel.get('focus'),
  154. labelStatesModels: getLabelStatesModels(hostModel)
  155. };
  156. }
  157. function isPointNaN(pt) {
  158. return isNaN(pt[0]) || isNaN(pt[1]);
  159. }
  160. function lineNeedsDraw(pts) {
  161. return pts && !isPointNaN(pts[0]) && !isPointNaN(pts[1]);
  162. }
  163. export default LineDraw;