styleCompat.js 11 KB

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