backwardCompat.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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);
  142. // Make sure series array for model initialization.
  143. option.series = normalizeToArray(option.series);
  144. each(option.series, function (seriesOpt) {
  145. if (!isObject(seriesOpt)) {
  146. return;
  147. }
  148. var seriesType = seriesOpt.type;
  149. if (seriesType === 'line') {
  150. if (seriesOpt.clipOverflow != null) {
  151. seriesOpt.clip = seriesOpt.clipOverflow;
  152. if (process.env.NODE_ENV !== 'production') {
  153. deprecateReplaceLog('clipOverflow', 'clip', 'line');
  154. }
  155. }
  156. } else if (seriesType === 'pie' || seriesType === 'gauge') {
  157. if (seriesOpt.clockWise != null) {
  158. seriesOpt.clockwise = seriesOpt.clockWise;
  159. if (process.env.NODE_ENV !== 'production') {
  160. deprecateReplaceLog('clockWise', 'clockwise');
  161. }
  162. }
  163. compatPieLabel(seriesOpt.label);
  164. var data = seriesOpt.data;
  165. if (data && !isTypedArray(data)) {
  166. for (var i = 0; i < data.length; i++) {
  167. compatPieLabel(data[i]);
  168. }
  169. }
  170. if (seriesOpt.hoverOffset != null) {
  171. seriesOpt.emphasis = seriesOpt.emphasis || {};
  172. if (seriesOpt.emphasis.scaleSize = null) {
  173. if (process.env.NODE_ENV !== 'production') {
  174. deprecateReplaceLog('hoverOffset', 'emphasis.scaleSize');
  175. }
  176. seriesOpt.emphasis.scaleSize = seriesOpt.hoverOffset;
  177. }
  178. }
  179. } else if (seriesType === 'gauge') {
  180. var pointerColor = get(seriesOpt, 'pointer.color');
  181. pointerColor != null && set(seriesOpt, 'itemStyle.color', pointerColor);
  182. } else if (seriesType === 'bar') {
  183. compatBarItemStyle(seriesOpt);
  184. compatBarItemStyle(seriesOpt.backgroundStyle);
  185. compatBarItemStyle(seriesOpt.emphasis);
  186. var data = seriesOpt.data;
  187. if (data && !isTypedArray(data)) {
  188. for (var i = 0; i < data.length; i++) {
  189. if (typeof data[i] === 'object') {
  190. compatBarItemStyle(data[i]);
  191. compatBarItemStyle(data[i] && data[i].emphasis);
  192. }
  193. }
  194. }
  195. } else if (seriesType === 'sunburst') {
  196. var highlightPolicy = seriesOpt.highlightPolicy;
  197. if (highlightPolicy) {
  198. seriesOpt.emphasis = seriesOpt.emphasis || {};
  199. if (!seriesOpt.emphasis.focus) {
  200. seriesOpt.emphasis.focus = highlightPolicy;
  201. if (process.env.NODE_ENV !== 'production') {
  202. deprecateReplaceLog('highlightPolicy', 'emphasis.focus', 'sunburst');
  203. }
  204. }
  205. }
  206. compatSunburstState(seriesOpt);
  207. traverseTree(seriesOpt.data, compatSunburstState);
  208. } else if (seriesType === 'graph' || seriesType === 'sankey') {
  209. compatGraphFocus(seriesOpt);
  210. // TODO nodes, edges?
  211. } else if (seriesType === 'map') {
  212. if (seriesOpt.mapType && !seriesOpt.map) {
  213. if (process.env.NODE_ENV !== 'production') {
  214. deprecateReplaceLog('mapType', 'map', 'map');
  215. }
  216. seriesOpt.map = seriesOpt.mapType;
  217. }
  218. if (seriesOpt.mapLocation) {
  219. if (process.env.NODE_ENV !== 'production') {
  220. deprecateLog('`mapLocation` is not used anymore.');
  221. }
  222. defaults(seriesOpt, seriesOpt.mapLocation);
  223. }
  224. }
  225. if (seriesOpt.hoverAnimation != null) {
  226. seriesOpt.emphasis = seriesOpt.emphasis || {};
  227. if (seriesOpt.emphasis && seriesOpt.emphasis.scale == null) {
  228. if (process.env.NODE_ENV !== 'production') {
  229. deprecateReplaceLog('hoverAnimation', 'emphasis.scale');
  230. }
  231. seriesOpt.emphasis.scale = seriesOpt.hoverAnimation;
  232. }
  233. }
  234. compatLayoutProperties(seriesOpt);
  235. });
  236. // dataRange has changed to visualMap
  237. if (option.dataRange) {
  238. option.visualMap = option.dataRange;
  239. }
  240. each(COMPATITABLE_COMPONENTS, function (componentName) {
  241. var options = option[componentName];
  242. if (options) {
  243. if (!isArray(options)) {
  244. options = [options];
  245. }
  246. each(options, function (option) {
  247. compatLayoutProperties(option);
  248. });
  249. }
  250. });
  251. }