npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

memory-viz

v0.5.0

Published

Library for creating beginner-friendly memory model diagrams.

Downloads

475

Readme

MemoryViz: Creating memory model diagrams

MemoryViz is a visualization tool that generates memory model diagrams for Python code, aimed at students and educators. MemoryViz is written in Javascript and is built on top of the Rough.js library.

For more information, check out our demo project documentation.

Installation

Install MemoryViz using npm (requires Node.js to be installed):

$ npm install memory-viz

Usage

MemoryViz can be run from the command line or using its Javascript API.

Command-line interface

Given a JSON file demo.json that encodes a state of Python memory and some styling options:

[
    {
        "type": ".frame",
        "name": "__main__",
        "id": null,
        "value": { "lst1": 82, "lst2": 84, "p": 99, "d": 10, "t": 11 }
    },
    {
        "type": "str",
        "id": 19,
        "value": "David is cool!",
        "style": ["highlight"]
    },
    {
        "type": "int",
        "id": 13,
        "value": 7
    }
]

you can run the following command in the terminal:

$ npx memory-viz --output demo_output.svg demo.json

This producs an SVG file, demo_output.svg, that visualizes the state of memory:

Sample usage svg output

Javascript API (Node.js)

Call the draw function on an array that encodes a state of Python memory and some styling options. Here's a complete example, which produces the same SVG output as above.

const { draw } = require("memory-viz");

const objects = [
    {
        type: ".frame",
        name: "__main__",
        id: null,
        value: { lst1: 82, lst2: 84, p: 99, d: 10, t: 11 },
    },
    {
        type: "str",
        id: 19,
        value: "David is cool!",
        style: ["highlight"],
    },
    {
        type: "int",
        id: 13,
        value: 7,
    },
];

const model = draw(objects, true, { width: 1300 });

model.save("demo_output.svg");

Javascript API (browser)

MemoryViz can also be run in the browser by loading the library from a CDN (e.g., jsDelivr) and accessing the global memoryViz object. Here is a standalone example.

Contributing

Installation

  1. Install Node.js.

  2. Clone the MemoryViz repository and cd into it:

    $ git clone https://github.com/david-yz-liu/memory-viz.git
    $ cd memory-viz
  3. Install the dependencies:

    $ npm install
  4. Install the pre-commit hooks to automatically format your code when you make commits:

    $ npx husky init
  5. Compile the MemoryViz library:

    $ npm run build-dev --workspace=memory-viz
  6. Run the test suite to check that all tests pass:

    $ npm test

Developer tips

Automatic Javascript compilation. Rather than running npm run build-dev to recompile your Javascript bundle every time you make a change, you can instead run the following command:

$ npm run watch --workspace=memory-viz

This will use webpack to watch for changes to the Javascript source files and recompile them automatically.

Note: this command will keep running until you manually terminate it (Ctrl + C), and so you'll need to open a new terminal window to enter new terminal commands like running the demo below.

Viewing Jest SVG snapshots. To easily view the Jest SVG snapshots, open the file memory-viz/src/tests/__snapshots__/snapshot.html and select the snapshot outputs with the *.snap extension.