Skip to content

New jsviewer css [rebased] - #4174

Merged
taldcroft merged 21 commits into
astropy:masterfrom
saimn:2982-rebased
Sep 25, 2015
Merged

taldcroft merged 21 commits into
astropy:masterfrom
saimn:2982-rebased

Conversation

@saimn

@saimn saimn commented Sep 20, 2015

Copy link
Copy Markdown
Contributor

This is a rebased version of #2982 with a few improvements:

cc @taldcroft

@saimn

saimn commented Sep 20, 2015

Copy link
Copy Markdown
Contributor Author

Hmm, the failing test is not related to this PR, it seems to be due to the use of an internal api of coverage, and coverage 4.0 has been released today, so this is probably related:

Traceback (most recent call last):

  File "<string>", line 1, in <module>

  File "astropy/tests/helper.py", line 307, in _save_coverage

    cov._harvest_data()

AttributeError: 'Coverage' object has no attribute '_harvest_data'

@saimn

saimn commented Sep 20, 2015

Copy link
Copy Markdown
Contributor Author

For the appveyor failing test, it is due to the new test I have added and some windows path format, I will check.

@saimn
saimn force-pushed the 2982-rebased branch 2 times, most recently from d243ef0 to 1ccbcf6 Compare September 20, 2015 22:43
Comment thread astropy/table/jsviewer.py Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The max_lines arg isn't being used anywhere and I was able to put a 10000 line table into the browser (which was really slow).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, this seems to go back to d18364d when the use of pformat has been replaced with the HTML write. Fixed with table slicing.

@taldcroft

Copy link
Copy Markdown
Member

I would echo the earlier comment that a sans-serif font would be cleaner.

@taldcroft

Copy link
Copy Markdown
Member

It seems like the table is forced to be 100% width, which looks awkward for a table that is just a few columns wide.

@saimn

saimn commented Sep 21, 2015

Copy link
Copy Markdown
Contributor Author

I have added a default style using the default sans-serif font, and 80% width for the table wrapper. Without knowledge on the content of the table it is hard to set a good value for all cases, but at least with this value present in the docstring and signature it will be more visible.

It seems from the code that the jsviewer table could be printed directly in an ipython notebook, , but I didn't found how, any hint ? I am trying somthing like this but it doesn't work:

HTML('\n'.join(JSViewer().ipynb('table%s' % id(t))))

@saimn
saimn force-pushed the 2982-rebased branch 2 times, most recently from 9e4fa59 to 616c0c3 Compare September 21, 2015 09:13
@saimn

saimn commented Sep 21, 2015

Copy link
Copy Markdown
Contributor Author

And Appveyor is passing :)

@taldcroft

Copy link
Copy Markdown
Member

Sorry, haven't dug in to the details of this, but can't the default just be without an explicit width set? Is 100% hardwired into DataTables or something? I'm just thinking of a plain old <table> that auto-sizes based on the contents.

@saimn

saimn commented Sep 21, 2015

Copy link
Copy Markdown
Contributor Author

It is possible, but then the header and footer (with the length selector, search field, pagination) will be aligned with the container's width and not the table, which doesn't look very nice. So setting the container size is a good compromise I think, we can maybe set a size smaller than 80% ?

@taldcroft

Copy link
Copy Markdown
Member

What about something that is functionally like this:

<table>
  <tr>
    <td align="left">Show entries</td>
    <td>&nbsp;</td>
    <td align="right">Search</td></tr>
  <tr>
    <td colspan=3>
      <table>
        <tr><th> Col1 </th> <th>Col2</th></tr>
        <tr><td> 100 </td> <td>200</td></tr>
        <tr><td> 300 </td> <td>400</td></tr>
      </table>
    </td>
  </tr>
  <tr>
    <td align="left">Showing 50 entries</td>
    <td>&nbsp;</td>
    <td align="right">First Previous 1 2 Next Last </td></tr>
</table>        

Which renders as:
image

Or for a wider table:
image

@saimn

saimn commented Sep 21, 2015

Copy link
Copy Markdown
Contributor Author

