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

vega-scenegraph

v4.13.0

Published

Vega scenegraph and renderers.

Downloads

668,409

Readme

vega-scenegraph

Vega scenegraph and renderers.

Renderers and event handlers for Vega's mark-based scenegraph. This package supports both pixel-based (canvas) and vector graphics (SVG) output. Renderers can either (re-)draw a complete scene or perform incremental re-rendering for a set of provided "dirty" items. A fast SVG string renderer is also provided to generate static SVG for export.

The node-canvas library is used for server-side canvas rendering and bounds calculation. Node-canvas requires the native Cairo graphics library and may attempt to compile native code as part of the installation process. In some instances this may result in installation hiccups. Should you run into issues, you are likely to resolve them more quickly if you first search for help regarding node-canvas (as opposed to vega-scenegraph) installation. However, node-canvas is not a strict dependency, and is not needed for SVG rendering. Bounds calculation can be performed without node-canvas, though in the case of text marks the resulting bounds may be inaccurate due to approximate text size calculations.

Scenegraph Definition

The Vega scenegraph is a hierarchical (tree) data structure. The levels of the tree alternate between an enclosing mark definition and contained sets of mark instances called items.

For example, here is a simple scenegraph containing three rectangles:

{
  "marktype": "rect",
  "items": [
    {"x": 0, "y": 0, "width": 50, "height": 50, "fill": "steelblue"},
    {"x": 100, "y": 50, "width": 50, "height": 50, "fill": "firebrick"},
    {"x": 50, "y": 100, "width": 50, "height": 50, "fill": "forestgreen"}
  ]
}

The supported mark types are rectangles (rect), plotting symbols (symbol), general paths or polygons (path), circular arcs (arc), filled areas (area), lines (line), images (image), text labels (text), and chart gridlines or rules (rule). Each item has a set of supported properties (x, y, width, fill, and so on) appropriate to the mark type.

Scenegraphs may also contain group marks, which serve as containers for other marks. For example, a top-level group mark may look like:

{
  "marktype": "group",
  "items": [
    {
      "x": 0,
      "y": 0,
      "width": 200,
      "height": 200,
      "items": [...] // array of contained mark instances
    }
  ]
}

In this example, the group mark contains only a single group item. In practice, a group mark may contain any number of group items, for example to describe a scene with multiple layers or sub-plots.

For more information regarding supported mark properties, please see the Vega marks documentation.

Scenegraph Serialization

The top-level export of this package includes sceneFromJSON and sceneToJSON methods to support scenegraph serialization. The sceneFromJSON method expects a JSON string as input (similar to the examples listed above). It will then add additional parent pointers to the tree structure. For example, each item will have a mark property pointing to its parent mark, and each mark will have a group property pointing to its parent group (if any). The sceneToJSON method maps a scenegraph instance to a JSON string, stripping any parent pointers or other non-standard properties.

Test Suite

The vega-scenegraph test suite compares rendered output for both Canvas (PNG) and SVG (text) renderers. Due to differences among platforms, pixel-level rendering by node-canvas can differ across operating systems. As a result, some test cases may break when running on a system other than Mac OS X (our standard platform for testing). If you are running on Linux or Windows and experience test failures, it does not necessarily indicate an issue with vega-scenegraph. In such cases, we recommend running the node-canvas test-server (npm run test-server from the node-canvas repository) to compare server-side and client-side rendering.