ParallelView.js 7.7 KB

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