TimelineModel.js 5.4 KB

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