jmgraph 3.1.95 → 3.1.96

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.
@@ -341,9 +341,6 @@ export default class jmControl extends jmProperty {
341
341
  style = style || jmUtils.clone(this.style, true);
342
342
  if(!style) return;
343
343
 
344
- // 当前根据屏幕放大倍数,如果有倍数,则需要对线宽等同比放大
345
- let scale = this.graph.devicePixelRatio;
346
-
347
344
  /**
348
345
  * 样式设定
349
346
  *
@@ -393,7 +390,7 @@ export default class jmControl extends jmProperty {
393
390
  }
394
391
 
395
392
  // 按比例需要放大的样式
396
- if(scale && style) {
393
+ /*if(scale && style) {
397
394
  switch(mpname) {
398
395
  case 'lineWidth': {
399
396
  style *= scale;
@@ -410,7 +407,7 @@ export default class jmControl extends jmProperty {
410
407
  break;
411
408
  }
412
409
  }
413
- }
410
+ } */
414
411
  this.context[mpname] = style;
415
412
  }
416
413
  else {
@@ -592,10 +589,10 @@ export default class jmControl extends jmProperty {
592
589
  local.height = this.height;
593
590
 
594
591
  let margin = jmUtils.clone(this.style.margin, {});
595
- margin.left = (margin.left || 0) * this.graph.devicePixelRatio;
596
- margin.top = (margin.top || 0) * this.graph.devicePixelRatio;
597
- margin.right = (margin.right || 0) * this.graph.devicePixelRatio;
598
- margin.bottom = (margin.bottom || 0) * this.graph.devicePixelRatio;
592
+ margin.left = (margin.left || 0);
593
+ margin.top = (margin.top || 0);
594
+ margin.right = (margin.right || 0);
595
+ margin.bottom = (margin.bottom || 0);
599
596
 
600
597
  //如果没有指定位置,但指定了margin。则位置取margin偏移量
601
598
  if(local.position) {
@@ -1114,14 +1111,7 @@ export default class jmControl extends jmProperty {
1114
1111
 
1115
1112
  const srcElement = args.srcElement || args.target;
1116
1113
 
1117
- const position = jmUtils.getEventPosition(args, graph.scaleSize);//初始化事件位置
1118
-
1119
- // 如果有指定scale高清处理,需要对坐标处理
1120
- // 因为是对canvas放大N倍,再把style指定为当前大小,所以坐标需要放大N && srcElement === graph.canvas
1121
- if(graph.devicePixelRatio > 0) {
1122
- position.x = position.offsetX = position.x * graph.devicePixelRatio;
1123
- position.y = position.offsetY = position.y * graph.devicePixelRatio;
1124
- }
1114
+ const position = jmUtils.getEventPosition(args, graph.scaleSize);//初始化事件位置
1125
1115
 
1126
1116
  args = {
1127
1117
  position: position,
@@ -100,11 +100,19 @@ export default class jmGraph extends jmControl {
100
100
  this.on('endDraw', function() {
101
101
  this.context.translate(-0.5, -0.5);
102
102
  });
103
-
103
+
104
+ // devicePixelRatio初始化
105
+ let dpr = typeof window != 'undefined' && window.devicePixelRatio > 1? window.devicePixelRatio : 1;
106
+ if(this.isWXMiniApp) {
107
+ dpr = wx.getSystemInfoSync().pixelRatio || 1;
108
+ }
109
+ this.devicePixelRatio = dpr;
110
+ // 为了解决锯齿问题,先放大canvas再缩放
111
+ this.dprScaleSize = this.devicePixelRatio > 1? this.devicePixelRatio : 2;
112
+
104
113
  if(this.option.width > 0) this.width = this.option.width;
105
114
  if(this.option.height > 0) this.height = this.option.height;
106
-
107
- this.resize();
115
+ this.resize();
108
116
 
109
117
  //绑定事件
110
118
  this.eventHandler = new jmEvents(this, this.canvas.canvas || this.canvas);
@@ -119,25 +127,19 @@ export default class jmGraph extends jmControl {
119
127
 
120
128
  // 重置canvas大小,并判断高清屏,画图先放大二倍
121
129
  resize(w, h) {
130
+ if(!this.canvas) return;
122
131
 
123
- let scale = typeof window != 'undefined' && window.devicePixelRatio > 1? window.devicePixelRatio : 1;
124
- if(this.isWXMiniApp) {
125
- scale = wx.getSystemInfoSync().pixelRatio || 1;
126
- }
127
- else if (scale > 1) {
128
- this.__normalSize = this.__normalSize || { width: 0, height: 0};
129
- w = w || this.__normalSize.width || this.width, h = h || this.__normalSize.height || this.height;
132
+ this.__normalSize = this.__normalSize || { width: 0, height: 0};
133
+ w = w || this.__normalSize.width || this.width, h = h || this.__normalSize.height || this.height;
130
134
 
131
- if(w) this.__normalSize.width = w;
132
- if(h) this.__normalSize.height = h;
133
-
134
- this.canvas.style && (this.canvas.style.width = w + "px");
135
- this.canvas.style && (this.canvas.style.height = h + "px");
136
- this.canvas.height = h * scale;
137
- this.canvas.width = w *scale;
138
- this.context.scale(scale, scale);
139
- this.devicePixelRatio = scale;
140
- }
135
+ if(w) this.__normalSize.width = w;
136
+ if(h) this.__normalSize.height = h;
137
+
138
+ this.css('width', w + "px");
139
+ this.css('height', h + "px");
140
+ this.canvas.height = h * this.dprScaleSize;
141
+ this.canvas.width = w * this.dprScaleSize;
142
+ this.context.scale(this.dprScaleSize, this.dprScaleSize);
141
143
  }
142
144
 
143
145
  /**
@@ -145,10 +147,10 @@ export default class jmGraph extends jmControl {
145
147
  * @param {x, y} point 内部坐标
146
148
  */
147
149
  pointToPixes(point) {
148
- if(this.devicePixelRatio && this.devicePixelRatio !== 1) {
150
+ if(this.dprScaleSize && this.dprScaleSize !== 1) {
149
151
  point = Object.assign({}, point, {
150
- x: point.x / this.devicePixelRatio,
151
- y: point.y / this.devicePixelRatio
152
+ x: point.x / this.dprScaleSize,
153
+ y: point.y / this.dprScaleSize
152
154
  });
153
155
  }
154
156
  return point;
@@ -160,13 +162,13 @@ export default class jmGraph extends jmControl {
160
162
  * @type {number}
161
163
  */
162
164
  get width() {
165
+ if(this.__normalSize && this.__normalSize.width) return this.__normalSize.width;
163
166
  if(this.canvas) return this.canvas.width;
164
167
  return 0;
165
168
  }
166
169
  set width(v) {
167
170
  this.needUpdate = true;
168
171
  if(this.canvas) {
169
- this.canvas.width = v;
170
172
  this.resize(v);
171
173
  }
172
174
  return v;
@@ -178,13 +180,13 @@ export default class jmGraph extends jmControl {
178
180
  * @type {number}
179
181
  */
180
182
  get height() {
183
+ if(this.__normalSize && this.__normalSize.height) return this.__normalSize.height;
181
184
  if(this.canvas) return this.canvas.height;
182
185
  return 0;
183
186
  }
184
187
  set height(v) {
185
188
  this.needUpdate = true;
186
189
  if(this.canvas) {
187
- this.canvas.height = v;
188
190
  this.resize(0, v);
189
191
  }
190
192
  return v;
@@ -343,23 +345,13 @@ export default class jmGraph extends jmControl {
343
345
  * @param {number} [h] 清除画布的高度
344
346
  */
345
347
  clear(w, h) {
346
- //this.canvas.width = this.canvas.width;
347
- if(w && h) {
348
- //this.zoomActual();//恢复比例缩放
349
- this.canvas.width = w;
350
- this.canvas.height = h;
351
- //保留原有缩放比例
352
- if(this.scaleSize) {
353
- if(this.context.scale) this.context.scale(this.scaleSize.x,this.scaleSize.y);
354
- }
355
- }
356
- else {
357
- w = this.canvas.width;
358
- h = this.canvas.height;
359
- if(this.scaleSize) {
348
+ if(!w || !h) {
349
+ w = this.width;
350
+ h = this.height;
351
+ /*if(this.scaleSize) {
360
352
  w = w / this.scaleSize.x;
361
353
  h = h / this.scaleSize.y;
362
- }
354
+ }*/
363
355
  }
364
356
  //如果有指定背景,则等到draw再全屏绘制一次,也同样达到清除画布的功能
365
357
  if(this.style && this.style.fill) {
@@ -504,6 +496,9 @@ export default class jmGraph extends jmControl {
504
496
  return;// 已销毁
505
497
  }
506
498
  if(self.needUpdate) self.redraw();
499
+ // 触发刷新事件
500
+ self.emit('update');
501
+
507
502
  self.__requestAnimationFrameFunHandler && jmUtils.cancelAnimationFrame(self.__requestAnimationFrameFunHandler);
508
503
  self.__requestAnimationFrameFunHandler = jmUtils.requestAnimationFrame(update);
509
504
  if(callback) callback();