These elements are added directly by DataTables, it must be possible to modify the HTML template but I'm not sure it is worth it:

  • by default this bar with Show entries/Search is responsive, it will not be the case with a custom template using a table.
  • it may be more difficult to parse the table (with the HTML Reader, I don't know if it is already possible ?)

And having a table which is only a few tens of pixels wide (when there is only 2 columns for example) is not especially beautiful imho, maybe a compromise could be to set a smaller width by defaut, in pixels to have the same for all screens, something like 600 or 800 px ?

@taldcroft

Copy link
Copy Markdown
Member

An example of a beaker notebook shows tables that I think are really beautiful:
http://sharing.beakernotebook.com/gist/anonymous/a400a57f2bf13966d77e

Note the second table which is just 4 columns and looks good. In most real-world tables the column names or data values are wide enough to make sure you never get a 30-pixel-wide output.

My example was just intended to roughly illustrate the desired layout, but wasn't a suggestion for how to implement it.

Anyway, I understand this PR was not intended to be a rewrite from scratch, and DataTables does seem to be quite powerful. I dug around a little in the docs, but I didn't see what I was looking for, naming some configuration to say "just act like a plain simple HTML table and make each column as wide as its widest element". Seems like not such an unusual desire, but all the examples I could see tended toward displaying a table where the number of columns is known in advance by the web page designer.

@saimn

saimn commented Sep 22, 2015

Copy link
Copy Markdown
Contributor Author

I tried something inspired by your beaker notebook, it works if Show entries/Search/pagination are left-aligned:
table
Then maybe the pagination block is too wide, it could be reduced with another option. Currently it is set to full_numbers, which is the more complete option:
http://datatables.net/reference/option/pagingType

@saimn

saimn commented Sep 24, 2015

Copy link
Copy Markdown
Contributor Author

Rebased, now tests are all green :)
@taldcroft What do you think about the latest capture ?

@taldcroft

Copy link
Copy Markdown
Member

Looks great! Does that screen shot reflect the current code?

@saimn

saimn commented Sep 25, 2015

Copy link
Copy Markdown
Contributor Author

@taldcroft yes !

@taldcroft

Copy link
Copy Markdown
Member

Ok, thanks for bringing this one home @saimn !! Merging.

taldcroft added a commit that referenced this pull request Sep 25, 2015
@taldcroft
taldcroft merged commit c7099d6 into astropy:master Sep 25, 2015
@saimn

saimn commented Sep 26, 2015

Copy link
Copy Markdown
Contributor Author

Great ! I will check if I can get something quickly to use this in the ipython notebook (#3937).

@taldcroft

Copy link
Copy Markdown
Member

Cool. I don't recall if there is an open issue, but it would also be great to be able to write out a table like this as an independent entity that can be copied into an existing HTML page.

@saimn

saimn commented Sep 26, 2015

Copy link
Copy Markdown
Contributor Author

Yes there is #4058, that what brought me here, I wanted to embed a generated HTML table in a website. I have made something without this, but it would be easier if astropy support this directly.

@saimn
saimn deleted the 2982-rebased branch September 26, 2015 21:06
@embray embray added this to the v1.1.0 milestone Sep 28, 2015
@embray

embray commented Sep 28, 2015

Copy link
Copy Markdown
Member

Nag: Most PRs, and in particular ones that add new features, should not be merged without assigning a milestone.

@taldcroft

Copy link
Copy Markdown
Member

@embray - copy, I'll work on burning this into my mental checklist.

saimn added a commit to saimn/astropy that referenced this pull request Oct 4, 2015
As astropy#4174 was based on an older PR, I didn't noticed that the changelog entry
was in the 1.0 version.
mhvk added a commit that referenced this pull request Oct 5, 2015
Fix changelog entry for #4174 added to the wrong version.
dhomeier pushed a commit to dhomeier/astropy that referenced this pull request Dec 17, 2015
As astropy#4174 was based on an older PR, I didn't noticed that the changelog entry
was in the 1.0 version.
dhomeier pushed a commit to dhomeier/astropy that referenced this pull request Jun 12, 2016
As astropy#4174 was based on an older PR, I didn't noticed that the changelog entry
was in the 1.0 version.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants