preprocessor.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. var zrUtil = require("zrender/lib/core/util");
  2. function _default(option) {
  3. var timelineOpt = option && option.timeline;
  4. if (!zrUtil.isArray(timelineOpt)) {
  5. timelineOpt = timelineOpt ? [timelineOpt] : [];
  6. }
  7. zrUtil.each(timelineOpt, function (opt) {
  8. if (!opt) {
  9. return;
  10. }
  11. compatibleEC2(opt);
  12. });
  13. }
  14. function compatibleEC2(opt) {
  15. var type = opt.type;
  16. var ec2Types = {
  17. 'number': 'value',
  18. 'time': 'time'
  19. }; // Compatible with ec2
  20. if (ec2Types[type]) {
  21. opt.axisType = ec2Types[type];
  22. delete opt.type;
  23. }
  24. transferItem(opt);
  25. if (has(opt, 'controlPosition')) {
  26. var controlStyle = opt.controlStyle || (opt.controlStyle = {});
  27. if (!has(controlStyle, 'position')) {
  28. controlStyle.position = opt.controlPosition;
  29. }
  30. if (controlStyle.position === 'none' && !has(controlStyle, 'show')) {
  31. controlStyle.show = false;
  32. delete controlStyle.position;
  33. }
  34. delete opt.controlPosition;
  35. }
  36. zrUtil.each(opt.data || [], function (dataItem) {
  37. if (zrUtil.isObject(dataItem) && !zrUtil.isArray(dataItem)) {
  38. if (!has(dataItem, 'value') && has(dataItem, 'name')) {
  39. // In ec2, using name as value.
  40. dataItem.value = dataItem.name;
  41. }
  42. transferItem(dataItem);
  43. }
  44. });
  45. }
  46. function transferItem(opt) {
  47. var itemStyle = opt.itemStyle || (opt.itemStyle = {});
  48. var itemStyleEmphasis = itemStyle.emphasis || (itemStyle.emphasis = {}); // Transfer label out
  49. var label = opt.label || opt.label || {};
  50. var labelNormal = label.normal || (label.normal = {});
  51. var excludeLabelAttr = {
  52. normal: 1,
  53. emphasis: 1
  54. };
  55. zrUtil.each(label, function (value, name) {
  56. if (!excludeLabelAttr[name] && !has(labelNormal, name)) {
  57. labelNormal[name] = value;
  58. }
  59. });
  60. if (itemStyleEmphasis.label && !has(label, 'emphasis')) {
  61. label.emphasis = itemStyleEmphasis.label;
  62. delete itemStyleEmphasis.label;
  63. }
  64. }
  65. function has(obj, attr) {
  66. return obj.hasOwnProperty(attr);
  67. }
  68. module.exports = _default;