Skip to content
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

Add "Show/Hide Inputs" button to navbar #681

Closed
wants to merge 3 commits into from

Conversation

parente
Copy link
Member

@parente parente commented Mar 7, 2017

Adds a button to toggle cell inputs to the navbar. Tries to collapse whitespace between visibly empty cells by removing padding and border while avoiding too much jitter and excessive animation. Super basic but very effective.

toggle-inputs

The original idea is from @csaid (http://chris-said.io/2016/02/13/how-to-make-polished-jupyter-presentations-with-optional-code-visibility/). I tweaked it a bit in http://mindtrove.info/code-hiding-on-nbviewer/. Any reason this shouldn't live in nbviewer itself?

@mariusvniekerk
Copy link

Nice

@Carreau
Copy link
Member

Carreau commented Mar 9, 2017

cc @michaelpacer who is working on tags.

I'm going to guess that sometime you don't want to hide all the code cells . I have no objections.

@parente
Copy link
Member Author

parente commented Mar 10, 2017

Agreed, @Carreau. I think this can grow over time to support tags for shown/hidden cells, the dashboard layout metadata , and other info stored in the notebook about how to present it. I've seen users get good mileage with the snippets linked above, and figured they would be a good starting point.

@parente
Copy link
Member Author

parente commented Mar 16, 2017

Correcting a "at" above: /cc @mpacer

@mpacer
Copy link
Member

mpacer commented Mar 16, 2017

Is there a reason you did this with js and not pure css animations (ala https://github.com/mpacer/hiding_tags_nbconvert/blob/master/toggle_hidden.tpl)?

also, is there a reason to not have individual I hide buttons on the margin in addition to the global button? It could be hidden until hover which would harm discoverability but would surface exactly the feature you want by default (by instantly toggling the state for all code
cells).

@parente
Copy link
Member Author

parente commented Mar 16, 2017

Is there a reason you did this with js and not pure css animations (ala https://github.com/mpacer/hiding_tags_nbconvert/blob/master/toggle_hidden.tpl)?

Only that I had working JS code to submit. I'm in favor of using a pure CSS approach. I'll look at updating this PR.

also, is there a reason to not have individual I hide buttons on the margin in addition to the global button?

Same reason as above mainly. Plus I'm a fan of building things incrementally with user feedback.

@mpacer
Copy link
Member

mpacer commented Mar 16, 2017

The biggest advantage that JS could give over my pure CSS approach that still (almost entirely) uses the pure CSS approach would be to have the JS extract and then fix the height of the cells (rather than leaving them on auto). Because then you won't need to use the max-height trick that I used to make animations occur (since CSS animations can't be applied to an auto defined height since they can't inspect the object directly).

Regardless, I think that it would be cleaner if you toggled a class and just had altered properties associated with the class in the actual CSS files (rather than a raw encoding).

One of the advantages of that is that once it's based on just toggling a class, the button for toggling/untoggling individual cells is really straightforward to implement (especially since we have a working example of it).

@parente
Copy link
Member Author

parente commented Mar 23, 2017

Thanks @mpacer for the pointers. Here's the new rendition using a CSS class a just a tiny bit of JS to toggle it in the nav bar.

toggle-inputs-css

There's no nbconvert config in nbviewer at the moment, other than one for the slideshow resources. We can follow-up by adding one to get the per-cell checkboxes in.

Copy link
Member

@mpacer mpacer left a comment

Choose a reason for hiding this comment

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

+1

Still, I think we can make the animation nicer by not taking some of the shortcuts that the almost pure CSS approach affords.

So we sacrifice a bit of that purity for the sake of substantially smoother animations by working with what we're actually trying to animate (height) rather than what we were allowed to animate using only CSS (max-height). I think that's worth doing.

Also it's still crazy to me that CSS can't animate from auto values…I'm sure it has something to do with computation. But you'd think that there'd be a low overhead way to pass that message back and allow animation from auto values. Because otherwise, this would be way easier.


body.hide_input_cells div.input {
overflow:hidden;
max-height: var(--max-height-small);
Copy link
Member

Choose a reason for hiding this comment

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

Rather than setting the max height, since you're using js, you can extract the height itself and use that as the basis for the animation.

That would avoid the shadowing effect that you see in your .gif.

Note: I wanted to do this, but unfortunately, you just can't do that in pure CSS. The problem has to do with the height being set to auto. But since you are using js, you aren't stuck with the auto value for the height. If the height is explicitly set in the DOM, you can then use the transitions to modify the height in a smooth manner.

Copy link
Member Author

Choose a reason for hiding this comment

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

I can give height a shot.

Copy link
Member Author

Choose a reason for hiding this comment

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

I see the same shadowing when animating the height by setting the div.input height on load and adding height: 0px !important when .hide_input_cells is applied.

toggle-inputs-css


/* adjust the max-height of input cells */
body div.input {
transition: max-height var(--in-time) var(--transition-path-in), padding .0s step-end;
Copy link
Member

Choose a reason for hiding this comment

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

You can similarly use height here, but you'll need to explicitly access the height at the time (e.g., for each of the inputs grab $(elem_id).height()) but you'll need to do that in the js.

<li>
<a href="javascript:{{js}}" title="{{name}}" {%if accesskey %}accesskey={{accesskey}}{% endif %}>
<span class="fa fa-{{icon}} fa-2x menu-icon"></span>
<span class="menu-text">{{name}}</span>
Copy link
Member

Choose a reason for hiding this comment

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

I like this, but it might be worth expanding the totality of the js that's included…

maybe something like (note this won't work and may not be valid js

<script>
for (x in $.('hide_input_cells')){
   $(x.id).height($(x.id).height())
}
</script>

Or should this go below since you're actually passing the javascript in there and there is minimal js in this actual macro…

NB: I've not seen this use of an href or a before, I'm intrigued.

@@ -14,6 +13,8 @@
{% endif %}
{% endfor %}

{{ layout.head_js_icon("$('body').toggleClass('hide_input_cells');", "Show/Hide Inputs", "eye", "i") }}
Copy link
Member

Choose a reason for hiding this comment

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

I think this is where the above code might actually go (inside the first argument (currently "$('body').toggleClass('hide_input_cells');"))…

I actually looked this up a bit more and think these are most of the necessary details though there are still things that need to be checked… E.g., If you can do this without explicitly iterating over all the elements that need to be toggled.
I'll look at this tomorrow after sleeping on it.

for (x in $.('.input_area')){//input areas are the only things that have the class input area
   x.height(x.height()); //first call sets it, second call retrieves it, they may need to be separated
// the key insight is that is that x.height() should return the pixel height and x.height(val) sets the height to that val.
   x.toggleClass('hide_input_cell');//applies the toggle
}

Right now, I think you're applying 'hide_input_cell' to the entire body, but I figure this would be better to apply to the individual input areas. It also makes it a lot easier to open the way to have checkboxes in the future if can toggle individual cells. Of course, that means that the logic I wrote above won't work for the hide/show all button because then they can be toggled individually and this will just swap state. That's probably going to need more than one line though.

@mpacer
Copy link
Member

mpacer commented Mar 26, 2017 via email

@parente
Copy link
Member Author

parente commented Apr 18, 2017

Sorry for not responding sooner.

Is it possible that this is an optical illusion? Or are the pixels actually doing that shadowing?

I believe it's shadowing. I can see the entire contents of the cell input appear over all of the content instantly, while the space to accommodate it all grows.

Since we're heading back toward using more JS to fix these issues, does it make sense to go back to the original JS implementation?

@parente
Copy link
Member Author

parente commented Jun 28, 2017

Returning to this PR, do folks think we try to work out the shadowing issues with CSS, go with a straight JS approach, or abandon it altogether for now and revisit when there's a final nbformat spec that we can code toward?

@damianavila
Copy link
Member

revisit when there's a final nbformat spec that we can code toward?

I think it would follow that option.

@parente
Copy link
Member Author

parente commented Jun 30, 2017

OK. Closing this out.

@parente parente closed this Jun 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants