jmchart 1.2.10 → 1.2.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,165 +1,165 @@
1
-
2
- /**
3
- * 显示提示控件
4
- * params参数:style=样式,value=显示的文字
5
- *
6
- * @class jmTooltip
7
- * @for jmGraph
8
- * @module jmGraph
9
- * @param {jmGraph} graph 当前画布
10
- * @param {object} params 参数
11
- */
12
- function jmTooltip(graph,params) {
13
- if(!params) params = {};
14
- var style = params.style || {};
15
- style.font = style.font || "15px Arial";
16
- this.type = 'jmTooltip';
17
-
18
- this.graph = graph;
19
-
20
- this.position(params.position || {x:0,y:0});
21
- this.initializing(graph.context,style);
22
-
23
- this.element = document.createElement('div');
24
- this.element.className = 'jm-tooltip';
25
- this.element.style.position = 'absolute';
26
- this.element.style.display = 'none';
27
- this.value(params.value);
28
- document.body.appendChild(this.element);
29
- }
30
-
31
- jmUtils.extend(jmTooltip,jmControl);//jmPath
32
-
33
- /**
34
- * 写入样式
35
- *
36
- * @method setStyle
37
- * @private
38
- */
39
- jmTooltip.prototype.setStyle = function(style) {
40
- style = style || this.style;
41
- if(style && typeof style == 'object') {
42
- for(var k in style) {
43
- if(typeof(k) != 'string' || typeof(style[k]) != 'string') continue;
44
- try {
45
- this.element.style[k] = style[k];
46
- }
47
- catch(e) {
48
- window.console.log(e);
49
- }
50
- }
51
- }
52
- }
53
-
54
- /**
55
- * 计算提示位并显示
56
- *
57
- * @method draw
58
- */
59
- jmTooltip.prototype.draw = function() {
60
- this.setPosition();
61
- }
62
-
63
- /**
64
- * 设置提示坐标位置
65
- *
66
- * @method setPosition
67
- * @param {number} x X轴坐标
68
- * @param {number} y Y轴坐标
69
- */
70
- jmTooltip.prototype.setPosition = function(x,y) {
71
- this.x = x || this.x || 0;
72
- this.y = y || this.y || 0;
73
- //获取当前控件的绝对位置
74
- var bounds = this.parent && this.parent.absoluteBounds?this.parent.absoluteBounds:this.absoluteBounds;
75
- var location = this.getLocation();
76
- x = this.x + location.left + bounds.left;
77
- y = this.y + location.top + bounds.top;
78
-
79
- var graphpostion = this.graph.getPosition();
80
- x += graphpostion.left;
81
- y += graphpostion.top;
82
-
83
- this.element.style.top = y + 'px';
84
- this.element.style.left = x + 'px';
85
- }
86
-
87
- /**
88
- * 移除当前控件
89
- *
90
- * @method remove
91
- */
92
- jmTooltip.prototype.remove = function() {
93
- if(this.element) {
94
- document.body.removeChild(this.element);
95
- }
96
- }
97
-
98
- /**
99
- * 显示当前控件
100
- *
101
- * @method remove
102
- */
103
- jmTooltip.prototype.show = function() {
104
- if(this.element) {
105
- this.element.style.display = 'inline';
106
- }
107
- }
108
-
109
- /**
110
- * 隐藏当前控件
111
- *
112
- * @method remove
113
- */
114
- jmTooltip.prototype.hide = function() {
115
- if(this.element) {
116
- this.element.style.display = 'none';
117
- }
118
- }
119
-
120
- /**
121
- * 设置或获取当前值
122
- *
123
- * @method value
124
- */
125
- jmTooltip.prototype.value = function(v) {
126
- if(this.element) {
127
- if(v !== undefined) {
128
- this.element.innerHTML = v;
129
- }
130
- return this.element.innerHTML;
131
- }
132
- }
133
-
134
- /**
135
- * 设置或获取当前宽度
136
- *
137
- * @method width
138
- * @param {number} w 宽度
139
- */
140
- jmTooltip.prototype.width = function(w) {
141
- if(this.element) {
142
- if(w !== undefined) {
143
- this.element.style.width = w + 'px';
144
- }
145
- return this.element.clientWidth;
146
- }
147
- }
148
-
149
- /**
150
- * 设置或获取当前高度
151
- *
152
- * @method width
153
- * @param {number} w 宽度
154
- */
155
- jmTooltip.prototype.height = function(h) {
156
- if(this.element) {
157
- if(h !== undefined) {
158
- this.element.style.height = h + 'px';
159
- }
160
- return this.element.clientHeight;
161
- }
162
- }
163
-
164
-
165
-
1
+
2
+ /**
3
+ * 显示提示控件
4
+ * params参数:style=样式,value=显示的文字
5
+ *
6
+ * @class jmTooltip
7
+ * @for jmGraph
8
+ * @module jmGraph
9
+ * @param {jmGraph} graph 当前画布
10
+ * @param {object} params 参数
11
+ */
12
+ function jmTooltip(graph,params) {
13
+ if(!params) params = {};
14
+ var style = params.style || {};
15
+ style.font = style.font || "15px Arial";
16
+ this.type = 'jmTooltip';
17
+
18
+ this.graph = graph;
19
+
20
+ this.position(params.position || {x:0,y:0});
21
+ this.initializing(graph.context,style);
22
+
23
+ this.element = document.createElement('div');
24
+ this.element.className = 'jm-tooltip';
25
+ this.element.style.position = 'absolute';
26
+ this.element.style.display = 'none';
27
+ this.value(params.value);
28
+ document.body.appendChild(this.element);
29
+ }
30
+
31
+ jmUtils.extend(jmTooltip,jmControl);//jmPath
32
+
33
+ /**
34
+ * 写入样式
35
+ *
36
+ * @method setStyle
37
+ * @private
38
+ */
39
+ jmTooltip.prototype.setStyle = function(style) {
40
+ style = style || this.style;
41
+ if(style && typeof style == 'object') {
42
+ for(var k in style) {
43
+ if(typeof(k) != 'string' || typeof(style[k]) != 'string') continue;
44
+ try {
45
+ this.element.style[k] = style[k];
46
+ }
47
+ catch(e) {
48
+ window.console.log(e);
49
+ }
50
+ }
51
+ }
52
+ }
53
+
54
+ /**
55
+ * 计算提示位并显示
56
+ *
57
+ * @method draw
58
+ */
59
+ jmTooltip.prototype.draw = function() {
60
+ this.setPosition();
61
+ }
62
+
63
+ /**
64
+ * 设置提示坐标位置
65
+ *
66
+ * @method setPosition
67
+ * @param {number} x X轴坐标
68
+ * @param {number} y Y轴坐标
69
+ */
70
+ jmTooltip.prototype.setPosition = function(x,y) {
71
+ this.x = x || this.x || 0;
72
+ this.y = y || this.y || 0;
73
+ //获取当前控件的绝对位置
74
+ var bounds = this.parent && this.parent.absoluteBounds?this.parent.absoluteBounds:this.absoluteBounds;
75
+ var location = this.getLocation();
76
+ x = this.x + location.left + bounds.left;
77
+ y = this.y + location.top + bounds.top;
78
+
79
+ var graphpostion = this.graph.getPosition();
80
+ x += graphpostion.left;
81
+ y += graphpostion.top;
82
+
83
+ this.element.style.top = y + 'px';
84
+ this.element.style.left = x + 'px';
85
+ }
86
+
87
+ /**
88
+ * 移除当前控件
89
+ *
90
+ * @method remove
91
+ */
92
+ jmTooltip.prototype.remove = function() {
93
+ if(this.element) {
94
+ document.body.removeChild(this.element);
95
+ }
96
+ }
97
+
98
+ /**
99
+ * 显示当前控件
100
+ *
101
+ * @method remove
102
+ */
103
+ jmTooltip.prototype.show = function() {
104
+ if(this.element) {
105
+ this.element.style.display = 'inline';
106
+ }
107
+ }
108
+
109
+ /**
110
+ * 隐藏当前控件
111
+ *
112
+ * @method remove
113
+ */
114
+ jmTooltip.prototype.hide = function() {
115
+ if(this.element) {
116
+ this.element.style.display = 'none';
117
+ }
118
+ }
119
+
120
+ /**
121
+ * 设置或获取当前值
122
+ *
123
+ * @method value
124
+ */
125
+ jmTooltip.prototype.value = function(v) {
126
+ if(this.element) {
127
+ if(v !== undefined) {
128
+ this.element.innerHTML = v;
129
+ }
130
+ return this.element.innerHTML;
131
+ }
132
+ }
133
+
134
+ /**
135
+ * 设置或获取当前宽度
136
+ *
137
+ * @method width
138
+ * @param {number} w 宽度
139
+ */
140
+ jmTooltip.prototype.width = function(w) {
141
+ if(this.element) {
142
+ if(w !== undefined) {
143
+ this.element.style.width = w + 'px';
144
+ }
145
+ return this.element.clientWidth;
146
+ }
147
+ }
148
+
149
+ /**
150
+ * 设置或获取当前高度
151
+ *
152
+ * @method width
153
+ * @param {number} w 宽度
154
+ */
155
+ jmTooltip.prototype.height = function(h) {
156
+ if(this.element) {
157
+ if(h !== undefined) {
158
+ this.element.style.height = h + 'px';
159
+ }
160
+ return this.element.clientHeight;
161
+ }
162
+ }
163
+
164
+
165
+
@@ -1,22 +1,22 @@
1
-
2
- export default {
3
-
4
- /**
5
- * 对比二个数组数据是否改变
6
- * @param {Array} source 被对比的数、组
7
- * @param {Array} target 对比数组
8
- * @param {Function} compare 比较函数
9
- */
10
- arrayIsChange(source, target, compare) {
11
- if(!source || !target) return true;
12
- if(source.length !== target.length) return true;
13
-
14
- if(typeof compare === 'function') {
15
- for(let i=0; i<source.length; i++) {
16
- if(!compare(source[i], target[i])) return true;
17
- }
18
- return false;
19
- }
20
- else return source == target;
21
- }
1
+
2
+ export default {
3
+ /**
4
+ * 对比二个数组数据是否改变
5
+ * @param {Array} source 被对比的数组
6
+ * @param {Array} target 对比数组
7
+ * @param {Function} compare 比较函数
8
+ * @return {boolean} 是否改变
9
+ */
10
+ arrayIsChange(source, target, compare) {
11
+ if(!source || !target) return true;
12
+ if(source.length !== target.length) return true;
13
+
14
+ if(typeof compare === 'function') {
15
+ for(let i = 0; i < source.length; i++) {
16
+ if(!compare(source[i], target[i])) return true;
17
+ }
18
+ return false;
19
+ }
20
+ return source != target;
21
+ }
22
22
  }
@@ -1,143 +1,130 @@
1
-
2
-
3
- import jmChart from '../../index.js';
4
-
5
- export default {
6
- props: {
7
- chartData: Array,
8
- chartOptions: Object,
9
- chartSeries: Array,
10
- width: {
11
- type: String,
12
- default: 200
13
- },
14
- height: {
15
- type: String,
16
- default: 200
17
- }
18
- },
19
- data: function() {
20
- return {
21
- //chartData: this.chartData,
22
- option: this.chartOptions
23
- }
24
- },
25
- // jmChart实例
26
- chartInstance: null,
27
-
28
- mounted () {
29
- this.option = Object.assign({
30
- enableAnimate: false,
31
- legendPosition: 'top',
32
- legendVisible: true, // 不显示图例
33
- width: this.width,
34
- height: this.height
35
- }, this.chartOptions);
36
-
37
- this.initChart();
38
- },
39
- // DOM更新
40
- updated() {
41
- this.initChart();
42
- },
43
-
44
- // 销毁
45
- destroyed() {
46
- this.chartInstance && this.chartInstance.destroy();
47
- },
48
-
49
- watch: {
50
- // 数据发生改变,刷新
51
- chartData: function(newData, oldData) {
52
- this.refresh();
53
- },
54
- width: function(newWidth, oldWidth) {
55
- if(!this.chartInstance) return;
56
- this.$nextTick(()=>{
57
- if(!this.chartInstance || !this.$refs.jmChartContainer) return;
58
- this.chartInstance.width = this.$refs.jmChartContainer.clientWidth||this.$refs.jmChartContainer.offsetWidth;
59
- //this.chartInstance.refresh();
60
- });
61
- },
62
- height: function(newHeight, oldHeight) {
63
- if(!this.chartInstance) return;
64
- this.$nextTick(()=>{
65
- if(!this.chartInstance || !this.$refs.jmChartContainer) return;
66
- this.chartInstance.height = this.$refs.jmChartContainer.clientHeight||this.$refs.jmChartContainer.offsetHeight;
67
- //this.chartInstance.refresh();
68
- });
69
- }
70
- },
71
-
72
- methods: {
73
- // 初始化图表组件
74
- initChart() {
75
- if(this.chartInstance) return;
76
-
77
- this.chartInstance = new jmChart(this.$refs.jmChartContainer, this.option);
78
-
79
- if(this.chartData && this.chartData.length) this.refresh(); // 这里有死循环的问题,但上面 chartInstance不为空就返回了,就没有这个问题了
80
-
81
- // touch改变数据点事件
82
- this.chartInstance.bind('touchPointChange', (args) => {
83
- this.$emit('touch-point-change', args);
84
- });
85
-
86
- // 图表标线事件
87
- this.chartInstance.bind('marklinelongtapstart', (args) => {
88
- this.$emit('markline-longtap-start', args);
89
- });
90
- this.chartInstance.bind('marklinestartmove', (args) => {
91
- this.$emit('markline-start-move', args);
92
- });
93
- this.chartInstance.bind('marklinemove', (args) => {
94
- this.$emit('markline-move', args);
95
- });
96
- this.chartInstance.bind('marklineendmove', (args) => {
97
- this.$emit('markline-end-move', args);
98
- });
99
-
100
- // touch事件
101
- this.chartInstance.touchGraph.bind('touchstart mousedown', (args) => {
102
- this.$emit('touchstart', args);
103
- this.$emit('mousedown', args);
104
- });
105
- this.chartInstance.touchGraph.bind('touchmove mousemove', (args) => {
106
- this.$emit('touchmove', args);
107
- this.$emit('mousemove', args);
108
- });
109
- this.chartInstance.touchGraph.bind('touchend touchcancel mouseup', (args) => {
110
- this.$emit('touchend', args);
111
- this.$emit('mouseup', args);
112
- });
113
- this.chartInstance.touchGraph.bind('touchleave', (args) => {
114
- this.$emit('touchleave', args);
115
- });
116
- },
117
-
118
- // 刷新图表
119
- refresh() {
120
- this.$nextTick(()=>{
121
- this.initChart();
122
-
123
- // 清空当前图形,重新生成
124
- this.chartInstance.reset();
125
-
126
- // 生成图
127
- if(this.chartSeries.length) {
128
- for(let s of this.chartSeries) {
129
- if(!s.type) {
130
- console.error('必须指定serie type');
131
- continue;
132
- }
133
- this.chartInstance.createSeries(s.type, s);
134
- }
135
- }
136
- this.chartInstance.data = this.chartData;
137
- this.chartInstance.refresh();
138
- });
139
- }
140
- },
141
-
142
- template: `<div ref="jmChartContainer" :style="{width: width, height: height}"></div>`
143
- }
1
+
2
+
3
+ import jmChart from '../../index.js';
4
+
5
+ export default {
6
+ props: {
7
+ chartData: Array,
8
+ chartOptions: Object,
9
+ chartSeries: Array,
10
+ width: {
11
+ type: String,
12
+ default: 200
13
+ },
14
+ height: {
15
+ type: String,
16
+ default: 200
17
+ }
18
+ },
19
+ data: function() {
20
+ return {
21
+ option: this.chartOptions
22
+ }
23
+ },
24
+ chartInstance: null,
25
+
26
+ mounted () {
27
+ this.option = Object.assign({
28
+ enableAnimate: false,
29
+ legendPosition: 'top',
30
+ legendVisible: true,
31
+ width: this.width,
32
+ height: this.height
33
+ }, this.chartOptions);
34
+
35
+ this.initChart();
36
+ },
37
+
38
+ updated() {
39
+ this.initChart();
40
+ },
41
+
42
+ destroyed() {
43
+ this.chartInstance && this.chartInstance.destroy();
44
+ },
45
+
46
+ watch: {
47
+ chartData: function(newData, oldData) {
48
+ this.refresh();
49
+ },
50
+ width: function(newWidth, oldWidth) {
51
+ if(!this.chartInstance) return;
52
+ this.$nextTick(() => {
53
+ if(!this.chartInstance || !this.$refs.jmChartContainer) return;
54
+ this.chartInstance.width = this.$refs.jmChartContainer.clientWidth || this.$refs.jmChartContainer.offsetWidth;
55
+ });
56
+ },
57
+ height: function(newHeight, oldHeight) {
58
+ if(!this.chartInstance) return;
59
+ this.$nextTick(() => {
60
+ if(!this.chartInstance || !this.$refs.jmChartContainer) return;
61
+ this.chartInstance.height = this.$refs.jmChartContainer.clientHeight || this.$refs.jmChartContainer.offsetHeight;
62
+ });
63
+ }
64
+ },
65
+
66
+ methods: {
67
+ initChart() {
68
+ if(this.chartInstance) return;
69
+
70
+ this.chartInstance = new jmChart(this.$refs.jmChartContainer, this.option);
71
+
72
+ if(this.chartData && this.chartData.length) this.refresh();
73
+
74
+ this.chartInstance.bind('touchPointChange', (args) => {
75
+ this.$emit('touch-point-change', args);
76
+ });
77
+
78
+ this.chartInstance.bind('marklinelongtapstart', (args) => {
79
+ this.$emit('markline-longtap-start', args);
80
+ });
81
+ this.chartInstance.bind('marklinestartmove', (args) => {
82
+ this.$emit('markline-start-move', args);
83
+ });
84
+ this.chartInstance.bind('marklinemove', (args) => {
85
+ this.$emit('markline-move', args);
86
+ });
87
+ this.chartInstance.bind('marklineendmove', (args) => {
88
+ this.$emit('markline-end-move', args);
89
+ });
90
+
91
+ this.chartInstance.touchGraph.bind('touchstart mousedown', (args) => {
92
+ this.$emit('touchstart', args);
93
+ this.$emit('mousedown', args);
94
+ });
95
+ this.chartInstance.touchGraph.bind('touchmove mousemove', (args) => {
96
+ this.$emit('touchmove', args);
97
+ this.$emit('mousemove', args);
98
+ });
99
+ this.chartInstance.touchGraph.bind('touchend touchcancel mouseup', (args) => {
100
+ this.$emit('touchend', args);
101
+ this.$emit('mouseup', args);
102
+ });
103
+ this.chartInstance.touchGraph.bind('touchleave', (args) => {
104
+ this.$emit('touchleave', args);
105
+ });
106
+ },
107
+
108
+ refresh() {
109
+ this.$nextTick(() => {
110
+ this.initChart();
111
+
112
+ this.chartInstance.reset();
113
+
114
+ if(this.chartSeries && this.chartSeries.length) {
115
+ for(let s of this.chartSeries) {
116
+ if(!s.type) {
117
+ console.error('必须指定serie type');
118
+ continue;
119
+ }
120
+ this.chartInstance.createSeries(s.type, s);
121
+ }
122
+ }
123
+ this.chartInstance.data = this.chartData;
124
+ this.chartInstance.refresh();
125
+ });
126
+ }
127
+ },
128
+
129
+ template: `<div ref="jmChartContainer" :style="{width: width, height: height}"></div>`
130
+ }