preprocessor.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. var zrUtil = require("zrender/lib/core/util");
  20. /*
  21. * Licensed to the Apache Software Foundation (ASF) under one
  22. * or more contributor license agreements. See the NOTICE file
  23. * distributed with this work for additional information
  24. * regarding copyright ownership. The ASF licenses this file
  25. * to you under the Apache License, Version 2.0 (the
  26. * "License"); you may not use this file except in compliance
  27. * with the License. You may obtain a copy of the License at
  28. *
  29. * http://www.apache.org/licenses/LICENSE-2.0
  30. *
  31. * Unless required by applicable law or agreed to in writing,
  32. * software distributed under the License is distributed on an
  33. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  34. * KIND, either express or implied. See the License for the
  35. * specific language governing permissions and limitations
  36. * under the License.
  37. */
  38. function _default(option) {
  39. var timelineOpt = option && option.timeline;
  40. if (!zrUtil.isArray(timelineOpt)) {
  41. timelineOpt = timelineOpt ? [timelineOpt] : [];
  42. }
  43. zrUtil.each(timelineOpt, function (opt) {
  44. if (!opt) {
  45. return;
  46. }
  47. compatibleEC2(opt);
  48. });
  49. }
  50. function compatibleEC2(opt) {
  51. var type = opt.type;
  52. var ec2Types = {
  53. 'number': 'value',
  54. 'time': 'time'
  55. }; // Compatible with ec2
  56. if (ec2Types[type]) {
  57. opt.axisType = ec2Types[type];
  58. delete opt.type;
  59. }
  60. transferItem(opt);
  61. if (has(opt, 'controlPosition')) {
  62. var controlStyle = opt.controlStyle || (opt.controlStyle = {});
  63. if (!has(controlStyle, 'position')) {
  64. controlStyle.position = opt.controlPosition;
  65. }
  66. if (controlStyle.position === 'none' && !has(controlStyle, 'show')) {
  67. controlStyle.show = false;
  68. delete controlStyle.position;
  69. }
  70. delete opt.controlPosition;
  71. }
  72. zrUtil.each(opt.data || [], function (dataItem) {
  73. if (zrUtil.isObject(dataItem) && !zrUtil.isArray(dataItem)) {
  74. if (!has(dataItem, 'value') && has(dataItem, 'name')) {
  75. // In ec2, using name as value.
  76. dataItem.value = dataItem.name;
  77. }
  78. transferItem(dataItem);
  79. }
  80. });
  81. }
  82. function transferItem(opt) {
  83. var itemStyle = opt.itemStyle || (opt.itemStyle = {});
  84. var itemStyleEmphasis = itemStyle.emphasis || (itemStyle.emphasis = {}); // Transfer label out
  85. var label = opt.label || opt.label || {};
  86. var labelNormal = label.normal || (label.normal = {});
  87. var excludeLabelAttr = {
  88. normal: 1,
  89. emphasis: 1
  90. };
  91. zrUtil.each(label, function (value, name) {
  92. if (!excludeLabelAttr[name] && !has(labelNormal, name)) {
  93. labelNormal[name] = value;
  94. }
  95. });
  96. if (itemStyleEmphasis.label && !has(label, 'emphasis')) {
  97. label.emphasis = itemStyleEmphasis.label;
  98. delete itemStyleEmphasis.label;
  99. }
  100. }
  101. function has(obj, attr) {
  102. return obj.hasOwnProperty(attr);
  103. }
  104. module.exports = _default;