install.js 7.4 KB

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