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

bisonica

v0.1.15

Published

bisonica is a minimalist and accessibility-first alternative renderer for the open source [Vega Lite](https://vega.github.io/vega-lite/) standard for data visualization, a replacement for the [original `vega-lite.js` library](https://github.com/vega/vega-

Downloads

17

Readme

Overview

bisonica is a minimalist and accessibility-first alternative renderer for the open source Vega Lite standard for data visualization, a replacement for the original vega-lite.js library which reads in the same JSON configuration objects and outputs charts.

Install

Install from npm using your tool of choice. For example:

npm install bisonica

Quick Start

The chart() function takes a Vega Lite JSON specification object and uses it to create a chart rendering function which can be run using d3-selection.

import { select } from 'd3';
import { chart } from 'bisonica';

const dimensions = {
    x: 500,
    y: 500
};

// create a chart rendering function
const renderer = chart(specification, dimensions);

// render the chart
renderer(select('div'));

Or the equivalent syntax with selection.call():

// render the chart
select('div').call(renderer);

You'll probably want to load the included stylesheet? Feel free to use your own alternative if you want, though.

You can load it directly:

<head>
    <link rel="stylesheet" href="./source/index.css" />
</head>

Or import with a packager or build tool:

import "bisonica/styles.css";

Why?

Accessibility

When faced with an accessibility concern, bisonica typically just defaults to the most accessible option, whereas vega-lite.js might require more elaborate JSON in the specification object in order to achieve the same result. Some accessibility features such as the keyboard navigation and audio sonification cannot be replicated with the standard vega-lite.js renderer at all.

Performance

bisonica is often considerably faster than rendering the same chart using vega-lite.js. This will depend on the specific chart configuration and the input data, but as an example, pie charts have been clocked rendering in as little as 1.25 milliseconds.

Customization

Unlike vega-lite.js, bisonica renders legends as HTML next to the SVG instead of inside the SVG, and as a result they are much easier to restyle with CSS or even control with custom JavaScript behaviors.

Comparison

In general, bisonica may be a good choice if you need to render straightforward charts with strong accessibility properties using Vega Lite's JSON as the backing format and you can handle writing the custom CSS that will probably be necessary to get the generated graphics over the finish line for your use case.

On the other hand, the standard vega-lite.js renderer is definitely still the way to go if you need its more elaborate graphical options, faceted trellis plots, charts which don't rely on custom styling, a dynamic exploratory workflow powered by evaluating string expressions, or any of the features bisonica has intentionally omitted.

Omissions

bisonica is still a work in progress and as such supports only a subset of Vega Lite functionality. The supported chart forms are listed in source/marks.js.

Data loading will not parse inline strings.

Nested fields must be looked up using dot notation (e.g. datum.field), not bracket notation (e.g. datum['field']).

Predicates defined with string expressions only support simple comparisons (e.g. "datum.value < 100" or "datum.group === 'a'").

The calculate transform only supports deriving new fields with string concatenation and static functions but can't do arbitrary math. (If you need arbitrary math, do it in JavaScript and attach the results to your specification before rendering.)

Escaping special characters in field names is not supported. Instead, you should mutate your data before rendering to clean up the affected field names.

Advanced Vega Lite features like facet and parameters are not yet available.

Rendering to alternative output formats such as <canvas> instead of <svg> will most likely never be supported.

Errors

Throwing

Errors inside the chart library are nested, and error handling typically appends information to error.message and then re-throws the same error object. This naturally has the effect of augmenting the messages generated by the runtime with written explanations meant for humans at every layer of the stack, sort of a "semantic stack trace."

Catching

To set a custom error handler, pass a function to the .error() method.

// create a chart renderer
const renderer = chart(specification, dimensions)

// error handling function
const errorHandler = (error) => alert(error.message);

// attach the error handling function to the chart renderer
renderer.error(errorHandler);

By default, errors are handled at the top level with console.error, equivalent to renderer.error(console.error).

Disabling

To disable default trapping of errors and instead surface the semantic stack traces to the consumer:

// disable catching and allow errors
// to propagate up to the caller
renderer.error(null);

You'll then want to handle these in your page or application.