Giter Club home page Giter Club logo

Comments (9)

caleb531 avatar caleb531 commented on September 24, 2024

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.

caleb531 avatar caleb531 commented on September 24, 2024

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.

dariop avatar dariop commented on September 24, 2024

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.

dariop avatar dariop commented on September 24, 2024

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
problem_jcanvas

Thank you in advance.

Dario

from jcanvas.

caleb531 avatar caleb531 commented on September 24, 2024

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.

dariop avatar dariop commented on September 24, 2024

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.

caleb531 avatar caleb531 commented on September 24, 2024

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.

caleb531 avatar caleb531 commented on September 24, 2024

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.

dariop avatar dariop commented on September 24, 2024

Thank you! Dario

from jcanvas.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.