preprocessor.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. // @ts-nocheck
  41. import * as zrUtil from 'zrender/lib/core/util.js';
  42. export default function timelinePreprocessor(option) {
  43. var timelineOpt = option && option.timeline;
  44. if (!zrUtil.isArray(timelineOpt)) {
  45. timelineOpt = timelineOpt ? [timelineOpt] : [];
  46. }
  47. zrUtil.each(timelineOpt, function (opt) {
  48. if (!opt) {
  49. return;
  50. }
  51. compatibleEC2(opt);
  52. });
  53. }
  54. function compatibleEC2(opt) {
  55. var type = opt.type;
  56. var ec2Types = {
  57. 'number': 'value',
  58. 'time': 'time'
  59. }; // Compatible with ec2
  60. if (ec2Types[type]) {
  61. opt.axisType = ec2Types[type];
  62. delete opt.type;
  63. }
  64. transferItem(opt);
  65. if (has(opt, 'controlPosition')) {
  66. var controlStyle = opt.controlStyle || (opt.controlStyle = {});
  67. if (!has(controlStyle, 'position')) {
  68. controlStyle.position = opt.controlPosition;
  69. }
  70. if (controlStyle.position === 'none' && !has(controlStyle, 'show')) {
  71. controlStyle.show = false;
  72. delete controlStyle.position;
  73. }
  74. delete opt.controlPosition;
  75. }
  76. zrUtil.each(opt.data || [], function (dataItem) {
  77. if (zrUtil.isObject(dataItem) && !zrUtil.isArray(dataItem)) {
  78. if (!has(dataItem, 'value') && has(dataItem, 'name')) {
  79. // In ec2, using name as value.
  80. dataItem.value = dataItem.name;
  81. }
  82. transferItem(dataItem);
  83. }
  84. });
  85. }
  86. function transferItem(opt) {
  87. var itemStyle = opt.itemStyle || (opt.itemStyle = {});
  88. var itemStyleEmphasis = itemStyle.emphasis || (itemStyle.emphasis = {}); // Transfer label out
  89. var label = opt.label || opt.label || {};
  90. var labelNormal = label.normal || (label.normal = {});
  91. var excludeLabelAttr = {
  92. normal: 1,
  93. emphasis: 1
  94. };
  95. zrUtil.each(label, function (value, name) {
  96. if (!excludeLabelAttr[name] && !has(labelNormal, name)) {
  97. labelNormal[name] = value;
  98. }
  99. });
  100. if (itemStyleEmphasis.label && !has(label, 'emphasis')) {
  101. label.emphasis = itemStyleEmphasis.label;
  102. delete itemStyleEmphasis.label;
  103. }
  104. }
  105. function has(obj, attr) {
  106. return obj.hasOwnProperty(attr);
  107. }