LineDraw.js 5.8 KB

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