styleCompat.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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, hasOwn } from 'zrender/lib/core/util.js';
  41. var deprecatedLogs = {};
  42. /**
  43. * Whether need to call `convertEC4CompatibleStyle`.
  44. */
  45. export function isEC4CompatibleStyle(style, elType, hasOwnTextContentOption, hasOwnTextConfig) {
  46. // Since echarts5, `RectText` is separated from its host element and style.text
  47. // does not exist any more. The compat work brings some extra burden on performance.
  48. // So we provide:
  49. // `legacy: true` force make compat.
  50. // `legacy: false`, force do not compat.
  51. // `legacy` not set: auto detect whether legacy.
  52. // But in this case we do not compat (difficult to detect and rare case):
  53. // Becuse custom series and graphic component support "merge", users may firstly
  54. // only set `textStrokeWidth` style or secondly only set `text`.
  55. return style && (style.legacy || style.legacy !== false && !hasOwnTextContentOption && !hasOwnTextConfig && elType !== 'tspan'
  56. // Difficult to detect whether legacy for a "text" el.
  57. && (elType === 'text' || hasOwn(style, 'text')));
  58. }
  59. /**
  60. * `EC4CompatibleStyle` is style that might be in echarts4 format or echarts5 format.
  61. * @param hostStyle The properties might be modified.
  62. * @return If be text el, `textContentStyle` and `textConfig` will not be returned.
  63. * Otherwise a `textContentStyle` and `textConfig` will be created, whose props area
  64. * retried from the `hostStyle`.
  65. */
  66. export function convertFromEC4CompatibleStyle(hostStyle, elType, isNormal) {
  67. var srcStyle = hostStyle;
  68. var textConfig;
  69. var textContent;
  70. var textContentStyle;
  71. if (elType === 'text') {
  72. textContentStyle = srcStyle;
  73. } else {
  74. textContentStyle = {};
  75. hasOwn(srcStyle, 'text') && (textContentStyle.text = srcStyle.text);
  76. hasOwn(srcStyle, 'rich') && (textContentStyle.rich = srcStyle.rich);
  77. hasOwn(srcStyle, 'textFill') && (textContentStyle.fill = srcStyle.textFill);
  78. hasOwn(srcStyle, 'textStroke') && (textContentStyle.stroke = srcStyle.textStroke);
  79. hasOwn(srcStyle, 'fontFamily') && (textContentStyle.fontFamily = srcStyle.fontFamily);
  80. hasOwn(srcStyle, 'fontSize') && (textContentStyle.fontSize = srcStyle.fontSize);
  81. hasOwn(srcStyle, 'fontStyle') && (textContentStyle.fontStyle = srcStyle.fontStyle);
  82. hasOwn(srcStyle, 'fontWeight') && (textContentStyle.fontWeight = srcStyle.fontWeight);
  83. textContent = {
  84. type: 'text',
  85. style: textContentStyle,
  86. // ec4 does not support rectText trigger.
  87. // And when text position is different in normal and emphasis
  88. // => hover text trigger emphasis;
  89. // => text position changed, leave mouse pointer immediately;
  90. // That might cause incorrect state.
  91. silent: true
  92. };
  93. textConfig = {};
  94. var hasOwnPos = hasOwn(srcStyle, 'textPosition');
  95. if (isNormal) {
  96. textConfig.position = hasOwnPos ? srcStyle.textPosition : 'inside';
  97. } else {
  98. hasOwnPos && (textConfig.position = srcStyle.textPosition);
  99. }
  100. hasOwn(srcStyle, 'textPosition') && (textConfig.position = srcStyle.textPosition);
  101. hasOwn(srcStyle, 'textOffset') && (textConfig.offset = srcStyle.textOffset);
  102. hasOwn(srcStyle, 'textRotation') && (textConfig.rotation = srcStyle.textRotation);
  103. hasOwn(srcStyle, 'textDistance') && (textConfig.distance = srcStyle.textDistance);
  104. }
  105. convertEC4CompatibleRichItem(textContentStyle, hostStyle);
  106. each(textContentStyle.rich, function (richItem) {
  107. convertEC4CompatibleRichItem(richItem, richItem);
  108. });
  109. return {
  110. textConfig: textConfig,
  111. textContent: textContent
  112. };
  113. }
  114. /**
  115. * The result will be set to `out`.
  116. */
  117. function convertEC4CompatibleRichItem(out, richItem) {
  118. if (!richItem) {
  119. return;
  120. }
  121. // (1) For simplicity, make textXXX properties (deprecated since ec5) has
  122. // higher priority. For example, consider in ec4 `borderColor: 5, textBorderColor: 10`
  123. // on a rect means `borderColor: 4` on the rect and `borderColor: 10` on an attached
  124. // richText in ec5.
  125. // (2) `out === richItem` if and only if `out` is text el or rich item.
  126. // So we can overwrite existing props in `out` since textXXX has higher priority.
  127. richItem.font = richItem.textFont || richItem.font;
  128. hasOwn(richItem, 'textStrokeWidth') && (out.lineWidth = richItem.textStrokeWidth);
  129. hasOwn(richItem, 'textAlign') && (out.align = richItem.textAlign);
  130. hasOwn(richItem, 'textVerticalAlign') && (out.verticalAlign = richItem.textVerticalAlign);
  131. hasOwn(richItem, 'textLineHeight') && (out.lineHeight = richItem.textLineHeight);
  132. hasOwn(richItem, 'textWidth') && (out.width = richItem.textWidth);
  133. hasOwn(richItem, 'textHeight') && (out.height = richItem.textHeight);
  134. hasOwn(richItem, 'textBackgroundColor') && (out.backgroundColor = richItem.textBackgroundColor);
  135. hasOwn(richItem, 'textPadding') && (out.padding = richItem.textPadding);
  136. hasOwn(richItem, 'textBorderColor') && (out.borderColor = richItem.textBorderColor);
  137. hasOwn(richItem, 'textBorderWidth') && (out.borderWidth = richItem.textBorderWidth);
  138. hasOwn(richItem, 'textBorderRadius') && (out.borderRadius = richItem.textBorderRadius);
  139. hasOwn(richItem, 'textBoxShadowColor') && (out.shadowColor = richItem.textBoxShadowColor);
  140. hasOwn(richItem, 'textBoxShadowBlur') && (out.shadowBlur = richItem.textBoxShadowBlur);
  141. hasOwn(richItem, 'textBoxShadowOffsetX') && (out.shadowOffsetX = richItem.textBoxShadowOffsetX);
  142. hasOwn(richItem, 'textBoxShadowOffsetY') && (out.shadowOffsetY = richItem.textBoxShadowOffsetY);
  143. }
  144. /**
  145. * Convert to pure echarts4 format style.
  146. * `itemStyle` will be modified, added with ec4 style properties from
  147. * `textStyle` and `textConfig`.
  148. *
  149. * [Caveat]: For simplicity, `insideRollback` in ec4 does not compat, where
  150. * `styleEmphasis: {textFill: 'red'}` will remove the normal auto added stroke.
  151. */
  152. export function convertToEC4StyleForCustomSerise(itemStl, txStl, txCfg) {
  153. var out = itemStl;
  154. // See `custom.ts`, a trick to set extra `textPosition` firstly.
  155. out.textPosition = out.textPosition || txCfg.position || 'inside';
  156. txCfg.offset != null && (out.textOffset = txCfg.offset);
  157. txCfg.rotation != null && (out.textRotation = txCfg.rotation);
  158. txCfg.distance != null && (out.textDistance = txCfg.distance);
  159. var isInside = out.textPosition.indexOf('inside') >= 0;
  160. var hostFill = itemStl.fill || '#000';
  161. convertToEC4RichItem(out, txStl);
  162. var textFillNotSet = out.textFill == null;
  163. if (isInside) {
  164. if (textFillNotSet) {
  165. out.textFill = txCfg.insideFill || '#fff';
  166. !out.textStroke && txCfg.insideStroke && (out.textStroke = txCfg.insideStroke);
  167. !out.textStroke && (out.textStroke = hostFill);
  168. out.textStrokeWidth == null && (out.textStrokeWidth = 2);
  169. }
  170. } else {
  171. if (textFillNotSet) {
  172. out.textFill = itemStl.fill || txCfg.outsideFill || '#000';
  173. }
  174. !out.textStroke && txCfg.outsideStroke && (out.textStroke = txCfg.outsideStroke);
  175. }
  176. out.text = txStl.text;
  177. out.rich = txStl.rich;
  178. each(txStl.rich, function (richItem) {
  179. convertToEC4RichItem(richItem, richItem);
  180. });
  181. return out;
  182. }
  183. function convertToEC4RichItem(out, richItem) {
  184. if (!richItem) {
  185. return;
  186. }
  187. hasOwn(richItem, 'fill') && (out.textFill = richItem.fill);
  188. hasOwn(richItem, 'stroke') && (out.textStroke = richItem.fill);
  189. hasOwn(richItem, 'lineWidth') && (out.textStrokeWidth = richItem.lineWidth);
  190. hasOwn(richItem, 'font') && (out.font = richItem.font);
  191. hasOwn(richItem, 'fontStyle') && (out.fontStyle = richItem.fontStyle);
  192. hasOwn(richItem, 'fontWeight') && (out.fontWeight = richItem.fontWeight);
  193. hasOwn(richItem, 'fontSize') && (out.fontSize = richItem.fontSize);
  194. hasOwn(richItem, 'fontFamily') && (out.fontFamily = richItem.fontFamily);
  195. hasOwn(richItem, 'align') && (out.textAlign = richItem.align);
  196. hasOwn(richItem, 'verticalAlign') && (out.textVerticalAlign = richItem.verticalAlign);
  197. hasOwn(richItem, 'lineHeight') && (out.textLineHeight = richItem.lineHeight);
  198. hasOwn(richItem, 'width') && (out.textWidth = richItem.width);
  199. hasOwn(richItem, 'height') && (out.textHeight = richItem.height);
  200. hasOwn(richItem, 'backgroundColor') && (out.textBackgroundColor = richItem.backgroundColor);
  201. hasOwn(richItem, 'padding') && (out.textPadding = richItem.padding);
  202. hasOwn(richItem, 'borderColor') && (out.textBorderColor = richItem.borderColor);
  203. hasOwn(richItem, 'borderWidth') && (out.textBorderWidth = richItem.borderWidth);
  204. hasOwn(richItem, 'borderRadius') && (out.textBorderRadius = richItem.borderRadius);
  205. hasOwn(richItem, 'shadowColor') && (out.textBoxShadowColor = richItem.shadowColor);
  206. hasOwn(richItem, 'shadowBlur') && (out.textBoxShadowBlur = richItem.shadowBlur);
  207. hasOwn(richItem, 'shadowOffsetX') && (out.textBoxShadowOffsetX = richItem.shadowOffsetX);
  208. hasOwn(richItem, 'shadowOffsetY') && (out.textBoxShadowOffsetY = richItem.shadowOffsetY);
  209. hasOwn(richItem, 'textShadowColor') && (out.textShadowColor = richItem.textShadowColor);
  210. hasOwn(richItem, 'textShadowBlur') && (out.textShadowBlur = richItem.textShadowBlur);
  211. hasOwn(richItem, 'textShadowOffsetX') && (out.textShadowOffsetX = richItem.textShadowOffsetX);
  212. hasOwn(richItem, 'textShadowOffsetY') && (out.textShadowOffsetY = richItem.textShadowOffsetY);
  213. }
  214. export function warnDeprecated(deprecated, insteadApproach) {
  215. if (process.env.NODE_ENV !== 'production') {
  216. var key = deprecated + '^_^' + insteadApproach;
  217. if (!deprecatedLogs[key]) {
  218. console.warn("[ECharts] DEPRECATED: \"" + deprecated + "\" has been deprecated. " + insteadApproach);
  219. deprecatedLogs[key] = true;
  220. }
  221. }
  222. }