-
-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resize column to fit text on double click #546
Resize column to fit text on double click #546
Conversation
Thanks for submitting your first pull request! You are awesome! 🤗 |
packages/datagrid/src/datagrid.ts
Outdated
const gc = this.canvasGC; | ||
gc.font = CellRenderer.resolveOption(renderer.font, config); | ||
const textWidth = gc.measureText(cellValue).width; | ||
const textWidth = this._getCellTextWidth( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NB that this does not translate to the same code as the original.
Initially, the cellValue
was procured from the corner-header
, however, the config
would refer to the column-header
area. I guess that's a bug?
Thanks for starting this!
We could have a dedicated code path for very large columns (say > 1000 rows) with a heuristic. It could find e.g. 100 cells with longest text (by character count) and then only |
DataGrid._getConfig(dataModel, idx, index, 'body') | ||
); | ||
|
||
// Heuristic: Sort by the length of the text to render and only fully calculate the text width |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can decrease the number of selected rows or try using a heap/quickselect for getting the top-N elements instead if this is not adequate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update: MinHeap won't really help with performance. The main issue seems to be that getting the values of the cells is extremely slow. This is possibly accounted by the fact that the data is stored in a row-major form:
lumino/packages/datagrid/src/jsonmodel.ts
Line 83 in 9c4933f
value = this._data[row][field.name]; |
I think that what I'm doing here is probably good-enough for now but can change it if you think that this is likely not adequate.
3e02d06
to
d4dafca
Compare
Issues I've looked into:
|
An issue that I'm seeing on the side is that I don't think that this is an issue with my code as I observe the same behaviour in Opened #547 for this. |
afeb24c
to
9c4933f
Compare
9c4933f
to
fed5425
Compare
Hi @krassowski, Would you be able to have another look at this PR? |
fed5425
to
91aef22
Compare
The CI seems a bit flakey at the moment. Do you know how I can rerun one of the builds? |
I kicked the CI, will look at all the PRs by Monday. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heads-up: we would like to gradually add tests for any APIs changed in datagrid (which will make reviewing easier and merging PR faster). I had started this in #585 and once it is in we could add a simple test for the APIs modified here too - I can help with this.
Hi, can I get an update on this? |
@vthemelis friendly ping - do you have time to finish this one up? |
Yes, will look into it this weekend |
91aef22
to
3b8bb40
Compare
Signed-off-by: Vasilis Themelis <vdthemelis@gmail.com>
3b8bb40
to
0f2f087
Compare
@krassowski, I made the changes suggested by your comments but I'm not sure how to best test my changes. The setup seems a bit too involved and I'm not very familiar with UI testing. Would you mind merging without tests for now? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @vthemelis
@krassowski would you have time to help with testing this or is it ok to move forward?
Let's move forward and add test in a follow up PR |
Implements: #535 and jupyter-widgets/ipydatagrid#302
Automatically resizes the width of columns by double clicking on the barriers between column headers.