columnify
columnify copied to clipboard
Utilize unused space from other columns
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.
gets complicated as then you need to recalculate widths based on word breaks etc
@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.
Note that the widths are calculated based on available word-breaks
I'll look into it.
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.
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...
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?
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.