TimelineModel.js 5.4 KB

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