Comments (9)
That's only because draggable shapes are able to be dragged by changing their x and y properties. In the case of a path, you have x1, y1, x2, y2, and so on (rather than x and y).
I will work on fixing that, and I will get back to you when I finish. ;)
-Caleb
On Oct 25, 2012, at 4:41 AM, dariop [email protected] wrote:
Hi
thank you for your excellent work!draggable property seems to be not working on drawLine layers
$("canvas").drawLine({
layer: true,
strokeStyle: "#900",
strokeWidth: 3,
fillStyle: "F90",
x1: 50, y1: 50,
x2: 100, y2: 150,
x3: 200, y3: 100,
x4: 50, y4: 50,
draggable: true,
bringToFront: true
});
Am I wrong? thank you!
Dario—
Reply to this email directly or view it on GitHub.
from jcanvas.
Okay, as promised, I have fixed the issue, which has been pushed to GitHub in the latest commit.
-Caleb
On Oct 25, 2012, at 4:41 AM, dariop [email protected] wrote:
Hi
thank you for your excellent work!draggable property seems to be not working on drawLine layers
$("canvas").drawLine({
layer: true,
strokeStyle: "#900",
strokeWidth: 3,
fillStyle: "F90",
x1: 50, y1: 50,
x2: 100, y2: 150,
x3: 200, y3: 100,
x4: 50, y4: 50,
draggable: true,
bringToFront: true
});
Am I wrong? thank you!
Dario—
Reply to this email directly or view it on GitHub.
from jcanvas.
Thank you so much, and congratulations, again ;)
A good idea could be making a full LayerGroup draggable, I'm trying to do this using dragstart, dragstop and drag callback functions!
Ciao ;)
Dario
from jcanvas.
Hi Caleb.
I think there's another little problem here.
During the drag of this kind of shape (drawn by drawLine) you shouldn't add any x or y properties.
I'm trying to explain why:
I have a draggable polygon and some circles (drawEllipse) that represent polygons's corners.
Corners are also draggable.
On polygon dragging, I want to move "everything".
On corners dragging, I want to resize the polygon.
Step1:
I drag the polygon, x and y properties are added to him.
Step2:
I drag corners, some handler updates poygon's coords.
In this case there's an offset in polygon's coords, depending on x and y, added in Step1
I hope I was clear ;)
Here is an image, representing the issue
Thank you in advance.
Dario
from jcanvas.
Well, I pushed out an update which might fix your issue (bb02968). If the update does not, however, I could certainly examine the issue further if you could provide the code you are using to reproduce the issue.
-Caleb
from jcanvas.
Issue seems to be not fixed.
Here's the code that reproduces the issue:
var sensorId = "newSensor";
var sensorXCoords = [ 100, 200, 200, 100 ];
var sensorYCoords = [ 100, 100, 200, 200 ];
var verticesNumber = 4;
var ball = {
layer : true,
group : sensorId,
fillStyle : "#FF0000",
width : 15,
height : 15,
draggable : true,
bringToFront : true,
dragstop : onBallDrag,
drag : onBallDrag
};
for ( var p = 0; p < verticesNumber; p += 1) {
ball["name"] = sensorId + "Ball" + p;
ball["x"] = sensorXCoords[p];
ball["y"] = sensorYCoords[p];
$("canvas").drawEllipse(ball);
}
var poly = {
layer : true,
name : sensorId + "SensorArea",
group : sensorId,
fillStyle : "#FF2222",
opacity : 0.3,
rounded : true,
draggable: true,
cursor: "move",
dragstart : function(layer) {
startX = layer.mouseX;
startY = layer.mouseY;
},
drag : function(layer) {
var dx, dy, tempx, tempy, newx, newy;
var tempx1, tempy1, tempx2, tempy2;
dx = layer.mouseX - startX;
dy = layer.mouseY - startY;
for ( var p = 0; p < verticesNumber; p += 1) {
tempx = $("canvas").getLayer(sensorId + "Ball" + p).x;
tempy = $("canvas").getLayer(sensorId + "Ball" + p).y;
newx = tempx + dx;
newy = tempy + dy;
$("canvas").setLayer(sensorId + "Ball" + p, {
x : newx,
y : newy
});
}
startX = layer.mouseX;
startY = layer.mouseY;
}
};
for ( var p = 0; p < verticesNumber; p += 1) {
poly["x" + (p + 1)] = sensorXCoords[p];
poly["y" + (p + 1)] = sensorYCoords[p];
}
$("canvas").drawLine(poly);
function onBallDrag(layer) {
var sensorId = layer.group;
updateSensor(sensorId);
}
function updateSensor(sensorId) {
var updatedSensorXCoords = new Array();
var updatedSensorYCoords = new Array();
var coords = getSensorCoordsFromSensorId(sensorId);
updatedSensorXCoords = coords.sensorXCoords;
updatedSensorYCoords = coords.sensorYCoords;
$("canvas").setLayer(sensorId + "SensorArea", {
x1 : updatedSensorXCoords[0],
y1 : updatedSensorYCoords[0],
x2 : updatedSensorXCoords[1],
y2 : updatedSensorYCoords[1],
x3 : updatedSensorXCoords[2],
y3 : updatedSensorYCoords[2],
x4 : updatedSensorXCoords[3],
y4 : updatedSensorYCoords[3]
});
}
function getSensorCoordsFromSensorId(sensorId) {
var p;
var sensorXCoords = new Array();
var sensorYCoords = new Array();
for (p = 0; p < verticesNumber; p++) {
sensorXCoords[p] = $("canvas").getLayer(sensorId + "Ball" + p).x;
sensorYCoords[p] = $("canvas").getLayer(sensorId + "Ball" + p).y;
}
return ({
sensorXCoords : sensorXCoords,
sensorYCoords : sensorYCoords
});
}
Dario
from jcanvas.
Thank you for the code. I see the issue now. Therefore, I am reopening this issue, and I will work on a fix when I can.
-Caleb
from jcanvas.
Okay, it seems after careful examination of your code, I can fix the issue without making any further modifications to jCanvas. You just need to subtract the polygon layer's x and y properties from the dot coordinates. I updated your code to demonstrate this:
var sensorId = "newSensor";
var sensorXCoords = [ 100, 200, 200, 100 ];
var sensorYCoords = [ 100, 100, 200, 200 ];
var verticesNumber = 4;
var ball = {
layer : true,
group : sensorId,
fillStyle : "#FF0000",
width : 15,
height : 15,
draggable : true,
bringToFront : true,
dragstop : onBallDrag,
drag : onBallDrag
};
for ( var p = 0; p < verticesNumber; p += 1) {
ball["name"] = sensorId + "Ball" + p;
ball["x"] = sensorXCoords[p];
ball["y"] = sensorYCoords[p];
$("canvas").drawEllipse(ball);
}
var poly = {
layer : true,
name : sensorId + "SensorArea",
group : sensorId,
fillStyle : "#FF2222",
opacity : 0.3,
rounded : true,
draggable: true,
cursor: "move",
dragstart : function(layer) {
startX = layer.mouseX;
startY = layer.mouseY;
},
drag : function(layer) {
var dx, dy, tempx, tempy, newx, newy;
var tempx1, tempy1, tempx2, tempy2;
dx = layer.mouseX - startX;
dy = layer.mouseY - startY;
for ( var p = 0; p < verticesNumber; p += 1) {
tempx = $("canvas").getLayer(sensorId + "Ball" + p).x;
tempy = $("canvas").getLayer(sensorId + "Ball" + p).y;
newx = tempx + dx;
newy = tempy + dy;
$("canvas").setLayer(sensorId + "Ball" + p, {
x : newx,
y : newy
});
}
startX = layer.mouseX;
startY = layer.mouseY;
}
};
for ( var p = 0; p < verticesNumber; p += 1) {
poly["x" + (p + 1)] = sensorXCoords[p];
poly["y" + (p + 1)] = sensorYCoords[p];
}
$("canvas").drawLine(poly);
function onBallDrag(layer) {
var sensorId = layer.group;
updateSensor(sensorId);
}
function updateSensor(sensorId) {
var polyLayer = $('canvas').getLayer('newSensorSensorArea');
var updatedSensorXCoords = new Array();
var updatedSensorYCoords = new Array();
var coords = getSensorCoordsFromSensorId(sensorId);
updatedSensorXCoords = coords.sensorXCoords;
updatedSensorYCoords = coords.sensorYCoords;
// The fix to the issue is reflected here
$("canvas").setLayer(sensorId + "SensorArea", {
x1 : updatedSensorXCoords[0] - polyLayer.x,
y1 : updatedSensorYCoords[0] - polyLayer.y,
x2 : updatedSensorXCoords[1] - polyLayer.x,
y2 : updatedSensorYCoords[1] - polyLayer.y,
x3 : updatedSensorXCoords[2] - polyLayer.x,
y3 : updatedSensorYCoords[2] - polyLayer.y,
x4 : updatedSensorXCoords[3] - polyLayer.x,
y4 : updatedSensorYCoords[3] - polyLayer.y
});
}
function getSensorCoordsFromSensorId(sensorId) {
var p;
var sensorXCoords = new Array();
var sensorYCoords = new Array();
for (p = 0; p < verticesNumber; p++) {
sensorXCoords[p] = $("canvas").getLayer(sensorId + "Ball" + p).x;
sensorYCoords[p] = $("canvas").getLayer(sensorId + "Ball" + p).y;
}
return ({
sensorXCoords : sensorXCoords,
sensorYCoords : sensorYCoords
});
}
from jcanvas.
Thank you! Dario
from jcanvas.
Related Issues (20)
- Triggering mouseover event with multi-layers HOT 3
- Handles not working properly after the canvas is resized HOT 7
- Animations are very CPU intensive HOT 1
- Handle plugin missing basic feature - Text HOT 3
- Handle plugin missing advanced feature - Rotation Handle HOT 1
- How to add space between the characters in text HOT 1
- Replacement for a deprecated method: $.jCanvas() HOT 1
- jcanvas21.0.1 in fireFox(70.0.1 ) removeLayer() and removeLayers() has bug HOT 1
- Rotate Text Alignment HOT 6
- How to animate the closed: true option line (drawLine) HOT 7
- if use css set canvas to half of it,and then can't drag,how to fixed this? HOT 1
- Submitting a project to the Gallery HOT 2
- Getting Uncaught TypeError: Cannot read property 'text' of undefined HOT 1
- Tainted canvases may not be exported HOT 1
- How to import jCanvas to work with Angular? HOT 11
- handle for text type HOT 6
- How to draw a Bezier in animation? HOT 1
- Export Canvas: Excluding certain objects HOT 4
- Handles can't vanish like a layer HOT 2
- multi-touch - future HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jcanvas.