davidclemens / Dingi

Dingi is a toolbox for processing data collected by marine research gear.
MIT License
1 stars 0 forks source link

Padding is wrong when printing table with `DataKit.Metadata.variable` column(s) #120

Open davidclemens opened 1 year ago

davidclemens commented 1 year ago

System information

-----------------------------------------------------------------------------------------------------
MATLAB Version: 9.3.0.713579 (R2017b)
MATLAB License Number: STUDENT
Operating System: Mac OS X  Version: 10.15.7 Build: 19H2 
Java Version: Java 1.8.0_121-b13 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
-----------------------------------------------------------------------------------------------------
MATLAB                                                Version 9.3         (R2017b)    
Simulink                                              Version 9.0         (R2017b)    
Aerospace Toolbox                                     Version 2.20        (R2017b)    
Control System Toolbox                                Version 10.3        (R2017b)    
Curve Fitting Toolbox                                 Version 3.5.6       (R2017b)    
DSP System Toolbox                                    Version 9.5         (R2017b)    
Dingi                                                 Version 0.1.0b1     (2022.5.0b1)
Image Processing Toolbox                              Version 10.1        (R2017b)    
Instrument Control Toolbox                            Version 3.12        (R2017b)    
Mapping Toolbox                                       Version 4.5.1       (R2017b)    
Optimization Toolbox                                  Version 8.0         (R2017b)    
Signal Processing Toolbox                             Version 7.5         (R2017b)    
Simulink Control Design                               Version 5.0         (R2017b)    
Statistics and Machine Learning Toolbox               Version 11.2        (R2017b)    
Symbolic Math Toolbox                                 Version 8.0         (R2017b)    
Utilities                                             Version 1.3.0       (2022.10.0) 

Bug description

When printing a table with a column containing an enumeration array, the padding is messed up.

What should have happened?

>> disp(T)
        Var1             Var2     
    _____________    _____________

    A                A            
    VeryLongEntry    VeryLongEntry
    Test             Test         

>> 

What did actually happened?

>> disp(T)
        Var1             Var2     
    _____________    _____________

    A    A
    VeryLongEntry    VeryLongEntry
    Test    Test

>> 

Steps to reproduce the bug

  1. Define an enumeration class with variable lengths:
    classdef TestEnum
    enumeration
        A
        VeryLongEntry
        Test
    end
    end
  2. Create an array C with instances of that class:
    C = arrayfun(@(S) S,enumeration('DataKit.Metadata.TestEnum'));
  3. Create a table T containing that array as columns:
    T = array2table([C,C]);
  4. Then print the table to the command window with disp(T)

Causes & solutions

The file MATLAB_R2017b.app/toolbox/matlab/datatypes/@tabular/disp.m has a faulty line for enumaration data types. Replace line 177

maxVarLen = max(strlength(varStr));

with

[varStr, maxVarLen, lostWidth] = alignTabularContents(varStr, lostWidth);