123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242 |
- var zrUtil = require("zrender/lib/core/util");
- var echarts = require("../echarts");
- var graphic = require("../util/graphic");
- var _layout = require("../util/layout");
- var getLayoutRect = _layout.getLayoutRect;
- var _format = require("../util/format");
- var windowOpen = _format.windowOpen;
- echarts.extendComponentModel({
- type: 'title',
- layoutMode: {
- type: 'box',
- ignoreSize: true
- },
- defaultOption: {
-
- zlevel: 0,
-
- z: 6,
- show: true,
- text: '',
-
-
-
- target: 'blank',
- subtext: '',
-
-
-
- subtarget: 'blank',
-
-
- left: 0,
-
-
- top: 0,
-
-
-
-
-
-
-
-
-
-
- backgroundColor: 'rgba(0,0,0,0)',
-
- borderColor: '#ccc',
-
- borderWidth: 0,
-
-
- padding: 5,
-
- itemGap: 10,
- textStyle: {
- fontSize: 18,
- fontWeight: 'bolder',
- color: '#333'
- },
- subtextStyle: {
- color: '#aaa'
- }
- }
- });
- echarts.extendComponentView({
- type: 'title',
- render: function (titleModel, ecModel, api) {
- this.group.removeAll();
- if (!titleModel.get('show')) {
- return;
- }
- var group = this.group;
- var textStyleModel = titleModel.getModel('textStyle');
- var subtextStyleModel = titleModel.getModel('subtextStyle');
- var textAlign = titleModel.get('textAlign');
- var textVerticalAlign = zrUtil.retrieve2(titleModel.get('textBaseline'), titleModel.get('textVerticalAlign'));
- var textEl = new graphic.Text({
- style: graphic.setTextStyle({}, textStyleModel, {
- text: titleModel.get('text'),
- textFill: textStyleModel.getTextColor()
- }, {
- disableBox: true
- }),
- z2: 10
- });
- var textRect = textEl.getBoundingRect();
- var subText = titleModel.get('subtext');
- var subTextEl = new graphic.Text({
- style: graphic.setTextStyle({}, subtextStyleModel, {
- text: subText,
- textFill: subtextStyleModel.getTextColor(),
- y: textRect.height + titleModel.get('itemGap'),
- textVerticalAlign: 'top'
- }, {
- disableBox: true
- }),
- z2: 10
- });
- var link = titleModel.get('link');
- var sublink = titleModel.get('sublink');
- var triggerEvent = titleModel.get('triggerEvent', true);
- textEl.silent = !link && !triggerEvent;
- subTextEl.silent = !sublink && !triggerEvent;
- if (link) {
- textEl.on('click', function () {
- windowOpen(link, '_' + titleModel.get('target'));
- });
- }
- if (sublink) {
- subTextEl.on('click', function () {
- windowOpen(sublink, '_' + titleModel.get('subtarget'));
- });
- }
- textEl.eventData = subTextEl.eventData = triggerEvent ? {
- componentType: 'title',
- componentIndex: titleModel.componentIndex
- } : null;
- group.add(textEl);
- subText && group.add(subTextEl);
- var groupRect = group.getBoundingRect();
- var layoutOption = titleModel.getBoxLayoutParams();
- layoutOption.width = groupRect.width;
- layoutOption.height = groupRect.height;
- var layoutRect = getLayoutRect(layoutOption, {
- width: api.getWidth(),
- height: api.getHeight()
- }, titleModel.get('padding'));
- if (!textAlign) {
-
- textAlign = titleModel.get('left') || titleModel.get('right');
- if (textAlign === 'middle') {
- textAlign = 'center';
- }
- if (textAlign === 'right') {
- layoutRect.x += layoutRect.width;
- } else if (textAlign === 'center') {
- layoutRect.x += layoutRect.width / 2;
- }
- }
- if (!textVerticalAlign) {
- textVerticalAlign = titleModel.get('top') || titleModel.get('bottom');
- if (textVerticalAlign === 'center') {
- textVerticalAlign = 'middle';
- }
- if (textVerticalAlign === 'bottom') {
- layoutRect.y += layoutRect.height;
- } else if (textVerticalAlign === 'middle') {
- layoutRect.y += layoutRect.height / 2;
- }
- textVerticalAlign = textVerticalAlign || 'top';
- }
- group.attr('position', [layoutRect.x, layoutRect.y]);
- var alignStyle = {
- textAlign: textAlign,
- textVerticalAlign: textVerticalAlign
- };
- textEl.setStyle(alignStyle);
- subTextEl.setStyle(alignStyle);
-
- groupRect = group.getBoundingRect();
- var padding = layoutRect.margin;
- var style = titleModel.getItemStyle(['color', 'opacity']);
- style.fill = titleModel.get('backgroundColor');
- var rect = new graphic.Rect({
- shape: {
- x: groupRect.x - padding[3],
- y: groupRect.y - padding[0],
- width: groupRect.width + padding[1] + padding[3],
- height: groupRect.height + padding[0] + padding[2],
- r: titleModel.get('borderRadius')
- },
- style: style,
- subPixelOptimize: true,
- silent: true
- });
- group.add(rect);
- }
- });
|