preprocessor.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. };
  60. // Compatible with ec2
  61. if (ec2Types[type]) {
  62. opt.axisType = ec2Types[type];
  63. delete opt.type;
  64. }
  65. transferItem(opt);
  66. if (has(opt, 'controlPosition')) {
  67. var controlStyle = opt.controlStyle || (opt.controlStyle = {});
  68. if (!has(controlStyle, 'position')) {
  69. controlStyle.position = opt.controlPosition;
  70. }
  71. if (controlStyle.position === 'none' && !has(controlStyle, 'show')) {
  72. controlStyle.show = false;
  73. delete controlStyle.position;
  74. }
  75. delete opt.controlPosition;
  76. }
  77. zrUtil.each(opt.data || [], function (dataItem) {
  78. if (zrUtil.isObject(dataItem) && !zrUtil.isArray(dataItem)) {
  79. if (!has(dataItem, 'value') && has(dataItem, 'name')) {
  80. // In ec2, using name as value.
  81. dataItem.value = dataItem.name;
  82. }
  83. transferItem(dataItem);
  84. }
  85. });
  86. }
  87. function transferItem(opt) {
  88. var itemStyle = opt.itemStyle || (opt.itemStyle = {});
  89. var itemStyleEmphasis = itemStyle.emphasis || (itemStyle.emphasis = {});
  90. // Transfer label out
  91. var label = opt.label || opt.label || {};
  92. var labelNormal = label.normal || (label.normal = {});
  93. var excludeLabelAttr = {
  94. normal: 1,
  95. emphasis: 1
  96. };
  97. zrUtil.each(label, function (value, name) {
  98. if (!excludeLabelAttr[name] && !has(labelNormal, name)) {
  99. labelNormal[name] = value;
  100. }
  101. });
  102. if (itemStyleEmphasis.label && !has(label, 'emphasis')) {
  103. label.emphasis = itemStyleEmphasis.label;
  104. delete itemStyleEmphasis.label;
  105. }
  106. }
  107. function has(obj, attr) {
  108. return obj.hasOwnProperty(attr);
  109. }