Giter Club home page Giter Club logo

Comments (5)

GordonSmith avatar GordonSmith commented on September 27, 2024

You can - you just need to create new file with one of the following extensions:

  • ojs
  • omd
  • ojsnb

from vscode-ojs.

skybrian avatar skybrian commented on September 27, 2024

Could you explain how?

When I create an new file with an ojs extension, it says "Observable JavaScript (OJS)" in the lower right, but it just behaves like a regular JavaScript file, and I don't see how to create a new cell.

By contrast, for Jupyter, there is a "Create: New Jupyter Notebook" command. It creates an unsaved file named "Untitled-1.ipynb" with a blank cell. I can type '2+2' and shift-return, and it execute and return 4.

The only way I see to get an ojs notebook that works is with the "OJS: Download Notebook" command.

Edit: I see now, the extension to use is .ojsnb. But what are the other extensions for?

from vscode-ojs.

GordonSmith avatar GordonSmith commented on September 27, 2024

An OJS file is essentially one big Observable Cell, without being limited to one statement, so the following would be valid:

md`# Hello Wold ${mol}`;

mol = 42;

{
  const context = DOM.context2d(width, height);
  let frame;
  
  (function tick() {
    const x = (Math.sin(Date.now() / 1000) + 1) / 2 * (width - 2 * radius) + radius;
    context.clearRect(0, 0, width, height);
    context.beginPath();
    context.arc(x, height / 2, radius, 0, 2 * Math.PI);
    context.fill();
    frame = requestAnimationFrame(tick);
  })();
  
  invalidation.then(() => cancelAnimationFrame(frame));  
  return context.canvas;
}

radius = 11;
height = 22;

Press the preview to see it:
image

OMD docs are essentially markdown documents, that expect valid ojs inside code pips:

image

from vscode-ojs.

skybrian avatar skybrian commented on September 27, 2024

Thanks!

Clearly, I wasn't reading very carefully. Sorry about that!

In retrospect, I picked the .ojs extension because it was the first one listed and you use 'OJS' as an abbreviation for the Observable JS extension itself, so I thought that was the main file extension to use. But .ojsnb is the one that behaves like a notebook.

I think that for the other extensions, if it's going to display the result for each 'cell', it might make sense to also display the variable name? Showing 'height = 22' in the output would be more meaningful than just '22'.

Displaying the source code that generated the variable might make sense too? On the Observable HQ website, you can choose whether to expand or collapse the source code for each cell. Similarly, it would make sense for the author of a Markdown document to somehow decide whether to show the source code for each 'cell' as well as what the expression evaluated to.

from vscode-ojs.

GordonSmith avatar GordonSmith commented on September 27, 2024

Thanks for the feedback - In the past I have debated this with myself as well and with the addition of the "ojsnb" support decided that it catered for the folks who wanted similar features.

I think the OMD format has scope to add additional meta information (next to the pips) per code cell, but for OJS it would be an all or nothing type switch (like a "debug" mode in the preview pane).

FWIW - If you use the "export to HTML" feature:
image

You will see that I am simply reusing the official Observable "Inspector" to render the cells.

from vscode-ojs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.