processing / p5.js

p5.js is a client-side JS platform that empowers artists, designers, students, and anyone to learn to code and express themselves creatively on the web. It is based on the core principles of Processing. http://twitter.com/p5xjs —
http://p5js.org/
GNU Lesser General Public License v2.1
21.53k stars 3.3k forks source link

Adding sort functionality for Table objects #5145

Open paraclete-pizza opened 3 years ago

paraclete-pizza commented 3 years ago

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

Most appropriate sub-area of p5.js?

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.

welcome[bot] commented 3 years ago

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.

alovictor commented 3 years ago

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 commented 3 years ago

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.

limzykenneth commented 3 years ago

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.

Qianqianye commented 2 years ago

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