p5.js icon indicating copy to clipboard operation
p5.js copied to clipboard

Adding sort functionality for Table objects

Open paraclete-pizza opened this issue 4 years ago • 5 comments
trafficstars

How would this new feature help increase access to p5.js?

Most appropriate sub-area of p5.js?

  • [ ] Accessibility (Web Accessibility)
  • [ ] Build tools and processes
  • [ ] Color
  • [ ] Core/Environment/Rendering
  • [ x] Data
  • [ ] DOM
  • [ ] Events
  • [ ] Friendly error system
  • [ ] Image
  • [ ] IO (Input/Output)
  • [ ] Localization
  • [ ] Math
  • [ ] Unit Testing
  • [ ] Typography
  • [ ] Utilities
  • [ ] WebGL
  • [ ] Other (specify if possible)

Feature enhancement details:

It would be helpful to have an equivalent of Processing's sort() function for Tables in p5.

The Table object is already quite robust. However, sorting items by column contents is a common enough data-manipulation task that I feel adding it would be very useful for folks using p5 to visualize or manage sets of data.

Thinking about accessibility in the broadest sense, making p5's data management tools more robust and easy to use may put powerful data visualization and manipulation tools in the hands of folks who may not have equitable access to costly tools like Tableau, or tools with a higher learning curve like R or D3.

paraclete-pizza avatar Mar 31 '21 15:03 paraclete-pizza

Welcome! 👋 Thanks for opening your first issue here! And to ensure the community is able to respond to your issue, be sure to follow the issue template if you haven't already.

welcome[bot] avatar Mar 31 '21 16:03 welcome[bot]

Hey, I like that. I've been thinking about this and I've came up with something simple like this:

table.sort(column, direction)

where column is the column to sort by and direction (optional) could be ascending or descending. I am not that familiar with sorting in tables, so I don't know what else would be important to have. I would like to hear more opinions to try to implement something.

alovictor avatar Apr 05 '21 21:04 alovictor

I started to implement and decided to do as it is in processing, two different functions for ascending and descending order.

table.sort(column);
table.sortReverse(column);

I had to make some extra internal functions in p5.Table to handle quicksort, but i dont really know if this is following the design pattern of p5.js. I know the lib is quite lean, so can any contributor tell me if its ok to do this? Or any idea on how to implement could be useful.

alovictor avatar Apr 06 '21 22:04 alovictor

I'm ok with adding this new feature. We need another maintainer to approve on this proposal then you can start putting together a PR. Thanks.

limzykenneth avatar Apr 11 '21 10:04 limzykenneth

Please go ahead and put together a Pull Request. Thank you!

Qianqianye avatar Jul 12 '22 22:07 Qianqianye