ParallelView.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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';
  42. import { setStatesStylesFromModel, enableHoverEmphasis } from '../../util/states';
  43. import ChartView from '../../view/Chart';
  44. import { numericToNumber } from '../../util/number';
  45. import { eqNaN } from 'zrender/lib/core/util';
  46. import { saveOldStyle } from '../../animation/basicTrasition';
  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. 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. } // First create
  93. if (!this._initialized) {
  94. this._initialized = true;
  95. var clipPath = createGridClipShape(coordSys, seriesModel, function () {
  96. // Callback will be invoked immediately if there is no animation
  97. setTimeout(function () {
  98. dataGroup.removeClipPath();
  99. });
  100. });
  101. dataGroup.setClipPath(clipPath);
  102. }
  103. this._data = data;
  104. };
  105. ParallelView.prototype.incrementalPrepareRender = function (seriesModel, ecModel, api) {
  106. this._initialized = true;
  107. this._data = null;
  108. this._dataGroup.removeAll();
  109. };
  110. ParallelView.prototype.incrementalRender = function (taskParams, seriesModel, ecModel) {
  111. var data = seriesModel.getData();
  112. var coordSys = seriesModel.coordinateSystem;
  113. var dimensions = coordSys.dimensions;
  114. var seriesScope = makeSeriesScope(seriesModel);
  115. for (var dataIndex = taskParams.start; dataIndex < taskParams.end; dataIndex++) {
  116. var line = addEl(data, this._dataGroup, dataIndex, dimensions, coordSys);
  117. line.incremental = true;
  118. updateElCommon(line, data, dataIndex, seriesScope);
  119. }
  120. };
  121. ParallelView.prototype.remove = function () {
  122. this._dataGroup && this._dataGroup.removeAll();
  123. this._data = null;
  124. };
  125. ParallelView.type = 'parallel';
  126. return ParallelView;
  127. }(ChartView);
  128. function createGridClipShape(coordSys, seriesModel, cb) {
  129. var parallelModel = coordSys.model;
  130. var rect = coordSys.getRect();
  131. var rectEl = new graphic.Rect({
  132. shape: {
  133. x: rect.x,
  134. y: rect.y,
  135. width: rect.width,
  136. height: rect.height
  137. }
  138. });
  139. var dim = parallelModel.get('layout') === 'horizontal' ? 'width' : 'height';
  140. rectEl.setShape(dim, 0);
  141. graphic.initProps(rectEl, {
  142. shape: {
  143. width: rect.width,
  144. height: rect.height
  145. }
  146. }, seriesModel, cb);
  147. return rectEl;
  148. }
  149. function createLinePoints(data, dataIndex, dimensions, coordSys) {
  150. var points = [];
  151. for (var i = 0; i < dimensions.length; i++) {
  152. var dimName = dimensions[i];
  153. var value = data.get(data.mapDimension(dimName), dataIndex);
  154. if (!isEmptyValue(value, coordSys.getAxis(dimName).type)) {
  155. points.push(coordSys.dataToPoint(value, dimName));
  156. }
  157. }
  158. return points;
  159. }
  160. function addEl(data, dataGroup, dataIndex, dimensions, coordSys) {
  161. var points = createLinePoints(data, dataIndex, dimensions, coordSys);
  162. var line = new graphic.Polyline({
  163. shape: {
  164. points: points
  165. },
  166. // silent: true,
  167. z2: 10
  168. });
  169. dataGroup.add(line);
  170. data.setItemGraphicEl(dataIndex, line);
  171. return line;
  172. }
  173. function makeSeriesScope(seriesModel) {
  174. var smooth = seriesModel.get('smooth', true);
  175. smooth === true && (smooth = DEFAULT_SMOOTH);
  176. smooth = numericToNumber(smooth);
  177. eqNaN(smooth) && (smooth = 0);
  178. return {
  179. smooth: smooth
  180. };
  181. }
  182. function updateElCommon(el, data, dataIndex, seriesScope) {
  183. el.useStyle(data.getItemVisual(dataIndex, 'style'));
  184. el.style.fill = null;
  185. el.setShape('smooth', seriesScope.smooth);
  186. var itemModel = data.getItemModel(dataIndex);
  187. var emphasisModel = itemModel.getModel('emphasis');
  188. setStatesStylesFromModel(el, itemModel, 'lineStyle');
  189. enableHoverEmphasis(el, emphasisModel.get('focus'), emphasisModel.get('blurScope'));
  190. } // function simpleDiff(oldData, newData, dimensions) {
  191. // let oldLen;
  192. // if (!oldData
  193. // || !oldData.__plProgressive
  194. // || (oldLen = oldData.count()) !== newData.count()
  195. // ) {
  196. // return true;
  197. // }
  198. // let dimLen = dimensions.length;
  199. // for (let i = 0; i < oldLen; i++) {
  200. // for (let j = 0; j < dimLen; j++) {
  201. // if (oldData.get(dimensions[j], i) !== newData.get(dimensions[j], i)) {
  202. // return true;
  203. // }
  204. // }
  205. // }
  206. // return false;
  207. // }
  208. // FIXME put in common util?
  209. function isEmptyValue(val, axisType) {
  210. return axisType === 'category' ? val == null : val == null || isNaN(val); // axisType === 'value'
  211. }
  212. export default ParallelView;