Exemple #1
0
    def cmagic(self, line, cell, **_kwargs):
        """Execute current cell as d3 script and displays output."""
        _ = line  # ignore

        opts = config.defaults._asdict()

        return execute_with_requirements(
            cell, required=['d3'], **sanitize_namespace(self.shell.user_ns, options=opts))
Exemple #2
0
    def lmagic(self, line, local_ns=None, **_kwargs):
        """Execute line as d3 command and displays output."""
        user_ns = self.shell.user_ns
        user_ns = user_ns.update(local_ns or dict())

        opts = config.defaults._asdict()

        return execute_with_requirements(
            line, required=['d3'], **sanitize_namespace(user_ns, options=opts))
Exemple #3
0
def display_suppressed_warnings():
    """Display all stderr output cells suppresed by `suppress_warnings`."""
    script = """
        $(element)
            .parents('.output')
            .find('.output_stderr')
            .css('display', 'block');
    """

    return execute_with_requirements(script, required=[])
Exemple #4
0
def iplot(data: pd.DataFrame,
          kind: str = 'diagonal',
          layout: str = 'tree',
          **kwargs):
    """Syntactic sugar which wraps dynamic plot visualizations."""
    js: str = _get_js_template(kind, static=False)

    return execute_with_requirements(js,
                                     required=list(REQUIRED_LIBRARIES),
                                     data=data.to_csv(index=False),
                                     layout=layout,
                                     **kwargs)
Exemple #5
0
def suppress_warnings(line: str = None, cell: str = None, local_ns: dict = None):
    """Suppress all stderr output produced by function call.

    NOTE: The output is still present in the DOM, but not visible.
    """
    _ = line  # line
    _ = local_ns  # ignore

    shell = get_ipython()

    code = cell
    last_command = None

    code_lines = cell.splitlines()
    if not re.search(r"^(\s)+", code_lines[-1]):
        # is not part of a block, evaluate separately
        last_command = code_lines.pop()
        code = '\n'.join(code_lines)

    # evaluate the whole script except the last line
    shell.ex(code)

    try:
        # try to evaluate and return last command
        ret = shell.ev(last_command)
    except SyntaxError:
        # if this one throws too, then its users error
        ret = shell.ex(last_command)

    # suppress warnings produced by the execution
    script = """
        $(element)
            .parents('.output')
            .find('.output_stderr')
            .css('display', 'none');
    """

    execute_with_requirements(script, required=[])

    return ret
Exemple #6
0
def activate_d3_syntax_highlight():
    """Activates syntax highlighting for the d3 cells."""
    script = """
      codecell.CodeCell.options_default.highlight_modes['magic_text/javascript'] = {'reg':[/^%%d3/]};
      
      Jupyter.notebook.events.one('kernel_ready.Kernel', function(){
          Jupyter.notebook.get_cells().map(function(cell){
              if (cell.cell_type == 'code'){ cell.auto_highlight(); } }) ;
      });
      
      console.log("JavaScript syntax highlight activated for '%%d3'.");
    """

    return execute_with_requirements(script, required=['notebook/js/codecell'])