1. #1
    Sencha Premium Member feelinforyou's Avatar
    Join Date
    Dec 2012
    Posts
    71
    Answers
    4
    Vote Rating
    4
    feelinforyou is on a distinguished road

      0  

    Default Answered: Add EventHandlers for Sprites

    Answered: Add EventHandlers for Sprites


    Hello everyone,

    is there a way, which i can easily extend the sprites of the chart lib that they can handle MouseEvents?
    I need this, which i think absolute necessary feature, that i can drag an drop rectangles and that they can listen to clickevents etc.

    Any suggestions welcome!!
    Thanks!

  2. Sprites do not have (and *should not* have) individual event handlers. A SpriteList is not a Sprite, so you can't build them into a 'group' and listen for events from one to show up on that list object. In theory we could build this at least for SVG (not sure if VML could do the same thing), but this would mean that we couldn't build Canvas support in the same way - either we couldn't support it at all with the same API, or we would need to add extra overhead around it to make use cases like this work.

    It often doesn't make sense to track the mouse's behavior on a single sprite, but usually makes more sense for part of a sprite (along a PathSprite for example) or for multiple sprites (as you are describing, joining a label with some other item). Additionally, you might have a case which is half and half - multiple sprites, but only part of some of them.

    Here is a sample I wrote a few weeks ago that draws a graph on the screen and animates it to use a force directed layout - the tools menu supports not one but three different DnD behaviors. If you read the source, you'll note that none of this is built into GXT itself, but was built specific for this use case. If you are doing your visualizations, you'll have specific needs that we may not be able to anticipate, and none of the existing charts are really meant to have DnD to rearrange items, etc, so we can't add behaviors without knowing exactly what will be expected for all cases.

    Demo: http://niloc132.github.io/simple-graph/
    Source code: https://github.com/niloc132/simple-graph/

    Note also that there is a generate menu to build increasing large sets of items to draw. I am using this as testing to see what changes I can make in the demo's implementation to make it perform better, as well as a proving ground for changes in GXT or GWT for better performance.

    Finally, you may notice that there is touch support in this sample - I have tested it *only* on android, in Chrome, Browser, as well as Firefox, and it seems to work okay. This is meant only as a proof of concept, and may not work on all devices or browsers. The menu system isn't very conducive for touch - this is something that I hope to improve (but patches are welcome!).

  3. #2
    Sencha Premium Member feelinforyou's Avatar
    Join Date
    Dec 2012
    Posts
    71
    Answers
    4
    Vote Rating
    4
    feelinforyou is on a distinguished road

      0  

    Default


    Okay i have found a thread about this.

    http://www.sencha.com/forum/showthread.php?259634

    But how can i relize drag n drop?
    There's missing a mouseMoveEventListener!

    Is there also a way to group the elements? So that i can combine a TextSprite with an RectangleSprite?
    Edit: Okay i found the SpriteList!

  4. #3
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,640
    Answers
    107
    Vote Rating
    80
    Colin Alworth is just really nice Colin Alworth is just really nice Colin Alworth is just really nice Colin Alworth is just really nice Colin Alworth is just really nice

      0  

    Default


    Sprites do not have (and *should not* have) individual event handlers. A SpriteList is not a Sprite, so you can't build them into a 'group' and listen for events from one to show up on that list object. In theory we could build this at least for SVG (not sure if VML could do the same thing), but this would mean that we couldn't build Canvas support in the same way - either we couldn't support it at all with the same API, or we would need to add extra overhead around it to make use cases like this work.

    It often doesn't make sense to track the mouse's behavior on a single sprite, but usually makes more sense for part of a sprite (along a PathSprite for example) or for multiple sprites (as you are describing, joining a label with some other item). Additionally, you might have a case which is half and half - multiple sprites, but only part of some of them.

    Here is a sample I wrote a few weeks ago that draws a graph on the screen and animates it to use a force directed layout - the tools menu supports not one but three different DnD behaviors. If you read the source, you'll note that none of this is built into GXT itself, but was built specific for this use case. If you are doing your visualizations, you'll have specific needs that we may not be able to anticipate, and none of the existing charts are really meant to have DnD to rearrange items, etc, so we can't add behaviors without knowing exactly what will be expected for all cases.

    Demo: http://niloc132.github.io/simple-graph/
    Source code: https://github.com/niloc132/simple-graph/

    Note also that there is a generate menu to build increasing large sets of items to draw. I am using this as testing to see what changes I can make in the demo's implementation to make it perform better, as well as a proving ground for changes in GXT or GWT for better performance.

    Finally, you may notice that there is touch support in this sample - I have tested it *only* on android, in Chrome, Browser, as well as Firefox, and it seems to work okay. This is meant only as a proof of concept, and may not work on all devices or browsers. The menu system isn't very conducive for touch - this is something that I hope to improve (but patches are welcome!).

  5. #4
    Sencha Premium Member feelinforyou's Avatar
    Join Date
    Dec 2012
    Posts
    71
    Answers
    4
    Vote Rating
    4
    feelinforyou is on a distinguished road

      0  

    Default


    Interesting! Theres is a mistake in your code. But it's working correctly. Why i don't know!!
    In my case it wasn't working correctly. If you look in the class GraphDnD you calculate the x and y coordinates for onMouseDown, onMouseMove and onMouseUp. In onMouseDown you take the relativeX and realativeY.

    For relativeX
    Code:
    return e.getClientX() - target.getAbsoluteLeft() + target.getScrollLeft() +
          target.getOwnerDocument().getScrollLeft();
    For relativeY
    Code:
    return e.getClientY() - target.getAbsoluteTop() + target.getScrollTop() +
          target.getOwnerDocument().getScrollTop();
    And in onMouseMove and onMouseUp the calculation is inverted.

    Code:
      int x = event.getClientX() - graph.getElement().getAbsoluteTop() + graph.getElement().getScrollTop() + graph.getElement().getOwnerDocument().getScrollTop();
        int y = event.getClientY() - graph.getElement().getAbsoluteLeft() + graph.getElement().getScrollLeft() + graph.getElement().getOwnerDocument().getScrollLeft();
    Can you tell me why? if i change this. It's now working correctly in my case!

  6. #5
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,640
    Answers
    107
    Vote Rating
    80
    Colin Alworth is just really nice Colin Alworth is just really nice Colin Alworth is just really nice Colin Alworth is just really nice Colin Alworth is just really nice

      0  

    Default


    Nice catch - no idea why I'm being inconsistent about this. My guess is that I grabbed that pixel-measuring code from within the Chart mouse move stuff (com.sencha.gxt.chart.client.draw.DrawComponent#getEventXY), but stuck with the easier (and wrong-er) code for mouse down and the touch code. I'd welcome a pull request to fix these inconsistencies, otherwise i'll try to clean this up and test it in the next week or two.

Thread Participants: 1

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar