backwardCompat.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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. import { each, isArray, isObject, isTypedArray, defaults } from 'zrender/lib/core/util.js';
  41. import compatStyle from './helper/compatStyle.js';
  42. import { normalizeToArray } from '../util/model.js';
  43. import { deprecateLog, deprecateReplaceLog } from '../util/log.js';
  44. function get(opt, path) {
  45. var pathArr = path.split(',');
  46. var obj = opt;
  47. for (var i = 0; i < pathArr.length; i++) {
  48. obj = obj && obj[pathArr[i]];
  49. if (obj == null) {
  50. break;
  51. }
  52. }
  53. return obj;
  54. }
  55. function set(opt, path, val, overwrite) {
  56. var pathArr = path.split(',');
  57. var obj = opt;
  58. var key;
  59. var i = 0;
  60. for (; i < pathArr.length - 1; i++) {
  61. key = pathArr[i];
  62. if (obj[key] == null) {
  63. obj[key] = {};
  64. }
  65. obj = obj[key];
  66. }
  67. if (overwrite || obj[pathArr[i]] == null) {
  68. obj[pathArr[i]] = val;
  69. }
  70. }
  71. function compatLayoutProperties(option) {
  72. option && 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. var BAR_ITEM_STYLE_MAP = [['borderRadius', 'barBorderRadius'], ['borderColor', 'barBorderColor'], ['borderWidth', 'barBorderWidth']];
  81. function compatBarItemStyle(option) {
  82. var itemStyle = option && option.itemStyle;
  83. if (itemStyle) {
  84. for (var i = 0; i < BAR_ITEM_STYLE_MAP.length; i++) {
  85. var oldName = BAR_ITEM_STYLE_MAP[i][1];
  86. var newName = BAR_ITEM_STYLE_MAP[i][0];
  87. if (itemStyle[oldName] != null) {
  88. itemStyle[newName] = itemStyle[oldName];
  89. if (process.env.NODE_ENV !== 'production') {
  90. deprecateReplaceLog(oldName, newName);
  91. }
  92. }
  93. }
  94. }
  95. }
  96. function compatPieLabel(option) {
  97. if (!option) {
  98. return;
  99. }
  100. if (option.alignTo === 'edge' && option.margin != null && option.edgeDistance == null) {
  101. if (process.env.NODE_ENV !== 'production') {
  102. deprecateReplaceLog('label.margin', 'label.edgeDistance', 'pie');
  103. }
  104. option.edgeDistance = option.margin;
  105. }
  106. }
  107. function compatSunburstState(option) {
  108. if (!option) {
  109. return;
  110. }
  111. if (option.downplay && !option.blur) {
  112. option.blur = option.downplay;
  113. if (process.env.NODE_ENV !== 'production') {
  114. deprecateReplaceLog('downplay', 'blur', 'sunburst');
  115. }
  116. }
  117. }
  118. function compatGraphFocus(option) {
  119. if (!option) {
  120. return;
  121. }
  122. if (option.focusNodeAdjacency != null) {
  123. option.emphasis = option.emphasis || {};
  124. if (option.emphasis.focus == null) {
  125. if (process.env.NODE_ENV !== 'production') {
  126. deprecateReplaceLog('focusNodeAdjacency', 'emphasis: { focus: \'adjacency\'}', 'graph/sankey');
  127. }
  128. option.emphasis.focus = 'adjacency';
  129. }
  130. }
  131. }
  132. function traverseTree(data, cb) {
  133. if (data) {
  134. for (var i = 0; i < data.length; i++) {
  135. cb(data[i]);
  136. data[i] && traverseTree(data[i].children, cb);
  137. }
  138. }
  139. }
  140. export default function globalBackwardCompat(option, isTheme) {
  141. compatStyle(option, isTheme); // Make sure series array for model initialization.
  142. option.series = normalizeToArray(option.series);
  143. each(option.series, function (seriesOpt) {
  144. if (!isObject(seriesOpt)) {
  145. return;
  146. }
  147. var seriesType = seriesOpt.type;
  148. if (seriesType === 'line') {
  149. if (seriesOpt.clipOverflow != null) {
  150. seriesOpt.clip = seriesOpt.clipOverflow;
  151. if (process.env.NODE_ENV !== 'production') {
  152. deprecateReplaceLog('clipOverflow', 'clip', 'line');
  153. }
  154. }
  155. } else if (seriesType === 'pie' || seriesType === 'gauge') {
  156. if (seriesOpt.clockWise != null) {
  157. seriesOpt.clockwise = seriesOpt.clockWise;
  158. if (process.env.NODE_ENV !== 'production') {
  159. deprecateReplaceLog('clockWise', 'clockwise');
  160. }
  161. }
  162. compatPieLabel(seriesOpt.label);
  163. var data = seriesOpt.data;
  164. if (data && !isTypedArray(data)) {
  165. for (var i = 0; i < data.length; i++) {
  166. compatPieLabel(data[i]);
  167. }
  168. }
  169. if (seriesOpt.hoverOffset != null) {
  170. seriesOpt.emphasis = seriesOpt.emphasis || {};
  171. if (seriesOpt.emphasis.scaleSize = null) {
  172. if (process.env.NODE_ENV !== 'production') {
  173. deprecateReplaceLog('hoverOffset', 'emphasis.scaleSize');
  174. }
  175. seriesOpt.emphasis.scaleSize = seriesOpt.hoverOffset;
  176. }
  177. }
  178. } else if (seriesType === 'gauge') {
  179. var pointerColor = get(seriesOpt, 'pointer.color');
  180. pointerColor != null && set(seriesOpt, 'itemStyle.color', pointerColor);
  181. } else if (seriesType === 'bar') {
  182. compatBarItemStyle(seriesOpt);
  183. compatBarItemStyle(seriesOpt.backgroundStyle);
  184. compatBarItemStyle(seriesOpt.emphasis);
  185. var data = seriesOpt.data;
  186. if (data && !isTypedArray(data)) {
  187. for (var i = 0; i < data.length; i++) {
  188. if (typeof data[i] === 'object') {
  189. compatBarItemStyle(data[i]);
  190. compatBarItemStyle(data[i] && data[i].emphasis);
  191. }
  192. }
  193. }
  194. } else if (seriesType === 'sunburst') {
  195. var highlightPolicy = seriesOpt.highlightPolicy;
  196. if (highlightPolicy) {
  197. seriesOpt.emphasis = seriesOpt.emphasis || {};
  198. if (!seriesOpt.emphasis.focus) {
  199. seriesOpt.emphasis.focus = highlightPolicy;
  200. if (process.env.NODE_ENV !== 'production') {
  201. deprecateReplaceLog('highlightPolicy', 'emphasis.focus', 'sunburst');
  202. }
  203. }
  204. }
  205. compatSunburstState(seriesOpt);
  206. traverseTree(seriesOpt.data, compatSunburstState);
  207. } else if (seriesType === 'graph' || seriesType === 'sankey') {
  208. compatGraphFocus(seriesOpt); // TODO nodes, edges?
  209. } else if (seriesType === 'map') {
  210. if (seriesOpt.mapType && !seriesOpt.map) {
  211. if (process.env.NODE_ENV !== 'production') {
  212. deprecateReplaceLog('mapType', 'map', 'map');
  213. }
  214. seriesOpt.map = seriesOpt.mapType;
  215. }
  216. if (seriesOpt.mapLocation) {
  217. if (process.env.NODE_ENV !== 'production') {
  218. deprecateLog('`mapLocation` is not used anymore.');
  219. }
  220. defaults(seriesOpt, seriesOpt.mapLocation);
  221. }
  222. }
  223. if (seriesOpt.hoverAnimation != null) {
  224. seriesOpt.emphasis = seriesOpt.emphasis || {};
  225. if (seriesOpt.emphasis && seriesOpt.emphasis.scale == null) {
  226. if (process.env.NODE_ENV !== 'production') {
  227. deprecateReplaceLog('hoverAnimation', 'emphasis.scale');
  228. }
  229. seriesOpt.emphasis.scale = seriesOpt.hoverAnimation;
  230. }
  231. }
  232. compatLayoutProperties(seriesOpt);
  233. }); // dataRange has changed to visualMap
  234. if (option.dataRange) {
  235. option.visualMap = option.dataRange;
  236. }
  237. each(COMPATITABLE_COMPONENTS, function (componentName) {
  238. var options = option[componentName];
  239. if (options) {
  240. if (!isArray(options)) {
  241. options = [options];
  242. }
  243. each(options, function (option) {
  244. compatLayoutProperties(option);
  245. });
  246. }
  247. });
  248. }