styleCompat.js 11 KB

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