columnify icon indicating copy to clipboard operation
columnify copied to clipboard

Utilize unused space from other columns

Open timoxley opened this issue 11 years ago • 8 comments

If a column is squished, but a neighboring column isn't using all of it's available space, then columnify should figure out how to readjust widths so every column is using optimal space.

timoxley avatar Jan 02 '14 08:01 timoxley

gets complicated as then you need to recalculate widths based on word breaks etc

timoxley avatar Jan 02 '14 08:01 timoxley

@danyshaanan currently columns will only use as much space as they need, within the specified min and max, ideally if a column is not using its maximum width, it could loan width to another column so it can be wider. Might need to introduce soft & hard min/max, default min/max would be soft min and max.

timoxley avatar Jul 29 '14 06:07 timoxley

Note that the widths are calculated based on available word-breaks

timoxley avatar Jul 29 '14 06:07 timoxley

I'll look into it.

danyshaanan avatar Jul 29 '14 06:07 danyshaanan

I Didn't have the time in the last few days, and not likely to have much of it this coming week. I'll write when I'll have the time.

danyshaanan avatar Aug 02 '14 19:08 danyshaanan

Ok, here is my take.

If I understand correctly, the idea is that this code:

var columnify = require('./index.js')
var options = {
  paddingChr: '.',
  config: {
    a: { minWidth: 5, maxWidth: 10 },
    b: { minWidth: 5, maxWidth: 10 }
  }
}
console.log(columnify([{a:'123456789AB',b:2},{a:3,b:4}], options))

that outputs this:

A......... B....
123456789… 2....
AB........ .....
3......... 4....

could instead output this:

A.......... B...
123456789AB 2...
........... ....
3.......... 4...

If so, I have a few concerns:

  • This requires another 'pass' on the data, meaning it requires a non trivial change to the logic and flow.
  • This will mean that even though someone defined A to be of maxWidth 10, we'll make it longer.
  • In case of multiple column, a finer definitions will be required to decide how the space should be divided.

The first concern makes me wonder if this is worth the complication to the code, the second makes me wonder if this is the right thing to do in term of the spec, and the third contributes a bit more weight to each of the previous ones...

danyshaanan avatar Aug 12 '14 15:08 danyshaanan

Sorry I didn't back to this sooner.

This requires another 'pass' on the data, meaning it requires a non trivial change to the logic and flow.

Correct, hence my reluctance to tackle it!

This will mean that even though someone defined A to be of maxWidth 10, we'll make it longer.

soft and hard limits perhaps?

timoxley avatar Aug 18 '14 11:08 timoxley

Soft and hard limits could be used, but I think that would overcomplicate both the code and the user experience - two things I wouldn't want to compromise on for something that I'd consider a bonus feature.

danyshaanan avatar Aug 18 '14 12:08 danyshaanan