forked from apache/echarts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
grid.js
148 lines (126 loc) · 4.22 KB
/
grid.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/**
* echarts组件: 网格
*
* @desc echarts基于Canvas,纯Javascript图表库,提供直观,生动,可交互,可个性化定制的数据统计图表。
* @author Kener (@Kener-林峰, [email protected])
*
*/
define(function (require) {
/**
* 构造函数
* @param {Object} messageCenter echart消息中心
* @param {ZRender} zr zrender实例
* @param {Object} option 图表选项
* @param {number=} option.grid.x 直角坐标系内绘图网格起始横坐标,数值单位px
* @param {number=} option.grid.y 直角坐标系内绘图网格起始纵坐标,数值单位px
* @param {number=} option.grid.width 直角坐标系内绘图网格宽度,数值单位px
* @param {number=} option.grid.height 直角坐标系内绘图网格高度,数值单位px
*/
function Grid(messageCenter, zr, option) {
var Base = require('./base');
Base.call(this, zr);
var ecConfig = require('../config');
var self = this;
self.type = ecConfig.COMPONENT_TYPE_GRID;
var _zlevelBase = self.getZlevelBase();
var _x;
var _y;
var _width;
var _height;
var _zrWidth;
var _zrHeight;
/**
* 构造函数默认执行的初始化方法,也用于创建实例后动态修改
* @param {Object} newZr
* @param {Object} newOption
*/
function init(newOption) {
option = newOption;
option.grid = self.reformOption(option.grid);
var gridOption = option.grid;
_x = gridOption.x;
_y = gridOption.y;
var x2 = gridOption.x2;
var y2 = gridOption.y2;
_zrWidth = zr.getWidth();
_zrHeight = zr.getHeight();
if (typeof gridOption.width == 'undefined') {
_width = _zrWidth - _x - x2;
}
else {
_width = gridOption.width;
}
if (typeof gridOption.height == 'undefined') {
_height = _zrHeight - _y - y2;
}
else {
_height = gridOption.height;
}
self.shapeList.push({
shape : 'rectangle',
id : zr.newShapeId('grid'),
zlevel : _zlevelBase,
hoverable : false,
style : {
x : _x,
y : _y,
width : _width,
height : _height,
brushType : 'both',
color : gridOption.backgroundColor,
strokeColor: gridOption.borderColor,
lineWidth : gridOption.borderWidth
// type : option.splitArea.areaStyle.type,
}
});
zr.addShape(self.shapeList[0]);
}
function getX() {
return _x;
}
function getY() {
return _y;
}
function getWidth() {
return _width;
}
function getHeight() {
return _height;
}
function getXend() {
return _x + _width;
}
function getYend() {
return _y + _height;
}
function getArea() {
return {
x : _x,
y : _y,
width : _width,
height : _height
};
}
function refresh(newOption) {
if (_zrWidth != zr.getWidth()
|| _zrHeight != zr.getHeight()
|| newOption
) {
self.clear();
init(newOption || option);
}
}
self.init = init;
self.getX = getX;
self.getY = getY;
self.getWidth = getWidth;
self.getHeight = getHeight;
self.getXend = getXend;
self.getYend = getYend;
self.getArea = getArea;
self.refresh = refresh;
init(option);
}
require('../component').define('grid', Grid);
return Grid;
});