TimelineModel.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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 ComponentModel from '../../model/Component.js';
  42. import SeriesData from '../../data/SeriesData.js';
  43. import { each, isObject, clone } from 'zrender/lib/core/util.js';
  44. import { convertOptionIdName, getDataItemValue } from '../../util/model.js';
  45. import tokens from '../../visual/tokens.js';
  46. var TimelineModel = /** @class */function (_super) {
  47. __extends(TimelineModel, _super);
  48. function TimelineModel() {
  49. var _this = _super !== null && _super.apply(this, arguments) || this;
  50. _this.type = TimelineModel.type;
  51. _this.layoutMode = 'box';
  52. return _this;
  53. }
  54. /**
  55. * @override
  56. */
  57. TimelineModel.prototype.init = function (option, parentModel, ecModel) {
  58. this.mergeDefaultAndTheme(option, ecModel);
  59. this._initData();
  60. };
  61. /**
  62. * @override
  63. */
  64. TimelineModel.prototype.mergeOption = function (option) {
  65. _super.prototype.mergeOption.apply(this, arguments);
  66. this._initData();
  67. };
  68. TimelineModel.prototype.setCurrentIndex = function (currentIndex) {
  69. if (currentIndex == null) {
  70. currentIndex = this.option.currentIndex;
  71. }
  72. var count = this._data.count();
  73. if (this.option.loop) {
  74. currentIndex = (currentIndex % count + count) % count;
  75. } else {
  76. currentIndex >= count && (currentIndex = count - 1);
  77. currentIndex < 0 && (currentIndex = 0);
  78. }
  79. this.option.currentIndex = currentIndex;
  80. };
  81. /**
  82. * @return {number} currentIndex
  83. */
  84. TimelineModel.prototype.getCurrentIndex = function () {
  85. return this.option.currentIndex;
  86. };
  87. /**
  88. * @return {boolean}
  89. */
  90. TimelineModel.prototype.isIndexMax = function () {
  91. return this.getCurrentIndex() >= this._data.count() - 1;
  92. };
  93. /**
  94. * @param {boolean} state true: play, false: stop
  95. */
  96. TimelineModel.prototype.setPlayState = function (state) {
  97. this.option.autoPlay = !!state;
  98. };
  99. /**
  100. * @return {boolean} true: play, false: stop
  101. */
  102. TimelineModel.prototype.getPlayState = function () {
  103. return !!this.option.autoPlay;
  104. };
  105. /**
  106. * @private
  107. */
  108. TimelineModel.prototype._initData = function () {
  109. var thisOption = this.option;
  110. var dataArr = thisOption.data || [];
  111. var axisType = thisOption.axisType;
  112. var names = this._names = [];
  113. var processedDataArr;
  114. if (axisType === 'category') {
  115. processedDataArr = [];
  116. each(dataArr, function (item, index) {
  117. var value = convertOptionIdName(getDataItemValue(item), '');
  118. var newItem;
  119. if (isObject(item)) {
  120. newItem = clone(item);
  121. newItem.value = index;
  122. } else {
  123. newItem = index;
  124. }
  125. processedDataArr.push(newItem);
  126. names.push(value);
  127. });
  128. } else {
  129. processedDataArr = dataArr;
  130. }
  131. var dimType = {
  132. category: 'ordinal',
  133. time: 'time',
  134. value: 'number'
  135. }[axisType] || 'number';
  136. var data = this._data = new SeriesData([{
  137. name: 'value',
  138. type: dimType
  139. }], this);
  140. data.initData(processedDataArr, names);
  141. };
  142. TimelineModel.prototype.getData = function () {
  143. return this._data;
  144. };
  145. /**
  146. * @public
  147. * @return {Array.<string>} categoreis
  148. */
  149. TimelineModel.prototype.getCategories = function () {
  150. if (this.get('axisType') === 'category') {
  151. return this._names.slice();
  152. }
  153. };
  154. TimelineModel.type = 'timeline';
  155. /**
  156. * @protected
  157. */
  158. TimelineModel.defaultOption = {
  159. // zlevel: 0, // 一级层叠
  160. z: 4,
  161. show: true,
  162. axisType: 'time',
  163. realtime: true,
  164. left: '20%',
  165. top: null,
  166. right: '20%',
  167. bottom: 0,
  168. width: null,
  169. height: 40,
  170. padding: tokens.size.m,
  171. controlPosition: 'left',
  172. autoPlay: false,
  173. rewind: false,
  174. loop: true,
  175. playInterval: 2000,
  176. currentIndex: 0,
  177. itemStyle: {},
  178. label: {
  179. color: tokens.color.secondary
  180. },
  181. data: []
  182. };
  183. return TimelineModel;
  184. }(ComponentModel);
  185. export default TimelineModel;