compatStyle.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  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 * as zrUtil from 'zrender/lib/core/util.js';
  41. import * as modelUtil from '../../util/model.js';
  42. import { deprecateLog, deprecateReplaceLog } from '../../util/log.js';
  43. var each = zrUtil.each;
  44. var isObject = zrUtil.isObject;
  45. var POSSIBLE_STYLES = ['areaStyle', 'lineStyle', 'nodeStyle', 'linkStyle', 'chordStyle', 'label', 'labelLine'];
  46. function compatEC2ItemStyle(opt) {
  47. var itemStyleOpt = opt && opt.itemStyle;
  48. if (!itemStyleOpt) {
  49. return;
  50. }
  51. for (var i = 0, len = POSSIBLE_STYLES.length; i < len; i++) {
  52. var styleName = POSSIBLE_STYLES[i];
  53. var normalItemStyleOpt = itemStyleOpt.normal;
  54. var emphasisItemStyleOpt = itemStyleOpt.emphasis;
  55. if (normalItemStyleOpt && normalItemStyleOpt[styleName]) {
  56. if (process.env.NODE_ENV !== 'production') {
  57. deprecateReplaceLog("itemStyle.normal." + styleName, styleName);
  58. }
  59. opt[styleName] = opt[styleName] || {};
  60. if (!opt[styleName].normal) {
  61. opt[styleName].normal = normalItemStyleOpt[styleName];
  62. } else {
  63. zrUtil.merge(opt[styleName].normal, normalItemStyleOpt[styleName]);
  64. }
  65. normalItemStyleOpt[styleName] = null;
  66. }
  67. if (emphasisItemStyleOpt && emphasisItemStyleOpt[styleName]) {
  68. if (process.env.NODE_ENV !== 'production') {
  69. deprecateReplaceLog("itemStyle.emphasis." + styleName, "emphasis." + styleName);
  70. }
  71. opt[styleName] = opt[styleName] || {};
  72. if (!opt[styleName].emphasis) {
  73. opt[styleName].emphasis = emphasisItemStyleOpt[styleName];
  74. } else {
  75. zrUtil.merge(opt[styleName].emphasis, emphasisItemStyleOpt[styleName]);
  76. }
  77. emphasisItemStyleOpt[styleName] = null;
  78. }
  79. }
  80. }
  81. function convertNormalEmphasis(opt, optType, useExtend) {
  82. if (opt && opt[optType] && (opt[optType].normal || opt[optType].emphasis)) {
  83. var normalOpt = opt[optType].normal;
  84. var emphasisOpt = opt[optType].emphasis;
  85. if (normalOpt) {
  86. if (process.env.NODE_ENV !== 'production') {
  87. // eslint-disable-next-line max-len
  88. deprecateLog("'normal' hierarchy in " + optType + " has been removed since 4.0. All style properties are configured in " + optType + " directly now.");
  89. }
  90. // Timeline controlStyle has other properties besides normal and emphasis
  91. if (useExtend) {
  92. opt[optType].normal = opt[optType].emphasis = null;
  93. zrUtil.defaults(opt[optType], normalOpt);
  94. } else {
  95. opt[optType] = normalOpt;
  96. }
  97. }
  98. if (emphasisOpt) {
  99. if (process.env.NODE_ENV !== 'production') {
  100. deprecateLog(optType + ".emphasis has been changed to emphasis." + optType + " since 4.0");
  101. }
  102. opt.emphasis = opt.emphasis || {};
  103. opt.emphasis[optType] = emphasisOpt;
  104. // Also compat the case user mix the style and focus together in ec3 style
  105. // for example: { itemStyle: { normal: {}, emphasis: {focus, shadowBlur} } }
  106. if (emphasisOpt.focus) {
  107. opt.emphasis.focus = emphasisOpt.focus;
  108. }
  109. if (emphasisOpt.blurScope) {
  110. opt.emphasis.blurScope = emphasisOpt.blurScope;
  111. }
  112. }
  113. }
  114. }
  115. function removeEC3NormalStatus(opt) {
  116. convertNormalEmphasis(opt, 'itemStyle');
  117. convertNormalEmphasis(opt, 'lineStyle');
  118. convertNormalEmphasis(opt, 'areaStyle');
  119. convertNormalEmphasis(opt, 'label');
  120. convertNormalEmphasis(opt, 'labelLine');
  121. // treemap
  122. convertNormalEmphasis(opt, 'upperLabel');
  123. // graph
  124. convertNormalEmphasis(opt, 'edgeLabel');
  125. }
  126. function compatTextStyle(opt, propName) {
  127. // Check whether is not object (string\null\undefined ...)
  128. var labelOptSingle = isObject(opt) && opt[propName];
  129. var textStyle = isObject(labelOptSingle) && labelOptSingle.textStyle;
  130. if (textStyle) {
  131. if (process.env.NODE_ENV !== 'production') {
  132. // eslint-disable-next-line max-len
  133. deprecateLog("textStyle hierarchy in " + propName + " has been removed since 4.0. All textStyle properties are configured in " + propName + " directly now.");
  134. }
  135. for (var i = 0, len = modelUtil.TEXT_STYLE_OPTIONS.length; i < len; i++) {
  136. var textPropName = modelUtil.TEXT_STYLE_OPTIONS[i];
  137. if (textStyle.hasOwnProperty(textPropName)) {
  138. labelOptSingle[textPropName] = textStyle[textPropName];
  139. }
  140. }
  141. }
  142. }
  143. function compatEC3CommonStyles(opt) {
  144. if (opt) {
  145. removeEC3NormalStatus(opt);
  146. compatTextStyle(opt, 'label');
  147. opt.emphasis && compatTextStyle(opt.emphasis, 'label');
  148. }
  149. }
  150. function processSeries(seriesOpt) {
  151. if (!isObject(seriesOpt)) {
  152. return;
  153. }
  154. compatEC2ItemStyle(seriesOpt);
  155. removeEC3NormalStatus(seriesOpt);
  156. compatTextStyle(seriesOpt, 'label');
  157. // treemap
  158. compatTextStyle(seriesOpt, 'upperLabel');
  159. // graph
  160. compatTextStyle(seriesOpt, 'edgeLabel');
  161. if (seriesOpt.emphasis) {
  162. compatTextStyle(seriesOpt.emphasis, 'label');
  163. // treemap
  164. compatTextStyle(seriesOpt.emphasis, 'upperLabel');
  165. // graph
  166. compatTextStyle(seriesOpt.emphasis, 'edgeLabel');
  167. }
  168. var markPoint = seriesOpt.markPoint;
  169. if (markPoint) {
  170. compatEC2ItemStyle(markPoint);
  171. compatEC3CommonStyles(markPoint);
  172. }
  173. var markLine = seriesOpt.markLine;
  174. if (markLine) {
  175. compatEC2ItemStyle(markLine);
  176. compatEC3CommonStyles(markLine);
  177. }
  178. var markArea = seriesOpt.markArea;
  179. if (markArea) {
  180. compatEC3CommonStyles(markArea);
  181. }
  182. var data = seriesOpt.data;
  183. // Break with ec3: if `setOption` again, there may be no `type` in option,
  184. // then the backward compat based on option type will not be performed.
  185. if (seriesOpt.type === 'graph') {
  186. data = data || seriesOpt.nodes;
  187. var edgeData = seriesOpt.links || seriesOpt.edges;
  188. if (edgeData && !zrUtil.isTypedArray(edgeData)) {
  189. for (var i = 0; i < edgeData.length; i++) {
  190. compatEC3CommonStyles(edgeData[i]);
  191. }
  192. }
  193. zrUtil.each(seriesOpt.categories, function (opt) {
  194. removeEC3NormalStatus(opt);
  195. });
  196. }
  197. if (data && !zrUtil.isTypedArray(data)) {
  198. for (var i = 0; i < data.length; i++) {
  199. compatEC3CommonStyles(data[i]);
  200. }
  201. }
  202. // mark point data
  203. markPoint = seriesOpt.markPoint;
  204. if (markPoint && markPoint.data) {
  205. var mpData = markPoint.data;
  206. for (var i = 0; i < mpData.length; i++) {
  207. compatEC3CommonStyles(mpData[i]);
  208. }
  209. }
  210. // mark line data
  211. markLine = seriesOpt.markLine;
  212. if (markLine && markLine.data) {
  213. var mlData = markLine.data;
  214. for (var i = 0; i < mlData.length; i++) {
  215. if (zrUtil.isArray(mlData[i])) {
  216. compatEC3CommonStyles(mlData[i][0]);
  217. compatEC3CommonStyles(mlData[i][1]);
  218. } else {
  219. compatEC3CommonStyles(mlData[i]);
  220. }
  221. }
  222. }
  223. // Series
  224. if (seriesOpt.type === 'gauge') {
  225. compatTextStyle(seriesOpt, 'axisLabel');
  226. compatTextStyle(seriesOpt, 'title');
  227. compatTextStyle(seriesOpt, 'detail');
  228. } else if (seriesOpt.type === 'treemap') {
  229. convertNormalEmphasis(seriesOpt.breadcrumb, 'itemStyle');
  230. zrUtil.each(seriesOpt.levels, function (opt) {
  231. removeEC3NormalStatus(opt);
  232. });
  233. } else if (seriesOpt.type === 'tree') {
  234. removeEC3NormalStatus(seriesOpt.leaves);
  235. }
  236. // sunburst starts from ec4, so it does not need to compat levels.
  237. }
  238. function toArr(o) {
  239. return zrUtil.isArray(o) ? o : o ? [o] : [];
  240. }
  241. function toObj(o) {
  242. return (zrUtil.isArray(o) ? o[0] : o) || {};
  243. }
  244. export default function globalCompatStyle(option, isTheme) {
  245. each(toArr(option.series), function (seriesOpt) {
  246. isObject(seriesOpt) && processSeries(seriesOpt);
  247. });
  248. var axes = ['xAxis', 'yAxis', 'radiusAxis', 'angleAxis', 'singleAxis', 'parallelAxis', 'radar'];
  249. isTheme && axes.push('valueAxis', 'categoryAxis', 'logAxis', 'timeAxis');
  250. each(axes, function (axisName) {
  251. each(toArr(option[axisName]), function (axisOpt) {
  252. if (axisOpt) {
  253. compatTextStyle(axisOpt, 'axisLabel');
  254. compatTextStyle(axisOpt.axisPointer, 'label');
  255. }
  256. });
  257. });
  258. each(toArr(option.parallel), function (parallelOpt) {
  259. var parallelAxisDefault = parallelOpt && parallelOpt.parallelAxisDefault;
  260. compatTextStyle(parallelAxisDefault, 'axisLabel');
  261. compatTextStyle(parallelAxisDefault && parallelAxisDefault.axisPointer, 'label');
  262. });
  263. each(toArr(option.calendar), function (calendarOpt) {
  264. convertNormalEmphasis(calendarOpt, 'itemStyle');
  265. compatTextStyle(calendarOpt, 'dayLabel');
  266. compatTextStyle(calendarOpt, 'monthLabel');
  267. compatTextStyle(calendarOpt, 'yearLabel');
  268. });
  269. // radar.name.textStyle
  270. each(toArr(option.radar), function (radarOpt) {
  271. compatTextStyle(radarOpt, 'name');
  272. // Use axisName instead of name because component has name property
  273. if (radarOpt.name && radarOpt.axisName == null) {
  274. radarOpt.axisName = radarOpt.name;
  275. delete radarOpt.name;
  276. if (process.env.NODE_ENV !== 'production') {
  277. deprecateLog('name property in radar component has been changed to axisName');
  278. }
  279. }
  280. if (radarOpt.nameGap != null && radarOpt.axisNameGap == null) {
  281. radarOpt.axisNameGap = radarOpt.nameGap;
  282. delete radarOpt.nameGap;
  283. if (process.env.NODE_ENV !== 'production') {
  284. deprecateLog('nameGap property in radar component has been changed to axisNameGap');
  285. }
  286. }
  287. if (process.env.NODE_ENV !== 'production') {
  288. each(radarOpt.indicator, function (indicatorOpt) {
  289. if (indicatorOpt.text) {
  290. deprecateReplaceLog('text', 'name', 'radar.indicator');
  291. }
  292. });
  293. }
  294. });
  295. each(toArr(option.geo), function (geoOpt) {
  296. if (isObject(geoOpt)) {
  297. compatEC3CommonStyles(geoOpt);
  298. each(toArr(geoOpt.regions), function (regionObj) {
  299. compatEC3CommonStyles(regionObj);
  300. });
  301. }
  302. });
  303. each(toArr(option.timeline), function (timelineOpt) {
  304. compatEC3CommonStyles(timelineOpt);
  305. convertNormalEmphasis(timelineOpt, 'label');
  306. convertNormalEmphasis(timelineOpt, 'itemStyle');
  307. convertNormalEmphasis(timelineOpt, 'controlStyle', true);
  308. var data = timelineOpt.data;
  309. zrUtil.isArray(data) && zrUtil.each(data, function (item) {
  310. if (zrUtil.isObject(item)) {
  311. convertNormalEmphasis(item, 'label');
  312. convertNormalEmphasis(item, 'itemStyle');
  313. }
  314. });
  315. });
  316. each(toArr(option.toolbox), function (toolboxOpt) {
  317. convertNormalEmphasis(toolboxOpt, 'iconStyle');
  318. each(toolboxOpt.feature, function (featureOpt) {
  319. convertNormalEmphasis(featureOpt, 'iconStyle');
  320. });
  321. });
  322. compatTextStyle(toObj(option.axisPointer), 'label');
  323. compatTextStyle(toObj(option.tooltip).axisPointer, 'label');
  324. // Clean logs
  325. // storedLogs = {};
  326. }