backwardCompat.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 _util = require("zrender/lib/core/util");
  20. var each = _util.each;
  21. var isArray = _util.isArray;
  22. var isObject = _util.isObject;
  23. var compatStyle = require("./helper/compatStyle");
  24. var _model = require("../util/model");
  25. var normalizeToArray = _model.normalizeToArray;
  26. /*
  27. * Licensed to the Apache Software Foundation (ASF) under one
  28. * or more contributor license agreements. See the NOTICE file
  29. * distributed with this work for additional information
  30. * regarding copyright ownership. The ASF licenses this file
  31. * to you under the Apache License, Version 2.0 (the
  32. * "License"); you may not use this file except in compliance
  33. * with the License. You may obtain a copy of the License at
  34. *
  35. * http://www.apache.org/licenses/LICENSE-2.0
  36. *
  37. * Unless required by applicable law or agreed to in writing,
  38. * software distributed under the License is distributed on an
  39. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  40. * KIND, either express or implied. See the License for the
  41. * specific language governing permissions and limitations
  42. * under the License.
  43. */
  44. // Compatitable with 2.0
  45. function get(opt, path) {
  46. path = path.split(',');
  47. var obj = opt;
  48. for (var i = 0; i < path.length; i++) {
  49. obj = obj && obj[path[i]];
  50. if (obj == null) {
  51. break;
  52. }
  53. }
  54. return obj;
  55. }
  56. function set(opt, path, val, overwrite) {
  57. path = path.split(',');
  58. var obj = opt;
  59. var key;
  60. for (var i = 0; i < path.length - 1; i++) {
  61. key = path[i];
  62. if (obj[key] == null) {
  63. obj[key] = {};
  64. }
  65. obj = obj[key];
  66. }
  67. if (overwrite || obj[path[i]] == null) {
  68. obj[path[i]] = val;
  69. }
  70. }
  71. function compatLayoutProperties(option) {
  72. each(LAYOUT_PROPERTIES, function (prop) {
  73. if (prop[0] in option && !(prop[1] in option)) {
  74. option[prop[1]] = option[prop[0]];
  75. }
  76. });
  77. }
  78. var LAYOUT_PROPERTIES = [['x', 'left'], ['y', 'top'], ['x2', 'right'], ['y2', 'bottom']];
  79. var COMPATITABLE_COMPONENTS = ['grid', 'geo', 'parallel', 'legend', 'toolbox', 'title', 'visualMap', 'dataZoom', 'timeline'];
  80. function _default(option, isTheme) {
  81. compatStyle(option, isTheme); // Make sure series array for model initialization.
  82. option.series = normalizeToArray(option.series);
  83. each(option.series, function (seriesOpt) {
  84. if (!isObject(seriesOpt)) {
  85. return;
  86. }
  87. var seriesType = seriesOpt.type;
  88. if (seriesType === 'line') {
  89. if (seriesOpt.clipOverflow != null) {
  90. seriesOpt.clip = seriesOpt.clipOverflow;
  91. }
  92. } else if (seriesType === 'pie' || seriesType === 'gauge') {
  93. if (seriesOpt.clockWise != null) {
  94. seriesOpt.clockwise = seriesOpt.clockWise;
  95. }
  96. } else if (seriesType === 'gauge') {
  97. var pointerColor = get(seriesOpt, 'pointer.color');
  98. pointerColor != null && set(seriesOpt, 'itemStyle.color', pointerColor);
  99. }
  100. compatLayoutProperties(seriesOpt);
  101. }); // dataRange has changed to visualMap
  102. if (option.dataRange) {
  103. option.visualMap = option.dataRange;
  104. }
  105. each(COMPATITABLE_COMPONENTS, function (componentName) {
  106. var options = option[componentName];
  107. if (options) {
  108. if (!isArray(options)) {
  109. options = [options];
  110. }
  111. each(options, function (option) {
  112. compatLayoutProperties(option);
  113. });
  114. }
  115. });
  116. }
  117. module.exports = _default;