Group elements based on values

Asked

Viewed 63 times

1

JSON:

var obj = {
    'itemA' : {
        'x' : '300',
        'y' : '200'
    },
    'itemB' : {
        'x' : '305',
        'y' : '210'
    },
   'itemC' : {
        'x' : '442',
        'y' : '210'
    }
};

What I need to do is take these items and instead of displaying the 3, display only groups that group the items next to each other. For example, the x and y of Itema and itemB are next then instead of displaying 2, it would display only 1 grouping. Already the itemC has the x far away and the y next, but as it has to be the x and y that has to be close, so would display it without grouping with others, so would display 2 items on the screen.

I still have no idea how to do this with Javascript or jQuery, and even in PHP if so, but would like on JS/jQuery.

  • First you would have to set a limit to where the "next" goes, for example if it is 10% more or less, so your range would be, for the itemA 270 to 330.

  • Second step, define what a grouped item would look like, so I understand ,x and y are the positions of the right elements? Soon if they are near what will be displayed on the screen? instead of displaying 2, it would display only 1 grouping got complicated because you can’t understand exactly what you’re going to do

  • It could be something of 20 in x and 20 in y (not percentage, but same value)

  • Each item has x and y. I want to group the closest ones into 1 only. If it’s too far, create a new group and so on. The x and y are the bases to check if you are near or not @Neuberoliveira

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.