slamdata / purescript-jtable

A Purescript table renderer capable of displaying multidimensional, heterogeneous JSON data
14 stars 11 forks source link

Rendering of point only json #9

Closed Fresheyeball closed 9 years ago

Fresheyeball commented 9 years ago

The following is technically valid json

[
    [
        1,
        2
    ],
    [
        3,
        4
    ]
]

I'd like some guidance on handling this case (thanks StrongCheck).

jdegoes commented 9 years ago

I believe this is the rendering most consistent with the spec (and most useful):

|---|---|
| 1 | 2 |
|---|---|
| 3 | 4 |
|---|---|

The top-level array is, as always, rendered as the rows of the table. Because the elements have no JCursor (or an empty / identity JCursor), there is no table header.

The two leaf values have the same length and schema, so the arrays are detected as tuples and rendered horizontally instead of vertically.

Thus yielding the above rendering, which I think is the most useful way to render this data (though am open to feedback, of course).

jdegoes commented 9 years ago

Interestingly, this rendering choice would also make a rectangular matrix render as a rectangular matrix, which seems correct.

kanterov commented 9 years ago

What about 3d matrix?

[
  [[1,2], [3,4]],
  [[5,6], [7,8]]
]

Generally it could be n-dimensional array, probably it makes sense to transform it and render as

{
  "0": [[1,2], [3,4]],
  "1": [[5,6], [7,8]]
}
Fresheyeball commented 9 years ago

So, is the idea here that no JFields equals no header at all?

What do you think about separator levels?

|---|---|
| 1 | 5 |
|---|---| <- level 1 separator 
| 2 | 6 |
|===|===| <- level 0 separator
| 3 | 7 |
|---|---| <- level 1 separator 
| 4 | 8 |
|---|---| 
jdegoes commented 9 years ago

@kanterov I like that idea. It also suggest to me it's possible to simplify the problem by rendering objects and arrays the same (using the array index as the label for the array element), and then to post-process the resulting table and deleting headers which can be implied from their spatial positions. Since you can only visualize 2 dimensions on a screen, this would imply higher-level array dimensions would still be labeled with array indexes.

This seems to result in nested tables. @Fresheyeball I like separator levels, albeit that should probably be a styling decision, which means we need nesting information to propagate to TableStyle.

Fresheyeball commented 9 years ago

I don't think this needs nested tables, just css classes in the dom to facilitate styling. It also makes the treating of array indexes as labels redundant.

Fresheyeball commented 9 years ago

Ok so other thing, if an array is at the top level, are we saying it should be rendered horizontally? Because I could see the largest collection being at the top level, which might result in unusable formatting, (consider a table with 10,000 columns and few rows). That said, the inverse is also possible. Perhaps the vertical vs horizontal display of top level collections should be a setting?

Fresheyeball commented 9 years ago
[
  [[1,2], [3,4]],
  [[5,6], [7,8]]
]

as

|---|---|
| 1 | 5 |
|---|---| 
| 2 | 6 |
|===|===|
| 3 | 7 |
|---|---| 
| 4 | 8 |
|---|---| 

vs

|---|---||---|---|
| 1 | 2 || 3 | 4 |
|---|---||---|---|
| 5 | 6 || 7 | 8 |
|---|---||---|---|