16

I'm using dillenmeisters Trello.Net API Wrapper, and on each Card it has a POS attribute. I thought that was for position in the list that it was in, but the numbers seem arbitrary, ranging from 4 to 5 digit numbers. Is there anyway to make sense of these enough to "place" a new Card between 2 others that already exist in the list?

B-Wint
  • 177
  • 1
  • 8

1 Answers1

23

Edit:

Available in version 0.5.9-beta1 of Trello.NET (on NuGet):

// Ways to set the position of a card
trello.Cards.ChangePos(card, 1234)
trello.Cards.ChangePos(card, Position.Top)
trello.Cards.ChangePos(card, Position.Bottom)

I haven't dug deeply into how pos works, but I think it's a sort order. If you want to move a card between two other cards, you could get the position of those two cards and add their Pos together and divide by two.

For example, if you want to insert Card C between Card A and Card B:

  1. Card A - Pos 16
  2. Card B - Pos 32
  3. Card C - Pos 64

(16 + 32) / 2 = 24. Set Card C Pos to 24.

  1. Card A - Pos 16
  2. Card C - Pos 24
  3. Card B - Pos 32

I think they do this so that they only have to update ONE Pos when a card is moved (instead of the Pos of all cards after it which would be necessary if they used a sequential Pos with no gaps).

dillenmeister
  • 1,627
  • 1
  • 10
  • 18
  • 4
    Also noticed that every time a new card is created, the pos is incremented exactly by 65536 (2^16). Has this been chosen randomly or is there any significance here? – Gaurav Gupta Nov 12 '13 at 08:34
  • 1
    what if you want to insert 17 cards between card a and b ? – MD. Sahib Bin Mahboob Nov 18 '13 at 17:51
  • @GauravGupta Trello.NET does not set the position, it's done automatically by Trello so I can't answer that. – dillenmeister Nov 19 '13 at 04:51
  • @MD.SahibBinMahboob I'm not sure. Try adding cards "manually" on trello.com and inserting them in different places to see what positions they get. – dillenmeister Nov 19 '13 at 04:53
  • @MD.SahibBinMahboob By the way, Pos is a double so there are alot more than 17 unique positions between 16 and 32. – dillenmeister Nov 19 '13 at 04:57
  • Even though , AFAIK in this type of operation linked list of data structure would be more suitable but only they know what they are after :p – MD. Sahib Bin Mahboob Nov 19 '13 at 06:57
  • 5
    I just tried placing more than 16 cards between 2 cards. The pos value starts getting into decimals.. for example: 77823.5, 77823.25, 77823.125 etc. – Gaurav Gupta Jan 23 '14 at 11:39
  • 5
    I am just looking into this myself and I noticed another quirk. Like @GauravGupta has pointed out, every new card is incremented by 65535. So if you continue to insert cards before this card then the position will continually decrement by half i.e. 32767.5, 16383.5, 8191.5, 4095.9375, etc...However, what I found was when I inserted a card which would have led to a position less than 0.1 the server would return a pos of 16384 (effectively 65535 / 4). This didn't really make sense because technically this card would be positioned after the card because it has a higher value. – James Jul 11 '14 at 17:38
  • 2
    Another oddity was when I refreshed the page, the positions that were previously set (and accepted) by the server had changed, it's like the server recalculates the positions before it serves the cards. So it seems that Trello is recalculating the positions at the server side when it receives a position that goes beyond 0.1 – James Jul 11 '14 at 17:39
  • @James did you ever figured out why do they use 16384? – Carlos Mendes Jun 17 '16 at 10:10
  • 2
    @CarlosMendes I didn't no, however, my guess was it's just an arbitrary number that gives them lots of range above & below should you continue to move cards around. FWIW we've adopted this strategy in our app and it works well, we've yet to hit an upper limit in prod. – James Sep 30 '16 at 13:23
  • 2
    @dillenmeister If I insert Card C into Card A - Pos. 16, it will get a greater position than Card A, Card B will be the same and will average. But if I insert Card A into Card C, it gets the position less than Card C, it's equal to Card B and averages. Trello does this, is this the correct way to do this? – Braian Silva Mar 27 '20 at 01:15
  • it is hard to digest why initially they used the odd value of 65535 and when pos reaches below 0.1 they refresh and start with 16384. why not again with 65535? – Akash Kumar Seth Aug 14 '23 at 22:54