compatStyle.js 12 KB

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