install.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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 { __extends } from "tslib";
  41. import * as zrUtil from 'zrender/lib/core/util.js';
  42. import * as graphic from '../../util/graphic.js';
  43. import { getECData } from '../../util/innerStore.js';
  44. import { createTextStyle } from '../../label/labelStyle.js';
  45. import { getLayoutRect } from '../../util/layout.js';
  46. import ComponentModel from '../../model/Component.js';
  47. import ComponentView from '../../view/Component.js';
  48. import { windowOpen } from '../../util/format.js';
  49. var TitleModel = /** @class */function (_super) {
  50. __extends(TitleModel, _super);
  51. function TitleModel() {
  52. var _this = _super !== null && _super.apply(this, arguments) || this;
  53. _this.type = TitleModel.type;
  54. _this.layoutMode = {
  55. type: 'box',
  56. ignoreSize: true
  57. };
  58. return _this;
  59. }
  60. TitleModel.type = 'title';
  61. TitleModel.defaultOption = {
  62. // zlevel: 0,
  63. z: 6,
  64. show: true,
  65. text: '',
  66. target: 'blank',
  67. subtext: '',
  68. subtarget: 'blank',
  69. left: 0,
  70. top: 0,
  71. backgroundColor: 'rgba(0,0,0,0)',
  72. borderColor: '#ccc',
  73. borderWidth: 0,
  74. padding: 5,
  75. itemGap: 10,
  76. textStyle: {
  77. fontSize: 18,
  78. fontWeight: 'bold',
  79. color: '#464646'
  80. },
  81. subtextStyle: {
  82. fontSize: 12,
  83. color: '#6E7079'
  84. }
  85. };
  86. return TitleModel;
  87. }(ComponentModel);
  88. // View
  89. var TitleView = /** @class */function (_super) {
  90. __extends(TitleView, _super);
  91. function TitleView() {
  92. var _this = _super !== null && _super.apply(this, arguments) || this;
  93. _this.type = TitleView.type;
  94. return _this;
  95. }
  96. TitleView.prototype.render = function (titleModel, ecModel, api) {
  97. this.group.removeAll();
  98. if (!titleModel.get('show')) {
  99. return;
  100. }
  101. var group = this.group;
  102. var textStyleModel = titleModel.getModel('textStyle');
  103. var subtextStyleModel = titleModel.getModel('subtextStyle');
  104. var textAlign = titleModel.get('textAlign');
  105. var textVerticalAlign = zrUtil.retrieve2(titleModel.get('textBaseline'), titleModel.get('textVerticalAlign'));
  106. var textEl = new graphic.Text({
  107. style: createTextStyle(textStyleModel, {
  108. text: titleModel.get('text'),
  109. fill: textStyleModel.getTextColor()
  110. }, {
  111. disableBox: true
  112. }),
  113. z2: 10
  114. });
  115. var textRect = textEl.getBoundingRect();
  116. var subText = titleModel.get('subtext');
  117. var subTextEl = new graphic.Text({
  118. style: createTextStyle(subtextStyleModel, {
  119. text: subText,
  120. fill: subtextStyleModel.getTextColor(),
  121. y: textRect.height + titleModel.get('itemGap'),
  122. verticalAlign: 'top'
  123. }, {
  124. disableBox: true
  125. }),
  126. z2: 10
  127. });
  128. var link = titleModel.get('link');
  129. var sublink = titleModel.get('sublink');
  130. var triggerEvent = titleModel.get('triggerEvent', true);
  131. textEl.silent = !link && !triggerEvent;
  132. subTextEl.silent = !sublink && !triggerEvent;
  133. if (link) {
  134. textEl.on('click', function () {
  135. windowOpen(link, '_' + titleModel.get('target'));
  136. });
  137. }
  138. if (sublink) {
  139. subTextEl.on('click', function () {
  140. windowOpen(sublink, '_' + titleModel.get('subtarget'));
  141. });
  142. }
  143. getECData(textEl).eventData = getECData(subTextEl).eventData = triggerEvent ? {
  144. componentType: 'title',
  145. componentIndex: titleModel.componentIndex
  146. } : null;
  147. group.add(textEl);
  148. subText && group.add(subTextEl);
  149. // If no subText, but add subTextEl, there will be an empty line.
  150. var groupRect = group.getBoundingRect();
  151. var layoutOption = titleModel.getBoxLayoutParams();
  152. layoutOption.width = groupRect.width;
  153. layoutOption.height = groupRect.height;
  154. var layoutRect = getLayoutRect(layoutOption, {
  155. width: api.getWidth(),
  156. height: api.getHeight()
  157. }, titleModel.get('padding'));
  158. // Adjust text align based on position
  159. if (!textAlign) {
  160. // Align left if title is on the left. center and right is same
  161. textAlign = titleModel.get('left') || titleModel.get('right');
  162. // @ts-ignore
  163. if (textAlign === 'middle') {
  164. textAlign = 'center';
  165. }
  166. // Adjust layout by text align
  167. if (textAlign === 'right') {
  168. layoutRect.x += layoutRect.width;
  169. } else if (textAlign === 'center') {
  170. layoutRect.x += layoutRect.width / 2;
  171. }
  172. }
  173. if (!textVerticalAlign) {
  174. textVerticalAlign = titleModel.get('top') || titleModel.get('bottom');
  175. // @ts-ignore
  176. if (textVerticalAlign === 'center') {
  177. textVerticalAlign = 'middle';
  178. }
  179. if (textVerticalAlign === 'bottom') {
  180. layoutRect.y += layoutRect.height;
  181. } else if (textVerticalAlign === 'middle') {
  182. layoutRect.y += layoutRect.height / 2;
  183. }
  184. textVerticalAlign = textVerticalAlign || 'top';
  185. }
  186. group.x = layoutRect.x;
  187. group.y = layoutRect.y;
  188. group.markRedraw();
  189. var alignStyle = {
  190. align: textAlign,
  191. verticalAlign: textVerticalAlign
  192. };
  193. textEl.setStyle(alignStyle);
  194. subTextEl.setStyle(alignStyle);
  195. // Render background
  196. // Get groupRect again because textAlign has been changed
  197. groupRect = group.getBoundingRect();
  198. var padding = layoutRect.margin;
  199. var style = titleModel.getItemStyle(['color', 'opacity']);
  200. style.fill = titleModel.get('backgroundColor');
  201. var rect = new graphic.Rect({
  202. shape: {
  203. x: groupRect.x - padding[3],
  204. y: groupRect.y - padding[0],
  205. width: groupRect.width + padding[1] + padding[3],
  206. height: groupRect.height + padding[0] + padding[2],
  207. r: titleModel.get('borderRadius')
  208. },
  209. style: style,
  210. subPixelOptimize: true,
  211. silent: true
  212. });
  213. group.add(rect);
  214. };
  215. TitleView.type = 'title';
  216. return TitleView;
  217. }(ComponentView);
  218. export function install(registers) {
  219. registers.registerComponentModel(TitleModel);
  220. registers.registerComponentView(TitleView);
  221. }