das-developers / das2java

The original das2 library. Provides interactive publication-ready 2-D plotting
https://das2.org
GNU Lesser General Public License v3.0
4 stars 0 forks source link

Data Point Recorder sorts using alpha, not numeric #28

Closed jbfaden closed 2 years ago

jbfaden commented 2 years ago

I just noticed the DataPointRecorder GUI sorts by column using an alpha sort, not numeric. I thought I could use the digitizer, then sort by the "sigmas" column, then delete the low ones, but I can't because of this limitation (and it would be easy to think it was a numeric sort, leading to mistakes). The units of the column should determine the sort type. ![Uploading 20220308_180217.png…]()

jbfaden commented 2 years ago

I've verified that this is still the case. The column "y" is sorted by alpha, not numerically.

image

jbfaden commented 2 years ago

This Autoplot script demos:

from org.das2.components import DataPointRecorder
setScriptDescription('Demo proper sort for DataPointRecorder https://github.com/das-developers/das2java/issues/28')

dpr= DataPointRecorder()

addTab( 'record',dpr )

tt = linspace( datum('2030-033'),datum('2030-043'),11)

d = dataset

dpr.addDataPoint( bundle( tt[0], d(8), d('aaa') ) )
dpr.addDataPoint( bundle( tt[1], d(9), d('bbb') ) )
dpr.addDataPoint( bundle( tt[2], d(10), d('fff') ) )
dpr.addDataPoint( bundle( tt[3], d(11), d('eee') ) )
dpr.addDataPoint( bundle( tt[4], d(12), d('ddd') ) )
dpr.addDataPoint( bundle( tt[5], d(13), d('ccc') ) )
dpr.addDataPoint( bundle( tt[6], d(14), d('hhh') ) )
dpr.addDataPoint( bundle( tt[7], d(15), d('jjj') ) )
dpr.addDataPoint( bundle( tt[8], d(16), d('iii') ) )
dpr.addDataPoint( bundle( tt[9], d(17), d('kkk') ) )
dpr.addDataPoint( bundle( tt[10], d(18), d('zzz') ) )

setStatus('test sort on each column')
jbfaden commented 2 years ago

The problem is that the TableModel's getValueAt would format the data to Strings, instead of letting a "view" object (MVC) format the data. I'm making it so that getValueAt returns a datum, and then a view layer will be used to format the data in the table. This is likely to introduce bugs and needs to be done carefully.

jbfaden commented 2 years ago

Also I notice that Datum's compareTo method always compares the number backing the Datum, so nominal data is sorted arbitrarily instead of alphabetically. ("Chicago" should come before "Denver", but if Denver is encountered first, this is not the case.) The method now checks the unit and sorts by string value in this case.

jbfaden commented 2 years ago

A new TableCellRenderer is needed to hide the units, which are provided in the column header.

jbfaden commented 2 years ago

When running addPointDigitizer, I see that if the table is sorted, then the selection doesn't work. https://abbith.physics.uiowa.edu/jbf/juno/-/blob/master/team/digitizer/addPointDigitizer.jy

jbfaden commented 2 years ago

This is fixed.