Home Forums FlexGanttFX Y coordinate of activity within graphics

  • Author
    Posts
  • Martin
    Participant
    Post count: 8
    #13004 |

    I’m trying to display a popup below the activity based on a MouseEvent. With the code below I do get the correct X coordinate, but not Y coordinate. Y coordinate is the relative value within the row.

    How do I get the “absolute” Y coordinate for an activity within gantt control?

     

    Here is my code:

    // mouse point
    double x = evt.getScreenX();
    double y = evt.getScreenY();

    ActivityBounds bounds = gantt.getGraphics().getActivityBoundsAt(evt.getX(), evt.getY());
    if (bounds != null)
    {
    Point2D pDownLeft = gantt.getGraphics().localToScene(bounds.getMinX(), bounds.getMaxY());
    x = pDownLeft.getX();
    y = pDownLeft.getY(); // Y position is not correct, it’s the offest within the row only
    }

    popup.show(gantt.getGraphics(), x, y, Duration.ONE);

  • Dirk Lemmermann
    Keymaster
    Post count: 60
    #13006 |

    The mouse event should have a target set to Canvas, right? Then you can calculate the screen y coordinate of the canvas and add the y coordinate of the activity to it.

    Please also submit a ticket for adding the screen coordinates to the activity bounds. Or a helper method to look them up.

    Dirk

  • Martin
    Participant
    Post count: 8
    #13008 |

    Yes, the mouse event has the RowCanvas in target. But in the code below I get the same Y coordinate for all rows…

    Bounds boundsRow = ((RowCanvas) target).getBoundsInLocal();
    Point2D pRow = gantt.getGraphics().localToScreen(boundsActivity.getMinX(), boundsActivity.getMinY());
  • Dirk Lemmermann
    Keymaster
    Post count: 60
    #13009 |

    Well, the code gets the row bounds but doesn’t use them. Important: you need to also convert the row bounds to screen bounds 🙂

  • Martin
    Participant
    Post count: 8
    #13010 |

    Sorry, my mistake when pasting the code here… real code is correct and having the issue as described.

    Full code:

    // mouse point
    double x = evt.getScreenX();
    double y = evt.getScreenY();
    
    ActivityBounds boundsActivity = gantt.getGraphics().getActivityBoundsAt(evt.getX(), evt.getY());
    if (boundsActivity != null)
    {
    EventTarget target = evt.getTarget();
    if (target instanceof RowCanvas)
    {
    Bounds boundsRow = ((RowCanvas) target).getBoundsInLocal();
    Point2D pRow = gantt.getGraphics().localToScreen(boundsRow.getMinX(), boundsRow.getMinY());
    
    Point2D pDownLeft = gantt.getGraphics().localToScreen(boundsActivity.getMinX(), boundsActivity.getMaxY());
    x = pDownLeft.getX() + (boundsActivity.getWidth() / 2);
    y = pRow.getY() + boundsActivity.getMinY();
    }
    
    }
    
    // position
    popup.show(gantt.getGraphics(), x, y, Duration.ONE);
  • Dirk Lemmermann
    Keymaster
    Post count: 60
    #13011 |

    Hmmmm, you will have to play around with these methods a little bit. You are definitely on the right track. You actually might want to first calculate the location of the row relative to the list view, then the list view location relative to the scene, then the scene to the screen. I know it can be confusing and I also always have to do trial and error until I get it right.

You must be logged in to reply to this topic.