ParallelView.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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 graphic from '../../util/graphic.js';
  42. import { setStatesStylesFromModel, toggleHoverEmphasis } from '../../util/states.js';
  43. import ChartView from '../../view/Chart.js';
  44. import { numericToNumber } from '../../util/number.js';
  45. import { eqNaN } from 'zrender/lib/core/util.js';
  46. import { saveOldStyle } from '../../animation/basicTransition.js';
  47. var DEFAULT_SMOOTH = 0.3;
  48. var ParallelView = /** @class */function (_super) {
  49. __extends(ParallelView, _super);
  50. function ParallelView() {
  51. var _this = _super !== null && _super.apply(this, arguments) || this;
  52. _this.type = ParallelView.type;
  53. _this._dataGroup = new graphic.Group();
  54. _this._initialized = false;
  55. return _this;
  56. }
  57. ParallelView.prototype.init = function () {
  58. this.group.add(this._dataGroup);
  59. };
  60. /**
  61. * @override
  62. */
  63. ParallelView.prototype.render = function (seriesModel, ecModel, api, payload) {
  64. // Clear previously rendered progressive elements.
  65. this._progressiveEls = null;
  66. var dataGroup = this._dataGroup;
  67. var data = seriesModel.getData();
  68. var oldData = this._data;
  69. var coordSys = seriesModel.coordinateSystem;
  70. var dimensions = coordSys.dimensions;
  71. var seriesScope = makeSeriesScope(seriesModel);
  72. data.diff(oldData).add(add).update(update).remove(remove).execute();
  73. function add(newDataIndex) {
  74. var line = addEl(data, dataGroup, newDataIndex, dimensions, coordSys);
  75. updateElCommon(line, data, newDataIndex, seriesScope);
  76. }
  77. function update(newDataIndex, oldDataIndex) {
  78. var line = oldData.getItemGraphicEl(oldDataIndex);
  79. var points = createLinePoints(data, newDataIndex, dimensions, coordSys);
  80. data.setItemGraphicEl(newDataIndex, line);
  81. graphic.updateProps(line, {
  82. shape: {
  83. points: points
  84. }
  85. }, seriesModel, newDataIndex);
  86. saveOldStyle(line);
  87. updateElCommon(line, data, newDataIndex, seriesScope);
  88. }
  89. function remove(oldDataIndex) {
  90. var line = oldData.getItemGraphicEl(oldDataIndex);
  91. dataGroup.remove(line);
  92. }
  93. // First create
  94. if (!this._initialized) {
  95. this._initialized = true;
  96. var clipPath = createGridClipShape(coordSys, seriesModel, function () {
  97. // Callback will be invoked immediately if there is no animation
  98. setTimeout(function () {
  99. dataGroup.removeClipPath();
  100. });
  101. });
  102. dataGroup.setClipPath(clipPath);
  103. }
  104. this._data = data;
  105. };
  106. ParallelView.prototype.incrementalPrepareRender = function (seriesModel, ecModel, api) {
  107. this._initialized = true;
  108. this._data = null;
  109. this._dataGroup.removeAll();
  110. };
  111. ParallelView.prototype.incrementalRender = function (taskParams, seriesModel, ecModel) {
  112. var data = seriesModel.getData();
  113. var coordSys = seriesModel.coordinateSystem;
  114. var dimensions = coordSys.dimensions;
  115. var seriesScope = makeSeriesScope(seriesModel);
  116. var progressiveEls = this._progressiveEls = [];
  117. for (var dataIndex = taskParams.start; dataIndex < taskParams.end; dataIndex++) {
  118. var line = addEl(data, this._dataGroup, dataIndex, dimensions, coordSys);
  119. line.incremental = true;
  120. updateElCommon(line, data, dataIndex, seriesScope);
  121. progressiveEls.push(line);
  122. }
  123. };
  124. ParallelView.prototype.remove = function () {
  125. this._dataGroup && this._dataGroup.removeAll();
  126. this._data = null;
  127. };
  128. ParallelView.type = 'parallel';
  129. return ParallelView;
  130. }(ChartView);
  131. function createGridClipShape(coordSys, seriesModel, cb) {
  132. var parallelModel = coordSys.model;
  133. var rect = coordSys.getRect();
  134. var rectEl = new graphic.Rect({
  135. shape: {
  136. x: rect.x,
  137. y: rect.y,
  138. width: rect.width,
  139. height: rect.height
  140. }
  141. });
  142. var dim = parallelModel.get('layout') === 'horizontal' ? 'width' : 'height';
  143. rectEl.setShape(dim, 0);
  144. graphic.initProps(rectEl, {
  145. shape: {
  146. width: rect.width,
  147. height: rect.height
  148. }
  149. }, seriesModel, cb);
  150. return rectEl;
  151. }
  152. function createLinePoints(data, dataIndex, dimensions, coordSys) {
  153. var points = [];
  154. for (var i = 0; i < dimensions.length; i++) {
  155. var dimName = dimensions[i];
  156. var value = data.get(data.mapDimension(dimName), dataIndex);
  157. if (!isEmptyValue(value, coordSys.getAxis(dimName).type)) {
  158. points.push(coordSys.dataToPoint(value, dimName));
  159. }
  160. }
  161. return points;
  162. }
  163. function addEl(data, dataGroup, dataIndex, dimensions, coordSys) {
  164. var points = createLinePoints(data, dataIndex, dimensions, coordSys);
  165. var line = new graphic.Polyline({
  166. shape: {
  167. points: points
  168. },
  169. // silent: true,
  170. z2: 10
  171. });
  172. dataGroup.add(line);
  173. data.setItemGraphicEl(dataIndex, line);
  174. return line;
  175. }
  176. function makeSeriesScope(seriesModel) {
  177. var smooth = seriesModel.get('smooth', true);
  178. smooth === true && (smooth = DEFAULT_SMOOTH);
  179. smooth = numericToNumber(smooth);
  180. eqNaN(smooth) && (smooth = 0);
  181. return {
  182. smooth: smooth
  183. };
  184. }
  185. function updateElCommon(el, data, dataIndex, seriesScope) {
  186. el.useStyle(data.getItemVisual(dataIndex, 'style'));
  187. el.style.fill = null;
  188. el.setShape('smooth', seriesScope.smooth);
  189. var itemModel = data.getItemModel(dataIndex);
  190. var emphasisModel = itemModel.getModel('emphasis');
  191. setStatesStylesFromModel(el, itemModel, 'lineStyle');
  192. toggleHoverEmphasis(el, emphasisModel.get('focus'), emphasisModel.get('blurScope'), emphasisModel.get('disabled'));
  193. }
  194. // function simpleDiff(oldData, newData, dimensions) {
  195. // let oldLen;
  196. // if (!oldData
  197. // || !oldData.__plProgressive
  198. // || (oldLen = oldData.count()) !== newData.count()
  199. // ) {
  200. // return true;
  201. // }
  202. // let dimLen = dimensions.length;
  203. // for (let i = 0; i < oldLen; i++) {
  204. // for (let j = 0; j < dimLen; j++) {
  205. // if (oldData.get(dimensions[j], i) !== newData.get(dimensions[j], i)) {
  206. // return true;
  207. // }
  208. // }
  209. // }
  210. // return false;
  211. // }
  212. // FIXME put in common util?
  213. function isEmptyValue(val, axisType) {
  214. return axisType === 'category' ? val == null : val == null || isNaN(val); // axisType === 'value'
  215. }
  216. export default ParallelView;