jupyterlab / lumino

Lumino is a library for building interactive web applications
https://lumino.readthedocs.io/
Other
634 stars 128 forks source link

Context aware cells and cell merging in the lumino DataGrid #103

Open ibdafna opened 4 years ago

ibdafna commented 4 years ago

Team,

I am opening this issue to discuss a potential enhancement to the lumino DataGrid. Specifically, I am interested in hearing your opinions on adding some mechanism where the DataGrid can have "context aware" cells.

We are big fans of the DataGrid and rely on it quite extensively in some of our internal projects. Some of the frequent use cases we have involve the notion of cell merging so we can represent hierarchies of nested columns and rows. Other ones involve setting the formatting of one cell based on the value of another cell, for example.

Custom data models are not enough for this type of functionality as there is no clear notion of a cell object. Cells are painted based on a calculated region, but they are not aware of their neighbors. This means that conditional formatting in one column based on the values in another column cannot be done. The same idea applies to cell hierarchies when rendering nested column and row headers. The existing data model, actually, can accommodate multiple header rows/columns: https://github.com/jupyterlab/lumino/blob/925377cb5d33f47a20924a3fed3a75195c3f82a8/packages/datagrid/src/jsonmodel.ts#L49

But that model assumes all cells are distinct, and does not allow for a visual representation of any merged regions.

To get around that, at the moment, we are maintaining a fork which has a quick and dirty hack to allow the for visual representation of nested columns. However the current implementation is not something we think is sustainable to maintain, and ideally we could have a better, well thought-of, model to address all these use cases, and that's why I am opening this PR!

I would appreciate any feedback you have on this idea.

Many thanks

ibdafna commented 4 years ago

@blink1073 @afshin @jasongrout

kgoo124 commented 4 years ago

@ibdafna Hi, my name is Kalen, and I am one of the Cal Poly interns. Our team is working on a Tabular Data Editor extension utilizing the DataGrid. We have defined our own model that is compatible with editing, and currently refactoring this model. This problem of "context-aware" cells is something that would be helpful for our extension as well. I would be happy to participate in this conversation and help out where I can.

nmichaud commented 4 years ago

Hi @ibdafna I'm also interested in both multi-span cells and context-aware cells. My use case for multi-span cells is similar to yours - mainly for showing hierarchical rows and columns (for a pivot table), and I likewise have a forked version with the horizontal/vertical line drawing hacked to fake it. A general version of this feature (arbitrary row/column spans) would be a big change in the grid and datamodel implementations, but i think hierarchical headers could fit in with some small additions to the datamodel.

For custom formatting based on the value of another cell, I think this is already possible by leveraging the metadata feature of the datamodel, which can be leveraged to provide linkages between different cells (coupled with text renderers that use CellRenderer::ConfigFuncs for dynamic formatting).

ibdafna commented 4 years ago

@kgoo124 @nmichaud Thank you both for the interest! I am in the process of designing a draft spec that I will soon share with everyone. I'll also try to bring this up in the next open developer meeting to see what the sentiment is.

afshin commented 4 years ago

I am in the process of designing a draft spec that I will soon share with everyone.

Awesome, thank you @ibdafna! I'm looking forward to seeing your draft.

ibdafna commented 4 years ago

https://docs.google.com/document/d/1WWeqpHRVTeZUfYk1TzYcTyO4u2JdjmyY1qmQZIark-4/edit?usp=sharing

Here is a higher level draft, there isn't any low level detail there yet, mostly high level discussion on potential avenue to take. Hoping to get consensus on the direction and then I can start working on an actual design. Please comment away! :)

nmichaud commented 4 years ago

Hi @ibdafna do you have some examples of formatting a cell based on another cell? As far as I can tell, every example i can think of can be satisfied using cell metadata, and i'd argue knowing about the linkage between cells is a datamodel concern.

ibdafna commented 4 years ago

@nmichaud all suggestions are welcome, we're brainstorming! I don't have a proposed solution for conditional formatting yet so it would be awesome if you could add your opinion in the document above.

nmichaud commented 4 years ago

@ibdafna what i'm saying is conditional formatting is already possible with the constructs provided by the datagrid (namely Metadata and renderers) - i don't think any changes are needed. Cells spanning rows/columns will likely need changes.

nmichaud commented 4 years ago

@ibdafna for example: https://bl.ocks.org/nmichaud/raw/83f68a0532e5475acf17780e68c282c8 The color of a cell in column 0 is dependent on the value in column 1 (<0 is red and >0 is green). It does require a bit of coordination between the renderer and the datamodel: https://gist.github.com/nmichaud/83f68a0532e5475acf17780e68c282c8#file-index-ts-L50-L55 https://gist.github.com/nmichaud/83f68a0532e5475acf17780e68c282c8#file-index-ts-L80-L90

Since the grid queries for metadata for each cell, it's possible to provide any additional data for rendering that cell that would be needed.

ibdafna commented 4 years ago

@nmichaud thank you, looks good. I'll focus on merged cell hierarchies.