Skip to content

Commit

Permalink
wx app touch
Browse files Browse the repository at this point in the history
  • Loading branch information
fefeding committed Oct 29, 2024
1 parent c4c7276 commit e89874c
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 30 deletions.
2 changes: 1 addition & 1 deletion dist/jmgraph.core.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/jmgraph.core.min.js.map

Large diffs are not rendered by default.

34 changes: 22 additions & 12 deletions dist/jmgraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ var _jmShadow = require("./jmShadow.js");
var _jmProperty2 = require("./jmProperty.js");
var _path = _interopRequireDefault(require("../lib/webgl/path.js"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _readOnlyError(r) { throw new TypeError('"' + r + '" is read-only'); }
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
Expand Down Expand Up @@ -275,6 +276,8 @@ var jmControl = exports.jmControl = exports["default"] = /*#__PURE__*/function (
//this.position = params.position || {x:0,y:0};
_this2.width = params.width || 0;
_this2.height = params.height || 0;
//this.lockSide = params.lockSide || null;

if (params.position) {
_this2.position = params.position;
}
Expand Down Expand Up @@ -1406,10 +1409,10 @@ var jmControl = exports.jmControl = exports["default"] = /*#__PURE__*/function (
// 由于高清屏会有放大坐标,所以这里用pagex就只能用真实的canvas大小
var right = position.left + this.width;
var bottom = position.top + this.height;
if (p.pageX > right || p.pageX < position.left) {
if (p.x > right || p.x < position.left) {
return false;
}
if (p.pageY > bottom || p.pageY < position.top) {
if (p.y > bottom || p.y < position.top) {
return false;
}
return true;
Expand Down Expand Up @@ -1672,33 +1675,37 @@ var jmControl = exports.jmControl = exports["default"] = /*#__PURE__*/function (

if (_this.__mvMonitor.mouseDown) {
_this.parent.bounds = null;
var parentbounds = _this.parent.getAbsoluteBounds();
//let parentbounds = _this.parent.getAbsoluteBounds();
var offsetx = evt.position.offsetX - _this.__mvMonitor.curposition.x;
var offsety = evt.position.offsetY - _this.__mvMonitor.curposition.y;
//console.log(offsetx + ',' + offsety);
//如果锁定边界
if (_this.lockSide) {
if (_this.option.lockSide) {
var thisbounds = _this.bounds || _this.getAbsoluteBounds();
//检查边界出界
var outside = _jmUtils.jmUtils.checkOutSide(parentbounds, thisbounds, {
var outside = _jmUtils.jmUtils.checkOutSide(_this.option.lockSide, thisbounds, {
x: offsetx,
y: offsety
});
if (outside.left < 0) {
if (_this.lockSide.left) offsetx -= outside.left;
//offsetx -= outside.left;
0, _readOnlyError("offsetx");
} else if (outside.right > 0) {
if (_this.lockSide.right) offsetx -= outside.right;
//offsetx -= outside.right;
0, _readOnlyError("offsetx");
}
if (outside.top < 0) {
if (_this.lockSide.top) offsety -= outside.top;
//offsety -= outside.top;
0, _readOnlyError("offsety");
} else if (outside.bottom > 0) {
if (_this.lockSide.bottom) offsety -= outside.bottom;
//offsety -= outside.bottom;
0, _readOnlyError("offsety");
}
}
if (offsetx || offsety) {
_this.offset(offsetx, offsety, true, evt);
_this.__mvMonitor.curposition.x = evt.position.offsetX;
_this.__mvMonitor.curposition.y = evt.position.offsetY;
if (offsetx) _this.__mvMonitor.curposition.x = evt.position.offsetX;
if (offsety) _this.__mvMonitor.curposition.y = evt.position.offsetY;
//console.log(offsetx + '.' + offsety);
}
return false;
Expand Down Expand Up @@ -2610,7 +2617,10 @@ var jmGraph = exports.jmGraph = exports["default"] = /*#__PURE__*/function (_jmC
* @return {postion} 返回定位坐标
*/
function getPosition() {
var p = _jmUtils.jmUtils.getElementPosition(this.canvas.canvas || this.canvas);
var p = this.isWXMiniApp ? {
left: 0,
top: 0
} : _jmUtils.jmUtils.getElementPosition(this.canvas.canvas || this.canvas);
p.width = this.width;
p.height = this.height;
p.right = p.left + p.width;
Expand Down
2 changes: 1 addition & 1 deletion dist/jmgraph.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"family": "jmgraph",
"name": "jmgraph",
"version": "3.2.11",
"version": "3.2.12",
"description": "一个简单的canvas画图库",
"homepage": "http://graph.jm47.com/",
"keywords": [
Expand Down
31 changes: 18 additions & 13 deletions src/core/jmControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export default class jmControl extends jmProperty {
//this.position = params.position || {x:0,y:0};
this.width = params.width || 0;
this.height = params.height || 0;
//this.lockSide = params.lockSide || null;

if(params.position) {
this.position = params.position;
Expand Down Expand Up @@ -1125,10 +1126,10 @@ export default class jmControl extends jmProperty {
// 由于高清屏会有放大坐标,所以这里用pagex就只能用真实的canvas大小
const right = position.left + this.width;
const bottom = position.top + this.height;
if(p.pageX > right || p.pageX < position.left) {
if(p.x > right || p.x < position.left) {
return false;
}
if(p.pageY > bottom || p.pageY < position.top) {
if(p.y > bottom || p.y < position.top) {
return false;
}
return true;
Expand Down Expand Up @@ -1381,33 +1382,37 @@ export default class jmControl extends jmProperty {

if(_this.__mvMonitor.mouseDown) {
_this.parent.bounds = null;
let parentbounds = _this.parent.getAbsoluteBounds();
let offsetx = evt.position.offsetX - _this.__mvMonitor.curposition.x;
let offsety = evt.position.offsetY - _this.__mvMonitor.curposition.y;
//let parentbounds = _this.parent.getAbsoluteBounds();
const offsetx = evt.position.offsetX - _this.__mvMonitor.curposition.x;
const offsety = evt.position.offsetY - _this.__mvMonitor.curposition.y;
//console.log(offsetx + ',' + offsety);
//如果锁定边界
if(_this.lockSide) {
if(_this.option.lockSide) {
let thisbounds = _this.bounds || _this.getAbsoluteBounds();
//检查边界出界
let outside = jmUtils.checkOutSide(parentbounds,thisbounds,{x:offsetx,y:offsety});
let outside = jmUtils.checkOutSide(_this.option.lockSide, thisbounds, { x: offsetx, y: offsety });
if(outside.left < 0) {
if(_this.lockSide.left) offsetx -= outside.left;
//offsetx -= outside.left;
offsetx = 0;
}
else if(outside.right > 0) {
if(_this.lockSide.right) offsetx -= outside.right;
//offsetx -= outside.right;
offsetx = 0;
}
if(outside.top < 0) {
if(_this.lockSide.top) offsety -= outside.top;
//offsety -= outside.top;
offsety = 0;
}
else if(outside.bottom > 0) {
if(_this.lockSide.bottom) offsety -= outside.bottom;
//offsety -= outside.bottom;
offsety = 0;
}
}

if(offsetx || offsety) {
_this.offset(offsetx, offsety, true, evt);
_this.__mvMonitor.curposition.x = evt.position.offsetX;
_this.__mvMonitor.curposition.y = evt.position.offsetY;
if(offsetx) _this.__mvMonitor.curposition.x = evt.position.offsetX;
if(offsety) _this.__mvMonitor.curposition.y = evt.position.offsetY;
//console.log(offsetx + '.' + offsety);
}
return false;
Expand Down
6 changes: 5 additions & 1 deletion src/core/jmGraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,11 @@ export default class jmGraph extends jmControl {
* @return {postion} 返回定位坐标
*/
getPosition() {
const p = jmUtils.getElementPosition(this.canvas.canvas || this.canvas);
const p = this.isWXMiniApp? {
left: 0,
top: 0
} :jmUtils.getElementPosition(this.canvas.canvas || this.canvas);

p.width = this.width;
p.height = this.height;
p.right = p.left + p.width;
Expand Down

0 comments on commit e89874c

Please sign in to comment.