constellation icon indicating copy to clipboard operation
constellation copied to clipboard

Sort numbers numerically in the Table View

Open arcturus2 opened this issue 3 years ago • 3 comments

Prerequisites

  • [X] Put an X between the brackets on this line if you have done all of the following:

    • Running the latest version of Constellation

    • Attached the Support Package via Help > Support Package

    • Checked the FAQs: https://github.com/constellation-app/constellation/wiki/FAQ

    • Checked that your issue isn’t already filed: https://github.com/constellation-app/constellation/issues

    • Checked that there is not already a module that provides the described functionality: https://github.com/constellation-app/constellation/wiki/Catalogue-of-Repositories

Description

The Table view sorts columns with numbers alphanumerically instead of numerically. For example, instead of:

1
10
100
2

it should be:

1
2
10
100

Steps to Reproduce

  1. File -> New Graph
  2. Experimental -> Build Graph -> Small world graph
  3. Open the Table View
  4. Switch to the nodes mode
  5. Add the x attribute as a column
  6. Sort the column

Expected behaviour: [What you expect to happen] Column should be sorted numerically

Actual behaviour: [What actually happens] Column is sorted as Strings instead

Reproduces how often: [What percentage of the time does it reproduce?] 100

arcturus2 avatar Aug 13 '21 02:08 arcturus2

A quick dig into the code confirms that the table has been constructed such that all inputs are Strings (hence all columns including ones that would appear to be numeric are sorted lexicographically). A refactor of a number of parts of the table would be required then in order to be able to handle numerical values properly

antares1470 avatar Oct 19 '21 23:10 antares1470

@antares1470 I first attempted to refactor the table columns and associated variables to the type of Object so that the columns themselves would infer the type, String or Integer, then sort accordingly.

That didn't seem to work so I tried implementing a custom comparator on the SortedList that populates the columns. It was either not being bound properly or being overridden at a later stage so that didn't affect the sorting either.

After discussing with @formalhaunt, a possible solution is to implement a comparator on the table columns as they are being created in Table.java.

sol695510 avatar Oct 19 '21 23:10 sol695510

This issue is stale because it has been open for 6 months with no activity. Consider reviewing and taking an action on this issue.

github-actions[bot] avatar May 18 '22 00:05 github-actions[bot]

Thank you @OrionsGuardian for fixing this up. This is super handy now and I can now sort on all the columns in the Table view as I would expect (text sorting correcting, numbers sorting correctly). Thank you!!

GammaVel avatar Nov 22 '22 03:11 GammaVel